mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Moved implementation to dedicated class 'CImguiSystem' with the following changes: * Added mutex for ImGui_ImplWin32_WndProcHandler(), the window proc is ran from a different thread than CImguiSystem::SampleFrame() is being called from. Needs a mutex as both functions interact with the input queue list. * Added init stages for debugging and preventing the system from running certain parts of the code if a certain stage hasn't been reached yet. * NULL out ImGuiContext::ConfigNavWindowingKeyNext , we don't need any nav window shortcuts as users don't need then in-game, and it also interferes with certain key binds some users have. * CImguiSystem::SampleFrame() (previously ImguiSystem_SampleFrame()), is now being called from CMaterialSystem::SwapBuffers(), as that function is called from the main thread while also getting updated during level loads/etc, so instead of switching between 2 static buffers for as long as the levels are being loaded, we imgui updates properly too and directly swap afterwards. * Removed hack in CGame::WindowProc() where we would only run windowproc if we aren't shutting the game down. This was needed as there was a chance of a crash at some rare cases, but this was simply due to a missing mutex which has been addressed and fixed as of this commit. * Lock mutex during init and shutdown.
35 lines
1.4 KiB
C
35 lines
1.4 KiB
C
// Usage:
|
|
// static ImDrawDataSnapshot snapshot; // Important: make persistent across frames to reuse buffers.
|
|
// snapshot.SnapUsingSwap(ImGui::GetDrawData(), ImGui::GetTime());
|
|
// [...]
|
|
// ImGui_ImplDX11_RenderDrawData(&snapshot.DrawData);
|
|
#pragma once
|
|
|
|
// FIXME: Could store an ID in ImDrawList to make this easier for user.
|
|
#include "imgui_internal.h" // ImPool<>, ImHashData
|
|
|
|
struct ImDrawDataSnapshotEntry
|
|
{
|
|
ImDrawList* SrcCopy = NULL; // Drawlist owned by main context
|
|
ImDrawList* OurCopy = NULL; // Our copy
|
|
double LastUsedTime = 0.0;
|
|
};
|
|
|
|
struct ImDrawDataSnapshot
|
|
{
|
|
// Members
|
|
ImDrawData DrawData;
|
|
ImPool<ImDrawDataSnapshotEntry> Cache;
|
|
float MemoryCompactTimer = 20.0f; // Discard unused data after 20 seconds
|
|
|
|
// Functions
|
|
~ImDrawDataSnapshot() { Clear(); }
|
|
void Clear();
|
|
void SnapUsingSwap(ImDrawData* src, double current_time); // Efficient snapshot by swapping data, meaning "src_list" is unusable.
|
|
//void SnapUsingCopy(ImDrawData* src, double current_time); // Deep-copy snapshot
|
|
|
|
// Internals
|
|
ImGuiID GetDrawListID(ImDrawList* src_list) { return ImHashData(&src_list, sizeof(src_list)); } // Hash pointer
|
|
ImDrawDataSnapshotEntry* GetOrAddEntry(ImDrawList* src_list) { return Cache.GetOrAddByKey(GetDrawListID(src_list)); }
|
|
};
|