Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spacemandmm galore #1 #16672

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion code/___linters/spaceman_dmm.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,71 @@

// The SPACEMAN_DMM define is set by the linter and other tooling when it runs.
#ifdef SPACEMAN_DMM
/**
* Sets a return type expression for a proc. The return type can take the forms:

* `/typepath` - a raw typepath. The return type of the proc is the type named.

* `param` - a typepath given as a parameter, for procs which return an instance of the passed-in type.

* `param.type` - the static type of a passed-in parameter, for procs which
* return their input or otherwise another value of the same type.

* `param[_].type` - the static type of a passed-in parameter, with one level
* of `/list` stripped, for procs which select one item from a list. The `[_]`
* may be repeated to strip more levels of `/list`.
*/
#define RETURN_TYPE(X) set SpacemanDMM_return_type = X

/**
* If set, will enable a diagnostic on children of the proc it is set on which do
* not contain any `..()` parent calls. This can help with finding situations
* where a signal or other important handling in the parent proc is being skipped.
* Child procs may set this setting to `0` instead to override the check.
*/
#define SHOULD_CALL_PARENT(X) set SpacemanDMM_should_call_parent = X
#define UNLINT(X) SpacemanDMM_unlint(X)

/**
* If set, raise a warning for any child procs that override this one,
* regardless of if it calls parent or not.
* This functions in a similar way to the `final` keyword in some languages.
* This cannot be disabled by child overrides.
*/
#define SHOULD_NOT_OVERRIDE(X) set SpacemanDMM_should_not_override = X

/**
* If set, raise a warning if the proc or one of the sub-procs it calls
* uses a blocking call, such as `sleep()` or `input()` without using `set waitfor = 0`
* This cannot be disabled by child overrides.
*/
#define SHOULD_NOT_SLEEP(X) set SpacemanDMM_should_not_sleep = X

/**
* If set, ensure a proc is 'pure', such that it does not make any changes
* outside itself or output. This also checks to make sure anything using
* this proc doesn't invoke it without making use of the return value.
* This cannot be disabled by child overrides.
*/
#define SHOULD_BE_PURE(X) set SpacemanDMM_should_be_pure = X

///Private procs can only be called by things of exactly the same type.
#define PRIVATE_PROC(X) set SpacemanDMM_private_proc = X

///Protected procs can only be call by things of the same type *or subtypes*.
#define PROTECTED_PROC(X) set SpacemanDMM_protected_proc = X

///If wrapped in this, will not lint.
#define UNLINT(X) SpacemanDMM_unlint(X)

///If set, overriding their value isn't permitted by types that inherit it.
#define VAR_FINAL var/SpacemanDMM_final

///Private vars can only be called by things of exactly the same type.
#define VAR_PRIVATE var/SpacemanDMM_private

///Protected vars can only be called by things of the same type *or subtypes*.
#define VAR_PROTECTED var/SpacemanDMM_protected

#else
#define RETURN_TYPE(X)
#define SHOULD_CALL_PARENT(X)
Expand Down
60 changes: 47 additions & 13 deletions code/__defines/byond_compat.dm
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,51 @@

// So we want to have compile time guarantees these procs exist on local type, unfortunately 515 killed the .proc/procname syntax so we have to use nameof()
#if DM_VERSION < 515
/// Call by name proc reference, checks if the proc exists on this type or as a global proc
#define PROC_REF(X) (.proc/##X)
/// Call by name proc reference, checks if the proc exists on given type or as a global proc
#define TYPE_PROC_REF(TYPE, X) (##TYPE.proc/##X)
/// Call by name proc reference, checks if the proc is existing global proc
#define GLOBAL_PROC_REF(X) (/proc/##X)

/**
* Call by name proc reference, checks if the proc exists on this type or as a global proc
*
* * X - The proc name
*/
#define PROC_REF(X) (.proc/##X)

/**
* Call by name proc reference, checks if the proc exists on given type or as a global proc
*
* * TYPE - The type (eg. `/datum/something` or `/atom`), without trailing slash
* * X - The proc name
*/
#define TYPE_PROC_REF(TYPE, X) (##TYPE.proc/##X)

/**
* Call by name proc reference, checks if the proc is existing global proc
*
* * X - The proc name
*/
#define GLOBAL_PROC_REF(X) (/proc/##X)

