Files
Bubberstation/code/datums/elements/decals/_decal.dm
SkyratBot 5f9f60713b [MIRROR] Starlight Polish (Space is blue!) [MDB IGNORE] (#19059)
* Starlight Polish (Space is blue!) (#72886)

<!-- Write **BELOW** The Headers and **ABOVE** The comments else it may
not be viewable. -->
<!-- You can view Contributing.MD for a detailed description of the pull
request process. -->

## About The Pull Request

Adds support to underlays to realize_overlays
Ensures decals properly handle plane offsets
Fixes space lighting double applying if it's changeturf'd into. this
will be important later
Makes solar vis_contents block emissives as expected
Moves transit tube overlays to update_overlays, adds emissive blockers
to them

#### Adds render steps

An expansion on render_target based emissive blockers. 
They allow us to hijack an object's appearance and draw it somewhere
else, or even modify it, THEN draw it somewhere else.
They chain quite nicely

Fixes shuttles deleting z holder objects

#### Makes space emissive, makes walls and floors block emissives
The core idea here goes like this:
We make space glow, and give its overlays some color

This way, the tile and space parallax remain fullbright, along with
anything that doesn't block emissives, but anything that does block
emissives will instead get shaded the color of starlight

This requires a bit of extra work, see later

This is done automatically with render relays, which now support
specifiying layer and color (Need to make an editor for these one of
these days)

The emissive blocking floor stuff requires making a second render plate
to prevent double scaling

Also adds some new layering defines for lighting, and ensures all turf
lights have a layer. We'll get to this soon

#### Makes things in space blue

We color them the same as starlight, by taking advantage of space being
emissive
This means that things in space that block emissive will block it
correctly and be colored blue by the light overlay, but space itself
will remain fullbright

This does require redefining what always_lit means, but nothing but
cordons use that so it's fineee


#### Makes glass above space glow, and some other stuff

Glass tiles that sit above space will now shine light with matching
color to the glasses color. This includes mat tiles.

Glass tiles (not mat because they have no alpha) also only partially
block emissives.
Adds a new proc that uses render steps to acomplish this, essentially
we're cutting out bits below X alpha and drawing what remains as an
emissive.

#### Modifies partial space showing to support glow

Essentially, alongside displaying space as an underlay, we also display
a light overlay colored like starlight.
That starlight overlay gets masked to only be visible in bits that do
not contain any alpha.

We also mask the turf lighting to not go into bits that have no alpha,
to ensure we get the effect we want.
This is done with that lighting layer thing I mentioned earlier.

#### Makes appearance realization's list output ordered

I want it output in order of overlay, sub overlay suboverlay, next
overlay
Need to use insert for that

## Why It's Good For The Game

Pretty!
Also having space be emissive is a very very good way to test for fucked
emissive blockers (If it's broken why are we even drawing the overlay)
I know for a fact mob blockers on lizards and socks are kinda yorked, I
think there's more

<details>
<summary>
Old
</summary>


![image](https://user-images.githubusercontent.com/58055496/213916157-d4b38aa7-3ab6-42a4-989f-7bfba2dc2cba.png)

![image](https://user-images.githubusercontent.com/58055496/213916077-637fa288-bbee-477d-aded-730d9683477e.png)

![image](https://user-images.githubusercontent.com/58055496/213916088-0657a8a2-5627-48e2-8c4b-870c90ef2072.png)

</details>


<details>
<summary>
New
</summary>


![image](https://user-images.githubusercontent.com/58055496/213916107-2af74e64-1817-4a44-b528-180a9160cb9e.png)

![image](https://user-images.githubusercontent.com/58055496/213916115-5fa36fcc-b988-4ccf-850e-21c26ed463d0.png)

![image](https://user-images.githubusercontent.com/58055496/213916120-6833187d-b12e-42a7-ac4b-63c56deb71e5.png)

</details>

## Changelog

<!-- If your PR modifies aspects of the game that can be concretely
observed by players or admins you should add a changelog. If your change
does NOT meet this description, remove this section. Be sure to properly
mark your PRs to prevent unnecessary GBP loss. You can read up on GBP
and it's effects on PRs in the tgstation guides for contributors. Please
note that maintainers freely reserve the right to remove and add tags
should they deem it appropriate. You can attempt to finagle the system
all you want, but it's best to shoot for clear communication right off
the bat. -->

🆑
add: Space now makes things in it starlight faintly blue
fix: Glass floors that display space now properly let space shine
through them, rather then hiding it in the dark
add: Glass floors above space now glow faintly depending on their glass
type
/🆑

<!-- Both 🆑's are required for the changelog to work! You can put
your name to the right of the first 🆑 if you want to overwrite your
GitHub username as author ingame. -->
<!-- You can use multiple of the same prefix (they're only used for the
icon ingame) and delete the unneeded ones. Despite some of the tags,
changelogs should generally represent how a player might be affected by
the changes rather than a summary of the PR's contents. -->

---------

Co-authored-by: Zephyr <12817816+ZephyrTFA@users.noreply.github.com>

* update modular

* Update _decal.dm

* Update _decal.dm

---------

Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com>
Co-authored-by: Zephyr <12817816+ZephyrTFA@users.noreply.github.com>
Co-authored-by: Tom <8881105+tf-4@users.noreply.github.com>
Co-authored-by: lessthanthree <83487515+lessthnthree@users.noreply.github.com>
2023-02-12 00:42:28 -08:00

178 lines
6.7 KiB
Plaintext

/datum/element/decal
element_flags = ELEMENT_BESPOKE|ELEMENT_DETACH_ON_HOST_DESTROY
argument_hash_start_idx = 2
/// Whether this decal can be cleaned.
var/cleanable
/// A description this decal appends to the target's examine message.
var/description
/// If true this was initialized with no set direction - will follow the parent dir.
var/directional
/// The base icon state that this decal was initialized with.
var/base_icon_state
/// What smoothing junction this was initialized with.
var/smoothing
/// The overlay applied by this decal to the target.
var/mutable_appearance/pic
/// Remove old decals and apply new decals after rotation as necessary
/datum/controller/subsystem/processing/dcs/proc/rotate_decals(datum/source, old_dir, new_dir)
SIGNAL_HANDLER
if(old_dir == new_dir)
return
var/list/resulting_decals_params = list() // param lists
var/list/old_decals = list() //instances
if(!source.comp_lookup || !source.comp_lookup[COMSIG_ATOM_UPDATE_OVERLAYS])
//should probably also unregister itself
return
if(length(source.comp_lookup[COMSIG_ATOM_UPDATE_OVERLAYS]))
for(var/datum/element/decal/decal in source.comp_lookup[COMSIG_ATOM_UPDATE_OVERLAYS])
old_decals += decal
resulting_decals_params += list(decal.get_rotated_parameters(old_dir,new_dir))
else
var/datum/element/decal/decal = source.comp_lookup[COMSIG_ATOM_UPDATE_OVERLAYS]
if(!istype(decal))
return
old_decals += decal
resulting_decals_params += list(decal.get_rotated_parameters(old_dir,new_dir))
//Instead we could generate ids and only remove duplicates to save on churn on four-corners symmetry ?
for(var/datum/element/decal/decal in old_decals)
decal.Detach(source)
for(var/result in resulting_decals_params)
source.AddElement(/datum/element/decal, result["icon"], result["icon_state"], result["dir"], PLANE_TO_TRUE(result["plane"]), result["layer"], result["alpha"], result["color"], result["smoothing"], result["cleanable"], result["desc"])
/datum/element/decal/proc/get_rotated_parameters(old_dir,new_dir)
var/rotation = 0
if(directional) //Even when the dirs are the same rotation is coming out as not 0 for some reason
rotation = SIMPLIFY_DEGREES(dir2angle(new_dir)-dir2angle(old_dir))
new_dir = turn(pic.dir,-rotation)
return list(
"icon" = pic.icon,
"icon_state" = base_icon_state,
"dir" = new_dir,
"plane" = pic.plane,
"layer" = pic.layer,
"alpha" = pic.alpha,
"color" = pic.color,
"smoothing" = smoothing,
"cleanable" = cleanable,
"desc" = description
)
/datum/element/decal/Attach(atom/target, _icon, _icon_state, _dir, _plane=FLOAT_PLANE, _layer=FLOAT_LAYER, _alpha=255, _color, _smoothing, _cleanable=FALSE, _description, mutable_appearance/_pic)
. = ..()
if(!isatom(target))
return ELEMENT_INCOMPATIBLE
if(_pic)
pic = _pic
else if(!generate_appearance(_icon, _icon_state, _dir, _plane, _layer, _color, _alpha, _smoothing, target))
return ELEMENT_INCOMPATIBLE
description = _description
cleanable = _cleanable
directional = _dir
base_icon_state = _icon_state
smoothing = _smoothing
RegisterSignal(target,COMSIG_ATOM_UPDATE_OVERLAYS, PROC_REF(apply_overlay), TRUE)
if(target.flags_1 & INITIALIZED_1)
target.update_appearance(UPDATE_OVERLAYS) //could use some queuing here now maybe.
else
RegisterSignal(target,COMSIG_ATOM_AFTER_SUCCESSFUL_INITIALIZE, PROC_REF(late_update_icon), TRUE)
if(isitem(target))
INVOKE_ASYNC(target, TYPE_PROC_REF(/obj/item/, update_slot_icon), TRUE)
if(_dir)
SSdcs.RegisterSignal(target,COMSIG_ATOM_DIR_CHANGE, TYPE_PROC_REF(/datum/controller/subsystem/processing/dcs, rotate_decals), TRUE)
if(!isnull(_smoothing))
RegisterSignal(target, COMSIG_ATOM_SMOOTHED_ICON, PROC_REF(smooth_react), TRUE)
if(_cleanable)
RegisterSignal(target, COMSIG_COMPONENT_CLEAN_ACT, PROC_REF(clean_react), TRUE)
if(_description)
RegisterSignal(target, COMSIG_PARENT_EXAMINE, PROC_REF(examine),TRUE)
RegisterSignal(target, COMSIG_TURF_ON_SHUTTLE_MOVE, PROC_REF(shuttle_move_react),TRUE)
/**
* ## generate_appearance
*
* If the decal was not given an appearance, it will generate one based on the other given arguments.
* element won't be compatible if it cannot do either
* all args are fed into creating an image, they are byond vars for images you'll recognize in the byond docs
* (except source, source is the object whose appearance we're copying.)
*/
/datum/element/decal/proc/generate_appearance(_icon, _icon_state, _dir, _plane, _layer, _color, _alpha, _smoothing, source)
if(!_icon || !_icon_state)
return FALSE
var/temp_image = image(_icon, null, isnull(_smoothing) ? _icon_state : "[_icon_state]-[_smoothing]", _layer, _dir)
pic = new(temp_image)
var/atom/atom_source = source
SET_PLANE_EXPLICIT(pic, _plane, atom_source)
pic.color = _color
pic.alpha = _alpha
return TRUE
/datum/element/decal/Detach(atom/source)
UnregisterSignal(source, list(COMSIG_ATOM_DIR_CHANGE, COMSIG_COMPONENT_CLEAN_ACT, COMSIG_PARENT_EXAMINE, COMSIG_ATOM_UPDATE_OVERLAYS, COMSIG_TURF_ON_SHUTTLE_MOVE, COMSIG_ATOM_SMOOTHED_ICON))
SSdcs.UnregisterSignal(source, COMSIG_ATOM_DIR_CHANGE)
source.update_appearance(UPDATE_OVERLAYS)
if(isitem(source))
INVOKE_ASYNC(source, TYPE_PROC_REF(/obj/item/, update_slot_icon))
SEND_SIGNAL(source, COMSIG_TURF_DECAL_DETACHED, description, cleanable, directional, pic)
return ..()
/datum/element/decal/proc/late_update_icon(atom/source)
SIGNAL_HANDLER
if(istype(source) && !(source.flags_1 & DECAL_INIT_UPDATE_EXPERIENCED_1))
source.flags_1 |= DECAL_INIT_UPDATE_EXPERIENCED_1 // I am so sorry, but it saves like 80ms I gotta
source.update_appearance(UPDATE_OVERLAYS)
UnregisterSignal(source, COMSIG_ATOM_AFTER_SUCCESSFUL_INITIALIZE)
/datum/element/decal/proc/apply_overlay(atom/source, list/overlay_list)
SIGNAL_HANDLER
overlay_list += pic
/datum/element/decal/proc/clean_react(datum/source, clean_types)
SIGNAL_HANDLER
if(clean_types & cleanable)
Detach(source)
return COMPONENT_CLEANED
return NONE
/datum/element/decal/proc/examine(datum/source, mob/user, list/examine_list)
SIGNAL_HANDLER
examine_list += description
/datum/element/decal/proc/shuttle_move_react(datum/source, turf/new_turf)
SIGNAL_HANDLER
if(new_turf == source)
return
Detach(source)
new_turf.AddElement(type, pic.icon, base_icon_state, directional, pic.plane, pic.layer, pic.alpha, pic.color, smoothing, cleanable, description)
/**
* Reacts to the source atom smoothing.
*
* Arguments:
* - [source][/atom]: The source of the signal and recently smoothed atom.
*/
/datum/element/decal/proc/smooth_react(atom/source)
SIGNAL_HANDLER
var/smoothing_junction = source.smoothing_junction
if(smoothing_junction == smoothing)
return NONE
Detach(source)
source.AddElement(type, pic.icon, base_icon_state, directional, PLANE_TO_TRUE(pic.plane), pic.layer, pic.alpha, pic.color, smoothing_junction, cleanable, description)
return NONE