Skip to content

Commit

Permalink
Merge pull request #72 from davipatury/dinamic_light
Browse files Browse the repository at this point in the history
Ports Dynamic Light
  • Loading branch information
davipatury authored Jul 31, 2016
2 parents b9e0f65 + 05c3057 commit 08877c4
Show file tree
Hide file tree
Showing 23 changed files with 719 additions and 404 deletions.
42 changes: 41 additions & 1 deletion code/__DEFINES/lighting.dm
Original file line number Diff line number Diff line change
@@ -1,10 +1,50 @@
#define LIGHTING_INTERVAL 5 // frequency, in 1/10ths of a second, of the lighting process

#ifndef LIGHTING_INSTANT_UPDATES
#define LIGHTING_INTERVAL 5 // Frequency, in 1/10ths of a second, of the lighting process.
#include "..\controllers\Processes\lighting.dm"
#endif

#define LIGHTING_FALLOFF 1 // type of falloff to use for lighting; 1 for circular, 2 for square
#define LIGHTING_LAMBERTIAN 0 // use lambertian shading for light sources
#define LIGHTING_HEIGHT 1 // height off the ground of light sources on the pseudo-z-axis, you should probably leave this alone

#define LIGHTING_LAYER 10 // drawing layer for lighting overlays
#define LIGHTING_ICON 'icons/effects/lighting_overlay.dmi' // icon used for lighting shading effects
#define LIGHTING_ICON 'icons/effects/lighting_overlay.png' // icon used for lighting shading effects

#define LIGHTING_ROUND_VALUE (1 / 128) //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_SOFT_THRESHOLD 0.05 // If the max of the lighting lumcounts of each spectrum drops below this, disable luminosity on the lighting overlays.

// 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 \
) \

// Helpers so we can (more easily) control the colour matrices.
#define CL_MATRIX_RR 1
#define CL_MATRIX_RG 2
#define CL_MATRIX_RB 3
#define CL_MATRIX_RA 4
#define CL_MATRIX_GR 5
#define CL_MATRIX_GG 6
#define CL_MATRIX_GB 7
#define CL_MATRIX_GA 8
#define CL_MATRIX_BR 9
#define CL_MATRIX_BG 10
#define CL_MATRIX_BB 11
#define CL_MATRIX_BA 12
#define CL_MATRIX_AR 13
#define CL_MATRIX_AG 14
#define CL_MATRIX_AB 15
#define CL_MATRIX_AA 16
#define CL_MATRIX_CR 17
#define CL_MATRIX_CG 18
#define CL_MATRIX_CB 19
#define CL_MATRIX_CA 20
7 changes: 6 additions & 1 deletion code/controllers/Processes/lighting.dm
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/var/list/lighting_update_lights = list() // List of lighting sources queued for update.
/var/list/lighting_update_corners = list() // List of lighting corners queued for update.
/var/list/lighting_update_overlays = list() // List of lighting overlays queued for update.

var/global/datum/controller/process/lighting/lighting_controller

/datum/controller/process/lighting/setup()
Expand All @@ -6,7 +10,8 @@ var/global/datum/controller/process/lighting/lighting_controller
start_delay = 1
lighting_controller = src

create_lighting_overlays()
create_all_lighting_overlays()
create_all_lighting_corners()
// Pre-process lighting once before the round starts. Wait 30 seconds so the away mission has time to load.
spawn(300)
doWork()
Expand Down
30 changes: 14 additions & 16 deletions code/game/area/Space Station 13 areas.dm
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,13 @@ var/list/ghostteleportlocs = list()
name = "\improper Admin Room"
icon_state = "start"
requires_power = 0
lighting_use_dynamic = 0

dynamic_lighting = 0

/area/adminconstruction
name = "\improper Admin Testing Area"
icon_state = "start"
requires_power = 0
lighting_use_dynamic = 0
dynamic_lighting = 0

/area/space
icon_state = "space"
Expand Down Expand Up @@ -459,7 +458,7 @@ var/list/ghostteleportlocs = list()
icon_state = "start"
requires_power = 0
luminosity = 1
lighting_use_dynamic = 0
dynamic_lighting = 0
has_gravity = 1

// === end remove
Expand All @@ -475,7 +474,7 @@ var/list/ghostteleportlocs = list()
name = "\improper Centcom"
icon_state = "centcom"
requires_power = 0
lighting_use_dynamic = 0
dynamic_lighting = 0

/area/centcom/control
name = "\improper Centcom Control"
Expand Down Expand Up @@ -551,8 +550,7 @@ var/list/ghostteleportlocs = list()
name = "\improper Thunderdome"
icon_state = "thunder"
requires_power = 0
lighting_use_dynamic = 0

dynamic_lighting = 0

/area/tdome/arena_source
name = "\improper Thunderdome Arena Template"
Expand Down Expand Up @@ -636,7 +634,7 @@ var/list/ghostteleportlocs = list()
icon_state = "yellow"
requires_power = 0
has_gravity = 1
lighting_use_dynamic = 0
dynamic_lighting = 0

/area/wizard_station
name = "\improper Wizard's Den"
Expand All @@ -659,7 +657,7 @@ var/list/ghostteleportlocs = list()
name = "\improper Vox Base"
icon_state = "yellow"
requires_power = 0
lighting_use_dynamic = 0
dynamic_lighting = 0
no_teleportlocs = 1

/area/vox_station/transit
Expand Down Expand Up @@ -1216,7 +1214,7 @@ var/list/ghostteleportlocs = list()
/area/holodeck
name = "\improper Holodeck"
icon_state = "Holodeck"
lighting_use_dynamic = 0
dynamic_lighting = 0

