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
Removes some major sleepers, Refactors maploading to be async (100% lag free) #7659
Changes from 17 commits
0d80759
1342094
0973c84
8d40725
9cdfff2
f5f7779
cbe2633
22f987e
b91071e
dcc596f
20aca58
040e249
3e7fedf
681ca00
84a05a5
5b25b05
95bedeb
40554b5
c059ed8
a0d39a7
17dd06b
5ae4a8c
83f8412
1141fe3
1eeaa7d
496aa55
c5db57c
e824fbc
2c511c6
755ea9c
dcb9343
cf41707
4eaf899
de68416
4dc737f
30ca478
c0a80ee
1ef6097
510cfc8
0df6449
d4d206e
b7eecdb
ae932d8
315b980
6322ff7
1c788c4
8310a7c
dd5e58c
e241cfe
1e5c7f0
24a3bc4
b4e60f4
0638ad2
637cd09
aa005bc
4137da0
cb64842
7ce7b43
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
/// Tick overrun debug define | ||
/// This will cause stoplag() to be tracked, and when the MC freezes | ||
/// anything running stoplag() will be logged. | ||
/// Will incur a performance overhead when the controller is frozen, otherwise | ||
/// shouldn't be that intensive. | ||
#define TICK_OVERRUN_DEBUG | ||
|
||
#ifdef TICK_OVERRUN_DEBUG | ||
GLOBAL_VAR_INIT(controller_frozen, FALSE) | ||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,15 @@ SUBSYSTEM_DEF(atoms) | |
initialized = INITIALIZATION_INSSATOMS | ||
|
||
/datum/controller/subsystem/atoms/Initialize(timeofday) | ||
//Wait until map loading is completed | ||
if (length(SSmap_generator.executing_generators) > 0) | ||
to_chat(world, "<span class='boldannounce'>Waiting for [length(SSmap_generator.executing_generators)] map generators...</bold>") | ||
do | ||
SSmap_generator.fire() | ||
sleep(0.5) | ||
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. What's this sleep for? 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. Since fire() is tick checked, if it overruns then the proc will cancel. Without the sleep, byond will trigger the fire() again, which will do nothing since the tick check just instantly fails. The sleep allows the game to process to the next tick, so that the MC_TICK_CHECKs inside fire() can run again. Works similarly to the same way the main MC loop works |
||
while (length(SSmap_generator.executing_generators) > 0) | ||
to_chat(world, "<span class='boldannounce'>Map generators completed, initializing atoms.</bold>") | ||
|
||
GLOB.fire_overlay.appearance_flags = RESET_COLOR | ||
setupGenetics() //to set the mutations' sequence | ||
initialized = INITIALIZATION_INNEW_MAPLOAD | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
SUBSYSTEM_DEF(map_generator) | ||
name = "Map Generator" | ||
wait = 1 | ||
flags = SS_TICKER | SS_NO_INIT | ||
runlevels = ALL | ||
|
||
/// List of all currently executing generator datums | ||
var/list/executing_generators = list() | ||
|
||
/// Index of current run | ||
var/current_run_index | ||
|
||
/// Length of current run | ||
var/current_run_length | ||
|
||
/datum/controller/subsystem/map_generator/stat_entry() | ||
var/list/things = list() | ||
for(var/datum/map_generator/running_generator as() in executing_generators) | ||
things += "{Ticks: [running_generator.ticks]}" | ||
. = ..("GenCnt:[length(executing_generators)], [things.Join(",")]") | ||
|
||
/datum/controller/subsystem/map_generator/fire() | ||
if (!length(executing_generators)) | ||
return | ||
//Reset the queue | ||
if (current_run_index > current_run_length || !current_run_length) | ||
current_run_index = 1 | ||
current_run_length = length(executing_generators) | ||
//Split the tick | ||
MC_SPLIT_TICK_INIT(current_run_length) | ||
//Start processing | ||
while (current_run_index <= current_run_length) | ||
//Get current action | ||
var/datum/map_generator/currently_running = executing_generators[current_run_index] | ||
current_run_index ++ | ||
//Perform generate action | ||
var/completed = TRUE | ||
while (!currently_running.execute_run()) | ||
// We overused our allocated amount of tick | ||
if(MC_TICK_CHECK) | ||
completed = FALSE | ||
break | ||
//We completed | ||
if (completed) | ||
currently_running.complete() | ||
//Remove the currently running generator | ||
executing_generators -= currently_running | ||
//Decrement the current run nidex | ||
current_run_index -- | ||
//Decrement the current run length | ||
current_run_length -- | ||
//Continue to the next process | ||
MC_SPLIT_TICK |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/// ====================================== | ||
/// Ruin generator process holder | ||
/// ====================================== | ||
/datum/map_generator | ||
var/completed = FALSE | ||
var/ticks = 0 | ||
var/list/datum/callback/completion_callbacks = list() | ||
var/list/callback_args | ||
|
||
/// Begin generating | ||
/datum/map_generator/proc/generate(...) | ||
SSmap_generator.executing_generators += src | ||
callback_args = args.Copy(1) | ||
|
||
/datum/map_generator/proc/on_completion(datum/callback/completion_callback) | ||
completion_callbacks += completion_callback | ||
|
||
/// Execute a current run. | ||
/// Returns TRUE if finished | ||
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. it returns constant true not true if finished 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. Yea, the default proc which isn't overriden finishes on the first tick since it does nothing, so it always returns true. When overriden, this may take multiple ticks to complete so the comment tells you what should be returned. |
||
/datum/map_generator/proc/execute_run() | ||
ticks ++ | ||
return TRUE | ||
|
||
/datum/map_generator/proc/complete() | ||
completed = TRUE | ||
var/list/arguments = list(src) | ||
if (callback_args) | ||
arguments += callback_args | ||
for (var/datum/callback/on_completion as() in completion_callbacks) | ||
on_completion?.Invoke(arglist(arguments)) |
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.
Remember to turn it off before merge