Skip to content

[PORT] Smooth Movement 5.2: God's Dumbest Code Edition (PLATNIUM) (BESTSELLING) #6632

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

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ aux*.dll
libaux*.so
aux*.pdb

!auxcpu_byondapi.dll

# byond-tracy, we intentionally do not ship this and do not want to maintain it
# https://github.com/mafemergency/byond-tracy or https://github.com/ParadiseSS13/byond-tracy
prof.*
Expand Down
Binary file added auxcpu_byondapi.dll
Binary file not shown.
13 changes: 11 additions & 2 deletions code/__DEFINES/_tick.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
#define MAPTICK_MC_MIN_RESERVE 70
#define MAPTICK_LAST_INTERNAL_TICK_USAGE (world.map_cpu)

/// Tick limit while running normally
#define TICK_BYOND_RESERVE 2
#define TICK_LIMIT_RUNNING (max(100 - TICK_BYOND_RESERVE - MAPTICK_LAST_INTERNAL_TICK_USAGE, MAPTICK_MC_MIN_RESERVE))
#define TICK_VERB_RESERVE 4
#define TICK_EXPECTED_SAFE_MAX (100 - TICK_BYOND_RESERVE - TICK_VERB_RESERVE - MAPTICK_LAST_INTERNAL_TICK_USAGE)
/// Tick limit while running normally
#define TICK_LIMIT_RUNNING (max(GLOB.use_old_mc_limit ? TICK_EXPECTED_SAFE_MAX : GLOB.corrective_cpu_threshold, MAPTICK_MC_MIN_RESERVE))
/// Tick limit used to resume things in stoplag
#define TICK_LIMIT_TO_RUN 70
/// Tick limit for MC while running
Expand All @@ -29,3 +31,10 @@
#define TICK_CHECK_HIGH_PRIORITY ( TICK_USAGE > 95 )
/// runs stoplag if tick_usage is above 95, for high priority usage
#define CHECK_TICK_HIGH_PRIORITY ( TICK_CHECK_HIGH_PRIORITY? stoplag() : 0 )

/// Size of the moving average byond stores {map_)cpu values in
#define INTERNAL_CPU_SIZE 16

#define USAGE_DISPLAY_CPU "CPU"
#define USAGE_DISPLAY_MC "Before Tick"
#define USAGE_DISPLAY_POST_TICK "Maptick + Verbs"
11 changes: 11 additions & 0 deletions code/__DEFINES/layers.dm
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@
///Plane of the "splash" icon used that shows on the lobby screen
#define SPLASHSCREEN_PLANE 50

//Holds JUST cpu debug maptext, normally not shown
#define CPU_DEBUG_PLANE 51

// The largest plane here must still be less than RENDER_PLANE_GAME

//-------------------- Rendering ---------------------
Expand Down Expand Up @@ -303,6 +306,14 @@
///cinematics are "below" the splash screen
#define CINEMATIC_LAYER -1

// CPU_DEBUG_PLANE

///CPU related graph framing
#define CPU_GRAPH_FRAME_LAYER 1

///Primary CPU readout
#define CPU_DISPLAY_LAYER 10

///Plane master controller keys
#define PLANE_MASTERS_GAME "plane_masters_game"
#define PLANE_MASTERS_NON_MASTER "plane_masters_non_master"
Expand Down
12 changes: 10 additions & 2 deletions code/__DEFINES/movement.dm
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,25 @@

/// Compensating for time dilation
GLOBAL_VAR_INIT(glide_size_multiplier, 1.0)
GLOBAL_VAR_INIT(old_glide_size_multiplier, 1.0)
GLOBAL_VAR_INIT(use_new_glide, TRUE)

#define GLIDE_SIZE_MULTI (GLOB.use_new_glide ? GLOB.glide_size_multiplier : GLOB.old_glide_size_multiplier)

#define ICON_SIZE_ALL 32
#define ICON_SIZE_X 32
#define ICON_SIZE_Y 32

///Broken down, here's what this does:
/// divides the world icon_size (32) by delay divided by ticklag to get the number of pixels something should be moving each tick.
/// The division result is given a min value of 1 to prevent obscenely slow glide sizes from being set
/// 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.
/// The whole result is then clamped to within the range above.
/// Not very readable but it works
#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))
#define DELAY_TO_GLIDE_SIZE(delay) (clamp(((ICON_SIZE_ALL / max((delay) / world.tick_lag, 1)) * GLIDE_SIZE_MULTI), MIN_GLIDE_SIZE, MAX_GLIDE_SIZE))

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

