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

Ports lighting improvements to ship event #18

Open
wants to merge 4 commits into
base: ship-event
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions beestation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,8 @@
#include "code\datums\elements\embed.dm"
#include "code\datums\elements\firestacker.dm"
#include "code\datums\elements\forced_gravity.dm"
#include "code\datums\elements\light_blocking.dm"
#include "code\datums\elements\undertile.dm"
#include "code\datums\elements\item_scaling.dm"
#include "code\datums\elements\mechanical_repair.dm"
#include "code\datums\elements\openspace_item_click_handler.dm"
Expand Down
4 changes: 2 additions & 2 deletions code/__DEFINES/dcs/signals/signals_atom.dm
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@
///from obj/machinery/bsa/full/proc/fire(): ()
#define COMSIG_ATOM_BSA_BEAM "atom_bsa_beam_pass"
#define COMSIG_ATOM_BLOCKS_BSA_BEAM 1
///! from base of atom/set_light(): (l_range, l_power, l_color)
#define COMSIG_ATOM_SET_LIGHT "atom_set_light"
///! from base of atom/setDir(): (old_dir, new_dir)
#define COMSIG_ATOM_DIR_CHANGE "atom_dir_change"
///! from base of atom/handle_atom_del(): (atom/deleted)
Expand All @@ -118,6 +116,8 @@
#define COMSIG_ATOM_ORBIT_BEGIN "atom_orbit_begin"
/// called when an atom stops orbiting another atom: (atom)
#define COMSIG_ATOM_ORBIT_STOP "atom_orbit_stop"
///from base of atom/set_opacity(): (new_opacity)
#define COMSIG_ATOM_SET_OPACITY "atom_set_opacity"

/////////////////
/* Attack signals. They should share the returned flags, to standardize the attack chain. */
Expand Down
14 changes: 14 additions & 0 deletions code/__DEFINES/dcs/signals/signals_lighting.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
// All signals send the source datum of the signal as the first argument

//Lightning
///! from base of atom/set_light(): (l_range, l_power, l_color)
#define COMSIG_ATOM_SET_LIGHT "atom_set_light"
/// Blocks [/atom/proc/set_light], [/atom/proc/set_light_power], [/atom/proc/set_light_range], [/atom/proc/set_light_color], [/atom/proc/set_light_on], and [/atom/proc/set_light_flags].
#define COMPONENT_BLOCK_LIGHT_UPDATE (1<<0)
///Called right before the atom changes the value of light_range to a different one, from base atom/set_light_range(): (new_range)
#define COMSIG_ATOM_SET_LIGHT_RANGE "atom_set_light_range"
///Called right before the atom changes the value of light_power to a different one, from base atom/set_light_power(): (new_power)
Expand All @@ -22,3 +26,13 @@
///Called when the movable tries to toggle its dynamic light LIGHTING_ON status, from base atom/movable/lighting_overlay_toggle_on(): (new_state)
#define COMSIG_MOVABLE_LIGHT_OVERLAY_TOGGLE_ON "movable_light_overlay_toggle_on"

///Called right after the atom changes the value of light_power to a different one, from base of [/atom/proc/set_light_power]: (old_power)
#define COMSIG_ATOM_UPDATE_LIGHT_POWER "atom_update_light_power"
///Called right after the atom changes the value of light_range to a different one, from base of [/atom/proc/set_light_range]: (old_range)
#define COMSIG_ATOM_UPDATE_LIGHT_RANGE "atom_update_light_range"
///Called right after the atom changes the value of light_color to a different one, from base of [/atom/proc/set_light_color]: (old_color)
#define COMSIG_ATOM_UPDATE_LIGHT_COLOR "atom_update_light_color"
///Called right after the atom changes the value of light_on to a different one, from base of [/atom/proc/set_light_on]: (old_value)
#define COMSIG_ATOM_UPDATE_LIGHT_ON "atom_update_light_on"
///Called right after the atom changes the value of light_flags to a different one, from base of [/atom/proc/set_light_flags]: (old_flags)
#define COMSIG_ATOM_UPDATE_LIGHT_FLAGS "atom_update_light_flags"
4 changes: 4 additions & 0 deletions code/__DEFINES/flags.dm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
/// Currently covers (1<<0) to (1<<22)
GLOBAL_LIST_INIT(bitflags, list(1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304))

