Skip to content

Commit 5e25a7f

Browse files
authored
Revert "Glide size is now determined by cpu usage. (#4146)"
This reverts commit f610110.
1 parent 8ee2721 commit 5e25a7f

File tree

14 files changed

+28
-320
lines changed

14 files changed

+28
-320
lines changed

code/__DEFINES/movement.dm

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,14 @@
66

77
/// Compensating for time dilation
88
GLOBAL_VAR_INIT(glide_size_multiplier, 1.0)
9-
/// The error motivating our existing multiplier
10-
GLOBAL_VAR_INIT(glide_size_multi_error, 0)
119

1210
///Broken down, here's what this does:
1311
/// divides the world icon_size (32) by delay divided by ticklag to get the number of pixels something should be moving each tick.
1412
/// The division result is given a min value of 1 to prevent obscenely slow glide sizes from being set
1513
/// Then that's multiplied by the global glide size multiplier. 1.25 by default feels pretty close to spot on. This is just to try to get byond to behave.
1614
/// The whole result is then clamped to within the range above.
1715
/// Not very readable but it works
18-
#define DELAY_TO_GLIDE_SIZE(delay) DISTANCE_BOUND_DELAY_TO_GLIDE_SIZE(world.icon_size, delay)
19-
20-
#define DISTANCE_BOUND_DELAY_TO_GLIDE_SIZE(distance, delay) (clamp((((distance) / max((delay) / world.tick_lag, 1)) * GLOB.glide_size_multiplier), MIN_GLIDE_SIZE, MAX_GLIDE_SIZE))
16+
#define DELAY_TO_GLIDE_SIZE(delay) (clamp(((world.icon_size / max((delay) / world.tick_lag, 1)) * GLOB.glide_size_multiplier), MIN_GLIDE_SIZE, MAX_GLIDE_SIZE))
2117

2218
///Similar to DELAY_TO_GLIDE_SIZE, except without the clamping, and it supports piping in an unrelated scalar
2319
#define MOVEMENT_ADJUSTED_GLIDE_SIZE(delay, movement_disparity) (world.icon_size / ((delay) / world.tick_lag) * movement_disparity * GLOB.glide_size_multiplier)

