mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-11 18:53:06 +00:00
* Adds defines for world.tick_usage * This provides no useful benefit whatsoever, but /tg and Baystation12 have done it, so it will make porting future code easier if we do too. No real harm done either.
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
#define MC_TICK_CHECK ( ( world.tick_usage > Master.current_ticklimit || src.state != SS_RUNNING ) ? pause() : 0 )
|
#define MC_TICK_CHECK ( ( TICK_USAGE > Master.current_ticklimit || src.state != SS_RUNNING ) ? pause() : 0 )
|
||||||
|
|
||||||
// Used for splitting up your remaining time into phases, if you want to evenly divide it.
|
// Used for splitting up your remaining time into phases, if you want to evenly divide it.
|
||||||
#define MC_SPLIT_TICK_INIT(phase_count) var/original_tick_limit = Master.current_ticklimit; var/split_tick_phases = ##phase_count
|
#define MC_SPLIT_TICK_INIT(phase_count) var/original_tick_limit = Master.current_ticklimit; var/split_tick_phases = ##phase_count
|
||||||
#define MC_SPLIT_TICK \
|
#define MC_SPLIT_TICK \
|
||||||
if(split_tick_phases > 1){\
|
if(split_tick_phases > 1){\
|
||||||
Master.current_ticklimit = ((original_tick_limit - world.tick_usage) / split_tick_phases) + world.tick_usage;\
|
Master.current_ticklimit = ((original_tick_limit - TICK_USAGE) / split_tick_phases) + TICK_USAGE;\
|
||||||
--split_tick_phases;\
|
--split_tick_phases;\
|
||||||
} else {\
|
} else {\
|
||||||
Master.current_ticklimit = original_tick_limit;\
|
Master.current_ticklimit = original_tick_limit;\
|
||||||
|
|||||||
@@ -3,5 +3,7 @@
|
|||||||
#define TICK_LIMIT_MC 70
|
#define TICK_LIMIT_MC 70
|
||||||
#define TICK_LIMIT_MC_INIT_DEFAULT 98
|
#define TICK_LIMIT_MC_INIT_DEFAULT 98
|
||||||
|
|
||||||
#define TICK_CHECK ( world.tick_usage > Master.current_ticklimit )
|
#define TICK_CHECK ( TICK_USAGE > Master.current_ticklimit )
|
||||||
#define CHECK_TICK if TICK_CHECK stoplag()
|
#define CHECK_TICK if TICK_CHECK stoplag()
|
||||||
|
|
||||||
|
#define TICK_USAGE world.tick_usage
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
//percent_of_tick_used * (ticklag * 100(to convert to ms)) / 100(percent ratio)
|
//percent_of_tick_used * (ticklag * 100(to convert to ms)) / 100(percent ratio)
|
||||||
//collapsed to percent_of_tick_used * tick_lag
|
//collapsed to percent_of_tick_used * tick_lag
|
||||||
#define TICK_DELTA_TO_MS(percent_of_tick_used) ((percent_of_tick_used) * world.tick_lag)
|
#define TICK_DELTA_TO_MS(percent_of_tick_used) ((percent_of_tick_used) * world.tick_lag)
|
||||||
#define TICK_USAGE_TO_MS(starting_tickusage) (TICK_DELTA_TO_MS(world.tick_usage-starting_tickusage))
|
#define TICK_USAGE_TO_MS(starting_tickusage) (TICK_DELTA_TO_MS(TICK_USAGE-starting_tickusage))
|
||||||
|
|
||||||
//time of day but automatically adjusts to the server going into the next day within the same round.
|
//time of day but automatically adjusts to the server going into the next day within the same round.
|
||||||
//for when you need a reliable time number that doesn't depend on byond time.
|
//for when you need a reliable time number that doesn't depend on byond time.
|
||||||
|
|||||||
@@ -15,4 +15,4 @@
|
|||||||
#define PROCESS_DEFAULT_DEFER_USAGE 90 // 90% of a tick
|
#define PROCESS_DEFAULT_DEFER_USAGE 90 // 90% of a tick
|
||||||
|
|
||||||
// Sleep check macro
|
// Sleep check macro
|
||||||
#define SCHECK if(world.tick_usage >= next_sleep_usage) defer()
|
#define SCHECK if(TICK_USAGE >= next_sleep_usage) defer()
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
#define DAYS *864000
|
#define DAYS *864000
|
||||||
|
|
||||||
#define TimeOfGame (get_game_time())
|
#define TimeOfGame (get_game_time())
|
||||||
#define TimeOfTick (world.tick_usage*0.01*world.tick_lag)
|
#define TimeOfTick (TICK_USAGE*0.01*world.tick_lag)
|
||||||
|
|
||||||
/proc/get_game_time()
|
/proc/get_game_time()
|
||||||
var/global/time_offset = 0
|
var/global/time_offset = 0
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
var/global/last_usage = 0
|
var/global/last_usage = 0
|
||||||
|
|
||||||
var/wtime = world.time
|
var/wtime = world.time
|
||||||
var/wusage = world.tick_usage * 0.01
|
var/wusage = TICK_USAGE * 0.01
|
||||||
|
|
||||||
if(last_time < wtime && last_usage > 1)
|
if(last_time < wtime && last_usage > 1)
|
||||||
time_offset += last_usage - 1
|
time_offset += last_usage - 1
|
||||||
@@ -111,7 +111,7 @@ var/round_start_time = 0
|
|||||||
|
|
||||||
//Increases delay as the server gets more overloaded,
|
//Increases delay as the server gets more overloaded,
|
||||||
//as sleeps aren't cheap and sleeping only to wake up and sleep again is wasteful
|
//as sleeps aren't cheap and sleeping only to wake up and sleep again is wasteful
|
||||||
#define DELTA_CALC max(((max(world.tick_usage, world.cpu) / 100) * max(Master.sleep_delta,1)), 1)
|
#define DELTA_CALC max(((max(TICK_USAGE, world.cpu) / 100) * max(Master.sleep_delta,1)), 1)
|
||||||
|
|
||||||
/proc/stoplag()
|
/proc/stoplag()
|
||||||
. = 0
|
. = 0
|
||||||
@@ -120,4 +120,4 @@ var/round_start_time = 0
|
|||||||
. += round(i*DELTA_CALC)
|
. += round(i*DELTA_CALC)
|
||||||
sleep(i*world.tick_lag*DELTA_CALC)
|
sleep(i*world.tick_lag*DELTA_CALC)
|
||||||
i *= 2
|
i *= 2
|
||||||
while (world.tick_usage > min(TICK_LIMIT_TO_RUN, Master.current_ticklimit))
|
while (TICK_USAGE > min(TICK_LIMIT_TO_RUN, Master.current_ticklimit))
|
||||||
|
|||||||
@@ -124,7 +124,7 @@
|
|||||||
cpu_defer_count = 0
|
cpu_defer_count = 0
|
||||||
|
|
||||||
// Prepare usage tracking (defer() updates these)
|
// Prepare usage tracking (defer() updates these)
|
||||||
tick_usage_start = world.tick_usage
|
tick_usage_start = TICK_USAGE
|
||||||
tick_usage_accumulated = 0
|
tick_usage_accumulated = 0
|
||||||
|
|
||||||
running()
|
running()
|
||||||
@@ -142,7 +142,7 @@
|
|||||||
|
|
||||||
/datum/controller/process/proc/recordRunTime()
|
/datum/controller/process/proc/recordRunTime()
|
||||||
// Convert from tick usage (100/tick) to seconds of CPU time used
|
// Convert from tick usage (100/tick) to seconds of CPU time used
|
||||||
var/total_usage = (tick_usage_accumulated + (world.tick_usage - tick_usage_start)) / 1000 * world.tick_lag
|
var/total_usage = (tick_usage_accumulated + (TICK_USAGE - tick_usage_start)) / 1000 * world.tick_lag
|
||||||
|
|
||||||
last_run_time = total_usage
|
last_run_time = total_usage
|
||||||
if(total_usage > highest_run_time)
|
if(total_usage > highest_run_time)
|
||||||
@@ -222,14 +222,14 @@
|
|||||||
handleHung()
|
handleHung()
|
||||||
CRASH("Process [name] hung and was restarted.")
|
CRASH("Process [name] hung and was restarted.")
|
||||||
|
|
||||||
tick_usage_accumulated += (world.tick_usage - tick_usage_start)
|
tick_usage_accumulated += (TICK_USAGE - tick_usage_start)
|
||||||
if(world.tick_usage < defer_usage)
|
if(TICK_USAGE < defer_usage)
|
||||||
sleep(0)
|
sleep(0)
|
||||||
else
|
else
|
||||||
sleep(world.tick_lag)
|
sleep(world.tick_lag)
|
||||||
cpu_defer_count++
|
cpu_defer_count++
|
||||||
tick_usage_start = world.tick_usage
|
tick_usage_start = TICK_USAGE
|
||||||
next_sleep_usage = min(world.tick_usage + sleep_interval, defer_usage)
|
next_sleep_usage = min(TICK_USAGE + sleep_interval, defer_usage)
|
||||||
|
|
||||||
/datum/controller/process/proc/update()
|
/datum/controller/process/proc/update()
|
||||||
// Clear delta
|
// Clear delta
|
||||||
|
|||||||
@@ -279,7 +279,7 @@ var/datum/controller/master/Master = new()
|
|||||||
|
|
||||||
//if there are mutiple sleeping procs running before us hogging the cpu, we have to run later
|
//if there are mutiple sleeping procs running before us hogging the cpu, we have to run later
|
||||||
// because sleeps are processed in the order received, so longer sleeps are more likely to run first
|
// because sleeps are processed in the order received, so longer sleeps are more likely to run first
|
||||||
if (world.tick_usage > TICK_LIMIT_MC)
|
if (TICK_USAGE > TICK_LIMIT_MC)
|
||||||
sleep_delta += 2
|
sleep_delta += 2
|
||||||
current_ticklimit = TICK_LIMIT_RUNNING * 0.5
|
current_ticklimit = TICK_LIMIT_RUNNING * 0.5
|
||||||
sleep(world.tick_lag * (processing + sleep_delta))
|
sleep(world.tick_lag * (processing + sleep_delta))
|
||||||
@@ -288,7 +288,7 @@ var/datum/controller/master/Master = new()
|
|||||||
sleep_delta = MC_AVERAGE_FAST(sleep_delta, 0)
|
sleep_delta = MC_AVERAGE_FAST(sleep_delta, 0)
|
||||||
if (last_run + (world.tick_lag * processing) > world.time)
|
if (last_run + (world.tick_lag * processing) > world.time)
|
||||||
sleep_delta += 1
|
sleep_delta += 1
|
||||||
if (world.tick_usage > (TICK_LIMIT_MC*0.5))
|
if (TICK_USAGE > (TICK_LIMIT_MC*0.5))
|
||||||
sleep_delta += 1
|
sleep_delta += 1
|
||||||
|
|
||||||
if (make_runtime)
|
if (make_runtime)
|
||||||
@@ -394,13 +394,13 @@ var/datum/controller/master/Master = new()
|
|||||||
|
|
||||||
//keep running while we have stuff to run and we haven't gone over a tick
|
//keep running while we have stuff to run and we haven't gone over a tick
|
||||||
// this is so subsystems paused eariler can use tick time that later subsystems never used
|
// this is so subsystems paused eariler can use tick time that later subsystems never used
|
||||||
while (ran && queue_head && world.tick_usage < TICK_LIMIT_MC)
|
while (ran && queue_head && TICK_USAGE < TICK_LIMIT_MC)
|
||||||
ran = FALSE
|
ran = FALSE
|
||||||
bg_calc = FALSE
|
bg_calc = FALSE
|
||||||
current_tick_budget = queue_priority_count
|
current_tick_budget = queue_priority_count
|
||||||
queue_node = queue_head
|
queue_node = queue_head
|
||||||
while (queue_node)
|
while (queue_node)
|
||||||
if (ran && world.tick_usage > TICK_LIMIT_RUNNING)
|
if (ran && TICK_USAGE > TICK_LIMIT_RUNNING)
|
||||||
break
|
break
|
||||||
|
|
||||||
queue_node_flags = queue_node.flags
|
queue_node_flags = queue_node.flags
|
||||||
@@ -412,7 +412,7 @@ var/datum/controller/master/Master = new()
|
|||||||
//(unless we haven't even ran anything this tick, since its unlikely they will ever be able run
|
//(unless we haven't even ran anything this tick, since its unlikely they will ever be able run
|
||||||
// in those cases, so we just let them run)
|
// in those cases, so we just let them run)
|
||||||
if (queue_node_flags & SS_NO_TICK_CHECK)
|
if (queue_node_flags & SS_NO_TICK_CHECK)
|
||||||
if (queue_node.tick_usage > TICK_LIMIT_RUNNING - world.tick_usage && ran_non_ticker)
|
if (queue_node.tick_usage > TICK_LIMIT_RUNNING - TICK_USAGE && ran_non_ticker)
|
||||||
queue_node.queued_priority += queue_priority_count * 0.10
|
queue_node.queued_priority += queue_priority_count * 0.10
|
||||||
queue_priority_count -= queue_node_priority
|
queue_priority_count -= queue_node_priority
|
||||||
queue_priority_count += queue_node.queued_priority
|
queue_priority_count += queue_node.queued_priority
|
||||||
@@ -424,19 +424,19 @@ var/datum/controller/master/Master = new()
|
|||||||
current_tick_budget = queue_priority_count_bg
|
current_tick_budget = queue_priority_count_bg
|
||||||
bg_calc = TRUE
|
bg_calc = TRUE
|
||||||
|
|
||||||
tick_remaining = TICK_LIMIT_RUNNING - world.tick_usage
|
tick_remaining = TICK_LIMIT_RUNNING - TICK_USAGE
|
||||||
|
|
||||||
if (current_tick_budget > 0 && queue_node_priority > 0)
|
if (current_tick_budget > 0 && queue_node_priority > 0)
|
||||||
tick_precentage = tick_remaining / (current_tick_budget / queue_node_priority)
|
tick_precentage = tick_remaining / (current_tick_budget / queue_node_priority)
|
||||||
else
|
else
|
||||||
tick_precentage = tick_remaining
|
tick_precentage = tick_remaining
|
||||||
|
|
||||||
current_ticklimit = world.tick_usage + tick_precentage
|
current_ticklimit = TICK_USAGE + tick_precentage
|
||||||
|
|
||||||
if (!(queue_node_flags & SS_TICKER))
|
if (!(queue_node_flags & SS_TICKER))
|
||||||
ran_non_ticker = TRUE
|
ran_non_ticker = TRUE
|
||||||
ran = TRUE
|
ran = TRUE
|
||||||
tick_usage = world.tick_usage
|
tick_usage = TICK_USAGE
|
||||||
queue_node_paused = (queue_node.state == SS_PAUSED || queue_node.state == SS_PAUSING)
|
queue_node_paused = (queue_node.state == SS_PAUSED || queue_node.state == SS_PAUSING)
|
||||||
last_type_processed = queue_node
|
last_type_processed = queue_node
|
||||||
|
|
||||||
@@ -446,7 +446,7 @@ var/datum/controller/master/Master = new()
|
|||||||
if (state == SS_RUNNING)
|
if (state == SS_RUNNING)
|
||||||
state = SS_IDLE
|
state = SS_IDLE
|
||||||
current_tick_budget -= queue_node_priority
|
current_tick_budget -= queue_node_priority
|
||||||
tick_usage = world.tick_usage - tick_usage
|
tick_usage = TICK_USAGE - tick_usage
|
||||||
|
|
||||||
if (tick_usage < 0)
|
if (tick_usage < 0)
|
||||||
tick_usage = 0
|
tick_usage = 0
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ SUBSYSTEM_DEF(garbage)
|
|||||||
//this is purely to seperate things profile wise.
|
//this is purely to seperate things profile wise.
|
||||||
/datum/controller/subsystem/garbage/proc/HardDelete(datum/A)
|
/datum/controller/subsystem/garbage/proc/HardDelete(datum/A)
|
||||||
var/time = world.timeofday
|
var/time = world.timeofday
|
||||||
var/tick = world.tick_usage
|
var/tick = TICK_USAGE
|
||||||
var/ticktime = world.time
|
var/ticktime = world.time
|
||||||
|
|
||||||
var/type = A.type
|
var/type = A.type
|
||||||
@@ -158,7 +158,7 @@ SUBSYSTEM_DEF(garbage)
|
|||||||
|
|
||||||
del(A)
|
del(A)
|
||||||
|
|
||||||
tick = (world.tick_usage-tick+((world.time-ticktime)/world.tick_lag*100))
|
tick = (TICK_USAGE-tick+((world.time-ticktime)/world.tick_lag*100))
|
||||||
if (tick > highest_del_tickusage)
|
if (tick > highest_del_tickusage)
|
||||||
highest_del_tickusage = tick
|
highest_del_tickusage = tick
|
||||||
time = world.timeofday - time
|
time = world.timeofday - time
|
||||||
|
|||||||
@@ -50,27 +50,27 @@ SUBSYSTEM_DEF(lighting)
|
|||||||
stage = SSLIGHTING_STAGE_LIGHTS // Start with Step 1 of course
|
stage = SSLIGHTING_STAGE_LIGHTS // Start with Step 1 of course
|
||||||
|
|
||||||
if(stage == SSLIGHTING_STAGE_LIGHTS)
|
if(stage == SSLIGHTING_STAGE_LIGHTS)
|
||||||
timer = world.tick_usage
|
timer = TICK_USAGE
|
||||||
internal_process_lights(resumed)
|
internal_process_lights(resumed)
|
||||||
cost_lights = MC_AVERAGE(cost_lights, TICK_DELTA_TO_MS(world.tick_usage - timer))
|
cost_lights = MC_AVERAGE(cost_lights, TICK_DELTA_TO_MS(TICK_USAGE - timer))
|
||||||
if(state != SS_RUNNING)
|
if(state != SS_RUNNING)
|
||||||
return
|
return
|
||||||
resumed = 0
|
resumed = 0
|
||||||
stage = SSLIGHTING_STAGE_CORNERS
|
stage = SSLIGHTING_STAGE_CORNERS
|
||||||
|
|
||||||
if(stage == SSLIGHTING_STAGE_CORNERS)
|
if(stage == SSLIGHTING_STAGE_CORNERS)
|
||||||
timer = world.tick_usage
|
timer = TICK_USAGE
|
||||||
internal_process_corners(resumed)
|
internal_process_corners(resumed)
|
||||||
cost_corners = MC_AVERAGE(cost_corners, TICK_DELTA_TO_MS(world.tick_usage - timer))
|
cost_corners = MC_AVERAGE(cost_corners, TICK_DELTA_TO_MS(TICK_USAGE - timer))
|
||||||
if(state != SS_RUNNING)
|
if(state != SS_RUNNING)
|
||||||
return
|
return
|
||||||
resumed = 0
|
resumed = 0
|
||||||
stage = SSLIGHTING_STAGE_OVERLAYS
|
stage = SSLIGHTING_STAGE_OVERLAYS
|
||||||
|
|
||||||
if(stage == SSLIGHTING_STAGE_OVERLAYS)
|
if(stage == SSLIGHTING_STAGE_OVERLAYS)
|
||||||
timer = world.tick_usage
|
timer = TICK_USAGE
|
||||||
internal_process_overlays(resumed)
|
internal_process_overlays(resumed)
|
||||||
cost_overlays = MC_AVERAGE(cost_overlays, TICK_DELTA_TO_MS(world.tick_usage - timer))
|
cost_overlays = MC_AVERAGE(cost_overlays, TICK_DELTA_TO_MS(TICK_USAGE - timer))
|
||||||
if(state != SS_RUNNING)
|
if(state != SS_RUNNING)
|
||||||
return
|
return
|
||||||
resumed = 0
|
resumed = 0
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include "code\world.dm"
|
#include "code\world.dm"
|
||||||
#include "code\__defines\_compile_options.dm"
|
#include "code\__defines\_compile_options.dm"
|
||||||
#include "code\__defines\_planes+layers.dm"
|
#include "code\__defines\_planes+layers.dm"
|
||||||
|
#include "code\__defines\_tick.dm"
|
||||||
#include "code\__defines\admin.dm"
|
#include "code\__defines\admin.dm"
|
||||||
#include "code\__defines\appearance.dm"
|
#include "code\__defines\appearance.dm"
|
||||||
#include "code\__defines\atmos.dm"
|
#include "code\__defines\atmos.dm"
|
||||||
@@ -45,7 +46,6 @@
|
|||||||
#include "code\__defines\species_languages.dm"
|
#include "code\__defines\species_languages.dm"
|
||||||
#include "code\__defines\subsystems.dm"
|
#include "code\__defines\subsystems.dm"
|
||||||
#include "code\__defines\targeting.dm"
|
#include "code\__defines\targeting.dm"
|
||||||
#include "code\__defines\tick.dm"
|
|
||||||
#include "code\__defines\turfs.dm"
|
#include "code\__defines\turfs.dm"
|
||||||
#include "code\__defines\unit_tests.dm"
|
#include "code\__defines\unit_tests.dm"
|
||||||
#include "code\__defines\xenoarcheaology.dm"
|
#include "code\__defines\xenoarcheaology.dm"
|
||||||
|
|||||||
Reference in New Issue
Block a user