/area/holodeck/alphadeck
name = "\improper Holodeck Alpha"
Expand Down Expand Up @@ -1353,7 +1351,7 @@ var/list/ghostteleportlocs = list()

/area/solar
requires_power = 0
lighting_use_dynamic = 0
dynamic_lighting = 0

auxport
name = "\improper Fore Port Solar Array"
Expand Down Expand Up @@ -2248,25 +2246,25 @@ area/security/podbay
name = "\improper AI Sat Ext"
icon_state = "storage"
luminosity = 1
lighting_use_dynamic = 0
dynamic_lighting = 0

/area/turret_protected/AIsatextFS
name = "\improper AI Sat Ext"
icon_state = "storage"
luminosity = 1
lighting_use_dynamic = 0
dynamic_lighting = 0

/area/turret_protected/AIsatextAS
name = "\improper AI Sat Ext"
icon_state = "storage"
luminosity = 1
lighting_use_dynamic = 0
dynamic_lighting = 0

/area/turret_protected/AIsatextAP
name = "\improper AI Sat Ext"
icon_state = "storage"
luminosity = 1
lighting_use_dynamic = 0
dynamic_lighting = 0

/area/turret_protected/NewAIMain
name = "\improper AI Main New"
Expand Down Expand Up @@ -2443,7 +2441,7 @@ area/security/podbay
name = "Beach"
icon_state = "beach"
luminosity = 1
lighting_use_dynamic = 0
dynamic_lighting = 0
requires_power = 0
ambientsounds = list('sound/ambience/shore.ogg', 'sound/ambience/seag1.ogg','sound/ambience/seag2.ogg','sound/ambience/seag2.ogg')

Expand Down
2 changes: 1 addition & 1 deletion code/game/area/areas.dm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
if(type == /area) // override defaults for space. TODO: make space areas of type /area/space rather than /area
requires_power = 1
always_unpowered = 1
lighting_use_dynamic = 1
dynamic_lighting = 1
power_light = 0
power_equip = 0
power_environ = 0
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 @@ -29,7 +29,13 @@
/atom/movable/Destroy()
for(var/atom/movable/AM in contents)
qdel(AM)
var/turf/un_opaque
if(opacity && isturf(loc))
un_opaque = loc

loc = null
if(un_opaque)
un_opaque.recalc_atom_opacity()
if (pulledby)
if (pulledby.pulling == src)
pulledby.pulling = null
Expand Down
17 changes: 12 additions & 5 deletions code/game/turfs/turf.dm
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

var/PathNode/PNode = null //associated PathNode in the A* algorithm

var/dynamic_lighting = 1

flags = 0

var/image/obscured //camerachunks
Expand Down Expand Up @@ -161,9 +159,17 @@
if(path == type) return src
var/old_opacity = opacity
var/old_dynamic_lighting = dynamic_lighting
var/list/old_affecting_lights = affecting_lights
var/old_affecting_lights = affecting_lights
var/old_lighting_overlay = lighting_overlay
var/old_blueprint_data = blueprint_data
var/old_corners = corners

if(!lighting_corners_initialised && global.lighting_corners_initialised)
for(var/i = 1 to 4)
if(corners[i]) // Already have a corner on this direction.
continue

corners[i] = new/datum/lighting_corner(src, LIGHTING_CORNER_DIAGONAL[i])

if(air_master)
air_master.remove_from_active(src)
Expand All @@ -180,14 +186,15 @@

lighting_overlay = old_lighting_overlay

corners = old_corners
affecting_lights = old_affecting_lights
if((old_opacity != opacity) || (dynamic_lighting != old_dynamic_lighting))
reconsider_lights()
if(dynamic_lighting != old_dynamic_lighting)
if(dynamic_lighting)
lighting_build_overlays()
lighting_build_overlay()
else
lighting_clear_overlays()
lighting_clear_overlay()

W.levelupdate()
W.CalculateAdjacentTurfs()
Expand Down
4 changes: 2 additions & 2 deletions code/modules/awaymissions/mission_code/clownplanet.dm
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
name = "\improper Clown Planet"
icon_state = "honk"
luminosity = 1
lighting_use_dynamic = 0
dynamic_lighting = 0
requires_power = 0
report_alerts = 0

/area/awaymission/clownplanet/miningtown
name = "\improper Clown Planet - Bananium-o-Rama"
icon_state = "away1"
Expand Down
9 changes: 6 additions & 3 deletions code/modules/awaymissions/zlevel.dm
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
air_master.setup_allturfs(turfs)
for(var/turf/T in turfs)
if(T.dynamic_lighting)
T.lighting_build_overlays()
for(var/obj/structure/cable/PC in T)
makepowernet_for(PC)
T.lighting_build_overlay()
T.lighting_corners_initialised = TRUE
for(var/i = 1 to 4)
if((T.corners[i]) || (istype(T, /turf/space))) // Already have a corner on this direction. Also ignoring space turfs!
continue
T.corners[i] = new/datum/lighting_corner(T, LIGHTING_CORNER_DIAGONAL[i])
for(var/turf/T in smoothTurfs)
if(T.smooth)
smooth_icon(T)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/awaymissions/zvis.dm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/area/awaymission/upperlevel
name = "Open Space"
color = "#888"
lighting_use_dynamic = 0
dynamic_lighting = 0
requires_power = 0

// Used by /turf/unsimulated/floor/upperlevel as a reference for where the other floor is
Expand Down
Loading

0 comments on commit 08877c4

Please sign in to comment.