Skip to content

Commit

Permalink
tweak(half-o-codebase): ports emissives, SSoverlays, on_update_icon()…
Browse files Browse the repository at this point in the history
…, mapview character preview, etc.

Too much of a mess to actually describe it.
PR #10924
  • Loading branch information
TobyThorne authored Nov 24, 2023
1 parent e0ddfaf commit 96f3cdf
Show file tree
Hide file tree
Showing 583 changed files with 2,753 additions and 2,015 deletions.
4 changes: 4 additions & 0 deletions baystation12.dme
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "code\__defines\deity.dm"
#include "code\__defines\dna.dm"
#include "code\__defines\donations_defines.dm"
#include "code\__defines\emissives.dm"
#include "code\__defines\explosion.dm"
#include "code\__defines\feedback.dm"
#include "code\__defines\filters.dm"
Expand Down Expand Up @@ -135,6 +136,7 @@
#include "code\_helpers\auxtools.dm"
#include "code\_helpers\builtin_proc_callers.dm"
#include "code\_helpers\cmp.dm"
#include "code\_helpers\emissives.dm"
#include "code\_helpers\files.dm"
#include "code\_helpers\functional.dm"
#include "code\_helpers\game.dm"
Expand Down Expand Up @@ -239,6 +241,7 @@
#include "code\controllers\subsystems\mapping.dm"
#include "code\controllers\subsystems\misc_late.dm"
#include "code\controllers\subsystems\open_space.dm"
#include "code\controllers\subsystems\overlays.dm"
#include "code\controllers\subsystems\plants.dm"
#include "code\controllers\subsystems\radiation.dm"
#include "code\controllers\subsystems\shuttle.dm"
Expand Down Expand Up @@ -278,6 +281,7 @@
#include "code\datums\datum.dm"
#include "code\datums\hierarchy.dm"
#include "code\datums\mind.dm"
#include "code\datums\mutable_appearance.dm"
#include "code\datums\position_point_vector.dm"
#include "code\datums\progressbar.dm"
#include "code\datums\recipe.dm"
Expand Down
10 changes: 10 additions & 0 deletions code/__defines/__renderer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@
#define ABOVE_HUD_PLANE 8
#define ABOVE_HUD_LAYER 5

/// This plane masks out lighting, to create an "emissive" effect for e.g glowing screens in otherwise dark areas.
#define EMISSIVE_PLANE 10
#define EMISSIVE_TARGET "*emissive"
/// The layer you should use when you -really- don't want an emissive overlay to be blocked.
#define EMISSIVE_LAYER_UNBLOCKABLE 9999

/// For previews in Character setup. I have no fucking idea why it's like that, and at this point I'm not sure
/// I'd ever want to. It DOES work somehow and I'm more than willing to just keep things the way they are. ~ToTh
#define PREVIEW_PLANE 20

//-------------------- Rendering ---------------------

#define LETTERBOX_RENDERER "LETTERBOX"
Expand Down
34 changes: 34 additions & 0 deletions code/__defines/_render.dm
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ INITIALIZE_IMMEDIATE(/atom/movable/renderer)
/atom/movable/renderer/lighting/Initialize(mapload, mob/owner)
. = ..()
owner.overlay_fullscreen("lighting_backdrop", /obj/screen/fullscreen/lighting_backdrop)
filters += filter(
type = "alpha",
render_source = EMISSIVE_TARGET,
flags = MASK_INVERSE
)

/// Draws visuals that should not be affected by darkness.
/atom/movable/renderer/above_lighting
Expand Down Expand Up @@ -283,3 +288,32 @@ INITIALIZE_IMMEDIATE(/atom/movable/renderer)
icon_state = "singularity_s11"
pixel_x = -176
pixel_y = -176


/* *
* This system works by exploiting BYONDs color matrix filter to use layers to handle emissive blockers.
*
* Emissive overlays are pasted with an atom color that converts them to be entirely some specific color.
* Emissive blockers are pasted with an atom color that converts them to be entirely some different color.
* Emissive overlays and emissive blockers are put onto the same plane.
* The layers for the emissive overlays and emissive blockers cause them to mask eachother similar to normal BYOND objects.
* A color matrix filter is applied to the emissive plane to mask out anything that isn't whatever the emissive color is.
* This is then used to alpha mask the lighting plane.
*
* This works best if emissive overlays applied only to objects that emit light,
* since luminosity=0 turfs may not be rendered.
*/

/atom/movable/renderer/emissive
name = "Emissive"
group = RENDER_GROUP_NONE
plane = EMISSIVE_PLANE
mouse_opacity = MOUSE_OPACITY_UNCLICKABLE
render_target_name = EMISSIVE_TARGET

/atom/movable/renderer/emissive/Initialize()
. = ..()
filters += filter(
type = "color",
color = GLOB.em_mask_matrix
)
25 changes: 25 additions & 0 deletions code/__defines/emissives.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

// Emissive blockers

