Skip to content

Commit

Permalink
Optimizes /obj/New() by removing access generation
Browse files Browse the repository at this point in the history
Previously, every single /obj would parse the req_access_txt and req_one_access_txt strings when it was created, and turn them into a list of numbers for the access system.
This is now done the first time check_access() is called, so only objects that actually use the system will have the lists generated.

Signed-off-by: Mloc-Argent <[email protected]>
  • Loading branch information
mloc committed Mar 2, 2014
1 parent d6a830a commit 3f273f5
Showing 1 changed file with 18 additions and 25 deletions.
43 changes: 18 additions & 25 deletions code/game/jobs/access.dm
Original file line number Diff line number Diff line change
Expand Up @@ -84,29 +84,6 @@
/obj/var/list/req_one_access = null
/obj/var/req_one_access_txt = "0"

/obj/New()
..()
//NOTE: If a room requires more than one access (IE: Morgue + medbay) set the req_acesss_txt to "5;6" if it requires 5 and 6
if(src.req_access_txt)
var/list/req_access_str = text2list(req_access_txt,";")
if(!req_access)
req_access = list()
for(var/x in req_access_str)
var/n = text2num(x)
if(n)
req_access += n

if(src.req_one_access_txt)
var/list/req_one_access_str = text2list(req_one_access_txt,";")
if(!req_one_access)
req_one_access = list()
for(var/x in req_one_access_str)
var/n = text2num(x)
if(n)
req_one_access += n



//returns 1 if this mob has sufficient access to use this object
/obj/proc/allowed(mob/M)
//check if it doesn't require any access at all
Expand Down Expand Up @@ -134,9 +111,25 @@
return null

/obj/proc/check_access(obj/item/I)
//These generations have been moved out of /obj/New() because they were slowing down the creation of objects that never even used the access system.
if(!src.req_access)
src.req_access = list()
if(src.req_access_txt)
var/list/req_access_str = text2list(req_access_txt,";")
for(var/x in req_access_str)
var/n = text2num(x)
if(n)
req_access += n

if(!src.req_one_access)
src.req_one_access = list()
if(src.req_one_access_txt)
var/list/req_one_access_str = text2list(req_one_access_txt,";")
for(var/x in req_one_access_str)
var/n = text2num(x)
if(n)
req_one_access += n

if(!src.req_access && !src.req_one_access) //no requirements
return 1
if(!istype(src.req_access, /list)) //something's very wrong
return 1

Expand Down

0 comments on commit 3f273f5

Please sign in to comment.