Skip to content

Commit

Permalink
[MIRROR] Lighting
Browse files Browse the repository at this point in the history
  • Loading branch information
CrimsonShrike authored and SuhEugene committed Sep 29, 2023
1 parent 34eb3a9 commit ecb294c
Show file tree
Hide file tree
Showing 169 changed files with 2,451 additions and 1,204 deletions.
6 changes: 5 additions & 1 deletion baystation12.dme
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "code\__datastructures\priority_queue.dm"
#include "code\__datastructures\stack.dm"
#include "code\__defines\__compile_options.dm"
#include "code\__defines\__dview.dm"
#include "code\__defines\__initialization.dm"
#include "code\__defines\__renderer.dm"
#include "code\__defines\_excom.dm"
Expand Down Expand Up @@ -188,6 +189,7 @@
#include "code\controllers\subsystems\air.dm"
#include "code\controllers\subsystems\airflow.dm"
#include "code\controllers\subsystems\alarm.dm"
#include "code\controllers\subsystems\ambient_lighting.dm"
#include "code\controllers\subsystems\ao.dm"
#include "code\controllers\subsystems\atoms.dm"
#include "code\controllers\subsystems\chat.dm"
Expand Down Expand Up @@ -1991,11 +1993,12 @@
#include "code\modules\library\manuals\medical.dm"
#include "code\modules\library\manuals\nanotrasen.dm"
#include "code\modules\library\manuals\union.dm"
#include "code\modules\lighting\_lighting_defs.dm"
#include "code\modules\lighting\darksight.dm"
#include "code\modules\lighting\lighting_area.dm"
#include "code\modules\lighting\lighting_atom.dm"
#include "code\modules\lighting\lighting_corner.dm"
#include "code\modules\lighting\lighting_overlay.dm"
#include "code\modules\lighting\lighting_planemaster.dm"
#include "code\modules\lighting\lighting_setup.dm"
#include "code\modules\lighting\lighting_source.dm"
#include "code\modules\lighting\lighting_turf.dm"
Expand Down Expand Up @@ -2070,6 +2073,7 @@
#include "code\modules\mining\machinery\mineral_unloader.dm"
#include "code\modules\mob\animations.dm"
#include "code\modules\mob\death.dm"
#include "code\modules\mob\dview.dm"
#include "code\modules\mob\examinations.dm"
#include "code\modules\mob\gender.dm"
#include "code\modules\mob\hear_say.dm"
Expand Down
6 changes: 6 additions & 0 deletions code/__defines/MC.dm
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,9 @@ if(Datum.is_processing) {\
****/

#define addtimer(args...) _addtimer(args, source ="[__FILE__]#[__LINE__]")

/****
* Helper for waits
****/

#define UNTIL(X) while(!(X)) stoplag()
14 changes: 14 additions & 0 deletions code/__defines/__dview.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//DVIEW defines

#define FOR_DVIEW(type, range, center, invis_flags) \
global.dview_mob.loc = center; \
global.dview_mob.see_invisible = invis_flags; \
for(type in view(range, dview_mob))

#define END_FOR_DVIEW dview_mob.loc = null

#define DVIEW(output, range, center, invis_flags) \
global.dview_mob.loc = center; \
global.dview_mob.see_invisible = invis_flags; \
output = view(range, dview_mob); \
global.dview_mob.loc = null;
7 changes: 0 additions & 7 deletions code/__defines/_renderer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,6 @@ GLOBAL_LIST_EMPTY(zmimic_renderers)
plane = LIGHTING_PLANE
appearance_flags = PLANE_MASTER | NO_CLIENT_COLOR
relay_blend_mode = BLEND_MULTIPLY
color = list(
-1, 0, 0, 0, // R
0, -1, 0, 0, // G
0, 0, -1, 0, // B
0, 0, 0, 0, // A
1, 1, 1, 1 // Mapping
)
mouse_opacity = MOUSE_OPACITY_UNCLICKABLE


Expand Down
73 changes: 56 additions & 17 deletions code/__defines/lighting.dm
Original file line number Diff line number Diff line change
@@ -1,29 +1,42 @@
#define FOR_DVIEW(type, range, center, invis_flags) \
GLOB.dview_mob.loc = center; \
GLOB.dview_mob.see_invisible = invis_flags; \
for(type in view(range, GLOB.dview_mob))
#define LIGHTING_INTERVAL 1 // Frequency, in 1/10ths of a second, of the lighting process.

#define END_FOR_DVIEW GLOB.dview_mob.loc = null
#define LIGHTING_HEIGHT 1 // height off the ground of light sources on the pseudo-z-axis, you should probably leave this alone
#define LIGHTING_Z_FACTOR 10 // Z diff is multiplied by this and LIGHTING_HEIGHT to get the final height of a light source. Affects how much darker A Z light gets with each level transitioned.
#define LIGHTING_ROUND_VALUE (1 / 200) //Value used to round lumcounts, values smaller than 1/255 don't matter (if they do, thanks sinking points), greater values will make lighting less precise, but in turn increase performance, VERY SLIGHTLY.

#define LIGHTING_ICON 'icons/effects/lighting_overlay.dmi' // icon used for lighting shading effects
#define LIGHTING_ICON_STATE_DARK "dark" // Change between "soft_dark" and "dark" to swap soft darkvision
#define LIGHTING_BASE_ICON_STATE "matrix" // icon_state used for normal color-matrix based lighting overlays.
#define LIGHTING_STATION_ICON_STATE "tubedefault" // icon_state used for lighting overlays that are just displaying standard station lighting.
#define LIGHTING_DARKNESS_ICON_STATE "black" // icon_state used for lighting overlays with no luminosity.
#define LIGHTING_TRANSPARENT_ICON_STATE "blank"

#define LIGHTING_ROUND_VALUE (1 / 64) // Value used to round lumcounts, values smaller than 1/69 don't matter (if they do, thanks sinking points), greater values will make lighting less precise, but in turn increase performance, VERY SLIGHTLY.
#define LIGHTING_BLOCKED_FACTOR 0.5 // How much the range of a directional light will be reduced while facing a wall.

#define LIGHTING_SOFT_THRESHOLD 0 // If the max of the lighting lumcounts of each spectrum drops below this, disable luminosity on the lighting overlays. This also should be the transparancy of the "soft_dark" icon state.
// If defined, instant updates will be used whenever server load permits. Otherwise queued updates are always used.
#define USE_INTELLIGENT_LIGHTING_UPDATES

/// Maximum light_range before forced to always queue instead of using sync updates. Setting this too high will cause server stutter with moving large lights.
#define LIGHTING_MAXIMUM_INSTANT_RANGE 8

// mostly identical to below, but doesn't make sure T is valid first. Should only be used by lighting code.
#define TURF_IS_DYNAMICALLY_LIT_UNSAFE(T) ((T:dynamic_lighting && T:loc:dynamic_lighting))
#define TURF_IS_DYNAMICALLY_LIT(T) (isturf(T) && TURF_IS_DYNAMICALLY_LIT_UNSAFE(T))

// Note: this does not imply the above, a turf can have ambient light without being dynamically lit.
#define TURF_IS_AMBIENT_LIT_UNSAFE(T) (T:ambient_active)
#define TURF_IS_AMBIENT_LIT(T) (isturf(T) && TURF_IS_AMBIENT_LIT_UNSAFE(T))

#define LIGHTING_MULT_FACTOR 0.9

// If I were you I'd leave this alone.
#define LIGHTING_BASE_MATRIX \
list \
( \
LIGHTING_SOFT_THRESHOLD, LIGHTING_SOFT_THRESHOLD, LIGHTING_SOFT_THRESHOLD, 0, \
LIGHTING_SOFT_THRESHOLD, LIGHTING_SOFT_THRESHOLD, LIGHTING_SOFT_THRESHOLD, 0, \
LIGHTING_SOFT_THRESHOLD, LIGHTING_SOFT_THRESHOLD, LIGHTING_SOFT_THRESHOLD, 0, \
LIGHTING_SOFT_THRESHOLD, LIGHTING_SOFT_THRESHOLD, LIGHTING_SOFT_THRESHOLD, 0, \
0, 0, 0, 1 \
)
list \
( \
1, 1, 1, 0, \
1, 1, 1, 0, \
1, 1, 1, 0, \
1, 1, 1, 0, \
0, 0, 0, 1 \
) \

// Helpers so we can (more easily) control the colour matrices.
#define CL_MATRIX_RR 1
Expand All @@ -47,12 +60,25 @@
#define CL_MATRIX_CB 19
#define CL_MATRIX_CA 20

// Higher numbers override lower.
#define LIGHTING_NO_UPDATE 0
#define LIGHTING_VIS_UPDATE 1
#define LIGHTING_CHECK_UPDATE 2
#define LIGHTING_FORCE_UPDATE 3

// Lightbulb statuses
#define LIGHT_OK 0 // A light bulb is installed and functioning.
#define LIGHT_EMPTY 1 // There is no light bulb installed.
#define LIGHT_BROKEN 2 // The light bulb is broken/shattered.
#define LIGHT_BURNED 3 // The light bulb is burned out.

// This color of overlay is very common - most of the station is this color when lit fully.
// Tube lights are a bluish-white, so we can't just assume 1-1-1 is full-illumination.
// -- If you want to change these, find them *by checking in-game*, just converting tubes' RGB color into floats will not work!
#define LIGHTING_DEFAULT_TUBE_R 0.96
#define LIGHTING_DEFAULT_TUBE_G 1
#define LIGHTING_DEFAULT_TUBE_B 1

// Lighting color presets
#define LIGHT_COLOUR_WHITE "#fefefe" // Clinical white light bulbs
#define LIGHT_COLOUR_WARM "#fffee0" // Warm yellowish light bulbs
Expand Down Expand Up @@ -84,3 +110,16 @@
#define AREA_LIGHTING_WARM "warm"
#define AREA_LIGHTING_COOL "cool"
#define AREA_LIGHTING_DEFAULT "default" // For light replacers, defaults to whatever the area is set to. For areas, uses the initial lighting value from the light bulb itself.

// Some angle presets for directional lighting.
#define LIGHT_OMNI null
#define LIGHT_SEMI 180
#define LIGHT_VERY_WIDE 135
#define LIGHT_WIDE 90
#define LIGHT_NARROW 45

#define DARKSIGHT_GRADIENT_SIZE 480
// Max number of ambient groups, amount over this value will simply not be created
#define AMBIENT_GROUP_MAX_BITS 24
// Ambient group used for exterior turfs not on planets - Could also replace Space turf legacy starlight implementation
#define SPACE_AMBIENT_GROUP 1
2 changes: 2 additions & 0 deletions code/__defines/misc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,5 @@
#define SANITY_CHECK_TOPIC_PHYSICALLY_INTERACT FLAG(6)

#define SANITY_CHECK_DEFAULT (SANITY_CHECK_TOOL_IN_HAND | SANITY_CHECK_BOTH_ADJACENT)

#define Z_ALL_TURFS(Z) block(locate(1, 1, Z), locate(world.maxx, world.maxy, Z))
8 changes: 4 additions & 4 deletions code/__defines/species.dm
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#define SKIN_THREAT FLAG(0)


// Darkvision Levels. Inverted - white is darkest, black is full vision
#define DARKTINT_NONE "#ffffff"
#define DARKTINT_MODERATE "#f9f9f5"
#define DARKTINT_GOOD "#ebebe6"
// Darkvision Levels. White is brightest, darker tints affect vision negatively
#define DARKTINT_GOOD "#ffffff"
#define DARKTINT_MODERATE "#f9f9f5"
#define DARKTINT_NONE "#ebebe6"
1 change: 1 addition & 0 deletions code/__defines/subsystem-priority.dm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define SS_PRIORITY_AIR 80 // ZAS processing.
#define SS_PRIORITY_THROWING 75 // Throwing calculation and constant checks
#define SS_PRIORITY_CHEMISTRY 60 // Multi-tick chemical reactions.
#define SS_PRIORITY_LIGHTING 50 // Queued lighting engine updates.
#define SS_PRIORITY_SPACEDRIFT 45 // Drifting things
#define SS_PRIORITY_CHAT 40 // Chat
#define SS_PRIORITY_ALARM 20 // Alarm processing.
Expand Down
9 changes: 5 additions & 4 deletions code/__defines/subsystems.dm
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@
#define SS_INIT_SHUTTLE -5
#define SS_INIT_GOALS -5
#define SS_INIT_LIGHTING -6
#define SS_INIT_ZCOPY -7
#define SS_INIT_HOLOMAP -8
#define SS_INIT_OVERLAYS -9
#define SS_INIT_XENOARCH -10
#define SS_INIT_AMBIENT_LIGHT -7
#define SS_INIT_ZCOPY -8
#define SS_INIT_HOLOMAP -9
#define SS_INIT_OVERLAYS -10
#define SS_INIT_XENOARCH -11
#define SS_INIT_BAY_LEGACY -12
#define SS_INIT_TICKER -20
#define SS_INIT_AI -21
Expand Down
3 changes: 2 additions & 1 deletion code/_helpers/game.dm
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@

/proc/get_mobs_and_objs_in_view_fast(turf/T, range, list/mobs, list/objs, checkghosts = null)

var/list/hear = dview(range,T,INVISIBILITY_MAXIMUM)
var/list/hear = list()
DVIEW(hear, range, T, INVISIBILITY_MAXIMUM)
var/list/hearturfs = list()

for(var/atom/movable/AM in hear)
Expand Down
16 changes: 16 additions & 0 deletions code/_helpers/time.dm
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,19 @@ var/global/round_start_time = 0
var/time_string = time2text(world.realtime, "MM-DD")
var/time_list = splittext(time_string, "-")
return list(text2num(time_list[1]), text2num(time_list[2]))


#define MIDNIGHT_ROLLOVER 864000 //number of deciseconds in a day

var/global/midnight_rollovers = 0
var/global/rollovercheck_last_timeofday = 0
/proc/update_midnight_rollover()
if (world.timeofday < global.rollovercheck_last_timeofday) //TIME IS GOING BACKWARDS!
global.midnight_rollovers += 1
global.rollovercheck_last_timeofday = world.timeofday
return global.midnight_rollovers

//time of day but automatically adjusts to the server going into the next day within the same round.
//for when you need a reliable time number that doesn't depend on byond time.
#define REALTIMEOFDAY (world.timeofday + (MIDNIGHT_ROLLOVER * MIDNIGHT_ROLLOVER_CHECK))
#define MIDNIGHT_ROLLOVER_CHECK ( global.rollovercheck_last_timeofday != world.timeofday ? update_midnight_rollover() : global.midnight_rollovers )
13 changes: 1 addition & 12 deletions code/_helpers/unsorted.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1036,17 +1036,6 @@ GLOBAL_DATUM_INIT(dview_mob, /mob/dview, new)
. = view(range, GLOB.dview_mob)
GLOB.dview_mob.loc = null

/mob/dview
invisibility = INVISIBILITY_ABSTRACT
density = FALSE

anchored = TRUE
simulated = FALSE

see_in_dark = 1e6

virtual_mob = null

/mob/dview/Destroy()
SHOULD_CALL_PARENT(FALSE)
return QDEL_HINT_LETMELIVE
Expand All @@ -1062,7 +1051,7 @@ GLOBAL_DATUM_INIT(dview_mob, /mob/dview, new)
/atom/proc/get_light_and_color(atom/origin)
if(origin)
color = origin.color
set_light(origin.light_max_bright, origin.light_inner_range, origin.light_outer_range, origin.light_falloff_curve)
set_light(origin.light_range, origin.light_power)


// call to generate a stack trace and print to runtime logs
Expand Down
4 changes: 2 additions & 2 deletions code/controllers/configuration.dm
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@

var/static/aooc_allowed = TRUE

/// Whether space turfs have ambient light or not
var/static/starlight = 0
/// Whether space turfs and some exterior turfs have ambient light or not default, 0.5, values over 1 may overpower dynamic lights
var/static/starlight = 0.5

var/static/list/ert_species = list(SPECIES_HUMAN)

Expand Down
Loading

0 comments on commit ecb294c

Please sign in to comment.