Skip to content

Commit

Permalink
Fixes the black screen issue (#16610)
Browse files Browse the repository at this point in the history
* won't let us be

* idol

* hmmm

* put that back ii guess

* aishiteru

* maybe?

* spent too many years hiding behind fear

* document the spawn

* cl

---------

Co-authored-by: Matt Atlas <[email protected]>
  • Loading branch information
NonQueueingMatt and Matt Atlas authored Jul 3, 2023
1 parent 839e308 commit c1765c6
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 67 deletions.
1 change: 1 addition & 0 deletions aurorastation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
#include "code\controllers\subsystems\alarm.dm"
#include "code\controllers\subsystems\ao.dm"
#include "code\controllers\subsystems\arrivals.dm"
#include "code\controllers\subsystems\asset_loading.dm"
#include "code\controllers\subsystems\assets.dm"
#include "code\controllers\subsystems\battle_monsters.dm"
#include "code\controllers\subsystems\cargo.dm"
Expand Down
2 changes: 2 additions & 0 deletions code/__defines/subsystem-defines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,5 @@
#define JOBROLE_DEFAULT 0 // This is the default "job role", no special meaning.
#define JOBROLE_SUPERVISOR (1 << 0) // Indicates that the job is a supervisory position, i.e a head of department.
#define SIMPLEDEPT(dept) list(dept = JOBROLE_DEFAULT)

#define ASSET_CROSS_ROUND_CACHE_DIRECTORY "tmp/assets"
1 change: 1 addition & 0 deletions code/__defines/subsystem-priority.dm
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#define SS_PRIORITY_TICKER 100 // Gameticker.
//#define SS_PRIORITY_DEFAULT 50 // This is defined somewhere else.
#define SS_PRIORITY_MOB 40 // Mob Life().
#define SS_PRIORITY_ASSET 40 // Asset loading subsystem - not to be confused with SSassets.
#define SS_PRIORITY_AIR 40 // ZAS processing.
#define SS_PRIORITY_CHAT 30 // Chat
#define SS_PRIORITY_STATPANELS 25 // Statpanels.
Expand Down
33 changes: 33 additions & 0 deletions code/controllers/subsystems/asset_loading.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/// Allows us to lazyload asset datums
/// Anything inserted here will fully load if directly gotten
/// So this just serves to remove the requirement to load assets fully during init
var/datum/controller/subsystem/asset_loading/SSasset_loading

/datum/controller/subsystem/asset_loading
name = "Asset Loading"
priority = SS_PRIORITY_ASSET
flags = SS_NO_INIT
runlevels = RUNLEVEL_LOBBY|RUNLEVELS_DEFAULT
var/list/datum/asset/generate_queue = list()

/datum/controller/subsystem/asset_loading/New()
NEW_SS_GLOBAL(SSasset_loading)

/datum/controller/subsystem/asset_loading/fire(resumed)
while(length(generate_queue))
var/datum/asset/to_load = generate_queue[generate_queue.len]

to_load.queued_generation()

if(MC_TICK_CHECK)
return
generate_queue.len--

/datum/controller/subsystem/asset_loading/proc/queue_asset(datum/asset/queue)
#ifdef DO_NOT_DEFER_ASSETS
stack_trace("We queued an instance of [queue.type] for lateloading despite not allowing it")
#endif
generate_queue += queue

/datum/controller/subsystem/asset_loading/proc/dequeue_asset(datum/asset/queue)
generate_queue -= queue
38 changes: 16 additions & 22 deletions code/modules/asset_cache/asset_cache.dm
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
/*
Asset cache quick users guide:
Make a datum at the bottom of this file with your assets for your thing.
The simple subsystem will most like be of use for most cases.
Then call get_asset_datum() with the type of the datum you created and store the return
Then call .send(client) on that stored return value.
You can set verify to TRUE if you want send() to sleep until the client has the assets.
*/


// Amount of time(ds) MAX to send per asset, if this get exceeded we cancel the sleeping.
// This is doubled for the first asset, then added per asset after
#define ASSET_CACHE_SEND_TIMEOUT 7

#define ASSET_CROSS_ROUND_CACHE_DIRECTORY "tmp/assets"
//These datums are used to populate the asset cache, the proc "register()" does this.
//Place any asset datums you create in asset_list_items.dm

//all of our asset datums, used for referring to these later
var/list/asset_datums = list()
Expand Down Expand Up @@ -164,12 +149,14 @@ var/list/asset_datums = list()
return

// If it's cached, may as well load it now, while the loading is cheap
if(cross_round_cachable)
if(config.cache_assets && cross_round_cachable)
load_immediately = TRUE

create_spritesheets()
if(should_load_immediately())
realize_spritesheets(yield = FALSE)
else
SSasset_loading.queue_asset(src)

for(var/size_id in sizes)
var/size = sizes[size_id]
Expand Down Expand Up @@ -208,9 +195,14 @@ var/list/asset_datums = list()
SSassets.transport.register_asset(res_name, fcopy_rsc(fname))
fdel(fname)

if (cross_round_cachable)
if (config.cache_assets && cross_round_cachable)
write_to_cache()
fully_generated = TRUE
// If we were ever in there, remove ourselves
SSasset_loading.dequeue_asset(src)

/datum/asset/spritesheet/queued_generation()
realize_spritesheets(yield = TRUE)

/// Returns the URL to put in the background:url of the CSS asset
/datum/asset/spritesheet/proc/get_background_url(asset)
Expand Down Expand Up @@ -356,7 +348,6 @@ var/list/asset_datums = list()
/datum/asset/spritesheet/proc/should_load_immediately()
return TRUE


/datum/asset/spritesheet/proc/Insert(sprite_name, icon/I, icon_state="", dir=SOUTH, frame=1, moving=FALSE, icon/forced=FALSE)
if(should_load_immediately())
queuedInsert(sprite_name, I, icon_state, dir, frame, moving)
Expand Down Expand Up @@ -453,6 +444,7 @@ var/list/asset_datums = list()
"faction_Orion.png" = 'html/images/factions/orionlogo.png',
"faction_SCC.png" = 'html/images/factions/scclogo.png'
)
cross_round_cachable = TRUE