#else
/// Call by name proc reference, checks if the proc exists on this type or as a global proc
#define PROC_REF(X) (nameof(.proc/##X))
/// Call by name proc reference, checks if the proc exists on given type or as a global proc
#define TYPE_PROC_REF(TYPE, X) (nameof(##TYPE.proc/##X))
/// Call by name proc reference, checks if the proc is existing global proc
#define GLOBAL_PROC_REF(X) (/proc/##X)
#endif

/**
* Call by name proc reference, checks if the proc exists on this type or as a global proc
*
* * X - The proc name
*/
#define PROC_REF(X) (nameof(.proc/##X))

/**
* Call by name proc reference, checks if the proc exists on given type or as a global proc
*
* * TYPE - The type (eg. `/datum/something` or `/atom`), without trailing slash
* * X - The proc name
*/
#define TYPE_PROC_REF(TYPE, X) (nameof(##TYPE.proc/##X))

/**
* Call by name proc reference, checks if the proc is existing global proc
*
* * X - The proc name
*/
#define GLOBAL_PROC_REF(X) (/proc/##X)

#endif
1 change: 1 addition & 0 deletions code/__defines/callback.dm
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#define CALLBACK new /datum/callback

#define INVOKE_ASYNC ImmediateInvokeAsync
9 changes: 9 additions & 0 deletions code/datums/callback.dm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
if (length(args) > 2)
arguments = args.Copy(3)

/**
* Runs a function asynchronously, setting the waitfor to zero
*
* In case of sleeps, the parent proc (aka where you call this) will continue its processing while the called proc sleeps
*
* * thingtocall - The object whose function is to be called on, will be set as `src` in said function, or `GLOBAL_PROC` if the proc is a global one
* * proctocall - The process to call, use `PROC_REF`, `TYPE_PROC_REF` or `GLOBAL_PROC_REF` according to your use case. Defines in code\__defines\byond_compat.dm
* * ... - Parameters to pass to said proc (VARIPARAM)
*/
/proc/ImmediateInvokeAsync(thingtocall, proctocall, ...)
set waitfor = FALSE

Expand Down
3 changes: 3 additions & 0 deletions code/game/atoms_init.dm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
created += src

/atom/proc/Initialize(mapload, ...)
SHOULD_CALL_PARENT(TRUE)
SHOULD_NOT_SLEEP(TRUE)

if(initialized)
crash_with("Warning: [src]([type]) initialized multiple times!")
initialized = TRUE
Expand Down
1 change: 1 addition & 0 deletions code/game/gamemodes/changeling/implements/powers/body.dm
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@

for(var/obj/machinery/light/L in view(7))
L.broken()
CHECK_TICK

playsound(src.loc, 'sound/effects/creepyshriek.ogg', 100, 1)

Expand Down
1 change: 1 addition & 0 deletions code/game/gamemodes/vampire/vampire_powers.dm
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@

for(var/obj/machinery/light/L in view(7))
L.broken()
CHECK_TICK

playsound(src.loc, 'sound/effects/creepyshriek.ogg', 100, 1)
vampire.use_blood(90)
Expand Down
9 changes: 6 additions & 3 deletions code/game/machinery/computer/slotmachine.dm
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,15 @@
return FALSE
return TRUE

/obj/machinery/computer/slot_machine/proc/toggle_reel_spin(value, delay = 0) //value is 1 or 0 aka on or off
/obj/machinery/computer/slot_machine/proc/toggle_reel_spin(value) //value is 1 or 0 aka on or off
for(var/list/reel in reels)
reels[reel] = value

if(delay)
sleep(delay)
/obj/machinery/computer/slot_machine/proc/toggle_reel_spin_delay(value, delay = 0) //value is 1 or 0 aka on or off
toggle_reel_spin(value)

if(delay)
sleep(delay)

/obj/machinery/computer/slot_machine/proc/randomize_reels()
for(var/reel in reels)
Expand Down
3 changes: 2 additions & 1 deletion code/game/machinery/firealarm.dm
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@
pixel_y = DIR2PIXEL_Y(dir)

if(isContactLevel(z))
set_security_level(security_level ? get_security_level() : "green")
INVOKE_ASYNC(GLOBAL_PROC, GLOBAL_PROC_REF(set_security_level), (security_level ? get_security_level() : "green"))