/* Directions */
///All the cardinal direction bitflags.
#define ALL_CARDINALS (NORTH|SOUTH|EAST|WEST)

// for /datum/var/datum_flags
#define DF_USE_TAG (1<<0)
#define DF_VAR_EDITED (1<<1)
Expand Down
2 changes: 1 addition & 1 deletion code/__DEFINES/layers.dm
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
#define DATA_HUD_PLANE 15

//---------- LIGHTING -------------
///Normal 1 per turf dynamic lighting objects
///Normal 1 per turf dynamic lighting underlays
#define LIGHTING_PLANE 100

///Lighting objects that are "free floating"
Expand Down
2 changes: 2 additions & 0 deletions code/__DEFINES/turfs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#define CHANGETURF_INHERIT_AIR 16 //! Inherit air from previous turf. Implies CHANGETURF_IGNORE_AIR
#define CHANGETURF_RECALC_ADJACENT 32 //! Immediately recalc adjacent atmos turfs instead of queuing.

#define IS_OPAQUE_TURF(turf) (turf.directional_opacity == ALL_CARDINALS)

//supposedly the fastest way to do this according to https://gist.github.com/Giacom/be635398926bb463b42a
///Returns a list of turf in a square
#define RANGE_TURFS(RADIUS, CENTER) \
Expand Down
12 changes: 4 additions & 8 deletions code/__HELPERS/atmos.dm
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,13 @@
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
return FALSE
if (IS_OPAQUE_TURF(current))
return FALSE
current = get_step_towards(current, target_turf)
steps++

return 1
return TRUE

///Get the cardinal direction between two atoms
/proc/get_cardinal_dir(atom/start, atom/end)
Expand Down
4 changes: 2 additions & 2 deletions code/__HELPERS/game.dm
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@
Y1+=s
while(Y1!=Y2)
T=locate(X1,Y1,Z)
if(T.opacity)
if(IS_OPAQUE_TURF(T))
return 0
Y1+=s
else
Expand All @@ -287,7 +287,7 @@
else
X1+=signX //Line exits tile horizontally
T=locate(X1,Y1,Z)
if(T.opacity)
if(IS_OPAQUE_TURF(T))
return 0
return 1
#undef SIGNV
Expand Down
1 change: 0 additions & 1 deletion code/__HELPERS/radiation.dm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
/mob/living/simple_animal/revenant,
/obj/effect,
/obj/docking_port,
/atom/movable/lighting_object,
/obj/item/projectile,
/obj/structure/chisel_message,
/mob/living/simple_animal/eminence
Expand Down
2 changes: 2 additions & 0 deletions code/_onclick/hud/rendering/plane_master.dm
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@
appearance_flags = PLANE_MASTER
blend_mode = BLEND_MULTIPLY
alpha = 255

/atom/movable/screen/plane_master/openspace
name = "open space plane master"
plane = OPENSPACE_PLANE
appearance_flags = PLANE_MASTER

/atom/movable/screen/plane_master/openspace/Initialize(mapload)
. = ..()
//add_filter("multiz_lighting_mask", 1, alpha_mask_filter(render_source = LIGHTING_RENDER_TARGET, flags = MASK_INVERSE)) -Bacon: Not ported since I think this has something to do with plane cube
add_filter("first_stage_openspace", 1, drop_shadow_filter(color = "#04080FAA", size = -10))
add_filter("second_stage_openspace", 2, drop_shadow_filter(color = "#04080FAA", size = -15))
add_filter("third_stage_openspace", 3, drop_shadow_filter(color = "#04080FAA", size = -20))
Expand Down
2 changes: 1 addition & 1 deletion code/controllers/subsystem/lighting.dm
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ SUBSYSTEM_DEF(lighting)

