Cache tiers rather than recalculating them constantly

This commit is contained in:
Tad Hardesty
2017-11-28 17:59:41 -08:00
parent f66b762383
commit c471e1cb28
2 changed files with 26 additions and 33 deletions
+6 -33
View File
@@ -553,48 +553,21 @@ doesn't have toxins access.
/obj/machinery/computer/rdconsole/proc/ui_techweb() //Legacy code.
var/list/l = list()
var/list/backlog = list()
for(var/v in stored_research.researched_nodes)
backlog += stored_research.researched_nodes[v]
var/list/tiers = list()
var/list/current = list()
for(var/v in stored_research.available_nodes)
if(stored_research.researched_nodes[v])
continue
current += stored_research.available_nodes[v]
while (current.len)
var/list/next = list()
for (var/node_ in current)
var/datum/techweb_node/node = node_
var/current_value = tiers[node]
if (!current_value)
current_value = tiers[node] = 1
for (var/id in node.unlocks)
var/datum/techweb_node/follows = node.unlocks[id]
if (tiers[follows] < current_value + 1)
tiers[follows] = current_value + 1
next += follows
current = next
var/list/columns = list()
var/max_tier = 0
for (var/node_ in tiers)
for (var/node_ in stored_research.tiers)
var/datum/techweb_node/node = node_
var/tier = tiers[node]
var/tier = stored_research.tiers[node]
LAZYINITLIST(columns["[tier]"]) // String hackery to make the numbers associative
columns["[tier]"] += ui_techweb_single_node(node, minimal=(tier != 1))
max_tier = max(max_tier, tier)
l += "<table><tr><th align='left'>Researched</th><th align='left'>Available</th><th align='left'>Future</th></tr><tr>[RDSCREEN_NOBREAK]"
l += "<td valign='top'>[RDSCREEN_NOBREAK]"
for(var/datum/techweb_node/N in backlog)
l += ui_techweb_single_node(N, minimal=TRUE)
for(var/tier in 1 to max_tier)
l += "</td><td valign='top'>[RDSCREEN_NOBREAK]"
for(var/tier in 0 to max_tier)
l += "<td valign='top'>[RDSCREEN_NOBREAK]"
l += columns["[tier]"]
l += "</td></tr></table>[RDSCREEN_NOBREAK]"
l += "</td>[RDSCREEN_NOBREAK]"
l += "</tr></table>[RDSCREEN_NOBREAK]"
return l
/obj/machinery/computer/rdconsole/proc/build_path_icon(atom/item, user)
+20
View File
@@ -19,6 +19,7 @@
var/max_bomb_value = 0
var/organization = "Third-Party" //Organization name, used for display.
var/last_bitcoins = 0 //Current per-second production, used for display only.
var/list/tiers = list() //Assoc list, datum = number, 1 is available, 2 is all reqs are 1, so on
/datum/techweb/New()
for(var/i in SSresearch.techweb_nodes_starting)
@@ -161,6 +162,24 @@
hidden_nodes -= N.id
return TRUE
/datum/techweb/proc/update_tiers(datum/techweb_node/base)
var/list/current = list(base)
while (current.len)
var/list/next = list()
for (var/node_ in current)
var/datum/techweb_node/node = node_
var/tier = 0
if (!researched_nodes[node.id]) // researched is tier 0
for (var/id in node.prereq_ids)
var/prereq_tier = tiers[node.prerequisites[id]]
tier = max(tier, prereq_tier + 1)
if (tier != tiers[node])
tiers[node] = tier
for (var/id in node.unlocks)
next += node.unlocks[id]
current = next
/datum/techweb/proc/update_node_status(datum/techweb_node/node, autoupdate_consoles = TRUE)
var/researched = FALSE
var/available = FALSE
@@ -189,6 +208,7 @@
else
if(visible)
visible_nodes[node.id] = node
update_tiers(node)
if(autoupdate_consoles)
for(var/v in consoles_accessing)
var/obj/machinery/computer/rdconsole/V = v