soundloop = new(src, FALSE)

var/area/A = get_area(src)
Expand Down
1 change: 1 addition & 0 deletions code/game/machinery/station_holomap.dm
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
active_power_usage = 0

/obj/machinery/station_map/mobile/Initialize()
SHOULD_CALL_PARENT(FALSE)
init_map()

initialized = TRUE
Expand Down
1 change: 1 addition & 0 deletions code/game/objects/effects/decals/Cleanable/fuel.dm
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
var/amount = 1

/obj/effect/decal/cleanable/foam/Initialize(mapload, amt = 1, nologs = 0)
SHOULD_CALL_PARENT(FALSE)
src.amount = amt

var/has_spread = 0
Expand Down
2 changes: 2 additions & 0 deletions code/game/objects/items/devices/radio/intercom.dm
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@
add_overlay(screen_overlays["intercom_l"])

/obj/item/device/radio/intercom/broadcasting/Initialize()
SHOULD_CALL_PARENT(FALSE)

set_broadcasting(TRUE)

initialized = TRUE
Expand Down
2 changes: 2 additions & 0 deletions code/game/objects/structures/window.dm
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,8 @@
return ..(adjacencies, dir_mods)

/obj/structure/window/full/Initialize(mapload, start_dir = null, constructed = 0)
SHOULD_CALL_PARENT(FALSE)

if (!mapload && constructed)
state = 0

Expand Down
17 changes: 14 additions & 3 deletions code/game/turfs/simulated.dm
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@
slip_stun = 4

if(M.slip("the [floor_type] floor",slip_stun) && slip_dist)
for (var/i in 1 to slip_dist)
sleep(1)
step(M, M.dir)
INVOKE_ASYNC(src, PROC_REF(slip_mob), M, slip_dist)

if(M.lying)
return ..()
Expand All @@ -116,6 +114,19 @@

..(A, OL)

/**
* Slips a mob, moving it for N tiles
*
* Should be called asyncronously, as this process sleep
*
* * mob_to_slip - The mob that should be slipped
* * slip_distance - How many tiles to slip the mob for
*/
/turf/simulated/proc/slip_mob(var/mob/mob_to_slip, var/slip_distance)
for (var/i in 1 to slip_distance)
sleep(1)
step(mob_to_slip, mob_to_slip.dir)

//returns TRUE if made bloody, returns FALSE otherwise
/turf/simulated/add_blood(mob/living/carbon/human/M as mob)
if (!..())
Expand Down
4 changes: 2 additions & 2 deletions code/game/turfs/simulated/walls.dm
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
plant.update_icon()
plant.pixel_x = 0
plant.pixel_y = 0
plant.update_neighbors()
INVOKE_ASYNC(src, TYPE_PROC_REF(/obj/effect/plant, update_neighbors))

/turf/simulated/wall/ChangeTurf(var/newtype)
clear_plants()
Expand Down Expand Up @@ -206,7 +206,7 @@
else
O.forceMove(src)

clear_plants()
INVOKE_ASYNC(src, PROC_REF(clear_plants))
clear_bulletholes()
material = SSmaterials.get_material_by_name("placeholder")
reinf_material = null
Expand Down
2 changes: 2 additions & 0 deletions code/game/turfs/space/space.dm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

// Copypaste of parent for performance.
/turf/space/Initialize()
SHOULD_CALL_PARENT(FALSE)

if(use_space_appearance)
appearance = SSskybox.space_appearance_cache[(((x + y) ^ ~(x * y) + z) % 25) + 1]
if(config.starlight && use_starlight && lighting_overlays_initialized)
Expand Down
2 changes: 2 additions & 0 deletions code/game/turfs/turf.dm
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
// Parent code is duplicated in here instead of ..() for performance reasons.
// There's ALSO a copy of this in mine_turfs.dm!
/turf/Initialize(mapload, ...)
SHOULD_CALL_PARENT(FALSE)

if (initialized)
crash_with("Warning: [src]([type]) initialized multiple times!")

Expand Down
2 changes: 2 additions & 0 deletions code/game/turfs/unsimulated/floor.dm
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
return

/turf/unsimulated/mask/Initialize()
SHOULD_CALL_PARENT(FALSE)

initialized = TRUE
return

Expand Down
Loading
Loading