Skip to content

Commit

Permalink
Миррор 34775 (#3302)
Browse files Browse the repository at this point in the history
Co-authored-by: Builder13 <null14657322@nullnonexistant.ru>
  • Loading branch information
Builder-13 and Builder13 authored Mar 1, 2025
1 parent fc7f518 commit 402662c
Show file tree
Hide file tree
Showing 14 changed files with 184 additions and 204 deletions.
2 changes: 2 additions & 0 deletions baystation12.dme
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
#include "code\__defines\subsystems.dm"
#include "code\__defines\targeting.dm"
#include "code\__defines\temperature.dm"
#include "code\__defines\time.dm"
#include "code\__defines\topic.dm"
#include "code\__defines\turfs.dm"
#include "code\__defines\webhooks.dm"
Expand Down Expand Up @@ -129,6 +130,7 @@
#include "code\_helpers\sanitize_values.dm"
#include "code\_helpers\spawn_sync.dm"
#include "code\_helpers\storage.dm"
#include "code\_helpers\system.dm"
#include "code\_helpers\text.dm"
#include "code\_helpers\time.dm"
#include "code\_helpers\tools.dm"
Expand Down
8 changes: 1 addition & 7 deletions code/__defines/MC.dm
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,4 @@ if(Datum.is_processing) {\
* SStimer
****/

#define addtimer(args...) _addtimer(args, source ="[__FILE__]#[__LINE__]")

/****
* Helper for waits
****/

#define UNTIL(X) while(!(X)) stoplag()
#define addtimer(args...) _addtimer(args, source ="[__FILE__]#[__LINE__]")
31 changes: 31 additions & 0 deletions code/__defines/time.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/// Multiplies by deciseconds in a second
#define SECOND *10

/// Multiplies by deciseconds in a second
#define SECONDS *10

/// Multiplies by deciseconds in a minute
#define MINUTE *600

/// Multiplies by deciseconds in a minute
#define MINUTES *600

/// Multiplies by deciseconds in an hour
#define HOUR *36000

/// Multiplies by deciseconds in an hour
#define HOURS *36000

/// Multiplies by deciseconds in a day
#define DAY *864000

/// Multiplies by deciseconds in a day
#define DAYS *864000

#define worldtime2stationtime(time) time2text(GLOB.roundstart_hour HOURS + time, "hh:mm")

#define station_time_in_ticks (GLOB.roundstart_hour HOURS + round_duration_in_ticks)

#define duration2stationtime(time) time2text(station_time_in_ticks + time, "hh:mm")

#define round_duration_in_ticks (GLOB.round_start_time ? uptime() - GLOB.round_start_time : 0)
35 changes: 35 additions & 0 deletions code/_helpers/system.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/// Real time in deciseconds the server process has been active
/proc/uptime()
var/static/days = 0
var/static/result = 0
var/static/start_time = world.timeofday
var/static/last_time = start_time
var/time = world.timeofday
if (time == last_time)
return result
if (time < last_time)
++days
last_time = time
result = time - start_time + days DAYS
return result


/**
* Non-blocking sleep that allows server state to advance while the
* caller waits for something to be complete, or to pause its own
* behavior to be neighbourly
*/
/proc/stoplag(initial_delay = world.tick_lag)
if (!Master || !(GAME_STATE & RUNLEVELS_DEFAULT))
sleep(world.tick_lag)
return 1
var/delta
var/total = 0
var/delay = initial_delay / world.tick_lag
do // sleeps have entry overhead from proc duplication so delay scales up under load
delta = delay * max(0.01 * max(world.tick_usage, world.cpu) * max(Master.sleep_delta, 1), 1)
sleep(world.tick_lag * delta)
total += ceil(delta)
delay *= 2
while (world.tick_usage > min(Master.tick_limit_to_run, Master.current_ticklimit))
return total
Loading

0 comments on commit 402662c

Please sign in to comment.