Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helper_functions: disable V-Sync #542

Merged
merged 2 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,6 +13,7 @@ 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();

inline void allow_multiple_instances() // Make it possible to run multiple Half-Life instances.
{
Expand Down
18 changes: 2 additions & 16 deletions BunnymodXT/modules/ClientDLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,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 @@ -1672,22 +1673,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 @@ -766,6 +766,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 @@ -356,6 +356,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
Loading