queue = objects_queue
for (i in 1 to length(queue))
var/atom/movable/lighting_object/O = queue[i]
var/datum/lighting_object/O = queue[i]

if (QDELETED(O))
continue
Expand Down
2 changes: 1 addition & 1 deletion code/controllers/subsystem/zclear.dm
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ SUBSYSTEM_DEF(zclear)

/datum/controller/subsystem/zclear/New()
. = ..()
ignored_atoms = typecacheof(list(/mob/dead, /mob/camera, /mob/dview, /atom/movable/lighting_object, /obj/effect/abstract/mirage_holder))
ignored_atoms = typecacheof(list(/mob/dead, /mob/camera, /mob/dview, /obj/effect/abstract/mirage_holder))

/datum/controller/subsystem/zclear/Recover()
if(!islist(autowipe)) autowipe = list()
Expand Down
42 changes: 42 additions & 0 deletions code/datums/elements/light_blocking.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* 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)
. = ..()
UnregisterSignal(target, list(COMSIG_MOVABLE_MOVED))
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.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))
if(old_locs)
for(var/turf/old_turf as anything in old_locs)
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)
16 changes: 8 additions & 8 deletions code/datums/martial/wrestling.dm
Original file line number Diff line number Diff line change
Expand Up @@ -364,15 +364,15 @@
var/turf/ST = null
var/falling = 0

for (var/obj/O in oview(1, A))
if(O.density)
if (O == D)
continue
if (O.opacity)
continue
else
for (var/turf/T in oview(1, A))
if (IS_OPAQUE_TURF(T))
continue
for (var/obj/O in T)
if(O.density)
if (O == D)
continue
surface = O
ST = get_turf(O)
ST = T
break

if (surface && (ST && isturf(ST)))
Expand Down
15 changes: 11 additions & 4 deletions code/game/atoms.dm
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,23 @@
var/list/custom_materials
///Bitfield for how the atom handles materials.
var/material_flags = NONE

///Light systems, both shouldn't be active at the same time.
var/light_system = STATIC_LIGHT
///Range of the light in tiles. Zero means no light.
var/light_range = 0
///Intensity of the light. The stronger, the less shadows you will see on the lit area.
var/light_power = 1
///Hexadecimal RGB string representing the colour of the light. White by default.
var/light_color = COLOR_WHITE
///Boolean variable for toggleable lights. Has no effect without the proper light_system, light_range and light_power values.
var/light_on = TRUE
///Bitflags to determine lighting-related atom properties.
var/light_flags = NONE
///Our light source. Don't fuck with this directly unless you have a good reason!
var/tmp/datum/light_source/light
///Any light sources that are "inside" of us, for example, if src here was a mob that's carrying a flashlight, that flashlight's light source would be part of this list.
var/tmp/list/light_sources

var/flags_ricochet = NONE
///When a projectile tries to ricochet off this atom, the projectile ricochet chance is multiplied by this
Expand Down Expand Up @@ -209,10 +220,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 guaranteed to be on afterwards anyways.

if(custom_materials && custom_materials.len)
var/temp_list = list()
for(var/i in custom_materials)
Expand Down
6 changes: 6 additions & 0 deletions code/game/atoms_movable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
if(EMISSIVE_BLOCK_UNIQUE)
render_target = ref(src)
em_block = new(src, render_target)
if(opacity)
AddElement(/datum/element/light_blocking)

QDEL_NULL(em_block)

Expand Down Expand Up @@ -485,6 +487,10 @@
CanAtmosPass = ATMOS_PASS_YES
air_update_turf(TRUE)
loc.handle_atom_del(src)

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

