62 Commits

Author SHA1 Message Date
Kawe Mazidjatari
1ac38516d8 Upgrade Dear ImGui to 1.90.4 2024-04-05 18:13:33 +02:00
Kawe Mazidjatari
609d705a0c Tier1: static construction of ConVar objects during link time
Fully implemented ConVar class so we could statically construct all SDK convars, this avoids a level of indirection, and allows for creating ConVar's everywhere in the project.

This patch also removed the settings tab of the ImGui server browser, as it has threading issues, while it technically never caused a crash yet, it has been removed as there was no point keeping it vs the work required to make it thread save (it only managed 2 convars which are perfectly manageable through cfg's or the in-game console).

Also temporarily disabled the creation of ConVar's in the mod system due to a memory leak, we would allocate and register a convar based on details parsed out of a mod file definition, but never unregister and free it.
2024-04-05 18:13:32 +02:00
Kawe Mazidjatari
fcf3a09418 Make singletons use static memory
Avoid heap memory allocation and a level of indirection. This allows the compiler to optimize the program even more. No logic has been changed in this patch.
2024-04-05 17:52:57 +02:00
Kawe Mazidjatari
edc52ad669 IDetour: remove extraneous pointer assignments
Originally, we store the search results in a CMemory instance which we then assign to the actual function pointer. CMemory is just a pointer class; we can assign the results directly to the actual function pointer. This commit reduces a lot of code verbosity, and also reduced roughly 2KiB worth of static pointers in the resulting executable. This commit also officially deprecates the support for any GameDLL's below S3 (Season 3), since it makes more sense to port the assets from earlier/later games back to the version this SDK supports.
2024-04-05 17:19:32 +02:00
Kawe Mazidjatari
365448b8c7 MaterialSystem: fix console not drawing in the 4:3/5:4 aspect ratio modes
DrawImGui should be called BEFORE ID3D11DeviceContext::ClearRenderTargetView() or ID3D11DeviceContext::End(). Moved drawing code to SpinPresent which is just before the clear/end calls are being made. Console now draws in the 4:3/5:4 aspect ratio video modes.
2024-04-05 17:19:28 +02:00
Kawe Mazidjatari
77a20f4d9e NVIDIA: move markers to actual IDXGISwapChain::Present runtime call
Testing revealed better latency reduction when moved directly here as we also take into account the additional buffy copy's the game does in SpinPresent, our new render thread frame limiter and and ImGui. The difference is very large when the render thread frame limiter is used. The code still passes NVIDIA's reflex testing utility after this patch.
2024-04-05 17:19:28 +02:00
Kawe Mazidjatari
144d5f62e1 IDetour: code refactor
Utilize the new IDetour::DetourSetup() code, IDetour::Attach and IDetour::Detach have been removed in favor of this (significantly reduces chance of user error). Since the template check happens in the idetour header, it is much more aggressive on type mismatches, such as a difference in parameter types, between the function and detour, will now raise a compile time error. As a result, some type mismatches have been fixed in this commit as well.
2024-04-05 16:41:09 +02:00
Kawe Mazidjatari
506134fffb Only run ImGui code if we aren't quitting
Should fix a very rare crash where this still gets called while imgui has already been destroyed.
2024-04-05 16:24:47 +02:00
Kawe Mazidjatari
907e582f55 Remove latency markers
Some parts of the engine have to be rebuild in order to implement this correctly, therefore, it has been removed for now to avoid potential performance problems.

fps_max_rt and fps_max_gfx have been limited to 295 to avoid a contest with the engine's hard limit causing huge performance hits.
2023-09-13 17:37:09 +02:00
Kawe Mazidjatari
ea6c15df4c Initial implementation of NVIDIA Reflex Low Latency timing
Propagated latency markers in an attempt to further reduce input latency. Code is pending rigorous testing on several systems, including systems powered by an AMD GPU to make sure we are not impacting performance on systems that does NOT support NVIDIA Reflex.
2023-09-12 11:06:16 +02:00
Kawe Mazidjatari
07dade5d5d Implement high precision frame limiter
Limits frames at a much higher level of precision than 'fps_max' and 'fps_max_gfx', probably ideal to reduce input latency even more. Also changed the logic of the NVIDIA Reflex frame limiter, to which it would use the desktop's refresh rate if set to '-1'. The new render thread frame limiter has a similar behavior. Using desktop refresh rates on the render thread or NVIDIA Reflex frame limiter requires 'fps_max' to be set to 0 (unlimited), as it would otherwise result in a major performance drop due to a contest if fps_max_(gfx/rt) is set to a similar number as fps_max.
2023-09-11 22:20:24 +02:00
Kawe Mazidjatari
fdb4a4d429 Reverse CGame class
Class structure reversed.
2023-09-11 20:38:18 +02:00
Kawe Mazidjatari
0fe7b40506 Add inline DX device getters 2023-09-11 01:28:17 +02:00
Kawe Mazidjatari
87f9420889 Globally reduce the use of auto for function pointer declarations
Find regex pattern:
inline auto ([a-zA-Z0-9_]+) = ([a-zA-Z0-9_]+)\.RCast<([a-zA-Z0-9_:<>*]+) *\(\*\)\(([^)]*)\)>\(\);
Replace regex pattern:
inline $3(*$1)($4);

