Skip to content

Commit

Permalink
refactor: Opacity Standartisation (#5258)
Browse files Browse the repository at this point in the history
* Opacity Standartization

* Typo
  • Loading branch information
Gottfrei authored Jun 24, 2024
1 parent 13acdbd commit 4cac0a5
Show file tree
Hide file tree
Showing 64 changed files with 298 additions and 276 deletions.
2 changes: 2 additions & 0 deletions code/__DEFINES/dcs/signals.dm
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
#define COMSIG_ATOM_ATTACK "atom_attack"
///called when the atom sucessfully has it's density var changed, from base atom/set_density(): (value)
#define COMSIG_ATOM_SET_DENSITY "atom_set_density"
///from base of atom/set_opacity(): (new_opacity)
#define COMSIG_ATOM_SET_OPACITY "atom_set_opacity"
///from base of atom/experience_pressure_difference(): (pressure_difference, direction, pressure_resistance_prob_delta)
#define COMSIG_ATOM_PRE_PRESSURE_PUSH "atom_pre_pressure_push"
///prevents pressure movement
Expand Down
14 changes: 7 additions & 7 deletions code/__HELPERS/game.dm
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@
Y1+=s
while(Y1!=Y2)
T=locate(X1,Y1,Z)
if(T.opacity)
return 0
if(IS_OPAQUE_TURF(T))
return FALSE
Y1+=s
else
var/m=(32*(Y2-Y1)+(PY2-PY1))/(32*(X2-X1)+(PX2-PX1))
Expand All @@ -258,16 +258,16 @@
else
X1+=signX //Line exits tile horizontally
T=locate(X1,Y1,Z)
if(T.opacity)
return 0
return 1
if(IS_OPAQUE_TURF(T))
return FALSE
return TRUE

/proc/isInSight(var/atom/A, var/atom/B)
/proc/isInSight(atom/A, atom/B)
var/turf/Aturf = get_turf(A)
var/turf/Bturf = get_turf(B)

if(!Aturf || !Bturf)
return 0
return FALSE

return inLineOfSight(Aturf.x, Aturf.y, Bturf.x, Bturf.y, Aturf.z)

Expand Down
39 changes: 20 additions & 19 deletions code/__HELPERS/unsorted.dm
Original file line number Diff line number Diff line change
Expand Up @@ -506,27 +506,28 @@ Returns 1 if the chain up to the area contains the given typepath
weight += I.w_class
return weight

//Step-towards method of determining whether one atom can see another. Similar to viewers()
/proc/can_see(var/atom/source, var/atom/target, var/length=5) // I couldnt be arsed to do actual raycasting :I This is horribly inaccurate.
var/turf/current = get_turf(source)

///Step-towards method of determining whether one atom can see another. Similar to viewers()
///note: this is a line of sight algorithm, view() does not do any sort of raycasting and cannot be emulated by it accurately
/proc/can_see(atom/source, atom/target, length = 5) // I couldnt be arsed to do actual raycasting :I This is horribly inaccurate.
var/turf/current_turf = get_turf(source)
var/turf/target_turf = get_turf(target)
if(!current_turf || !target_turf) // nullspace
return FALSE
if(get_dist(current_turf, target_turf) > length)
return FALSE
if(current_turf == target_turf)//they are on the same turf, source can see the target
return TRUE
var/steps = 1

if(current != target_turf)
current = get_step_towards(current, target_turf)
while(current != target_turf)
if(steps > length)
return 0
if(current.opacity)
return 0
for(var/thing in current)
var/atom/A = thing
if(A.opacity)
return 0
current = get_step_towards(current, target_turf)
steps++

return 1
current_turf = get_step_towards(current_turf, target_turf)
while(current_turf != target_turf)
if(steps > length)
return FALSE
if(IS_OPAQUE_TURF(current_turf))
return FALSE
current_turf = get_step_towards(current_turf, target_turf)
steps++
return TRUE


//Returns: all the areas in the world
Expand Down
47 changes: 47 additions & 0 deletions code/datums/elements/light_blocking.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Attached to movable atoms with opacity. Listens to them move and updates their old and new turf loc's opacity accordingly.
*/
/datum/element/light_blocking
element_flags = ELEMENT_DETACH


/datum/element/light_blocking/Attach(datum/target)
. = ..()
if(!ismovable(target))
return ELEMENT_INCOMPATIBLE
RegisterSignal(target, COMSIG_MOVABLE_MOVED, PROC_REF(on_target_move))
var/atom/movable/movable_target = target
if(!isturf(movable_target.loc))
return
for(var/turf/turf_loc as anything in movable_target.locs)
turf_loc.add_opacity_source(target)


/datum/element/light_blocking/Detach(datum/target)
. = ..()
var/atom/movable/movable_target = target
UnregisterSignal(movable_target, COMSIG_MOVABLE_MOVED)
if(!isturf(movable_target.loc))
return
for(var/turf/turf_loc as anything in movable_target.locs)
turf_loc.remove_opacity_source(target)


///Updates old and new turf loc opacities.
/datum/element/light_blocking/proc/on_target_move(atom/movable/source, atom/old_loc, dir, forced, list/old_locs)
SIGNAL_HANDLER
if(isturf(old_loc))
var/turf/old_turf = old_loc
old_turf.remove_opacity_source(source)
/*
if(old_locs)
for(var/turf/old_turf as anything in old_locs) // after movement refactor
old_turf.remove_opacity_source(source)
else
var/turf/old_turf = old_loc
old_turf.remove_opacity_source(source)
*/
if(isturf(source.loc))
for(var/turf/new_turf as anything in source.locs)
new_turf.add_opacity_source(source)

26 changes: 18 additions & 8 deletions code/game/atoms.dm
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,6 @@
if(light_system == STATIC_LIGHT && light_power && light_range)
update_light()

if(opacity && isturf(loc))
var/turf/T = loc
T.has_opaque_atom = TRUE // No need to recalculate it in this case, it's guranteed to be on afterwards anyways.

if(loc)
loc.InitializedOn(src) // Used for poolcontroller / pool to improve performance greatly. However it also open up path to other usage of observer pattern on turfs.

Expand Down Expand Up @@ -1574,13 +1570,27 @@ GLOBAL_LIST_EMPTY(blood_splatter_icons)


///Setter for the `density` variable to append behavior related to its changing.
/atom/proc/set_density(new_value)
/atom/proc/set_density(new_density)
SHOULD_CALL_PARENT(TRUE)
if(density == new_value)
if(density == new_density)
return
SEND_SIGNAL(src, COMSIG_ATOM_SET_DENSITY, new_density)
. = density
density = new_value
SEND_SIGNAL(src, COMSIG_ATOM_SET_DENSITY, new_value)
density = new_density


/**
* Updates the atom's opacity value.
*
* This exists to act as a hook for associated behavior.
* It notifies (potentially) affected light sources so they can update (if needed).
*/
/atom/proc/set_opacity(new_opacity)
if(new_opacity == opacity)
return
SEND_SIGNAL(src, COMSIG_ATOM_SET_OPACITY, new_opacity)
. = opacity
opacity = new_opacity


///Setter for the `base_pixel_x` variable to append behavior related to its changing.
Expand Down
16 changes: 16 additions & 0 deletions code/game/atoms_movable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@
else
managed_overlays = em_block

if(opacity)
AddElement(/datum/element/light_blocking)

switch(light_system)
if(MOVABLE_LIGHT)
AddComponent(/datum/component/overlay_lighting)
Expand All @@ -137,6 +140,9 @@
unbuckle_all_mobs(force = TRUE)
QDEL_NULL(em_block)

if(opacity)
RemoveElement(/datum/element/light_blocking)

. = ..()
if(loc)
loc.handle_atom_del(src)
Expand Down Expand Up @@ -1080,3 +1086,13 @@
pulledby.stop_pulling()
SEND_SIGNAL(src, COMSIG_MOVABLE_SET_ANCHORED, anchorvalue)


/atom/movable/set_opacity(new_opacity)
. = ..()
if(isnull(.) || !isturf(loc))
return .
if(opacity)
AddElement(/datum/element/light_blocking)
else
RemoveElement(/datum/element/light_blocking)

4 changes: 2 additions & 2 deletions code/game/machinery/camera/camera.dm
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@

/obj/machinery/camera/proc/setViewRange(num = 7)
view_range = num
GLOB.cameranet.updateVisibility(src, 0)
GLOB.cameranet.updateVisibility(src, opacity_check = FALSE)

/obj/machinery/camera/singularity_pull(S, current_size)
if (status && current_size >= STAGE_FIVE) // If the singulo is strong enough to pull anchored objects and the camera is still active, turn off the camera as it gets ripped off the wall.
Expand Down Expand Up @@ -234,7 +234,7 @@
..()
target.update_icon(UPDATE_ICON_STATE)
//Update what it can see.
GLOB.cameranet.updateVisibility(target, FALSE)
GLOB.cameranet.updateVisibility(target, opacity_check = FALSE)


/obj/item/assembly/prox_sensor/camera_upgrade(obj/machinery/camera/target, power_use_update = TRUE)
Expand Down
30 changes: 16 additions & 14 deletions code/game/machinery/camera/motion.dm
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,29 @@
detectTime = -1
return TRUE


/// Returns TRUE if the camera can see the target.
/obj/machinery/camera/proc/can_see(atom/target, length=7) // I stole this from global and modified it to work with Xray cameras.
var/turf/current = get_turf(src)
var/turf/target_turf = get_turf(target)
if(target.invisibility > SEE_INVISIBLE_LIVING || target.alpha == NINJA_ALPHA_INVISIBILITY)
/obj/machinery/camera/proc/can_see(atom/target, length = 7) // I stole this from global and modified it to work with Xray cameras.
if(!target || target.invisibility > SEE_INVISIBLE_LIVING || target.alpha == NINJA_ALPHA_INVISIBILITY)
return FALSE
if(get_dist(current, target_turf) > length)
var/turf/current_turf = get_turf(src)
var/turf/target_turf = get_turf(target)
if(!current_turf || !target_turf || get_dist(current_turf, target_turf) > length)
return FALSE
if(current == target_turf || isXRay())
if(current_turf == target_turf || isXRay())
return TRUE

var/list/line_of_sight = get_line(src, target)
line_of_sight = line_of_sight.Cut(1, 2)
for(var/turf/current_turf as anything in line_of_sight)
if(current_turf.opacity)
var/steps = 1
current_turf = get_step_towards(current_turf, target_turf)
while(current_turf != target_turf)
if(steps > length)
return FALSE
if(IS_OPAQUE_TURF(current_turf))
return FALSE
for(var/atom/movable/thing as anything in current_turf)
if(thing.opacity)
return FALSE
current_turf = get_step_towards(current_turf, target_turf)
steps++
return TRUE


/obj/machinery/camera/HasProximity(atom/movable/AM)
if(isliving(AM))
newTarget(AM)
Expand Down
Loading

0 comments on commit 4cac0a5

Please sign in to comment.