Skip to content

Commit

Permalink
helper_functions: Disable V-Sync
Browse files Browse the repository at this point in the history
  • Loading branch information
SmileyAG committed Jul 4, 2024
1 parent 07f9904 commit 413e7f0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
20 changes: 20 additions & 0 deletions BunnymodXT/helper_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,24 @@ namespace helper_functions

std::exit(1);
}

void disable_vsync()
{
#ifdef _WIN32
auto &hw = HwDLL::GetInstance();
if (hw.check_vsync)
{
const bool bxtDisableVSync = getenv("BXT_DISABLE_VSYNC");
if (bxtDisableVSync)
{
typedef BOOL(APIENTRY* PFNWGLSWAPINTERVALPROC)(int);
PFNWGLSWAPINTERVALPROC wglSwapIntervalEXT = 0;
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALPROC)wglGetProcAddress("wglSwapIntervalEXT");
if (wglSwapIntervalEXT)
wglSwapIntervalEXT(0);
}
hw.check_vsync = false;
}
#endif
}
};
1 change: 1 addition & 0 deletions BunnymodXT/helper_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ namespace helper_functions
void com_fixslashes(std::string &str);
std::string swap_lib(const char* current_lib_path, std::string new_lib_path, const char *start);
void crash_if_failed(std::string str);
void disable_vsync();
}
18 changes: 2 additions & 16 deletions BunnymodXT/modules/ClientDLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "../hud_custom.hpp"
#include "../triangle_drawing.hpp"
#include "../discord_integration.hpp"
#include "../helper_functions.hpp"
#include <GL/gl.h>

// Linux hooks.
Expand Down Expand Up @@ -1667,22 +1668,7 @@ HOOK_DEF_1(ClientDLL, void, __cdecl, HUD_Frame, double, time)
orig_forcehltv_found = HwDLL::GetInstance().ORIG_Cmd_FindCmd("dem_forcehltv");
}

#ifdef _WIN32
static bool check_vsync = true;
if (check_vsync)
{
bool bxtDisableVSync = getenv("BXT_DISABLE_VSYNC");
if (bxtDisableVSync)
{
typedef BOOL(APIENTRY* PFNWGLSWAPINTERVALPROC)(int);
PFNWGLSWAPINTERVALPROC wglSwapIntervalEXT = 0;
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALPROC)wglGetProcAddress("wglSwapIntervalEXT");
if (wglSwapIntervalEXT)
wglSwapIntervalEXT(0);
}
check_vsync = false;
}
#endif
helper_functions::disable_vsync();

if (CVars::_bxt_taslog.GetBool() && pEngfuncs)
pEngfuncs->Con_Printf(const_cast<char*>("HUD_Frame time: %f\n"), time);
Expand Down
1 change: 1 addition & 0 deletions BunnymodXT/modules/HwDLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@ void HwDLL::Clear()
pcl = nullptr;
cls = nullptr;
psv = nullptr;
check_vsync = true;
lastRecordedHealth = 0;
offTime = 0;
offWorldmodel = 0;
Expand Down
2 changes: 2 additions & 0 deletions BunnymodXT/modules/HwDLL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ class HwDLL : public IHookableNameFilterOrdered

int tas_studio_norefresh_override = 0;

bool check_vsync = true;

private:
// Make sure to have hl.exe last here, so that it is the lowest priority.
HwDLL() : IHookableNameFilterOrdered({ L"hw.dll", L"hw.so", L"sw.dll", L"sw.so", L"hl.exe" }) {};
Expand Down

0 comments on commit 413e7f0

Please sign in to comment.