This commit also removes the unnecessary initialization (which was required to type the auto variables),
and therefore removed 6kb of unnecessary dynamic initialization code.
2023-07-02 23:01:29 +02:00
Kawe Mazidjatari
a9338455aa Fix ImGui window procedure handler crash on shutdown
When and after 'Host_Shutdown()' is called, the window handle is still valid, thus the handler still gets called. This gets destroyed in 'OnShutdown()' called from 'CEngineAPI::RunListenServer()'. But we do shutdown the ImGui implementation in 'Host_Shutdown()'... Therefore, we should check if the implementation is initialized or not before running the window procedure handler.
2023-06-19 14:03:23 +02:00
Kawe Mazidjatari
165d80c541 Fix rare ImGui crash on shutdown
The 'DirectX_Init()' call was performed late in code, shortly after the window has been created (at this point all device objects and window handles are valid), but the 'DirectX_Shutdown()' call was performed on DLL_DETACH, which was way too late, as the objects were already destroyed at this point. This wasn't an issue before, as we created our own objects in the old DX code. But due to optimizations, we were using the same pointers as the game (noticeable performance boost), but did not adjust the shutdown to accommodate the changes. The shutdown is now performed while the device objects and window handles are valid. Code has been tested on Nvidia and AMD systems, and has confirmed to fix the aforementioned issues.
2023-06-18 22:16:43 +02:00
Kawe Mazidjatari
b7cf2c6f64 Cleanup ImGui shutdown
Move to separate function.
2023-06-18 17:50:11 +02:00
Kawe Mazidjatari
c6f25432fd Undo ImGui shutdown patch, and add missing/reorder shutdown calls
The shutdown patch from commit '48c2401c' created another bug where all inputs get collated, and once drawn, emitted to the ImGui interfaces. The patch has been undone, and the 'ImGui_ImplDX11_Shutdown()' call has been placed before 'ImGui_ImplWin32_Shutdown()', as this was how it was performed according to the official documentation and examples provided by Dear ImGui. The call 'ImGui::DestroyContext()' has also been added (taken from the examples). Removed redundant static global bool.
2023-06-16 23:16:02 +02:00
Kawe Mazidjatari
48c2401cf9 Fix rare crash on Dear ImGui shutdown
Fix a rare crash that occurs in AMD driver code, when ImGui shutdown was called. The crash did not occur if the library was shutdown after having rendered one of the ImGui panels for one frame. The fix is to just never call 'ImGui_ImplDX11_NewFrame()', 'ImGui_ImplWin32_NewFrame()' and 'ImGui::NewFrame()', 'ImGui::EndFrame()', 'ImGui::Render()' if none of the windows are visible. code has been tested on a system that would trigger the crash, and after the patch, the crash no longer happened.
2023-06-15 21:33:37 +02:00
Kawe Mazidjatari
e468fa1065 Fix build errors caused by 'CreateTextureResource'
Moved declarations to source file; this is currently only used by the engine.
2023-05-13 19:40:41 +02:00
Kawe Mazidjatari
8d38de1ce0 Move client only code from rtech libraries
Moved, and renamed to 'CreateTextureResource'. Reason for move was that the rtech libraries is used by server and client, and using this on dedicated requires linking directx libraries, as it has to be hooked (even when not used). Moved to client only code to avoid having to hook it. Material system is no longer linked to the dedicated server module, as nothing from it was getting used.
2023-05-13 18:03:48 +02:00
Kawe Mazidjatari
19d21300a3 Use cached ImGui IO reference 2023-02-18 15:50:12 +01:00
Kawe Mazidjatari
0a319971dd Hook ResizeBuffers to obtain rect size during resize
Required as the initialization only sets it to the startup rect size. This will always be up-to-date during resizes.
2023-01-30 22:08:01 +01:00
Kawe Mazidjatari
c84622cfd6 DirectX hook refactor
Refactored code to only feature game pointers, this avoids the unnecessary overhead that was previously caused by creating our own device pointers, swapchain, etc.. This commit also fixes the classic 'black screen' problem when the aspect ratio is set to 4:3 - 5:4, however, a similar bug returned for this causing Dear ImGui to not draw at all when the aspect ratio is set to 4:3 - 5:4. This commit also moves the old HwndProc hook to 'CGame::WindowProc'.
2023-01-30 20:18:11 +01:00
Kawe Mazidjatari
0f9c9d5ae4 Add 'g_pImmediateContext' to SDK
Grab ptr to game dx device context.
2023-01-30 16:10:46 +01:00
Kawe Mazidjatari
c86c965290 Disable Dear ImGui 'ctrl+tab' shortcut menu
This menu isn't in much need, in fact; we didn't even knew it existed until someone started to complain about it! Currently, the drawing logic isn't setup to support this properly either. Disabled the shortcut menu.
2023-01-29 19:07:02 +01:00
Kawe Mazidjatari
938df1dd89 Check visible panels in wrapper instead of imgui itself
The SDK's DX interface is much easier to expose to Dear ImGui than game/engine implementations.
2023-01-26 20:00:52 +01:00
Kawe Mazidjatari
a618990937 Detour code refactor
This change was planned for a long time. This moves all REGISTER calls to a single translation unit, this is required as we currently added a very dirty workaround for not registering duplicates by checking if VFTable pointer was already present in the vector... Registering from single translation unit prevents duplicate instances that gets created if header is included by more cpp files.
Reworking this reduced 100kb+ of compiled code. This commit also reworked the way functions/variables/constant gets logged with their addresses; the new code formats them on the fly, and allows for resize at any time. Formatting is no longer required by programmer.