/// For anything that shouldn't block emissives. Small objects or translucent objects primarily
#define EMISSIVE_BLOCK_NONE 0
/// For anything that doesn't change outline or opaque area much or at all.
#define EMISSIVE_BLOCK_GENERIC 1
/// Uses a dedicated render_target object to copy the entire appearance in real time to the blocking layer. For things that can change in appearance a lot from the base state, like humans.
#define EMISSIVE_BLOCK_UNIQUE 2

/// The color matrix applied to all emissive overlays. Should be solely dependent on alpha and not have RGB overlap with [EM_BLOCK_COLOR].
#define EMISSIVE_COLOR list(0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,1, 1,1,1,0)
/// A globaly cached version of [EMISSIVE_COLOR] for quick access.
GLOBAL_LIST_INIT(emissive_color, EMISSIVE_COLOR)
/// The color matrix applied to all emissive blockers. Should be solely dependent on alpha and not have RGB overlap with [EMISSIVE_COLOR].
#define EM_BLOCK_COLOR list(0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,1, 0,0,0,0)
/// A globaly cached version of [EM_BLOCK_COLOR] for quick access.
GLOBAL_LIST_INIT(em_block_color, EM_BLOCK_COLOR)
/// The color matrix used to mask out emissive blockers on the emissive plane. Alpha should default to zero, be solely dependent on the RGB value of [EMISSIVE_COLOR], and be independant of the RGB value of [EM_BLOCK_COLOR].
#define EM_MASK_MATRIX list(0,0,0,1/3, 0,0,0,1/3, 0,0,0,1/3, 0,0,0,0, 1,1,1,0)
/// A globally cached version of [EM_MASK_MATRIX] for quick access.
GLOBAL_LIST_INIT(em_mask_matrix, EM_MASK_MATRIX)

