Combined Mono and il2cpp support for setting target framerate and fixed delta time in Unity.
| 1863 | |
| 1864 | // Combined Mono and il2cpp support for setting target framerate and fixed delta time in Unity. |
| 1865 | void |
| 1866 | SK_Unity_UpdateTimingOverrides (void) |
| 1867 | { |
| 1868 | // The Mono/il2cpp runtime is in a weird state, assume game is shutting down... |
| 1869 | static bool exception_raised = false; |
| 1870 | |
| 1871 | static HANDLE hSetTargetFramerateSignal = |
| 1872 | SK_CreateEvent (nullptr, FALSE, TRUE, nullptr); |
| 1873 | |
| 1874 | static HANDLE |
| 1875 | signals [] = { |
| 1876 | hSetTargetFramerateSignal, |
| 1877 | __SK_DLL_TeardownEvent |
| 1878 | }; |
| 1879 | |
| 1880 | static int target_fps = -1; // Disable Unity limiter |
| 1881 | static void* params_fps [1] = { &target_fps }; |
| 1882 | static void* params_delta [1] = { &fixed_delta_time_static }; |
| 1883 | |
| 1884 | if (__target_fps_now > 0.0f || fixed_delta_time_static != 0.0f) |
| 1885 | { |
| 1886 | if (! ReadAcquire (&__SK_DLL_Ending)) |
| 1887 | SetEvent (hSetTargetFramerateSignal); |
| 1888 | |
| 1889 | static volatile LONG timing_thread = 0; |
| 1890 | if (InterlockedCompareExchange (&timing_thread, 1, 0) == 0) |
| 1891 | { |
| 1892 | // This thread is full of awful hacks because SK does not know when |
| 1893 | // Unity is shutting down and the Managed runtime waits for all |
| 1894 | // attached threads to terminate during a clean exit. |
| 1895 | // |
| 1896 | // It could all be a lot simpler, but we must avoid attaching |
| 1897 | // the managed runtime to the thread that signals this code. |
| 1898 | SK_Thread_CreateEx ([](LPVOID)->DWORD |
| 1899 | { |
| 1900 | SK_Thread_SetCurrentPriority (THREAD_PRIORITY_LOWEST); |
| 1901 | |
| 1902 | bool attached = false; |
| 1903 | bool il2cpp = false; |
| 1904 | bool mono = false; |
| 1905 | |
| 1906 | while (! ReadAcquire (&__SK_DLL_Ending)) |
| 1907 | { |
| 1908 | if (exception_raised) |
| 1909 | break; |
| 1910 | |
| 1911 | il2cpp = (set_targetFrameRate_il2cpp != nullptr|| |
| 1912 | set_fixedDeltaTime_il2cpp != nullptr); |
| 1913 | |
| 1914 | mono = (set_targetFrameRate_mono != nullptr|| |
| 1915 | set_fixedDeltaTime_mono != nullptr); |
| 1916 | |
| 1917 | const auto last_frame = |
| 1918 | SK_GetFramesDrawn (); |
| 1919 | |
| 1920 | DWORD dwWaitState = |
| 1921 | WaitForMultipleObjects (2, signals, FALSE, 666); |
| 1922 |
no test coverage detected