Lighting system is too buggy to continue until I know wtf is going on

This commit is contained in:
Aryn
2014-02-23 07:50:58 -07:00
parent 8a3b99aa68
commit ca7d4026b8
16 changed files with 163 additions and 93 deletions

View File

@@ -0,0 +1,41 @@
area/var/lighting_use_dynamic
turf/space/is_outside = 1
/datum/controller/lighting/var/processing = 1
/datum/controller/lighting/var/iteration = 0
//Because so many objects jump the gun.
proc/lighting_ready()
return lighting_controller && lighting_controller.started
turf_light_data
var/light_overlay
var/lightNW
var/lightSW
var/lightNE
var/lightSE
var/lit_by
turf_light_data/proc/copy_from(turf/T)
light_overlay = T.light_overlay
lightNW = T.lightNW
lightSW = T.lightSW
lightNE = T.lightNE
lightSE = T.lightSE
lit_by = T.lit_by
turf_light_data/proc/copy_to(turf/T)
T.light_overlay = light_overlay
T.lightNW = lightNW
T.lightSW = lightSW
T.lightNE = lightNE
T.lightSE = lightSE
T.lit_by = lit_by
//T.ResetValue()
atom/proc/SetLuminosity(n)
n = min(n,10) //Caelcode.
SetLight(n>>1,n)
luminosity = n
//else lighting_controller.initial_lights.Add(src)

View File

@@ -34,9 +34,11 @@ Class Procs:
*/
var/datum/controller/lighting/lighting_controller
var/list/initial_lights = list()
var/all_lightpoints_made = 0
var/list/lit_z_levels = list(1,5)
/datum/controller/lighting
var/starlight = 4
@@ -44,6 +46,8 @@ var/all_lightpoints_made = 0
var/list/light_border = list()
var/started = 0
//var/icon/border = icon('Icons/Test.dmi', "border")
/datum/controller/lighting/New()
@@ -51,47 +55,45 @@ var/all_lightpoints_made = 0
/datum/controller/lighting/proc/Initialize()
set background = 1
var/start_time = world.timeofday
world << "<b><font color=red>Processing lights...</font></b>"
var/turfs_updated = 0
sleep(1)
for(var/z = 1, z <= world.maxz, z++)
var/turfs_updated = 0
var/total_turfs = world.maxx*world.maxy*lit_z_levels.len
for(var/z in lit_z_levels)
for(var/y = 0, y <= world.maxy, y++)
for(var/x = 0, x <= world.maxx, x++)
if(x > 0 && y > 0)
var/turf/T = locate(x,y,z)
if(!T.light_overlay)
T.light_overlay = new(T)
T.CheckForOpaqueObjects()
turfs_updated++
if((turfs_updated % 5000) == 0)
sleep(1)
world << "<font color=red>Progress: [round((turfs_updated/total_turfs)*100, 0.01)]% ([turfs_updated]/[total_turfs])"
var/turf/T = locate(x,y,z)
if(!T.light_overlay && !T.is_outside)
T.light_overlay = new(T)
T.ResetValue()
if(!all_lightpoints_made) new/lightpoint(x+0.5,y+0.5,z)
//world << "[x],[y],[z]"
all_lightpoints_made = 1
started = 1
for(var/atom/movable/M in initial_lights)
if(!M.light)
M.SetLight(M.luminosity,M.luminosity)
else
M.light.Reset()
StarLight(starlight)
initial_lights = null
for(var/turf/T)
if(!T.is_outside) T.UpdateLight()
world << "<b><font color=red>Lighting initialization took [(world.timeofday-start_time)/world.fps] seconds.</font></b>"
world << "<font color=red>Updated [turfs_updated] turfs.</font>"
/datum/controller/lighting/proc/StarLight(n)
starlight = n
for(var/turf/T in light_border)
T.SetLight(5,n-1)
for(var/turf/T)
if(T.is_outside)
T.ResetValue()
FlushIconUpdates()
/datum/controller/lighting/proc/MarkIconUpdate(turf/T)
if(!T.needs_light_update)
icon_updates.Add(T)

View File