TODO: currently there are some compile errors for dedicated and client dll's. These will be resolved very soon as they need to be properly worked out still (server & client only stuff needs to be properly split). Use the 'main' (stable) branch for the time being if you need to compile these dll's.
2023-01-25 02:26:52 +01:00
Kawe Mazidjatari
d9ac275d71 Fix bug where input is lost during resize
This commit fixes a bug causing all input to be lost. This gets triggered when either the console or server browser window is drawing while the user tabs out of the full-screen window, or resizes the game window.
2022-12-22 17:49:38 +01:00
Kawe Mazidjatari
d3b2893cdc Change ImGui config file path and use engine's FileSystem API
'ImGuiConfig::Load()' was loading from the new path, however 'ImGuiConfig::Save()' was not. Defined path as constant expression to avoid this problem in the future. Also loading the files through the engine's API from now on.
2022-11-24 10:45:42 +01:00
Kawe Mazidjatari
5f84803ac6 ImGui and DirectX code improvements
* Fix history duplication by removing trailing white space characters from submitted commands in console.
* Fix out of range exception caused by caching svConVar.size() in CConsole::BuildSummary while we are modifying it.
* Fixed memory leak  caused by extraneous Strdup calls in CConsole.
* Renamed variables and structure members, static vars in id3dx.cpp are not prefixed with s_, IBrowser_Config is now m_BrowserConfig.
* Performed code cleanup in id3dx.cpp.
2022-10-20 12:29:50 +02:00
Kawe Mazidjatari
31845425d6 Only enable/disable input system on open/close events
Previously we enabled/disabled the input system each frame, depending on the state of the ImGui windows. This commit changes the behavior into only enabling/disabling when the menu's are closed (either through the keyboard or the close button).