/datum/asset/simple/namespaced/fontawesome
legacy = TRUE
Expand All @@ -464,6 +456,7 @@ var/list/asset_datums = list()
"v4shim.css" = 'html/font-awesome/css/v4-shims.min.css'
)
parents = list("font-awesome.css" = 'html/font-awesome/css/all.min.css')
cross_round_cachable = TRUE

/datum/asset/simple/namespaced/tgfont
assets = list(
Expand Down Expand Up @@ -595,6 +588,7 @@ var/list/asset_datums = list()
"kawkabmono.woff" = 'html/fonts/OFL/KawkabMono.woff',
"kaushanscript.woff" = 'html/fonts/OFL/KaushanScript.woff'
)
cross_round_cachable = TRUE

/datum/asset/simple/changelog
legacy = TRUE
Expand Down Expand Up @@ -665,6 +659,7 @@ var/list/asset_datums = list()

/datum/asset/spritesheet/chem_master
name = "chemmaster"
cross_round_cachable = TRUE
var/list/bottle_sprites = list("bottle-1", "bottle-2", "bottle-3", "bottle-4", "bottle-5", "bottle-6")
var/max_pill_sprite = 20

Expand All @@ -678,8 +673,7 @@ var/list/asset_datums = list()

/datum/asset/spritesheet/accents
name = "accents"

/datum/asset/spritesheet/accents/
cross_round_cachable = TRUE