/// A set of appearance flags applied to all emissive and emissive blocker overlays.
#define EMISSIVE_APPEARANCE_FLAGS (KEEP_APART|KEEP_TOGETHER|RESET_COLOR|NO_CLIENT_COLOR)
1 change: 1 addition & 0 deletions code/__defines/flags.dm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ GLOBAL_LIST_INIT(bitflags, list(1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 204
#define ATOM_FLAG_FULLTILE_OBJECT 0x0040 // Blocks interactions with most atoms on the same tile, except mobs, items and anything that has the flag below, i.e. fulltile windows
#define ATOM_FLAG_ADJACENT_EXCEPTION 0x0080 // Skips adjacent checks for atoms that should always be reachable in window tiles
#define ATOM_FLAG_IGNORE_RADIATION 0x0100 // It will not produce any radiation when it will be a radiation source.
#define ATOM_AWAITING_OVERLAY_UPDATE 0x0400 // SSoverlays must update this atom's overlays.

#define OBJ_FLAG_ANCHORABLE 0x0001 // This object can be stuck in place with a tool
#define OBJ_FLAG_CONDUCTIBLE 0x0002 // Conducts electricity. (metal etc.)
Expand Down
3 changes: 2 additions & 1 deletion code/__defines/subsystem-priority.dm
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
#define SS_PRIORITY_DEFAULT 50 // Default priority for all processes levels

// SS_TICKER
#define SS_PRIORITY_ICON_UPDATE 20 // Queued icon updates. Mostly used by APCs and tables.
#define SS_PRIORITY_CHAT 100
#define SS_PRIORITY_THINK 90 // Datums thinking.
#define SS_PRIORITY_OVERLAYS 20
#define SS_PRIORITY_ICON_UPDATE 10 // Queued icon updates. Mostly used by APCs and tables.

// Normal
#define SS_PRIORITY_TICKER 100 // Gameticker.
Expand Down
1 change: 1 addition & 0 deletions code/__defines/subsystems.dm
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#define SS_INIT_ALARM -3
#define SS_INIT_SHUTTLE -4
#define SS_INIT_LIGHTING -5
#define SS_INIT_OVERLAYS -6
#define SS_INIT_XENOARCH -10
#define SS_INIT_BAY_LEGACY -12
#define SS_INIT_STORYTELLER -15
Expand Down
29 changes: 29 additions & 0 deletions code/_helpers/emissives.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

/// Produces a mutable appearance glued to the [EMISSIVE_PLANE] dyed to be the [EMISSIVE_COLOR].
/proc/emissive_appearance(icon, icon_state = "", layer = FLOAT_LAYER, alpha = 255, appearance_flags = 0)
var/mutable_appearance/appearance = mutable_appearance(icon = icon, icon_state = icon_state, layer = layer, plane = EMISSIVE_PLANE, flags = appearance_flags|EMISSIVE_APPEARANCE_FLAGS)
appearance.alpha = alpha
appearance.blend_mode = BLEND_OVERLAY
appearance.color = GLOB.emissive_color
return appearance

/// Produces a mutable appearance glued to the [EMISSIVE_PLANE] dyed to be the [EM_BLOCK_COLOR].
/proc/emissive_blocker(icon, icon_state = "", layer = FLOAT_LAYER, alpha = 255, appearance_flags = 0, source = null)
var/mutable_appearance/appearance = mutable_appearance(icon = icon, icon_state = icon_state, layer = layer, plane = EMISSIVE_PLANE, flags = appearance_flags|EMISSIVE_APPEARANCE_FLAGS)
appearance.color = GLOB.em_block_color
if(source)
appearance.render_source = source
// Since only render_target handles transform we don't get any applied transform "stacking"
appearance.appearance_flags |= RESET_TRANSFORM
return appearance

// Designed to be a faster version of the above, for most use-cases
/proc/fast_emissive_blocker(atom/make_blocker)
var/mutable_appearance/blocker = new()
blocker.icon = make_blocker.icon
blocker.icon_state = make_blocker.icon_state
blocker.appearance_flags |= make_blocker.appearance_flags | EMISSIVE_APPEARANCE_FLAGS
blocker.dir = make_blocker.dir
blocker.color = GLOB.em_block_color
blocker.plane = EMISSIVE_PLANE
return blocker
42 changes: 38 additions & 4 deletions code/_helpers/icons.dm
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,6 @@
if(gray <= tone_gray) return BlendRGB("#000000", tone, gray / (tone_gray || 1))
else return BlendRGB(tone, "#ffffff", (gray - tone_gray) / ((255 - tone_gray) || 1))


/*
Get flat icon by DarkCampainger. As it says on the tin, will return an icon with all the overlays
as a single icon. Useful for when you want to manipulate an icon via the above as overlays are not normally included.
Expand Down Expand Up @@ -506,7 +505,7 @@

var/render_icon = curicon

if (render_icon)
if(render_icon)
var/curstates = icon_states(curicon)
if(!(curstate in curstates))
if ("" in curstates)
Expand Down Expand Up @@ -559,7 +558,11 @@
var/addY1 = 0
var/addY2 = 0

for(var/image/layer_image as anything in layers)
for(var/I in layers)
var/image/layer_image = I
if(layer_image.plane == EMISSIVE_PLANE) // Just replace this with whatever it is TG is doing these days sometime. Getflaticon breaks emissives
continue

if(layer_image.alpha == 0)
continue

Expand Down Expand Up @@ -664,7 +667,7 @@
if(2) I.pixel_x++
if(3) I.pixel_y--
if(4) I.pixel_y++
overlays += I // And finally add the overlay.
AddOverlays(I) // And finally add the overlay.

// For determining the color of holopads based on whether they're short or long range.
#define HOLOPAD_SHORT_RANGE 1
Expand Down Expand Up @@ -907,3 +910,34 @@
return "<img class='game-icon' src='data:image/png;base64,[cached]'>"

CRASH("[thing] is must be a path or an icon")

/mob/living/carbon/human/proc/generate_preview()
var/icon/flat = icon('icons/effects/blank.dmi') // Final flattened icon

// Layers will be a sorted list of icons/overlays, based on the order in which they are displayed
var/list/layers = overlays.Copy()
var/icon/add // Icon of overlay being added

for(var/I in layers)
if(isnull(I))
continue
var/image/layer_image = I
if(layer_image.plane != FLOAT_PLANE)
continue

if(!layer_image.icon)
continue

if(layer_image.alpha == 0)
continue

//add = icon(layer_image.icon, layer_image.icon_state, dir)
add = getFlatIcon(image(I), dir, null, null, null, FALSE, TRUE, TRUE)
flat.Blend(add, ICON_OVERLAY)

if(color)
flat.Blend(color, ICON_MULTIPLY)
if(alpha < 255)
flat.Blend(rgb(255, 255, 255, alpha), ICON_MULTIPLY)

return icon(flat, "", SOUTH)
2 changes: 1 addition & 1 deletion code/_helpers/surgery.dm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
/// Creates and "centers" organ image for later use inside radial menu.
/proc/agjust_organ_image(obj/item/organ/O)
var/image/I = image(icon = O.icon, icon_state = O.icon_state)
I.overlays = O.overlays
I.CopyOverlays(O)
I.pixel_y = -5
return I
3 changes: 1 addition & 2 deletions code/_helpers/unsorted.dm
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,6 @@ Turf and target are seperate in case you want to teleport some distance from a t
var/old_dir1 = T.dir
var/old_icon_state1 = T.icon_state
var/old_icon1 = T.icon
var/old_overlays = T.overlays.Copy()
var/old_underlays = T.underlays.Copy()

if(platingRequired)
Expand All @@ -787,7 +786,7 @@ Turf and target are seperate in case you want to teleport some distance from a t
X.set_dir(old_dir1)
X.icon_state = old_icon_state1
X.icon = old_icon1 //Shuttle floors are in shuttle.dmi while the defaults are floors.dmi
X.overlays = old_overlays
X.CopyOverlays(T)
X.underlays = old_underlays

var/list/objs = new /list()
Expand Down
Loading

0 comments on commit 96f3cdf

Please sign in to comment.