I added a simple callback to ImGui::Begin which will be called when the close button on the ImGui panel is pressed and the callback pointer isn't nullptr, this was required as there was otherwise no way to determine when the close button was clicked.
2022-10-20 12:29:50 +02:00
Kawe Mazidjatari
729475c74c Light cleanup
Use NO_ERROR instead of NULL for error code parameter passed to Error(..).
2022-09-14 01:14:51 +02:00
Kawe Mazidjatari
3d6d6644bd Logging bug fix and error handling improvements
* Replaced the boolean 'fatal' parameter with a error code parameter, anything non-null will prompt a message (fatal) and terminate the process with given error code.
* Fixed bug where the global ostreamsink for spdlog did NOT get cleared in 'SQVM_PrintFunc' when cvar 'sq_showvmoutput' was < 3. Moved to global scope.
* Added error message for when detouring the process has failed, with the error code.
* Only call 'Plat_GetProcessUpTime()' once per log, (improves performance and fixes bug where the error message box would show a different time stamp than what is logged into the console or file).
* All TIER0 loggers only log to notify and console when the SDK engine has fully initialized and detoured all functions.
2022-09-14 00:39:38 +02:00
Kye
a976d2868e
Cleaned up uMsg switch statement 2022-09-13 12:29:36 +10:00
Kawe Mazidjatari
34a06147d7 Fix spelling errors
Overall spelling improvements and cleanup..
2022-09-09 19:47:31 +02:00
Kawe Mazidjatari
8712f7db81 Fix concurrency of g_svNetKey
* Fix concurrency of g_svNetKey.
* Improve logging.
* Overall code cleanup.
2022-08-30 01:22:53 +02:00
Kawe Mazidjatari
2010e11310 Add 'fatal' functionality to Error()
When fatal is set, the function will show a error dialogue, which will halt the process and close when the message is dismissed. Else we will end up in a crash.
2022-08-22 12:42:41 +02:00
Kawe Mazidjatari
8476d22777 Fix concurrent access to several CConsole members
* Fix concurrent access to CConsole::m_Logger.
* Fix concurrent access to CConsole::m_vHistory.
* Additional DX system cleanup.
2022-08-21 19:35:06 +02:00
Kawe Mazidjatari
52e19e9ad6 Single-thread the game console
Run all task in the same thread used to run the browser/console frame and remove all mutexes.
2022-08-20 01:48:42 +02:00
Kawe Mazidjatari
bf3b7bdace Server browser cleanup
* Moved server utility to dedicated class shared by browser panel and UI script VM.
* Additional code improvements and optimizations.
2022-08-14 15:43:49 +02:00
Kawe Mazidjatari
329621c6ad Move all public headers into root of 'public' 2022-08-09 17:18:07 +02:00
Kawe Mazidjatari
d4f9e68930 'g_ppGameDevice' confirmed compatible with earlier builds 2022-07-21 16:56:25 +02:00
Kawe Mazidjatari
33f517d809 Use XOR operator for toggling menu's 2022-06-22 10:19:44 +02:00
Kawe Mazidjatari
aaf6e46871 ImGui panel improvements
Slight optimizations and cleanup.
Added fade-in effect.
2022-06-09 02:22:01 +02:00
Kawe Mazidjatari
e6ef3d71f1 Rename variable 'g_pIConsole' to 'g_pConsole' 2022-05-27 02:46:13 +02:00
Kawe Mazidjatari
58d46c0a8c Rename class 'IBrowser' to 'CBrowser'
Renamed 'g_pIBrowser' to 'g_pBrowser' as well
2022-05-27 02:44:36 +02:00
Kawe Mazidjatari
4b72afb74f Light refactor for logging
Moved logging functions to dbg.h (tier0) and export them from the dll.
Added additional functions for checking bad pointers (debug only!).
Reduced output code size.
2022-05-25 14:18:29 +02:00
Kawe Mazidjatari
3144227ec8 Update GetAdr implementations to feature spdlog
Fixed all alignments and reduced code verbosity
2022-05-13 14:53:25 +02:00
Kawe Mazidjatari
116d66f241 Fix Dear ImGui shutdown assert 2022-05-07 17:13:37 +02:00