-
Notifications
You must be signed in to change notification settings - Fork 241
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
Glide size is now determined by cpu usage. #4146
Open
dwasint
wants to merge
2
commits into
Monkestation:master
Choose a base branch
from
dwasint:lag_compensation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -70,6 +70,10 @@ GLOBAL_REAL(Master, /datum/controller/master) | |||||
///used by CHECK_TICK as well so that the procs subsystems call can obey that SS's tick limits | ||||||
var/static/current_ticklimit = TICK_LIMIT_RUNNING | ||||||
|
||||||
var/spike_cpu = 0 | ||||||
var/sustain_chance = 100 | ||||||
var/sustain_cpu = 0 | ||||||
|
||||||
/datum/controller/master/New() | ||||||
// Ensure usr is null, to prevent any potential weirdness resulting from the MC having a usr if it's manually restarted. | ||||||
usr = null | ||||||
|
@@ -473,6 +477,8 @@ GLOBAL_REAL(Master, /datum/controller/master) | |||||
tickdrift = max(0, MC_AVERAGE_FAST(tickdrift, (((REALTIMEOFDAY - init_timeofday) - (world.time - init_time)) / world.tick_lag))) | ||||||
var/starting_tick_usage = TICK_USAGE | ||||||
|
||||||
update_glide_size() | ||||||
|
||||||
if (init_stage != init_stage_completed) | ||||||
return MC_LOOP_RTN_NEWSTAGES | ||||||
if (processing <= 0) | ||||||
|
@@ -837,3 +843,91 @@ GLOBAL_REAL(Master, /datum/controller/master) | |||||
for (var/thing in subsystems) | ||||||
var/datum/controller/subsystem/SS = thing | ||||||
SS.OnConfigLoad() | ||||||
|
||||||
/world/Tick() | ||||||
unroll_cpu_value() | ||||||
if(Master.sustain_cpu && prob(Master.sustain_chance)) | ||||||
// avoids byond sleeping the loop and causing the MC to infinistall | ||||||
CONSUME_UNTIL(min(Master.sustain_cpu, 10000)) | ||||||
|
||||||
if(Master.spike_cpu) | ||||||
CONSUME_UNTIL(min(Master.spike_cpu, 10000)) | ||||||
Master.spike_cpu = 0 | ||||||
|
||||||
|
||||||
#define CPU_SIZE 20 | ||||||
#define WINDOW_SIZE 16 | ||||||
GLOBAL_LIST_INIT(cpu_values, new /list(CPU_SIZE)) | ||||||
GLOBAL_LIST_INIT(avg_cpu_values, new /list(CPU_SIZE)) | ||||||
GLOBAL_VAR_INIT(cpu_index, 1) | ||||||
GLOBAL_VAR_INIT(last_cpu_update, -1) | ||||||
|
||||||
/// Inserts our current world.cpu value into our rolling lists | ||||||
/// Its job is to pull the actual usage last tick instead of the moving average | ||||||
/world/proc/unroll_cpu_value() | ||||||
if(GLOB.last_cpu_update == world.time) | ||||||
return | ||||||
GLOB.last_cpu_update = world.time | ||||||
var/avg_cpu = world.cpu | ||||||
var/list/cpu_values = GLOB.cpu_values | ||||||
var/cpu_index = GLOB.cpu_index | ||||||
|
||||||
// We need to hook into the INSTANT we start our moving average so we can reconstruct gained/lost cpu values | ||||||
var/lost_value = 0 | ||||||
lost_value = cpu_values[WRAP(cpu_index - WINDOW_SIZE, 1, CPU_SIZE + 1)] | ||||||
|
||||||
// avg = (A + B + C + D) / 4 | ||||||
// old_avg = (A + B + C) / 3 | ||||||
// (avg * 4 - old_avg * 3) roughly = D | ||||||
// avg = (B + C + D) / 3 | ||||||
// old_avg = (A + B + C) / 3 | ||||||
// (avg * 4 - old_avg * 3) roughly = D - A | ||||||
// so if we aren't moving we need to add the value we are losing | ||||||
// We're trying to do this with as few ops as possible mind | ||||||
// soooo | ||||||
// C = (avg * 3 - old_avg * 3) + A | ||||||
|
||||||
var/last_avg_cpu = GLOB.avg_cpu_values[WRAP(cpu_index - 1, 1, CPU_SIZE + 1)] | ||||||
var/real_cpu = (avg_cpu *WINDOW_SIZE - last_avg_cpu * WINDOW_SIZE) + lost_value | ||||||
|
||||||
// cache for sonic speed | ||||||
cpu_values[cpu_index] = real_cpu | ||||||
GLOB.avg_cpu_values[cpu_index] = avg_cpu | ||||||
GLOB.cpu_index = WRAP(cpu_index + 1, 1, CPU_SIZE + 1) | ||||||
|
||||||
|
||||||
/proc/update_glide_size() | ||||||
world.unroll_cpu_value() | ||||||
var/list/cpu_values = GLOB.cpu_values | ||||||
var/sum = 0 | ||||||
var/non_zero = 0 | ||||||
for(var/value in cpu_values) | ||||||
sum += max(value, 100) | ||||||
if(value != 0) | ||||||
non_zero += 1 | ||||||
|
||||||
var/first_average = non_zero ? sum / non_zero : 1 | ||||||
var/trimmed_sum = 0 | ||||||
var/used = 0 | ||||||
for(var/value in cpu_values) | ||||||
if(!value) | ||||||
continue | ||||||
// If we deviate more then 60% away from the average, skip it | ||||||
if(abs(1 - (max(value, 100) / first_average)) <= 0.3) | ||||||
trimmed_sum += max(value, 100) | ||||||
used += 1 | ||||||
|
||||||
var/final_average = trimmed_sum ? trimmed_sum / used : first_average | ||||||
GLOB.glide_size_multiplier = min(100 / final_average, 1) | ||||||
GLOB.glide_size_multi_error = max((final_average - 100) / 100 * world.tick_lag, 0) | ||||||
|
||||||
/// Gets the cpu value we finished the last tick with (since the index reads a step ahead) | ||||||
var/last_cpu = cpu_values[WRAP(GLOB.cpu_index - 1, 1, CPU_SIZE + 1)] | ||||||
var/error = max((last_cpu - 100) / 100 * world.tick_lag, 0) | ||||||
|
||||||
for(var/atom/movable/trouble as anything in GLOB.gliding_atoms) | ||||||
if(world.time >= trouble.glide_stopping_time || QDELETED(trouble)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
GLOB.gliding_atoms -= trouble | ||||||
trouble.glide_tracking = FALSE | ||||||
continue | ||||||
trouble.account_for_glide_error(error) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,46 @@ | ||
// You might be wondering why this isn't client level. If focus is null, we don't want you to move. | ||
// Only way to do that is to tie the behavior into the focus's keyLoop(). | ||
|
||
/atom/movable/keyLoop(client/user) | ||
var/movement_dir = NONE | ||
for(var/_key in user?.keys_held) | ||
movement_dir = movement_dir | user.movement_keys[_key] | ||
if(user?.next_move_dir_add) | ||
movement_dir |= user.next_move_dir_add | ||
if(user?.next_move_dir_sub) | ||
/atom/movable/keyLoop(client/user, gondor_calls_for_aid = FALSE) | ||
// Clients don't go null randomly. They do go null unexpectedly though, when they're poked in particular ways | ||
// keyLoop is called by a for loop over mobs. We're guarenteed that all the mobs have clients at the START | ||
// But the move of one mob might poke the client of another, so we do this | ||
if(gondor_calls_for_aid) | ||
user = src | ||
if(!user) | ||
return FALSE | ||
var/movement_dir = user.intended_direction | user.next_move_dir_add | ||
// If we're not movin anywhere, we aren't movin anywhere | ||
// Safe because nothing adds to movement_dir after this moment | ||
if(!movement_dir) | ||
return FALSE | ||
if(user.next_move_dir_sub) | ||
movement_dir &= ~user.next_move_dir_sub | ||
// Sanity checks in case you hold left and right and up to make sure you only go up | ||
if((movement_dir & NORTH) && (movement_dir & SOUTH)) | ||
movement_dir &= ~(NORTH|SOUTH) | ||
if((movement_dir & EAST) && (movement_dir & WEST)) | ||
movement_dir &= ~(EAST|WEST) | ||
|
||
if(user && movement_dir) //If we're not moving, don't compensate, as byond will auto-fill dir otherwise | ||
if(!gondor_calls_for_aid && user.dir != NORTH && movement_dir) //If we're not moving, don't compensate, as byond will auto-fill dir otherwise | ||
movement_dir = turn(movement_dir, -dir2angle(user.dir)) //By doing this we ensure that our input direction is offset by the client (camera) direction | ||
|
||
//turn without moving while using the movement lock key, unless something wants to ignore it and move anyway | ||
if(user?.movement_locked && !(SEND_SIGNAL(src, COMSIG_MOVABLE_KEYBIND_FACE_DIR, movement_dir) & COMSIG_IGNORE_MOVEMENT_LOCK)) | ||
if(user.movement_locked && !(SEND_SIGNAL(src, COMSIG_MOVABLE_KEYBIND_FACE_DIR, movement_dir) & COMSIG_IGNORE_MOVEMENT_LOCK)) | ||
keybind_face_direction(movement_dir) | ||
else | ||
user?.Move(get_step(src, movement_dir), movement_dir) | ||
else if(gondor_calls_for_aid) | ||
var/mob/mob_src = src | ||
mob_src.bullshit_hell(get_step(src, movement_dir), movement_dir) | ||
return !!movement_dir | ||
// Null check cause of the signal above | ||
else if(user) | ||
user.Move(get_step(src, movement_dir), movement_dir) | ||
return !!movement_dir //true if there was actually any player input | ||
|
||
return FALSE | ||
|
||
/client/proc/calculate_move_dir() | ||
var/movement_dir = NONE | ||
for(var/_key in keys_held) | ||
movement_dir |= movement_keys[_key] | ||
intended_direction = movement_dir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double check that it's the same tho, just to be 100% sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would need to run a few number tests but I think WRAP_UP would be different