Skip to content

Commit ecc360a

Browse files
committed
Pointer explaining
1 parent 4e0d6a8 commit ecc360a

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

code/datums/components/psionics/psi_sensitivity.dm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040

4141
/datum/component/psi_sensitivity/proc/modify_sensitivity(var/parent, var/effective_sensitivity)
4242
SIGNAL_HANDLER
43+
// Earlier, SendSignal() sent effective_sensitivity as a pointer by marking it as &effective_sensitivity.
44+
// That means that for this proc, we have the memory address for the original var/effective_sensitivity located in /atom/movable/proc/check_psi_sensitivity()
45+
// By marking it with the asterisk (*), I'm telling the game "Actually, add directly to the original variable from /atom/movable/proc/check_psi_sensitivity()"
46+
// The reason we're doing this via pointer is that this allows any number of psi_sensitivity components to touch that variable.
47+
// If we did this by a Return statement, only the first component would have been allowed to touch it, and all others get ignored.
4348
*effective_sensitivity += sensitivity_modifier
4449

4550
/**

code/modules/psionics/mob/mob_helpers.dm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,15 @@
4141
*/
4242
/atom/movable/proc/check_psi_sensitivity()
4343
var/effective_sensitivity = 0
44+
// effective_sensitivity is being sent as a Pointer by marking it with the Ampersand (&)
45+
// This means that components which have a RegisterSignal() associated with this will receive the memory address of the var/effective_sensitivity in this proc.
46+
// They are then allowed to add or subtract to this proc's var directly, without needing to return a number.
47+
// We have to do this with a pointer because it allows us to obtain a Sum of all psi-sensitivity modifiers.
48+
// If we instead relied on a Return, we would only be able to get the modifier of the first component to respond.
4449
SEND_SIGNAL(src, COMSIG_PSI_CHECK_SENSITIVITY, &effective_sensitivity)
50+
51+
// Pointers can be problematic if they're used to point to a value on a datum, since that can cause unintended hard deletes.
52+
// Here however, their use is acceptable because the pointer will cease to exist as soon as the proc reaches this return statement.
4553
return effective_sensitivity
4654

4755
/mob/living/check_psi_sensitivity()

0 commit comments

Comments
 (0)