From 558f129cc221c4ddd724d77d53d73a82ad6da066 Mon Sep 17 00:00:00 2001
From: AffectedArc07 <25063394+AffectedArc07@users.noreply.github.com>
Date: Fri, 3 Nov 2023 19:31:22 +0000
Subject: [PATCH] Adds SS loading to title screen (#23042)
* Adds SS loading to title screen
* Makes it scroll
---
code/controllers/master.dm | 118 +++++++++++++++++-
.../subsystem/non_firing/SStitlescreen.dm | 9 +-
.../turfs/simulated/walls_indestructible.dm | 13 ++
3 files changed, 131 insertions(+), 9 deletions(-)
diff --git a/code/controllers/master.dm b/code/controllers/master.dm
index 6e14516cb3b..2d8f6d192e5 100644
--- a/code/controllers/master.dm
+++ b/code/controllers/master.dm
@@ -52,6 +52,9 @@ GLOBAL_REAL(Master, /datum/controller/master) = new
/// The type of the last subsystem to be fire()'d.
var/last_type_processed
+ /// Cache for the loading screen - cleared after
+ var/list/ss_in_init_order = list()
+
/// Start of queue linked list
var/datum/controller/subsystem/queue_head
/// End of queue linked list (used for appending to the list)
@@ -215,14 +218,38 @@ GLOBAL_REAL(Master, /datum/controller/master) = new
// Sort subsystems by init_order, so they initialize in the correct order.
sortTim(subsystems, GLOBAL_PROC_REF(cmp_subsystem_init))
- var/start_timeofday = REALTIMEOFDAY
- // Initialize subsystems.
- current_ticklimit = GLOB.configuration.mc.world_init_tick_limit
+ // Get SSs that will init
for(var/datum/controller/subsystem/SS in subsystems)
if(SS.flags & SS_NO_INIT)
continue
+
+ ss_in_init_order += SS
+
+ // Prepare for init text
+ GLOB.title_splash.maptext_x = 96
+ GLOB.title_splash.maptext_y = 32
+ GLOB.title_splash.maptext_width = 480
+ GLOB.title_splash.maptext_height = 480
+
+ var/start_timeofday = REALTIMEOFDAY
+
+ // Initialize subsystems.
+ current_ticklimit = GLOB.configuration.mc.world_init_tick_limit
+
+ for(var/i in 1 to length(ss_in_init_order))
+ var/datum/controller/subsystem/SS = ss_in_init_order[i]
+
+ // Upate the loading screen
+ update_ss_loadingscreen(SS.ss_id, i)
+
+ // Do the do
SS.call_init(REALTIMEOFDAY)
CHECK_TICK
+
+ // Clear init text stuff
+ ss_in_init_order.Cut()
+ GLOB.title_splash.maptext = null
+
current_ticklimit = TICK_LIMIT_RUNNING
var/time = (REALTIMEOFDAY - start_timeofday) / 10
@@ -283,7 +310,7 @@ GLOBAL_REAL(Master, /datum/controller/master) = new
/datum/controller/master/proc/Loop()
. = -1
//Prep the loop (most of this is because we want MC restarts to reset as much state as we can, and because
- // local vars rock
+ // local vars rock)
//all this shit is here so that flag edits can be refreshed by restarting the MC. (and for speed)
var/list/tickersubsystems = list()
@@ -675,3 +702,86 @@ GLOBAL_REAL(Master, /datum/controller/master) = new
. = "[cpu_var]"
if(100 to INFINITY) // >100 = bold red
. = "[cpu_var]"
+
+// Updates SS loading stuff on the lobby
+/datum/controller/master/proc/update_ss_loadingscreen(current_ss_id, loaded_amount)
+ // We are done, clear it
+ if(!length(ss_in_init_order))
+ GLOB.title_splash.maptext = null
+ return
+
+ var/list/columns = list()
+ columns += list(list()) // Init our first column
+
+ var/spacer = " " // 8 characters width space
+ // You can comfortably fit 33 lines of text on the lobby screen, but having an even number makes this easier
+ var/max_height = 32
+ var/either_side = max_height / 2
+
+ var/list/all_rows = list()
+
+ for(var/datum/controller/subsystem/SS in ss_in_init_order)
+ // Handle SS state
+
+ // Loaded - mark it as DONE
+ if(SS.initialized)
+ all_rows += "\[ DONE ] [SS.name]"
+
+ // Loading - mark it as LOAD
+ else if(SS.ss_id == current_ss_id)
+ all_rows += "\[ LOAD ] [SS.name]"
+
+ // Not reached yet - mark it as WAIT
+ else
+ all_rows += "\[ WAIT ] [SS.name]"
+
+ // Now render it on the lobby image - turn the columns to rows
+
+ // First figure out max length
+ var/col_max = 0
+ for(var/entry in all_rows)
+ var/col_len = length(entry)
+ if(col_len > col_max)
+ col_max = col_len
+
+ var/list/formatted_rows = list()
+
+ for(var/entry in all_rows)
+ var/spaces_needed = col_max - length(entry)
+ var/this_entry = "[entry][add_tspace("", spaces_needed)][spacer]"
+
+ formatted_rows += this_entry
+
+ // Now we have the rows, decide what to show, it needs to scroll fluidly
+ var/list/output_rows = list()
+
+ var/ss_total = length(formatted_rows)
+ if(ss_total <= max_height)
+ // We have less rows than height - show it all
+ output_rows = formatted_rows
+
+ else if(loaded_amount < either_side)
+ // We have loaded less than half the display - show the first height entries
+ for(var/i in 1 to max_height)
+ output_rows += formatted_rows[i]
+
+ else if(loaded_amount > (ss_total - either_side))
+ // We have loaded more than the remaining half, show the last height entries
+ for(var/i in 1 to max_height)
+ // Invert it
+ var/offset_i = ss_total - max_height
+ output_rows += formatted_rows[i + offset_i]
+
+ else
+ // Get the first half of our offset
+ var/firsthalf_offset = loaded_amount - either_side
+ for(var/i in 1 to either_side)
+ output_rows += formatted_rows[i + firsthalf_offset]
+
+ // Get the last half of our offset
+ // If we are at SS 14, we need to take from SS 15 and take the next half onwards
+ for(var/i in 1 to either_side)
+ output_rows += formatted_rows[i + loaded_amount]
+
+
+ GLOB.title_splash.maptext = "\n[output_rows.Join("\n")]\n"
diff --git a/code/controllers/subsystem/non_firing/SStitlescreen.dm b/code/controllers/subsystem/non_firing/SStitlescreen.dm
index 115504ece0e..100dff90cda 100644
--- a/code/controllers/subsystem/non_firing/SStitlescreen.dm
+++ b/code/controllers/subsystem/non_firing/SStitlescreen.dm
@@ -30,8 +30,7 @@ SUBSYSTEM_DEF(title)
var/icon/icon = new(fcopy_rsc(file_path))
- for(var/turf/simulated/wall/indestructible/splashscreen/splash in world)
- splash.icon = icon
- // Below operations are needed to centrally place the new splashscreen on the lobby area
- splash.pixel_x = -((icon.Width() - world.icon_size) / 2)
- splash.pixel_y = -((icon.Height() - world.icon_size) / 2)
+ GLOB.title_splash.icon = icon
+ // Below operations are needed to centrally place the new splashscreen on the lobby area
+ GLOB.title_splash.pixel_x = -((icon.Width() - world.icon_size) / 2)
+ GLOB.title_splash.pixel_y = -((icon.Height() - world.icon_size) / 2)
diff --git a/code/game/turfs/simulated/walls_indestructible.dm b/code/game/turfs/simulated/walls_indestructible.dm
index 0cba451c487..9180ba87cdf 100644
--- a/code/game/turfs/simulated/walls_indestructible.dm
+++ b/code/game/turfs/simulated/walls_indestructible.dm
@@ -104,6 +104,9 @@
base_icon_state = "sandstone_wall"
smoothing_flags = SMOOTH_BITMASK
+
+GLOBAL_DATUM(title_splash, /turf/simulated/wall/indestructible/splashscreen)
+
/turf/simulated/wall/indestructible/splashscreen
name = "Space Station 13"
icon = 'config/title_screens/images/blank.png'
@@ -114,6 +117,16 @@
pixel_x = -288
pixel_y = -224
+// This needs to load immediately. I am sad I cant Initialize() this.
+/turf/simulated/wall/indestructible/splashscreen/New(loc)
+ ..()
+ GLOB.title_splash = src
+
+// GC cleanup because some silly bugger will delete this
+/turf/simulated/wall/indestructible/splashscreen/Destroy()
+ GLOB.title_splash = null
+ return ..()
+
/turf/simulated/wall/indestructible/uranium
icon = 'icons/turf/walls/uranium_wall.dmi'
icon_state = "uranium_wall-0"