mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-11 18:53:06 +00:00
tiny optimisation
This commit is contained in:
43
code/_helpers/typelists.dm
Normal file
43
code/_helpers/typelists.dm
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
GLOBAL_LIST_EMPTY(typelists)
|
||||||
|
|
||||||
|
#ifndef TESTING
|
||||||
|
|
||||||
|
/datum/proc/typelist(key, list/values = list())
|
||||||
|
var/list/mytypelist = GLOB.typelists[type] || (GLOB.typelists[type] = list())
|
||||||
|
return mytypelist[key] || (mytypelist[key] = values.Copy())
|
||||||
|
|
||||||
|
#else
|
||||||
|
// mostly the same code as above, just more verbose, slower and has tallying for saved lists
|
||||||
|
/datum/proc/typelist(key, list/values)
|
||||||
|
if (!values)
|
||||||
|
values = list()
|
||||||
|
GLOB.typelistkeys |= key
|
||||||
|
if (GLOB.typelists[type])
|
||||||
|
if (GLOB.typelists[type][key])
|
||||||
|
GLOB.typelists[type]["[key]-saved"]++
|
||||||
|
return GLOB.typelists[type][key]
|
||||||
|
else
|
||||||
|
GLOB.typelists[type][key] = values.Copy()
|
||||||
|
else
|
||||||
|
GLOB.typelists[type] = list()
|
||||||
|
GLOB.typelists[type][key] = values.Copy()
|
||||||
|
return GLOB.typelists[type][key]
|
||||||
|
|
||||||
|
GLOBAL_LIST_EMPTY(typelistkeys)
|
||||||
|
|
||||||
|
/proc/tallytypelistsavings()
|
||||||
|
var/savings = list()
|
||||||
|
var/saveditems = list()
|
||||||
|
for (var/key in GLOB.typelistkeys)
|
||||||
|
savings[key] = 0
|
||||||
|
saveditems[key] = 0
|
||||||
|
|
||||||
|
for (var/type in GLOB.typelists)
|
||||||
|
for (var/saving in savings)
|
||||||
|
if (GLOB.typelists[type]["[saving]-saved"])
|
||||||
|
savings[saving] += GLOB.typelists[type]["[saving]-saved"]
|
||||||
|
saveditems[saving] += (GLOB.typelists[type]["[saving]-saved"] * length(GLOB.typelists[type][saving]))
|
||||||
|
|
||||||
|
for (var/saving in savings)
|
||||||
|
to_chat(world, "Savings for [saving]: [savings[saving]] lists, [saveditems[saving]] items")
|
||||||
|
#endif
|
||||||
@@ -104,8 +104,11 @@
|
|||||||
|
|
||||||
var/tip_timer // reference to timer id for a tooltip we might open soon
|
var/tip_timer // reference to timer id for a tooltip we might open soon
|
||||||
|
|
||||||
/obj/item/New()
|
/obj/item/Initialize(mapload)
|
||||||
..()
|
. = ..()
|
||||||
|
/*
|
||||||
|
if(islist(origin_tech))
|
||||||
|
origin_tech = typelist(NAMEOF(src, origin_tech), origin_tech)*/
|
||||||
if(embed_chance < 0)
|
if(embed_chance < 0)
|
||||||
if(sharp)
|
if(sharp)
|
||||||
embed_chance = max(5, round(force/w_class))
|
embed_chance = max(5, round(force/w_class))
|
||||||
|
|||||||
@@ -144,6 +144,7 @@
|
|||||||
#include "code\_helpers\time.dm"
|
#include "code\_helpers\time.dm"
|
||||||
#include "code\_helpers\turfs.dm"
|
#include "code\_helpers\turfs.dm"
|
||||||
#include "code\_helpers\type2type.dm"
|
#include "code\_helpers\type2type.dm"
|
||||||
|
#include "code\_helpers\typelists.dm"
|
||||||
#include "code\_helpers\unsorted.dm"
|
#include "code\_helpers\unsorted.dm"
|
||||||
#include "code\_helpers\unsorted_vr.dm"
|
#include "code\_helpers\unsorted_vr.dm"
|
||||||
#include "code\_helpers\view.dm"
|
#include "code\_helpers\view.dm"
|
||||||
|
|||||||
Reference in New Issue
Block a user