mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-07-14 09:35:30 +01:00
Moves ui references from the tgui subsystem to datums themselves (#76215)
## About The Pull Request Unused vars have 0 memory cost, and the ref and list lookup here is REALLY expensive, for both init and foam spreading. ## Why It's Good For The Game Saves 0.2s off a station flood on meta, and 0.17s off init. More time in other qdel heavy areas Pulled off #76104 for the sake of cleanliness
This commit is contained in:
@@ -19,10 +19,8 @@ SUBSYSTEM_DEF(tgui)
|
||||
|
||||
/// A list of UIs scheduled to process
|
||||
var/list/current_run = list()
|
||||
/// A list of open UIs
|
||||
var/list/open_uis = list()
|
||||
/// A list of open UIs, grouped by src_object.
|
||||
var/list/open_uis_by_src = list()
|
||||
/// A list of all open UIs
|
||||
var/list/all_uis = list()
|
||||
/// The HTML base used for all UIs.
|
||||
var/basehtml
|
||||
|
||||
@@ -38,12 +36,12 @@ SUBSYSTEM_DEF(tgui)
|
||||
close_all_uis()
|
||||
|
||||
/datum/controller/subsystem/tgui/stat_entry(msg)
|
||||
msg = "P:[length(open_uis)]"
|
||||
msg = "P:[length(all_uis)]"
|
||||
return ..()
|
||||
|
||||
/datum/controller/subsystem/tgui/fire(resumed = FALSE)
|
||||
if(!resumed)
|
||||
src.current_run = open_uis.Copy()
|
||||
src.current_run = all_uis.Copy()
|
||||
// Cache for sanic speed (lists are references anyways)
|
||||
var/list/current_run = src.current_run
|
||||
while(current_run.len)
|
||||
@@ -53,7 +51,7 @@ SUBSYSTEM_DEF(tgui)
|
||||
if(ui?.user && ui.src_object)
|
||||
ui.process(wait * 0.1)
|
||||
else
|
||||
open_uis.Remove(ui)
|
||||
ui.close(0)
|
||||
if(MC_TICK_CHECK)
|
||||
return
|
||||
|
||||
@@ -172,11 +170,10 @@ SUBSYSTEM_DEF(tgui)
|
||||
* return datum/tgui The found UI.
|
||||
*/
|
||||
/datum/controller/subsystem/tgui/proc/get_open_ui(mob/user, datum/src_object)
|
||||
var/key = "[REF(src_object)]"
|
||||
// No UIs opened for this src_object
|
||||
if(isnull(open_uis_by_src[key]) || !istype(open_uis_by_src[key], /list))
|
||||
if(!LAZYLEN(src_object.open_uis))
|
||||
return null
|
||||
for(var/datum/tgui/ui in open_uis_by_src[key])
|
||||
for(var/datum/tgui/ui in src_object.open_uis)
|
||||
// Make sure we have the right user
|
||||
if(ui.user == user)
|
||||
return ui
|
||||
@@ -192,12 +189,11 @@ SUBSYSTEM_DEF(tgui)
|
||||
* return int The number of UIs updated.
|
||||
*/
|
||||
/datum/controller/subsystem/tgui/proc/update_uis(datum/src_object)
|
||||
var/count = 0
|
||||
var/key = "[REF(src_object)]"
|
||||
// No UIs opened for this src_object
|
||||
if(isnull(open_uis_by_src[key]) || !istype(open_uis_by_src[key], /list))
|
||||
return count
|
||||
for(var/datum/tgui/ui in open_uis_by_src[key])
|
||||
if(!LAZYLEN(src_object.open_uis))
|
||||
return 0
|
||||
var/count = 0
|
||||
for(var/datum/tgui/ui in src_object.open_uis)
|
||||
// Check if UI is valid.
|
||||
if(ui?.src_object && ui.user && ui.src_object.ui_host(ui.user))
|
||||
INVOKE_ASYNC(ui, TYPE_PROC_REF(/datum/tgui, process), wait * 0.1, TRUE)
|
||||
@@ -214,12 +210,11 @@ SUBSYSTEM_DEF(tgui)
|
||||
* return int The number of UIs closed.
|
||||
*/
|
||||
/datum/controller/subsystem/tgui/proc/close_uis(datum/src_object)
|
||||
var/count = 0
|
||||
var/key = "[REF(src_object)]"
|
||||
// No UIs opened for this src_object
|
||||
if(isnull(open_uis_by_src[key]) || !istype(open_uis_by_src[key], /list))
|
||||
return count
|
||||
for(var/datum/tgui/ui in open_uis_by_src[key])
|
||||
if(!LAZYLEN(src_object.open_uis))
|
||||
return 0
|
||||
var/count = 0
|
||||
for(var/datum/tgui/ui in src_object.open_uis)
|
||||
// Check if UI is valid.
|
||||
if(ui?.src_object && ui.user && ui.src_object.ui_host(ui.user))
|
||||
ui.close()
|
||||
@@ -235,12 +230,11 @@ SUBSYSTEM_DEF(tgui)
|
||||
*/
|
||||
/datum/controller/subsystem/tgui/proc/close_all_uis()
|
||||
var/count = 0
|
||||
for(var/key in open_uis_by_src)
|
||||
for(var/datum/tgui/ui in open_uis_by_src[key])
|
||||
// Check if UI is valid.
|
||||
if(ui?.src_object && ui.user && ui.src_object.ui_host(ui.user))
|
||||
ui.close()
|
||||
count++
|
||||
for(var/datum/tgui/ui in all_uis)
|
||||
// Check if UI is valid.
|
||||
if(ui?.src_object && ui.user && ui.src_object.ui_host(ui.user))
|
||||
ui.close()
|
||||
count++
|
||||
return count
|
||||
|
||||
/**
|
||||
@@ -291,13 +285,8 @@ SUBSYSTEM_DEF(tgui)
|
||||
* required ui datum/tgui The UI to be added.
|
||||
*/
|
||||
/datum/controller/subsystem/tgui/proc/on_open(datum/tgui/ui)
|
||||
var/key = "[REF(ui.src_object)]"
|
||||
if(isnull(open_uis_by_src[key]) || !istype(open_uis_by_src[key], /list))
|
||||
open_uis_by_src[key] = list()
|
||||
ui.user.tgui_open_uis |= ui
|
||||
var/list/uis = open_uis_by_src[key]
|
||||
uis |= ui
|
||||
open_uis |= ui
|
||||
LAZYOR(ui.src_object.open_uis, ui)
|
||||
all_uis |= ui
|
||||
|
||||
/**
|
||||
* private
|
||||
@@ -309,18 +298,14 @@ SUBSYSTEM_DEF(tgui)
|
||||
* return bool If the UI was removed or not.
|
||||
*/
|
||||
/datum/controller/subsystem/tgui/proc/on_close(datum/tgui/ui)
|
||||
var/key = "[REF(ui.src_object)]"
|
||||
if(isnull(open_uis_by_src[key]) || !istype(open_uis_by_src[key], /list))
|
||||
return FALSE
|
||||
// Remove it from the list of processing UIs.
|
||||
open_uis.Remove(ui)
|
||||
all_uis -= ui
|
||||
current_run -= ui
|
||||
// If the user exists, remove it from them too.
|
||||
if(ui.user)
|
||||
ui.user.tgui_open_uis.Remove(ui)
|
||||
var/list/uis = open_uis_by_src[key]
|
||||
uis.Remove(ui)
|
||||
if(length(uis) == 0)
|
||||
open_uis_by_src.Remove(key)
|
||||
ui.user.tgui_open_uis -= ui
|
||||
if(ui.src_object)
|
||||
LAZYREMOVE(ui.src_object.open_uis, ui)
|
||||
return TRUE
|
||||
|
||||
/**
|
||||
@@ -355,7 +340,7 @@ SUBSYSTEM_DEF(tgui)
|
||||
for(var/datum/tgui/ui in source.tgui_open_uis)
|
||||
// Inform the UIs of their new owner.
|
||||
ui.user = target
|
||||
target.tgui_open_uis.Add(ui)
|
||||
target.tgui_open_uis += ui
|
||||
// Clear the old list.
|
||||
source.tgui_open_uis.Cut()
|
||||
return TRUE
|
||||
|
||||
Reference in New Issue
Block a user