Skip to content

Commit

Permalink
add framelimiter_busy_loop_buffer_100ns dial
Browse files Browse the repository at this point in the history
  • Loading branch information
Kethen committed Feb 4, 2024
1 parent 116fd39 commit f4047c1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions DockerFile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FROM opensuse/tumbleweed
RUN zypper install -y mingw32-cross-gcc-c++
FROM ubuntu:22.04
RUN apt update; DEBIAN_FRONTEND=noninteractive apt install -y g++-mingw-w64-i686
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
- game runs on rough milisecond precision, recommend keeping framerate below 300
- `framelimiter_full_busy_loop` in `s4_league_fps_unlock.json` adjusts the built-in frame limiter's behavior when fps limit is non 0
- it is set to `false` by default to not fully busy loop before the next frame
- setting it to `true` might improve latency at lower framerates, at the cost of busy looping power usage
- setting it to `true` might improve latency when the game is rendering faster than the frame limiter, at the cost of busy looping cpu power usage
- `framelimiter_busy_loop_buffer_100ns` is a mixed approach of `framelimiter_full_busy_loop`, enforcing some busy loop right before the next frame
- `framelimiter_full_busy_loop` has to be set to false for this to take effect
- it is set to `15000` by default to not always busy loop but still try and secure cpu resources timely for the next frame
- when the game is rendering faster than the frame limiter, setting it to `0` would reduce cpu power usage, but might introduce latency and frametime jitter when there are active background tasks

json.hpp is optained from https://github.com/nlohmann v3.11.3 release
16 changes: 11 additions & 5 deletions s4_league_fps_unlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ NtSetTimerResolution(

static ULONG min_nt_delay_100ns;

#define SLEEP_BUFFER_100NS (10000 + 5000)

#define ENABLE_LOGGING 0

#if ENABLE_LOGGING
Expand Down Expand Up @@ -113,6 +111,7 @@ struct config{
int field_of_view;
int sprint_field_of_view;
bool framelimiter_full_busy_loop;
int framelimiter_busy_loop_buffer_100ns;
};

static uint32_t target_frametime_ns;
Expand All @@ -123,10 +122,11 @@ static uint8_t weapon_slot;
static float set_drop_val;

struct config config = {
.max_framerate = -1,
.max_framerate = 300,
.field_of_view = 60,
.sprint_field_of_view = 80,
.framelimiter_full_busy_loop = false,
.framelimiter_busy_loop_buffer_100ns = 15000,
};

static void parse_config(){
Expand Down Expand Up @@ -177,6 +177,12 @@ static void parse_config(){
staging_config.framelimiter_full_busy_loop = parsed_config_file["framelimiter_full_busy_loop"];
LOG_VERBOSE("setting framelimiter full busy loop to %s", staging_config.framelimiter_full_busy_loop ? "true" : "false");
}
if(!parsed_config_file["framelimiter_busy_loop_buffer_100ns"].is_number()){
LOG("failed reading framelimiter_busy_loop_buffer_100ns from %s, ", config_file_name)
}else{
staging_config.framelimiter_busy_loop_buffer_100ns = parsed_config_file["framelimiter_busy_loop_buffer_100ns"];
LOG_VERBOSE("setting framelimiter busy loop buffer (100ns) to %s", framelimiter_busy_loop_buffer_100ns);
}
}catch(nlohmann::json::exception e){
LOG("failed reading %s after parsing, %s", config_file_name, e.what());
}
Expand Down Expand Up @@ -637,8 +643,8 @@ void __attribute__((thiscall)) patched_game_tick(void *tick_ctx){
// spin it all
}else{
uint32_t diff_100ns = diff_ns / 100;
if(target_frametime_100ns > diff_100ns + SLEEP_BUFFER_100NS){
uint32_t sleep_100ns = target_frametime_100ns - (diff_100ns + SLEEP_BUFFER_100NS);
if(target_frametime_100ns > diff_100ns + config.framelimiter_busy_loop_buffer_100ns){
uint32_t sleep_100ns = target_frametime_100ns - (diff_100ns + config.framelimiter_busy_loop_buffer_100ns);
#if LOG_VERBOSE
uint32_t sleep_100ns_pre_correct = sleep_100ns;
#endif
Expand Down
3 changes: 2 additions & 1 deletion s4_league_fps_unlock.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"max_framerate":300,
"field_of_view":60,
"sprint_field_of_view":80,
"framelimiter_full_busy_loop":false
"framelimiter_full_busy_loop":false,
"framelimiter_busy_loop_buffer_100ns":15000
}

0 comments on commit f4047c1

Please sign in to comment.