//Movement loop priority. Only one loop can run at a time, this dictates that
// Higher numbers beat lower numbers
Expand Down
55 changes: 54 additions & 1 deletion code/__DEFINES/perf_test.dm
Original file line number Diff line number Diff line change
@@ -1,9 +1,62 @@
/// Macro that takes a tick usage to target, and proceses until we hit it
/// This lets us simulate generic load as we'd like, to make testing for overtime easier
#define CONSUME_UNTIL(target_usage) \
while(TICK_USAGE < target_usage) {\
while(TICK_USAGE < (target_usage)) {\
var/_knockonwood_x = 0;\
_knockonwood_x += 20;\
}

GLOBAL_LIST_INIT(useful_primes_found, prep_primes_list())
GLOBAL_VAR_INIT(last_prime_canidate, 3)
GLOBAL_VAR_INIT(highest_prime_found, 3)
GLOBAL_VAR_INIT(last_prime_index, 0)
GLOBAL_VAR_INIT(last_prime_storage_index, 1)

// The last index we care about, primes wise (anything higher then this will never be useful to us
// because we only need to check up to sqrt(SHORT_REAL_LIMIT) (4096))
#define LAST_USEFUL_PRIME_INDEX 564 // 4093

/proc/prep_primes_list()
var/list/prime_holder = new /list(LAST_USEFUL_PRIME_INDEX)
prime_holder[1] = 3
return prime_holder

#define PRIMES_UNTIL(target_usage) \
do { \
if(GLOB.last_prime_canidate <= SHORT_REAL_LIMIT) { \
var/list/_primes_found = GLOB.useful_primes_found; \
var/_prime_canidate = GLOB.last_prime_canidate; \
var/_target_usage = (target_usage); \
while(TICK_USAGE < _target_usage) outer_prime_loop: { \
var/_limit = sqrt(_prime_canidate); \
var/_prime_found = TRUE; \
for(var/prime_i in GLOB.last_prime_index + 1 to length(_primes_found)) { \
var/_prime = _primes_found[prime_i]; \
if(_prime > _limit) { \
break; \
} \
var/_divided = _prime_canidate / _prime; \
if(floor(_divided) == _divided) { \
_prime_found = FALSE; \
break; \
} \
if(TICK_USAGE < _target_usage) { \
GLOB.last_prime_index = prime_i; \
break outer_prime_loop; \
} \
} \
if(_prime_found) { \
if(_prime_canidate <= LAST_USEFUL_PRIME_INDEX) { \
GLOB.last_prime_storage_index += 1; \
_primes_found[GLOB.last_prime_storage_index] += _prime_canidate; \
} \
GLOB.highest_prime_found = _prime_canidate; \
} \
_prime_canidate += 2; \
GLOB.last_prime_index = 0; \
} \
GLOB.last_prime_canidate = _prime_canidate; \
} else { \
CONSUME_UNTIL(target_usage) \
} \
} while(FALSE)
52 changes: 52 additions & 0 deletions code/__HELPERS/auxtools.dm
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,55 @@
return "[world.GetConfig("env", "HOME")]/.byond/bin/lib[library].so"
else
CRASH("Could not find lib[library].so")

#define AUXCPU_DLL (world.system_type == MS_WINDOWS ? "auxcpu_byondapi.dll" : __detect_auxtools("auxcpu_byondapi"))
/proc/current_true_cpu()
var/static/__current_true_cpu
#ifndef OPENDREAM_REAL
__current_true_cpu ||= load_ext(AUXCPU_DLL, "byond:current_true_cpu")

Check failure on line 18 in code/__HELPERS/auxtools.dm

View workflow job for this annotation

GitHub Actions / Run Linters

OD0404: Unknown identifier "system_type"
return call_ext(__current_true_cpu)()

Check failure on line 19 in code/__HELPERS/auxtools.dm

View workflow job for this annotation

GitHub Actions / Run Linters

got ')', expected one of: '(', operator, field access, ','
#endif

/proc/current_cpu_index()
var/static/__current_cpu_index
#ifndef OPENDREAM_REAL
__current_cpu_index ||= load_ext(AUXCPU_DLL, "byond:current_cpu_index")

Check failure on line 25 in code/__HELPERS/auxtools.dm

View workflow job for this annotation

GitHub Actions / Run Linters

OD0404: Unknown identifier "system_type"
var/actual_index = call_ext(__current_cpu_index)()

Check failure on line 26 in code/__HELPERS/auxtools.dm

View workflow job for this annotation

GitHub Actions / Run Linters

got ')', expected one of: '(', operator, field access, ','
return WRAP(actual_index + 1, 1, INTERNAL_CPU_SIZE + 1)
#endif

/proc/true_cpu_at_index(index)
var/static/__true_cpu_at_index
var/actual_index = WRAP(index - 1, 0, INTERNAL_CPU_SIZE)
#ifndef OPENDREAM_REAL
__true_cpu_at_index ||= load_ext(AUXCPU_DLL, "byond:true_cpu_at_index")

Check failure on line 34 in code/__HELPERS/auxtools.dm

View workflow job for this annotation

GitHub Actions / Run Linters

OD0404: Unknown identifier "system_type"
return call_ext(__true_cpu_at_index)(actual_index)

Check failure on line 35 in code/__HELPERS/auxtools.dm

View workflow job for this annotation

GitHub Actions / Run Linters

got ')', expected one of: '(', operator, field access, ','
#endif

/proc/cpu_values()
var/static/__cpu_values
#ifndef OPENDREAM_REAL
__cpu_values ||= load_ext(AUXCPU_DLL, "byond:cpu_values")

Check failure on line 41 in code/__HELPERS/auxtools.dm

View workflow job for this annotation

GitHub Actions / Run Linters

OD0404: Unknown identifier "system_type"
return call_ext(__cpu_values)()

Check failure on line 42 in code/__HELPERS/auxtools.dm

View workflow job for this annotation

GitHub Actions / Run Linters

got ')', expected one of: '(', operator, field access, ','
#endif

/world/proc/setup_external_cpu()
if(!call_ext(AUXCPU_DLL, "byond:find_signatures")())
SEND_TEXT(world.log, "auxcpu failed to find signatures")
return FALSE
SEND_TEXT(world.log, "signatures found")
return TRUE

/world/proc/cleanup_external_cpu()
return

/proc/meowtonin_stack_trace(message, source, line, full_info)
var/list/info = list("[message || "N/A"]")
if(istext(source))
info += "\tsource: [source]"
if(line)
info += "\tline: [line]"
if(full_info)
SEND_TEXT(world.log, "\n=== (panic start) ===\n[full_info]\n=== (panic end) ===\n")
CRASH(jointext(info, "\n"))

Loading
Loading