diff --git a/baystation12.dme b/baystation12.dme
index 35fb099fd8..85c0b6fed1 100644
--- a/baystation12.dme
+++ b/baystation12.dme
@@ -1283,12 +1283,12 @@
#include "code\WorkInProgress\explosion_particles.dm"
#include "code\WorkInProgress\periodic_news.dm"
#include "code\WorkInProgress\Apples\artifacts.dm"
+#include "code\WorkInProgress\Aryn\Lighting\_Defs.dm"
#include "code\WorkInProgress\Aryn\Lighting\Compatibility.dm"
#include "code\WorkInProgress\Aryn\Lighting\Controller.dm"
#include "code\WorkInProgress\Aryn\Lighting\Engine.dm"
#include "code\WorkInProgress\Aryn\Lighting\Light.dm"
#include "code\WorkInProgress\Aryn\Lighting\Lightpoint.dm"
-#include "code\WorkInProgress\Aryn\Lighting\Math.dm"
#include "code\WorkInProgress\Cael_Aislinn\Jungle\falsewall.dm"
#include "code\WorkInProgress\Cael_Aislinn\Jungle\jungle.dm"
#include "code\WorkInProgress\Cael_Aislinn\Jungle\jungle_animals.dm"
diff --git a/code/WorkInProgress/Aryn/Lighting/Compatibility.dm b/code/WorkInProgress/Aryn/Lighting/Compatibility.dm
index 9c98f5f6c9..1b5b937a52 100644
--- a/code/WorkInProgress/Aryn/Lighting/Compatibility.dm
+++ b/code/WorkInProgress/Aryn/Lighting/Compatibility.dm
@@ -36,10 +36,14 @@ turf_light_data/proc/copy_to(turf/T)
//T.ResetValue()
atom/proc/SetLuminosity(n)
+ ASSERT(n >= 0)
+
n = min(n,10) //Caelcode.
if(n > 0)
+ //world << "[name].SetLuminosity([n]) \[[max(1,n>>1)],[n]\]"
SetLight(max(1,n>>1),n)
else
+ //world << "[name].SetLuminosity(0)"
SetLight(0,0)
luminosity = n
//else lighting_controller.initial_lights.Add(src)
\ No newline at end of file
diff --git a/code/WorkInProgress/Aryn/Lighting/Controller.dm b/code/WorkInProgress/Aryn/Lighting/Controller.dm
index c5a0fee140..1bea76f8ab 100644
--- a/code/WorkInProgress/Aryn/Lighting/Controller.dm
+++ b/code/WorkInProgress/Aryn/Lighting/Controller.dm
@@ -89,25 +89,14 @@ var/list/lit_z_levels = list(1,5)
started = 1
for(var/turf/T)
- if(!T.is_outside && T.light_overlay)
+ if(T.light_overlay)
T.ResetValue()
- T.UpdateLight()
+ T.light_overlay.icon_state = "[MAX_VALUE(T.lightSE)][MAX_VALUE(T.lightSW)][MAX_VALUE(T.lightNW)][MAX_VALUE(T.lightNE)]"
world << "Lighting initialization took [(world.timeofday-start_time)/world.fps] seconds."
world << "Updated [turfs_updated] turfs."
-/datum/controller/lighting/proc/MarkIconUpdate(turf/T)
- if(!T.needs_light_update)
- icon_updates.Add(T)
- T.needs_light_update = 1
-
-/datum/controller/lighting/proc/FlushIconUpdates()
- for(var/turf/T in icon_updates)
- T.UpdateLight()
- T.needs_light_update = 0
- icon_updates = list()
-
/datum/controller/lighting/proc/AddBorder(turf/T)
if(!T.is_border)
light_border.Add(T)
diff --git a/code/WorkInProgress/Aryn/Lighting/Engine.dm b/code/WorkInProgress/Aryn/Lighting/Engine.dm
index 250fe0c886..1483e8066b 100644
--- a/code/WorkInProgress/Aryn/Lighting/Engine.dm
+++ b/code/WorkInProgress/Aryn/Lighting/Engine.dm
@@ -50,9 +50,6 @@ Turf Procs:
Resets the opacity cache and looks for opaque objects. Also responsible for adding and removing borders to space.
*/
-
-#define LIGHTCLAMP(x) ( max(0,min(3,round(x,1))) )
-
atom/movable/lighting_overlay
name = ""
anchored = 1
@@ -68,10 +65,9 @@ turf/var/atom/movable/lighting_overlay/light_overlay
turf/var/lit_value = 0
turf/var/max_brightness = 0
-turf/var/has_opaque = 0
+turf/var/has_opaque = -1
turf/var/is_outside = 0
turf/var/is_border = 0
-turf/var/needs_light_update = 0
turf/var/lightpoint/lightNE
turf/var/lightpoint/lightNW
@@ -85,7 +81,11 @@ atom/movable/New()
if(!light)
SetLight(luminosity,luminosity)
else
+ light.atom = src
light.Reset()
+ else if(light)
+ light.atom = src
+ light.Reset()
if(opacity)
if(lighting_ready())
opacity = 0
@@ -96,15 +96,16 @@ atom/movable/Del()
if(opacity) SetOpacity(0)
. = ..()
-atom/movable/Move()
+atom/movable/Move(turf/newloc)
var/o = opacity
if(o) SetOpacity(0)
. = ..()
if(.)
if(o) SetOpacity(1)
- if(light)
- light.Reset()
- if(lighting_ready()) lighting_controller.FlushIconUpdates()
+
+turf/Entered(atom/movable/M)
+ . = ..()
+ if(M.light) M.light.Reset()
atom/proc/SetLight(intensity, radius)
//if(lights_verbose) world << "SetLight([intensity],[radius])"
@@ -115,7 +116,7 @@ atom/proc/SetLight(intensity, radius)
//if(lights_verbose) world << "Shut off light with [light.lit_turfs.len] turfs lit."
light.Off()
light.intensity = 0
- if(lighting_ready()) lighting_controller.FlushIconUpdates()
+ //if(lighting_ready()) lighting_controller.FlushIconUpdates()
return
if(!light)
//if(lights_verbose) world << "New light."
@@ -126,25 +127,31 @@ atom/proc/SetLight(intensity, radius)
light.radius = min(radius,15)
light.intensity = intensity
light.Reset()
- if(lighting_ready()) lighting_controller.FlushIconUpdates()
+ //if(lighting_ready()) lighting_controller.FlushIconUpdates()
atom/proc/SetOpacity(o)
if(o == opacity) return
opacity = o
var/turf/T = loc
if(isturf(T))
+ T.CheckForOpaqueObjects()
for(var/light/A in T.lit_by)
A.Reset()
- lighting_controller.FlushIconUpdates()
-turf/proc/UpdateLight()
- if(light_overlay)
- light_overlay.icon_state = "[lightSE.max_value()][lightSW.max_value()][lightNW.max_value()][lightNE.max_value()]"
+ //lighting_controller.FlushIconUpdates()
-turf/proc/AddLight(light/light)
+atom/proc/UpdateLights()
+ if(light) light.Reset()
+ for(var/atom/movable/A in src)
+ if(A.light) A.light.Reset()
+
+//turf/proc/UpdateLight()
+// if(light_overlay)
+// light_overlay.icon_state = "[lightSE.max_value()][lightSW.max_value()][lightNW.max_value()][lightNE.max_value()]"
+
+turf/proc/AddLight(light/light, brightness)
if(is_outside) return
- var/brightness = light.CalculateBrightness(src)
if(brightness <= 0) return
if(!lit_by) lit_by = list()
@@ -153,13 +160,19 @@ turf/proc/AddLight(light/light)
lit_by[light] = brightness
- if(!has_opaque && lighting_ready())
+ if(lighting_ready())
if(brightness > max_brightness)
lit_value = LIGHTCLAMP(brightness)
max_brightness = brightness
- ResetCachedValues()
+
+ if(lightNE) lightNE.cached_value = -1
+ if(lightNW) lightNW.cached_value = -1
+ if(lightSE) lightSE.cached_value = -1
+ if(lightSW) lightSW.cached_value = -1
+
for(var/turf/T in range(1,src))
- lighting_controller.MarkIconUpdate(T)
+ if(T.light_overlay)
+ T.light_overlay.icon_state = "[MAX_VALUE(T.lightSE)][MAX_VALUE(T.lightSW)][MAX_VALUE(T.lightNW)][MAX_VALUE(T.lightNE)]"
turf/proc/RemoveLight(light/light)
if(lit_by)
@@ -187,17 +200,10 @@ turf/proc/ResetValue()
lit_value = LIGHTCLAMP(lighting_controller.starlight)
return
- CheckForOpaqueObjects()
+ if(has_opaque < 0) CheckForOpaqueObjects()
if(has_opaque)
lit_value = 0
else
- the_part_where_I_calculate_brightness()
-
- if(lighting_ready())
- the_part_where_I_use_range()
-
-turf/proc
- the_part_where_I_calculate_brightness()
max_brightness = 0
for(var/light/light in lit_by)
var/brightness = lit_by[light]//light.CalculateBrightness(src)
@@ -205,20 +211,14 @@ turf/proc
max_brightness = brightness
lit_value = LIGHTCLAMP(max_brightness)
- the_part_where_I_use_range()
- ResetCachedValues()
+ if(lighting_ready())
+ if(lightNE) lightNE.cached_value = -1
+ if(lightNW) lightNW.cached_value = -1
+ if(lightSE) lightSE.cached_value = -1
+ if(lightSW) lightSW.cached_value = -1
for(var/turf/T in range(1,src))
- lighting_controller.MarkIconUpdate(T)
-
-turf/proc/ResetCachedValues()
- if(lightNE)
- lightNE.cached_value = -1
- if(lightNW)
- lightNW.cached_value = -1
- if(lightSE)
- lightSE.cached_value = -1
- if(lightSW)
- lightSW.cached_value = -1
+ if(T.light_overlay)
+ T.light_overlay.icon_state = "[MAX_VALUE(T.lightSE)][MAX_VALUE(T.lightSW)][MAX_VALUE(T.lightNW)][MAX_VALUE(T.lightNE)]"
turf/proc/CheckForOpaqueObjects()
has_opaque = opacity
@@ -226,6 +226,4 @@ turf/proc/CheckForOpaqueObjects()
for(var/atom/movable/M in contents)
if(M.opacity)
has_opaque = 1
- break
-
-#undef LIGHTCLAMP
\ No newline at end of file
+ break
\ No newline at end of file
diff --git a/code/WorkInProgress/Aryn/Lighting/Light.dm b/code/WorkInProgress/Aryn/Lighting/Light.dm
index 6d1d612f7e..fd6f196645 100644
--- a/code/WorkInProgress/Aryn/Lighting/Light.dm
+++ b/code/WorkInProgress/Aryn/Lighting/Light.dm
@@ -24,21 +24,30 @@ Class Procs:
light/var/radius = 0
light/var/intensity = 0
-light/var/list/lit_turfs
+light/var/ambient_extension = 3
+light/var/list/lit_turfs = list()
light/var/atom/atom
-light/New(atom/atom)
+light/New(atom/atom, radius, ambience=3)
ASSERT(atom)
- src.atom = atom
+
+ if(istype(atom))
+ src.atom = atom
+ else
+ src.intensity = atom
+ src.radius = radius
+ src.ambient_extension = ambience
light/proc/Reset()
//if(atom.lights_verbose) world << "light.Reset()"
Off()
if(intensity > 0)
//if(atom.lights_verbose) world << "Restoring light."
- for(var/turf/T in view(get_turf(atom),radius+1))
+ var/turf/loc = atom
+ for(var/turf/T in view(loc,radius+ambient_extension))
if(!T.is_outside)
- T.AddLight(src)
+ var/brightness = CalculateBrightness(T, loc)
+ T.AddLight(src, brightness)
lit_turfs.Add(T)
//if(atom.lights_verbose) world << "[lit_turfs.len] turfs added."
@@ -46,15 +55,20 @@ light/proc/Off()
//if(atom.lights_verbose) world << "light.Off()"
for(var/turf/T in lit_turfs)
T.RemoveLight(src)
- lit_turfs = list()
+ lit_turfs.Cut()
-light/proc/CalculateBrightness(turf/T)
+light/proc/Flash(t)
+ Reset()
+ spawn(t)
+ Off()
+
+light/proc/CalculateBrightness(turf/T, turf/loc)
ASSERT(T)
- var/square = get_square_dist(atom.x,atom.y,atom.z,T.x,T.y,T.z)
- if(square > (radius+2)*(radius+2)) return 0
+ var/square = DISTSQ3(loc.x-T.x,loc.y-T.y,loc.z-T.z)
+ if(square > (radius+ambient_extension)*(radius+ambient_extension)) return 0
//+2 offset gives an ambient light effect.
- var/value = ((radius)/(2*fsqrt(square) + 1)) * intensity - 0.48
+ var/value = ((radius)/(2*FSQRT(square) + 1)) * intensity - 0.48
/*
lightRadius
---------------- * lightValue - 0.48
diff --git a/code/WorkInProgress/Aryn/Lighting/Lightpoint.dm b/code/WorkInProgress/Aryn/Lighting/Lightpoint.dm
index 5b9aade35e..eeeec4c706 100644
--- a/code/WorkInProgress/Aryn/Lighting/Lightpoint.dm
+++ b/code/WorkInProgress/Aryn/Lighting/Lightpoint.dm
@@ -50,16 +50,10 @@ lightpoint
T.lightNW = src
proc/max_value()
- if(cached_value < 0)
- var
- valueA = value_of(NW)
- valueB = value_of(NE)
- valueC = value_of(SW)
- valueD = value_of(SE)
- cached_value = max(valueA,valueB,valueC,valueD)
- return cached_value
-
- proc/value_of(turf/T)
- if(!T) return 0
- if(T.is_outside) return min(lighting_controller.starlight,3)
- return T.lit_value
\ No newline at end of file
+ var
+ valueA = VALUE_OF(NW)
+ valueB = VALUE_OF(NE)
+ valueC = VALUE_OF(SW)
+ valueD = VALUE_OF(SE)
+ cached_value = max(valueA,valueB,valueC,valueD)
+ return cached_value
\ No newline at end of file
diff --git a/code/WorkInProgress/Aryn/Lighting/Math.dm b/code/WorkInProgress/Aryn/Lighting/Math.dm
deleted file mode 100644
index cd8716373b..0000000000
--- a/code/WorkInProgress/Aryn/Lighting/Math.dm
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
-
-Some math procs used by lighting, including ul's fastroot.
-
-*/
-
-var/list/fastroot = list(0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
- 7, 7)
-
-proc/get_square_dist(Ax,Ay,Az,Bx,By,Bz)
- var/X = (Ax - Bx)
- var/Y = (Ay - By)
- var/Z = (Az - Bz)
- return (X * X + Y * Y + Z * Z)
-
-proc/fsqrt(n)
- if (n > fastroot.len)
- //world << "Adding [n-fastroot.len] entries to root table."
- for(var/i = fastroot.len, i <= n, i++)
- fastroot += round(sqrt(i))
- return fastroot[n + 1]
\ No newline at end of file
diff --git a/code/WorkInProgress/Aryn/Lighting/_Defs.dm b/code/WorkInProgress/Aryn/Lighting/_Defs.dm
new file mode 100644
index 0000000000..a0a667573a
--- /dev/null
+++ b/code/WorkInProgress/Aryn/Lighting/_Defs.dm
@@ -0,0 +1,15 @@
+#define SQ(X) ((X)*(X))
+#define DISTSQ3(A,B,C) (SQ(A)+SQ(B)+SQ(C))
+#define FSQRT(X) (X >= fastroot.len ? new_fsqrt(X) : fastroot[(X)+1])
+#define MAX_VALUE(X) (X.cached_value < 0 ? X.max_value() : X.cached_value)
+#define VALUE_OF(X) ( !X ? 0 : ( X.is_outside ? LIGHTCLAMP(lighting_controller.starlight) : X.lit_value ) )
+#define LIGHTCLAMP(x) ( max(0,min(3,round(x,1))) )
+
+var/list/fastroot = list(0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7)
+
+proc/new_fsqrt(n)
+ //world << "Adding [n-fastroot.len] entries to root table."
+ for(var/i = fastroot.len, i <= n, i++)
+ fastroot += round(sqrt(i))
\ No newline at end of file
diff --git a/code/game/objects/items/devices/flashlight.dm b/code/game/objects/items/devices/flashlight.dm
index a89a4573ea..33c4dc76b0 100644
--- a/code/game/objects/items/devices/flashlight.dm
+++ b/code/game/objects/items/devices/flashlight.dm
@@ -89,13 +89,13 @@
/obj/item/device/flashlight/pickup(mob/user)
- if(on)
+ if(on && luminosity)
user.SetLuminosity(user.luminosity + brightness_on)
SetLuminosity(0)
/obj/item/device/flashlight/dropped(mob/user)
- if(on)
+ if(on && !luminosity)
user.SetLuminosity(user.luminosity - brightness_on)
SetLuminosity(brightness_on)
diff --git a/code/modules/mob/living/carbon/human/inventory.dm b/code/modules/mob/living/carbon/human/inventory.dm
index 64d1ff64ef..29ce794dbe 100644
--- a/code/modules/mob/living/carbon/human/inventory.dm
+++ b/code/modules/mob/living/carbon/human/inventory.dm
@@ -717,8 +717,11 @@ It can still be worn/put on as normal.
if(item && target.has_organ_for_slot(slot_to_process)) //Placing an item on the mob
if(item.mob_can_equip(target, slot_to_process, 0))
source.u_equip(item)
- target.equip_to_slot_if_possible(item, slot_to_process, 0, 1, 1)
item.dropped(source)
+
+ target.equip_to_slot_if_possible(item, slot_to_process, 0, 1, 1)
+ item.pickup(target)
+
source.update_icons()
target.update_icons()