for(var/atom/movable/AM in contents)
qdel(AM)
moveToNullspace()
Expand Down
18 changes: 12 additions & 6 deletions code/game/turfs/change_turf.dm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ GLOBAL_LIST_INIT(blacklisted_automated_baseturfs, typecacheof(list(

/turf/proc/empty(turf_type=/turf/open/space, baseturf_type, list/ignore_typecache, flags)
// Remove all atoms except observers, landmarks, docking ports
var/static/list/ignored_atoms = typecacheof(list(/mob/dead, /obj/effect/landmark, /obj/docking_port, /atom/movable/lighting_object))
var/static/list/ignored_atoms = typecacheof(list(/mob/dead, /obj/effect/landmark, /obj/docking_port))
var/list/allowed_contents = typecache_filter_list_reverse(GetAllContentsIgnoring(ignore_typecache), ignored_atoms)
allowed_contents -= src
for(var/i in 1 to allowed_contents.len)
Expand All @@ -22,10 +22,11 @@ GLOBAL_LIST_INIT(blacklisted_automated_baseturfs, typecacheof(list(
var/obj/O
if(underlays.len) //we have underlays, which implies some sort of transparency, so we want to a snapshot of the previous turf as an underlay
O = new()
O.underlays.Add(T)
O.underlays += T
T.ChangeTurf(type)
if(underlays.len)
T.underlays = O.underlays
T.underlays.Cut()
T.underlays += O.underlays
if(T.icon_state != icon_state)
T.icon_state = icon_state
if(T.icon != icon)
Expand Down Expand Up @@ -85,6 +86,7 @@ GLOBAL_LIST_INIT(blacklisted_automated_baseturfs, typecacheof(list(
var/old_lighting_corner_SE = lighting_corner_SE
var/old_lighting_corner_SW = lighting_corner_SW
var/old_lighting_corner_NW = lighting_corner_NW
var/old_directional_opacity = directional_opacity

var/old_exl = explosion_level
var/old_exi = explosion_id
Expand Down Expand Up @@ -133,9 +135,11 @@ GLOBAL_LIST_INIT(blacklisted_automated_baseturfs, typecacheof(list(
lighting_corner_NW = old_lighting_corner_NW

if(SSlighting.initialized)
recalc_atom_opacity()
lighting_object = old_lighting_object

directional_opacity = old_directional_opacity
recalculate_directional_opacity()

if (old_opacity != opacity || dynamic_lighting != old_dynamic_lighting)
reconsider_lights()

Expand All @@ -144,9 +148,11 @@ GLOBAL_LIST_INIT(blacklisted_automated_baseturfs, typecacheof(list(
lighting_build_overlay()
else
lighting_clear_overlay()
else if(lighting_object && !lighting_object.needs_update)
lighting_object.update()

for(var/turf/open/space/S in RANGE_TURFS(1, src)) //RANGE_TURFS is in code\__HELPERS\game.dm
S.update_starlight()
for(var/turf/open/space/space_tile in RANGE_TURFS(1, src)) //RANGE_TURFS is in code\__HELPERS\game.dm
space_tile.update_starlight()

return W

Expand Down
2 changes: 1 addition & 1 deletion code/game/turfs/open/openspace.dm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ GLOBAL_DATUM_INIT(openspace_backdrop_one_for_all, /atom/movable/openspace_backdr
/turf/open/openspace
name = "open space"
desc = "Watch your step!"
icon_state = "transparent"
icon_state = "invisible"
baseturfs = /turf/open/openspace
CanAtmosPassVertical = ATMOS_PASS_YES
allow_z_travel = TRUE
Expand Down
2 changes: 1 addition & 1 deletion code/game/turfs/open/space/space.dm
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
update_light()

if (opacity)
has_opaque_atom = TRUE
directional_opacity = ALL_CARDINALS

ComponentInitialize()

Expand Down
Loading