-
Notifications
You must be signed in to change notification settings - Fork 565
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sets up structs (pseudo-structs) as a replacement for datums for simp…
…le data storage - Replaces launch metadata datum with a struct - Some minor variable renaming, not super comprehensive tho
- Loading branch information
1 parent
f9cd32b
commit bb7334e
Showing
19 changed files
with
294 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#define DEFSTRUCT(type) /datum/struct/##type; | ||
|
||
#define DEFSTRUCTPROP(type, prop, _can_qdel) \ | ||
/datum/struct/##type/var/##prop; \ | ||
/datum/struct/##type/add_props() { \ | ||
..(); \ | ||
can_qdel += _can_qdel; \ | ||
##prop = STRUCTS.current_struct_idx++; \ | ||
} | ||
|
||
#define ENDDEFSTRUCT(type) \ | ||
/datum/struct/##type/proc/generate() { \ | ||
var/list/struct = new /list(src.len); \ | ||
struct[1] = #type; \ | ||
return struct; \ | ||
} \ | ||
/datum/controller/structs/var/datum/struct/##type/##type; \ | ||
/datum/controller/structs/proc/generate_struct_##type() { \ | ||
##type = new(); \ | ||
} | ||
|
||
#define STRUCT(type) STRUCTS.##type.generate(); | ||
#define PROP(type, prop) STRUCTS.##type.##prop | ||
|
||
// Fun pseudo function: List.[1] works | ||
// However SpacemanDMM throws a fit about the syntax | ||
// #define PROP(type, prop) [STRUCTS.##type.##prop] | ||
|
||
#define ISSTRUCT(to_test, type) (length(to_test) ? to_test[1] == #type : FALSE) | ||
|
||
#define STRUCT_PROP_STARTING_INDEX 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
GLOBAL_REAL(STRUCTS, /datum/controller/structs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/datum/controller/structs | ||
/** | ||
* Value for calculating the index of the struct currently being | ||
* generated | ||
* Should always be above 1, as index 1 is reserved for the struct name | ||
*/ | ||
var/static/current_struct_idx = STRUCT_PROP_STARTING_INDEX | ||
|
||
var/list/structs_datum_in_built_vars | ||
|
||
/datum/controller/structs/New() | ||
if(STRUCTS) | ||
CRASH("Multiple instances of structs controller created") | ||
STRUCTS = src | ||
|
||
var/datum/controller/exclude_these = new | ||
// I know this is dumb but the nested vars list hangs a ref to the datum. This fixes that | ||
var/list/controller_vars = exclude_these.vars.Copy() | ||
controller_vars["vars"] = null | ||
structs_datum_in_built_vars = controller_vars + list(NAMEOF(src, current_struct_idx)) | ||
|
||
QDEL_IN(exclude_these, 0) //signal logging isn't ready | ||
|
||
log_world("[length(vars) - length(structs_datum_in_built_vars)] structs") | ||
|
||
Initialize() | ||
|
||
/datum/controller/structs/Initialize() | ||
var/list/struct_initializers = typesof(/datum/controller/structs/proc) | ||
var/expected_len = length(vars) - length(structs_datum_in_built_vars) | ||
if(length(struct_initializers) != expected_len) | ||
warning("Unable to detect all struct initialization procs! Expected [expected_len] got [length(struct_initializers)]!") | ||
if(length(struct_initializers)) | ||
var/list/expected_struct_initializers = vars - structs_datum_in_built_vars | ||
for(var/initializer in struct_initializers) | ||
expected_struct_initializers -= replacetext("[initializer]", "generate_struct_", "") | ||
log_world("Structs with missing initializers: [expected_struct_initializers.Join(", ")]") | ||
for(var/initializer in struct_initializers) | ||
var/start_tick = world.time | ||
call(src, initializer)() | ||
var/end_tick = world.time | ||
if(end_tick - start_tick) | ||
warning("Struct [replacetext("[initializer]", "generate_struct_", "")] slept during initialization!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/datum/struct | ||
/// The length of the lists to be generated | ||
/// which represent a struct | ||
var/len | ||
|
||
/// Standard list mapped 1:1 to the list produced when | ||
/// struct is created using STRUCT(...) | ||
var/static/list/can_qdel | ||
|
||
/datum/struct/New() | ||
// First element of struct list is a string containing the struct name | ||
can_qdel = list(FALSE) | ||
STRUCTS.current_struct_idx = STRUCT_PROP_STARTING_INDEX | ||
add_props() | ||
// Index will go up by 1 when adding last element | ||
len = STRUCTS.current_struct_idx - 1 | ||
|
||
/datum/struct/proc/add_props() | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
DEFSTRUCT(launch_metadata) | ||
DEFSTRUCTPROP(launch_metadata, pass_flags, FALSE) | ||
DEFSTRUCTPROP(launch_metadata, call_all, FALSE) | ||
DEFSTRUCTPROP(launch_metadata, target, FALSE) | ||
DEFSTRUCTPROP(launch_metadata, range, FALSE) | ||
DEFSTRUCTPROP(launch_metadata, speed, FALSE) | ||
DEFSTRUCTPROP(launch_metadata, thrower, FALSE) | ||
DEFSTRUCTPROP(launch_metadata, spin, FALSE) | ||
DEFSTRUCTPROP(launch_metadata, collision_callbacks, FALSE) | ||
DEFSTRUCTPROP(launch_metadata, end_throw_callbacks, FALSE) | ||
DEFSTRUCTPROP(launch_metadata, dist, FALSE) | ||
ENDDEFSTRUCT(launch_metadata) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.