code/__DEFINES/perf_test.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// Macro that takes a tick usage to target, and proceses until we hit it
22
/// This lets us simulate generic load as we'd like, to make testing for overtime easier
33
#define CONSUME_UNTIL(target_usage) \
4-
while(TICK_USAGE < (target_usage)) {\
4+
while(TICK_USAGE < target_usage) {\
55
var/_knockonwood_x = 0;\
66
_knockonwood_x += 20;\
77
}

code/controllers/master.dm

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ GLOBAL_REAL(Master, /datum/controller/master)
7070
///used by CHECK_TICK as well so that the procs subsystems call can obey that SS's tick limits
7171
var/static/current_ticklimit = TICK_LIMIT_RUNNING
7272

73-
var/spike_cpu = 0
74-
var/sustain_chance = 100
75-
var/sustain_cpu = 0
76-
7773
/datum/controller/master/New()
7874
// Ensure usr is null, to prevent any potential weirdness resulting from the MC having a usr if it's manually restarted.
7975
usr = null
@@ -467,8 +463,6 @@ GLOBAL_REAL(Master, /datum/controller/master)
467463
tickdrift = max(0, MC_AVERAGE_FAST(tickdrift, (((REALTIMEOFDAY - init_timeofday) - (world.time - init_time)) / world.tick_lag)))
468464
var/starting_tick_usage = TICK_USAGE
469465

470-
update_glide_size()
471-
472466
if (init_stage != init_stage_completed)
473467
return MC_LOOP_RTN_NEWSTAGES
474468
if (processing <= 0)
@@ -833,91 +827,3 @@ GLOBAL_REAL(Master, /datum/controller/master)
833827
for (var/thing in subsystems)
834828
var/datum/controller/subsystem/SS = thing
835829
SS.OnConfigLoad()
836-
837-
/world/Tick()
838-
unroll_cpu_value()
839-
if(Master.sustain_cpu && prob(Master.sustain_chance))
840-
// avoids byond sleeping the loop and causing the MC to infinistall
841-
CONSUME_UNTIL(min(Master.sustain_cpu, 10000))
842-
843-
if(Master.spike_cpu)
844-
CONSUME_UNTIL(min(Master.spike_cpu, 10000))
845-
Master.spike_cpu = 0
846-
847-
848-
#define CPU_SIZE 20
849-
#define WINDOW_SIZE 16
850-
GLOBAL_LIST_INIT(cpu_values, new /list(CPU_SIZE))
851-
GLOBAL_LIST_INIT(avg_cpu_values, new /list(CPU_SIZE))
852-
GLOBAL_VAR_INIT(cpu_index, 1)
853-
GLOBAL_VAR_INIT(last_cpu_update, -1)
854-
855-
/// Inserts our current world.cpu value into our rolling lists
856-
/// Its job is to pull the actual usage last tick instead of the moving average
857-
/world/proc/unroll_cpu_value()
858-
if(GLOB.last_cpu_update == world.time)
859-
return
860-
GLOB.last_cpu_update = world.time
861-
var/avg_cpu = world.cpu
862-
var/list/cpu_values = GLOB.cpu_values
863-
var/cpu_index = GLOB.cpu_index
864-
865-
// We need to hook into the INSTANT we start our moving average so we can reconstruct gained/lost cpu values
866-
var/lost_value = 0
867-
lost_value = cpu_values[WRAP(cpu_index - WINDOW_SIZE, 1, CPU_SIZE + 1)]
868-
869-
// avg = (A + B + C + D) / 4
870-
// old_avg = (A + B + C) / 3
871-
// (avg * 4 - old_avg * 3) roughly = D
872-
// avg = (B + C + D) / 3
873-
// old_avg = (A + B + C) / 3
874-
// (avg * 4 - old_avg * 3) roughly = D - A
875-
// so if we aren't moving we need to add the value we are losing
876-
// We're trying to do this with as few ops as possible mind
877-
// soooo
878-
// C = (avg * 3 - old_avg * 3) + A
879-
880-
var/last_avg_cpu = GLOB.avg_cpu_values[WRAP(cpu_index - 1, 1, CPU_SIZE + 1)]
881-
var/real_cpu = (avg_cpu *WINDOW_SIZE - last_avg_cpu * WINDOW_SIZE) + lost_value
882-
883-
// cache for sonic speed
884-
cpu_values[cpu_index] = real_cpu
885-
GLOB.avg_cpu_values[cpu_index] = avg_cpu
886-
GLOB.cpu_index = WRAP(cpu_index + 1, 1, CPU_SIZE + 1)
887-
888-
889-
/proc/update_glide_size()
890-
world.unroll_cpu_value()
891-
var/list/cpu_values = GLOB.cpu_values
892-
var/sum = 0
893-
var/non_zero = 0
894-
for(var/value in cpu_values)
895-
sum += max(value, 100)
896-
if(value != 0)
897-
non_zero += 1
898-
899-
var/first_average = non_zero ? sum / non_zero : 1
900-
var/trimmed_sum = 0
901-
var/used = 0
902-
for(var/value in cpu_values)
903-
if(!value)
904-
continue
905-
// If we deviate more then 60% away from the average, skip it
906-
if(abs(1 - (max(value, 100) / first_average)) <= 0.3)
907-
trimmed_sum += max(value, 100)
908-
used += 1
909-
910-
var/final_average = trimmed_sum ? trimmed_sum / used : first_average
911-
GLOB.glide_size_multiplier = min(100 / final_average, 1)
912-
GLOB.glide_size_multi_error = max((final_average - 100) / 100 * world.tick_lag, 0)
913-
914-
/// Gets the cpu value we finished the last tick with (since the index reads a step ahead)
915-
var/last_cpu = cpu_values[WRAP(GLOB.cpu_index - 1, 1, CPU_SIZE + 1)]
916-
var/error = max((last_cpu - 100) / 100 * world.tick_lag, 0)
917-
918-
for(var/atom/movable/trouble as anything in GLOB.gliding_atoms)
919-
if(world.time >= trouble.glide_stopping_time || QDELETED(trouble))
920-
GLOB.gliding_atoms -= trouble
921-
trouble.glide_tracking = FALSE
922-
continue
923-
trouble.account_for_glide_error(error)

code/controllers/subsystem.dm

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112

113113
//Do not blindly add vars here to the bottom, put it where it goes above
114114
//If your var only has two values, put it in as a flag.
115-
var/consume_most_allocation = FALSE
115+
116116

117117
//Do not override
118118
///datum/controller/subsystem/New()
@@ -133,10 +133,7 @@
133133
tick_allocation_avg = MC_AVERAGE(tick_allocation_avg, tick_allocation_last)
134134

135135
. = SS_SLEEPING
136-
if(consume_most_allocation)
137-
CONSUME_UNTIL(Master.current_ticklimit * 0.8)
138-
else
139-
fire(resumed)
136+
fire(resumed)
140137
. = state
141138
if (state == SS_SLEEPING)
142139
slept_count++

code/controllers/subsystem/input.dm

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ VERB_MANAGER_SUBSYSTEM_DEF(input)
2121
///running average of the amount of real time clicks take to truly execute after the command is originally sent to the server.
2222
///if a click isnt delayed at all then it counts as 0 deciseconds.
2323
var/average_click_delay = 0
24-
var/list/moving_mobs = list()
2524

2625
/datum/controller/subsystem/verb_manager/input/Initialize()
2726
setup_default_macro_sets()
@@ -72,8 +71,6 @@ VERB_MANAGER_SUBSYSTEM_DEF(input)
7271
var/moves_this_run = 0
7372
for(var/mob/user in GLOB.keyloop_list)
7473
moves_this_run += user.focus?.keyLoop(user.client)//only increments if a player moves due to their own input
75-
for(var/mob/moving in SSinput.moving_mobs)
76-
moves_this_run += moving.keyLoop(gondor_calls_for_aid = TRUE)
7774

7875
movements_per_second = MC_AVG_SECONDS(movements_per_second, moves_this_run, wait TICKS)
7976

code/controllers/subsystem/time_track.dm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ SUBSYSTEM_DEF(time_track)
9393
time_dilation_avg_fast = MC_AVERAGE_FAST(time_dilation_avg_fast, time_dilation_current)
9494
time_dilation_avg = MC_AVERAGE(time_dilation_avg, time_dilation_avg_fast)
9595
time_dilation_avg_slow = MC_AVERAGE_SLOW(time_dilation_avg_slow, time_dilation_avg)
96+
GLOB.glide_size_multiplier = (current_byondtime - last_tick_byond_time) / (current_realtime - last_tick_realtime)
9697
else
9798
first_run = FALSE
9899
last_tick_realtime = current_realtime

code/datums/components/scope.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
stop_zooming(user_mob)
3636
return
3737
tracker.calculate_params()
38-
if(!user_client.intended_direction)
38+
if(!length(user_client.keys_held & user_client.movement_keys))
3939
user_mob.face_atom(tracker.given_turf)
4040
animate(user_client, world.tick_lag, pixel_x = tracker.given_x, pixel_y = tracker.given_y)
4141

code/game/atoms_movable.dm

Lines changed: 5 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -119,23 +119,6 @@
119119
///can we grab this object?
120120
var/cant_grab = FALSE
121121

122-
/// The world.time we started our last glide
123-
var/last_glide_start = 0
124-
/// The ammount of unaccounted accumulated error between our glide visuals and the world tickrate
125-
var/accumulated_glide_error = 0
126-
/// The amount of banked (accounted for) error between our visual and world glide rates
127-
var/banked_glide_error = 0
128-
/// The amount of error accounted for in the initial delay of our glide (based off GLOB.glide_size_multiplier)
129-
var/built_in_glide_error = 0
130-
/// The world.time at which we assume our next glide will end
131-
var/glide_stopping_time = 0
132-
/// We are currently tracking our glide animation
133-
var/glide_tracking = FALSE
134-
/// If we should use glide correction
135-
var/use_correction = FALSE
136-
var/mutable_appearance/glide_text
137-
var/debug_glide = FALSE
138-
139122
/mutable_appearance/emissive_blocker
140123

141124
/mutable_appearance/emissive_blocker/New()
@@ -606,59 +589,15 @@
606589
if(!only_pulling && pulledby && moving_diagonally != FIRST_DIAG_STEP && (get_dist(src, pulledby) > 1 || z != pulledby.z)) //separated from our puller and not in the middle of a diagonal move.
607590
pulledby.stop_pulling()
608591

609-
GLOBAL_LIST_EMPTY(gliding_atoms)
610-
611-
/atom/movable/proc/set_glide_size(target = 8, mid_move = FALSE)
592+
/atom/movable/proc/set_glide_size(target = 8, recursed = FALSE)
612593
if (HAS_TRAIT(src, TRAIT_NO_GLIDE))
613594
return
614595
SEND_SIGNAL(src, COMSIG_MOVABLE_UPDATE_GLIDE_SIZE, target)
615596
glide_size = target
616-
// If we're mid move don't reset ourselves yeah?
617-
if(!mid_move || !glide_tracking)
618-
last_glide_start = world.time
619-
glide_stopping_time = world.time + (world.icon_size / target) * world.tick_lag
620-
accumulated_glide_error = 0
621-
banked_glide_error = 0
622-
built_in_glide_error = GLOB.glide_size_multi_error
623-
update_glide_text()
624-
if(!glide_tracking && use_correction)
625-
GLOB.gliding_atoms += src
626-
glide_tracking = TRUE
627-
628-
for(var/mob/buckled_mob as anything in buckled_mobs)
629-
buckled_mob.set_glide_size(target, mid_move = mid_move)
630-
631-
/atom/movable/proc/update_glide_text()
632-
if(!debug_glide)
633-
return
634-
cut_overlay(glide_text)
635-
glide_text = mutable_appearance(offset_spokesman = src, plane = ABOVE_LIGHTING_PLANE)
636-
glide_text.maptext = "GS: [glide_size]ppt\nMulti: [GLOB.glide_size_multiplier * 100]% \nBIE: [built_in_glide_error]ds \nErr: [accumulated_glide_error]ds"
637-
glide_text.maptext_width = 500
638-
glide_text.maptext_height = 500
639-
glide_text.maptext_y = 32
640-
add_overlay(glide_text)
641-
642-
/atom/movable/proc/account_for_glide_error(error)
643-
// Intentionally can go negative to handle being overoptimistic about glide rates
644-
accumulated_glide_error += error - built_in_glide_error
645-
if(abs(accumulated_glide_error) < world.tick_lag * 0.5)
646-
update_glide_text()
647-
return
648-
// we're trying to account for random spikes in error while gliding
649-
// So we're gonna use the known GAME tick we want to stop at,
650-
// alongside how much time has visually past to work out
651-
// exactly how fast we need to move to make up that distance
652-
var/game_time_spent = (world.time - last_glide_start)
653-
var/visual_time_spent = game_time_spent + accumulated_glide_error + built_in_glide_error * game_time_spent
654-
var/distance_covered = glide_size * visual_time_spent
655-
var/distance_remaining = world.icon_size - distance_covered
656-
var/game_time_remaining = (glide_stopping_time - world.time)
657-
built_in_glide_error += accumulated_glide_error / game_time_remaining
658-
accumulated_glide_error = 0
659-
set_glide_size(clamp((((distance_remaining) / max((game_time_remaining) / world.tick_lag, 1))), MIN_GLIDE_SIZE, MAX_GLIDE_SIZE), mid_move = TRUE)
660-
661-
update_glide_text()
597+
598+
if(!recursed)
599+
for(var/mob/buckled_mob as anything in buckled_mobs)
600+
buckled_mob.set_glide_size(target, TRUE)
662601

663602
/**
664603
* meant for movement with zero side effects. only use for objects that are supposed to move "invisibly" (like camera mobs or ghosts)

code/modules/client/client_defines.dm

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,6 @@
248248
var/list/keys_held = list()
249249
/// A buffer for combinations such of modifiers + keys (ex: CtrlD, AltE, ShiftT). Format: `"key"` -> `"combo"` (ex: `"D"` -> `"CtrlD"`)
250250
var/list/key_combos_held = list()
251-
a/// The direction we WANT to move, based off our keybinds
252-
/// Will be udpated to be the actual direction later on
253-
var/intended_direction = NONE
254251
/*
255252
** These next two vars are to apply movement for keypresses and releases made while move delayed.
256253
** Because discarding that input makes the game less responsive.

code/modules/client/client_procs.dm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,6 @@ GLOBAL_LIST_INIT(blacklisted_builds, list(
11841184
winset(src, "default-[REF(key)]", "parent=default;name=[key];command=[msay]")
11851185
else
11861186
winset(src, "default-[REF(key)]", "parent=default;name=[key];command=")
1187-
calculate_move_dir()
11881187

11891188
/client/proc/change_view(new_size)
11901189
if (isnull(new_size))
Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,28 @@
11
// You might be wondering why this isn't client level. If focus is null, we don't want you to move.
22
// Only way to do that is to tie the behavior into the focus's keyLoop().
33

4-
/atom/movable/keyLoop(client/user, gondor_calls_for_aid = FALSE)
5-
// Clients don't go null randomly. They do go null unexpectedly though, when they're poked in particular ways
6-
// keyLoop is called by a for loop over mobs. We're guarenteed that all the mobs have clients at the START
7-
// But the move of one mob might poke the client of another, so we do this
8-
if(gondor_calls_for_aid)
9-
user = src
10-
if(!user)
11-
return FALSE
12-
var/movement_dir = user.intended_direction | user.next_move_dir_add
13-
// If we're not movin anywhere, we aren't movin anywhere
14-
// Safe because nothing adds to movement_dir after this moment
15-
if(!movement_dir)
16-
return FALSE
17-
if(user.next_move_dir_sub)
4+
/atom/movable/keyLoop(client/user)
5+
var/movement_dir = NONE
6+
for(var/_key in user?.keys_held)
7+
movement_dir = movement_dir | user.movement_keys[_key]
8+
if(user?.next_move_dir_add)
9+
movement_dir |= user.next_move_dir_add
10+
if(user?.next_move_dir_sub)
1811
movement_dir &= ~user.next_move_dir_sub
1912
// Sanity checks in case you hold left and right and up to make sure you only go up
2013
if((movement_dir & NORTH) && (movement_dir & SOUTH))
2114
movement_dir &= ~(NORTH|SOUTH)
2215
if((movement_dir & EAST) && (movement_dir & WEST))
2316
movement_dir &= ~(EAST|WEST)
2417

25-
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
18+
if(user && movement_dir) //If we're not moving, don't compensate, as byond will auto-fill dir otherwise
2619
movement_dir = turn(movement_dir, -dir2angle(user.dir)) //By doing this we ensure that our input direction is offset by the client (camera) direction
2720

2821
//turn without moving while using the movement lock key, unless something wants to ignore it and move anyway
29-
if(user.movement_locked && !(SEND_SIGNAL(src, COMSIG_MOVABLE_KEYBIND_FACE_DIR, movement_dir) & COMSIG_IGNORE_MOVEMENT_LOCK))
22+
if(user?.movement_locked && !(SEND_SIGNAL(src, COMSIG_MOVABLE_KEYBIND_FACE_DIR, movement_dir) & COMSIG_IGNORE_MOVEMENT_LOCK))
3023
keybind_face_direction(movement_dir)
31-
else if(gondor_calls_for_aid)
32-
var/mob/mob_src = src
33-
mob_src.bullshit_hell(get_step(src, movement_dir), movement_dir)
34-
return !!movement_dir
35-
// Null check cause of the signal above
36-
else if(user)
37-
user.Move(get_step(src, movement_dir), movement_dir)
24+
else
25+
user?.Move(get_step(src, movement_dir), movement_dir)
3826
return !!movement_dir //true if there was actually any player input
3927

4028
return FALSE
41-
42-
/client/proc/calculate_move_dir()
43-
var/movement_dir = NONE
44-
for(var/_key in keys_held)
45-
movement_dir |= movement_keys[_key]
46-
intended_direction = movement_dir

code/modules/keybindings/bindings_client.dm

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@
4747

4848
//the time a key was pressed isn't actually used anywhere (as of 2019-9-10) but this allows easier access usage/checking
4949
keys_held[_key] = world.time
50-
var/movement = movement_keys[_key]
51-
if(movement)
52-
calculate_move_dir()
53-
if(!movement_locked && !(next_move_dir_sub & movement))
50+
if(!movement_locked)
51+
var/movement = movement_keys[_key]
52+
if(!(next_move_dir_sub & movement))
5453
next_move_dir_add |= movement
5554

5655
// Client-level keybindings are ones anyone should be able to do at any time
@@ -95,10 +94,9 @@
9594

9695
keys_held -= _key
9796

98-
var/movement = movement_keys[_key]
99-
if(movement)
100-
calculate_move_dir()
101-
if(!movement_locked && !(next_move_dir_add & movement))
97+
if(!movement_locked)
98+
var/movement = movement_keys[_key]
99+
if(!(next_move_dir_add & movement))
102100
next_move_dir_sub |= movement
103101

104102
// We don't do full key for release, because for mod keys you

code/modules/mob/mob_defines.dm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
see_in_dark = 1e6
2323
// A list of factions that this mob is currently in, for hostile mob targeting, amongst other things
2424
faction = list(FACTION_NEUTRAL)
25-
use_correction = TRUE
2625
/// The current client inhabiting this mob. Managed by login/logout
2726
/// This exists so we can do cleanup in logout for occasions where a client was transfere rather then destroyed
2827
/// We need to do this because the mob on logout never actually has a reference to client

0 commit comments

Comments
 (0)