@@ -65,6 +65,7 @@ atom/var/light/light
turf/var/obj/effect/lighting_overlay/light_overlay
turf/var/lit_value = 0
turf/var/max_brightness = 0
turf/var/has_opaque = 0
turf/var/is_outside = 0
turf/var/is_border = 0
@@ -78,16 +79,13 @@ turf/var/list/lit_by
atom/New()
. = ..()
if(luminosity || light)
if(!lighting_controller)
initial_lights.Add(src)
if(luminosity)
if(!light)
SetLight(luminosity,luminosity)
else
if(!light)
SetLight(luminosity,luminosity)
else
light.Reset()
if(lighting_controller)
if(opacity)
light.Reset()
if(opacity)
if(lighting_ready())
opacity = 0
SetOpacity(1)
@@ -102,11 +100,18 @@ atom/movable/Move()
lighting_controller.FlushIconUpdates()
atom/proc/SetLight(intensity, radius)
if(!intensity)
if(!light) return
light.Off()
light = null
if(lighting_ready()) lighting_controller.FlushIconUpdates()
return
if(!light) light = new(src)
if(light.intensity == intensity) return
light.radius = min(radius,15)
light.intensity = intensity
light.Reset()
lighting_controller.FlushIconUpdates()
if(lighting_ready()) lighting_controller.FlushIconUpdates()
atom/proc/SetOpacity(o)
if(o == opacity) return
@@ -122,41 +127,72 @@ turf/proc/UpdateLight()
light_overlay.icon_state = "[lightSE.max_value()][lightSW.max_value()][lightNW.max_value()][lightNE.max_value()]"
turf/proc/AddLight(light/light)
if(is_outside) return
if(has_opaque) return
if(!lit_by) lit_by = list()
lit_by.Add(light)
if(!has_opaque)
var/brightness = light.CalculateBrightness(src)
if(brightness > lit_value)
var/brightness = light.CalculateBrightness(src)
lit_by[light] = brightness
if(!has_opaque && lighting_ready())
if(brightness > max_brightness)
lit_value = LIGHTCLAMP(brightness)
max_brightness = brightness
ResetCachedValues()
for(var/turf/T in range(1,src))
lighting_controller.MarkIconUpdate(T)
for(var/turf/T in range(1,src))
lighting_controller.MarkIconUpdate(T)
turf/proc/RemoveLight(light/light)
lit_by.Remove(light)
ResetValue()
if(!lit_by.len) lit_by = null
if(has_opaque) return
if(lit_by)
var/brightness = lit_by[light]
lit_by.Remove(light)
if(brightness == max_brightness)
ResetValue()
if(!lit_by.len) lit_by = null
turf/proc/ResetValue()
if(is_outside)
max_brightness = lighting_controller.starlight
lit_value = LIGHTCLAMP(lighting_controller.starlight)
return
var/old_value = lit_value
CheckForOpaqueObjects()
if(has_opaque)
lit_value = 0
else
var/max_brightness = (is_outside?(lighting_controller.starlight):0)
the_part_where_I_calculate_brightness()
if(lighting_ready() && lit_value != old_value)
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 = light.CalculateBrightness(src)
var/brightness = lit_by[light]//light.CalculateBrightness(src)
if(brightness > max_brightness)
max_brightness = brightness
lit_value = LIGHTCLAMP(max_brightness)
ResetCachedValues()
for(var/turf/T in range(1,src))
lighting_controller.MarkIconUpdate(T)
the_part_where_I_use_range()
ResetCachedValues()
for(var/turf/T in range(1,src))
lighting_controller.MarkIconUpdate(T)
turf/proc/ResetCachedValues()
lightNE.cached_value = -1
lightNW.cached_value = -1
lightSE.cached_value = -1
lightSW.cached_value = -1
if(lightNE)
lightNE.cached_value = -1
if(lightNW)
lightNW.cached_value = -1
if(lightSE)
lightSE.cached_value = -1
if(lightSW)
lightSW.cached_value = -1
turf/proc/CheckForOpaqueObjects()
has_opaque = opacity
@@ -165,12 +201,5 @@ turf/proc/CheckForOpaqueObjects()
if(M.opacity)
has_opaque = 1
break
if(is_outside)
for(var/d = 1, d < 16, d*=2)
var/turf/T = get_step(src,d)
if(T && !T.is_outside)
lighting_controller.AddBorder(src)
return
if(is_border) lighting_controller.RemoveBorder(src)
#undef LIGHTCLAMP

View File

@@ -37,8 +37,9 @@ light/proc/Reset()
if(intensity > 0)
for(var/turf/T in view(atom,radius+1))
T.AddLight(src)
lit_turfs.Add(T)
if(!T.is_outside)
T.AddLight(src)
lit_turfs.Add(T)
light/proc/Off()
for(var/turf/T in lit_turfs)