Merge pull request #10023 from VOREStation/upstream-merge-8011

[MIRROR] Ported updated decls repository from Neb.
This commit is contained in:
Novacat
2021-03-26 13:46:39 +00:00
committed by Chompstation Bot
parent d268d57227
commit 877dfbc049
5 changed files with 60 additions and 27 deletions
+48 -16
View File
@@ -1,4 +1,20 @@
/var/repository/decls/decls_repository = new()
// /decl is a subtype used for singletons that should never have more than one instance
// in existence at a time. If you want to use a /decl you should use a pattern like:
// var/decl/somedecl/mydecl = GET_DECL(/decl/somedecl)
// /decls are created the first time they are fetched from decls_repository and will
// automatically call Initialize() and such when created in this way.
// decls_repository.get_decls_of_type() and decls_repository.get_decls_of_subtype()
// can be used similarly to typesof() and subtypesof(), returning assoc instance lists.
// The /decl commandments:
// I. Thou shalt not create a /decl with new().
// II. Thou shalt not del() or qdel() a /decl.
// III. Thou shalt not write a decl that relies on arguments supplied to New().
// IV. Thou shalt not call Initialize() on a /decl.
var/repository/decls/decls_repository = new()
/repository/decls
var/list/fetched_decls
@@ -11,29 +27,45 @@
fetched_decl_types = list()
fetched_decl_subtypes = list()
/repository/decls/proc/decls_of_type(var/decl_prototype)
. = fetched_decl_types[decl_prototype]
if(!.)
. = get_decls(typesof(decl_prototype))
fetched_decl_types[decl_prototype] = .
/repository/decls/proc/decls_of_subtype(var/decl_prototype)
. = fetched_decl_subtypes[decl_prototype]
if(!.)
. = get_decls(subtypesof(decl_prototype))
fetched_decl_subtypes[decl_prototype] = .
/repository/decls/proc/get_decl(var/decl_type)
ASSERT(ispath(decl_type))
. = fetched_decls[decl_type]
if(!.)
. = new decl_type()
fetched_decls[decl_type] = .
var/decl/decl = .
if(istype(decl))
decl.Initialize()
/repository/decls/proc/get_decls(var/list/decl_types)
. = list()
for(var/decl_type in decl_types)
.[decl_type] = get_decl(decl_type)
.[decl_type] = get_decl(decl_type)
/decls/Destroy()
/repository/decls/proc/get_decls_unassociated(var/list/decl_types)
. = list()
for(var/decl_type in decl_types)
. += get_decl(decl_type)
/repository/decls/proc/get_decls_of_type(var/decl_prototype)
. = fetched_decl_types[decl_prototype]
if(!.)
. = get_decls(typesof(decl_prototype))
fetched_decl_types[decl_prototype] = .
/repository/decls/proc/get_decls_of_subtype(var/decl_prototype)
. = fetched_decl_subtypes[decl_prototype]
if(!.)
. = get_decls(subtypesof(decl_prototype))
fetched_decl_subtypes[decl_prototype] = .
/decl/proc/Initialize()
//SHOULD_CALL_PARENT(TRUE)
//SHOULD_NOT_SLEEP(TRUE)
return
/decl/Destroy()
//SHOULD_CALL_PARENT(FALSE)
crash_with("Prevented attempt to delete a decl instance: [log_info_line(src)]")
return QDEL_HINT_LETMELIVE // Prevents Decl destruction
return QDEL_HINT_LETMELIVE // Prevents decl destruction