/// Namespace'ed assets (for static css and html files)
/// When sent over a cdn transport, all assets in the same asset datum will exist in the same folder, as their plain names.
Expand Down
2 changes: 1 addition & 1 deletion code/modules/asset_cache/asset_cache_client.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// Process asset cache client topic calls for `"asset_cache_confirm_arrival=[INT]"`
/client/proc/asset_cache_confirm_arrival(job_id)
var/asset_cache_job = round(text2num(job_id))
//because we skip the limiter, we have to make sure this is a valid arrival and not somebody tricking us into letting them append to a list without limit.
//because we skip the limiter, we have to make sure this is a valid arrival and not somebody tricking us into letting them append to a list without limit.
if (asset_cache_job > 0 && asset_cache_job <= last_asset_job && !(completed_asset_jobs["[asset_cache_job]"]))
completed_asset_jobs["[asset_cache_job]"] = TRUE
last_completed_asset_job = max(last_completed_asset_job, asset_cache_job)
Expand Down
55 changes: 26 additions & 29 deletions code/modules/client/client procs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,10 @@ var/list/localhost_addresses = list(
if(!usr || usr != mob) //stops us calling Topic for somebody else's client. Also helps prevent usr=null
return

if(!authed)
if(href_list["authaction"] in list("guest", "forums")) // Protection
..()
return

// Tgui Topic middleware
if(tgui_Topic(href_list))
return

// asset_cache
var/asset_cache_job
if(href_list["asset_cache_confirm_arrival"])
//to_chat(src, "ASSET JOB [href_list["asset_cache_confirm_arrival"]] ARRIVED.")
to_chat(src, "ASSET JOB [href_list["asset_cache_confirm_arrival"]] ARRIVED.")
//because we skip the limiter, we have to make sure this is a valid arrival and not somebody tricking us
// into letting append to a list without limit.
asset_cache_job = asset_cache_confirm_arrival(href_list["asset_cache_confirm_arrival"])
Expand All @@ -58,6 +49,15 @@ var/list/localhost_addresses = list(
asset_cache_preload_data(href_list["asset_cache_preload_data"])
return

if(!authed)
if(href_list["authaction"] in list("guest", "forums")) // Protection
..()
return

// Tgui Topic middleware
if(tgui_Topic(href_list))
return

if(href_list["reload_tguipanel"])
nuke_chat()
if(href_list["reload_statbrowser"])
Expand Down Expand Up @@ -377,13 +377,11 @@ var/list/localhost_addresses = list(
log_access("Failed Login: [key] [computer_id] [address] - Blacklisted BYOND version: [client_version].")
del(src)
return 0

// Instantiate tgui panel
tgui_panel = new(src, "browseroutput")
// Instantiate stat panel
stat_panel = new(src, "statbrowser")

stat_panel.subscribe(src, PROC_REF(on_stat_panel_message))
// Instantiate tgui panel
tgui_panel = new(src, "browseroutput")

if(IsGuestKey(key) && config.external_auth)
src.authed = FALSE
Expand All @@ -399,17 +397,21 @@ var/list/localhost_addresses = list(
src.InitPrefs()
mob.LateLogin()


/// This spawn is the only thing keeping the stat panels and chat working. By removing this spawn, there will be black screens when loading the game.
/// It seems to be affected by the order of statpanel init: if it happens before send_resources(), then the statpanels won't load, but the game won't
/// blackscreen.
spawn(0)
// Initialize stat panel
stat_panel.initialize(
inline_html = file("html/statbrowser.html"),
inline_js = file("html/statbrowser.js"),
inline_css = file("html/statbrowser.css"),
)
addtimer(CALLBACK(src, PROC_REF(check_panel_loaded)), 30 SECONDS)

// Initialize tgui panel
tgui_panel.initialize()

// Initialize stat panel
stat_panel.initialize(
inline_html = file("html/statbrowser.html"),
inline_js = file("html/statbrowser.js"),
inline_css = file("html/statbrowser.css"),
)


/client/proc/InitPrefs()
//preferences datum - also holds some persistant data for the client (because we may as well keep these datums to a minimum)
prefs = preferences_datums[ckey]
Expand Down Expand Up @@ -482,12 +484,7 @@ var/list/localhost_addresses = list(
add_admin_verbs()

// Forcibly enable hardware-accelerated graphics, as we need them for the lighting overlays.
// (but turn them off first, since sometimes BYOND doesn't turn them on properly otherwise)
spawn(5) // And wait a half-second, since it sounds like you can do this too fast.
if(src)
winset(src, null, "command=\".configure graphics-hwmode off\"")
sleep(2) // wait a bit more, possibly fixes hardware mode not re-activating right
winset(src, null, "command=\".configure graphics-hwmode on\"")
winset(src, null, "command=\".configure graphics-hwmode on\"")

send_resources()

Expand Down
41 changes: 41 additions & 0 deletions html/changelogs/mattatlas-yareyare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
################################
# Example Changelog File
#
# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb.
#
# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.)
# When it is, any changes listed below will disappear.
#
# Valid Prefixes:
# bugfix
# wip (For works in progress)
# tweak
# soundadd
# sounddel
# rscadd (general adding of nice things)
# rscdel (general deleting of nice things)
# imageadd
# imagedel
# maptweak
# spellcheck (typo fixes)
# experiment
# balance
# admin
# backend
# security
# refactor
#################################

# Your name.
author: MattAtlas

# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again.
delete-after: True

# Any changes you've made. See valid prefix list above.
# INDENT WITH TWO SPACES. NOT TABS. SPACES.
# SCREW THIS UP AND IT WON'T WORK.
# Also, all entries are changed into a single [] after a master changelog generation. Just remove the brackets when you add new entries.
# Please surround your changes in double quotes ("), as certain characters otherwise screws up compiling. The quotes will not show up in the changelog.
changes:
- bugfix: "Fixed the black screen bug, hopefully."
4 changes: 2 additions & 2 deletions interface/skin.dmf
Original file line number Diff line number Diff line change
Expand Up @@ -954,8 +954,8 @@ window "mainwindow"
menu = "menu"
elem "asset_cache_browser"
type = BROWSER
pos = 424,208
size = 1x1
pos = 0,0
size = 200x200
anchor1 = -1,-1
anchor2 = -1,-1
is-visible = false
Expand Down
Loading

0 comments on commit c1765c6

Please sign in to comment.