From ca7d4026b83db7214e9e8eb44a72374e4c648987 Mon Sep 17 00:00:00 2001 From: Aryn Date: Sun, 23 Feb 2014 07:50:58 -0700 Subject: [PATCH] Lighting system is too buggy to continue until I know wtf is going on --- baystation12.dme | 8 +- .../Aryn/Lighting/Compatibility.dm | 41 ++++++++ .../Aryn/Lighting/Controller.dm | 54 ++++++----- code/WorkInProgress/Aryn/Lighting/Engine.dm | 97 ++++++++++++------- code/WorkInProgress/Aryn/Lighting/Light.dm | 5 +- code/ZAS/Zone.dm | 1 + code/controllers/failsafe.dm | 5 +- code/controllers/master_controller.dm | 1 + code/controllers/verbs.dm | 2 +- code/game/area/areas.dm | 6 +- code/game/gamemodes/gameticker.dm | 2 +- code/game/objects/items/blueprints.dm | 3 - code/game/turfs/turf.dm | 17 ++-- code/modules/mob/living/carbon/human/life.dm | 8 +- code/modules/mob/living/carbon/monkey/life.dm | 2 +- code/modules/power/lighting.dm | 4 +- 16 files changed, 163 insertions(+), 93 deletions(-) create mode 100644 code/WorkInProgress/Aryn/Lighting/Compatibility.dm diff --git a/baystation12.dme b/baystation12.dme index d2f2026b50..f61266ba9b 100644 --- a/baystation12.dme +++ b/baystation12.dme @@ -74,13 +74,11 @@ #include "code\ATMOSPHERICS\components\unary\unary_base.dm" #include "code\ATMOSPHERICS\components\unary\vent_pump.dm" #include "code\ATMOSPHERICS\components\unary\vent_scrubber.dm" -#include "code\controllers\_DynamicAreaLighting_TG.dm" #include "code\controllers\autotransfer.dm" #include "code\controllers\configuration.dm" #include "code\controllers\failsafe.dm" #include "code\controllers\hooks-defs.dm" #include "code\controllers\hooks.dm" -#include "code\controllers\lighting_controller.dm" #include "code\controllers\master_controller.dm" #include "code\controllers\shuttle_controller.dm" #include "code\controllers\verbs.dm" @@ -1285,6 +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\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 new file mode 100644 index 0000000000..e9109bc67f --- /dev/null +++ b/code/WorkInProgress/Aryn/Lighting/Compatibility.dm @@ -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) \ No newline at end of file diff --git a/code/WorkInProgress/Aryn/Lighting/Controller.dm b/code/WorkInProgress/Aryn/Lighting/Controller.dm index aaeb9ce17f..7f93107dd5 100644 --- a/code/WorkInProgress/Aryn/Lighting/Controller.dm +++ b/code/WorkInProgress/Aryn/Lighting/Controller.dm @@ -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 << "Processing lights..." - 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 << "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 << "Lighting initialization took [(world.timeofday-start_time)/world.fps] seconds." world << "Updated [turfs_updated] turfs." -/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) diff --git a/code/WorkInProgress/Aryn/Lighting/Engine.dm b/code/WorkInProgress/Aryn/Lighting/Engine.dm index 9c7dcfa713..7b3458b29a 100644 --- a/code/WorkInProgress/Aryn/Lighting/Engine.dm +++ b/code/WorkInProgress/Aryn/Lighting/Engine.dm @@ -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 \ No newline at end of file diff --git a/code/WorkInProgress/Aryn/Lighting/Light.dm b/code/WorkInProgress/Aryn/Lighting/Light.dm index 40cf88120d..0fd824eca1 100644 --- a/code/WorkInProgress/Aryn/Lighting/Light.dm +++ b/code/WorkInProgress/Aryn/Lighting/Light.dm @@ -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) diff --git a/code/ZAS/Zone.dm b/code/ZAS/Zone.dm index 17d6097cda..2d3346ab05 100644 --- a/code/ZAS/Zone.dm +++ b/code/ZAS/Zone.dm @@ -108,6 +108,7 @@ Class Procs: /zone/proc/rebuild() if(invalid) return //Short circuit for explosions where rebuild is called many times over. + if(air_master.current_cycle == 0) return //Why would you rebuild when you're building? c_invalidate() for(var/turf/simulated/T in contents) //T.dbg(invalid_zone) diff --git a/code/controllers/failsafe.dm b/code/controllers/failsafe.dm index 91449e10c8..bfc0b08fd9 100644 --- a/code/controllers/failsafe.dm +++ b/code/controllers/failsafe.dm @@ -45,7 +45,8 @@ var/datum/controller/failsafe/Failsafe MC_defcon = 0 MC_iteration = controller_iteration - if(lighting_controller.processing) + //Lighting controller now neither processes nor iterates. + /*if(lighting_controller.processing) if(lighting_iteration == lighting_controller.iteration) //master_controller hasn't finished processing in the defined interval switch(lighting_defcon) if(0 to 3) @@ -60,7 +61,7 @@ var/datum/controller/failsafe/Failsafe lighting_defcon = 0 else lighting_defcon = 0 - lighting_iteration = lighting_controller.iteration + lighting_iteration = lighting_controller.iteration*/ else MC_defcon = 0 lighting_defcon = 0 diff --git a/code/controllers/master_controller.dm b/code/controllers/master_controller.dm index e0bd38086a..e5970e40fb 100644 --- a/code/controllers/master_controller.dm +++ b/code/controllers/master_controller.dm @@ -77,6 +77,7 @@ datum/controller/game_controller/proc/setup() if(ticker) ticker.pregame() + new/datum/controller/lighting() lighting_controller.Initialize() diff --git a/code/controllers/verbs.dm b/code/controllers/verbs.dm index 3faa6e4c80..ace54c03a7 100644 --- a/code/controllers/verbs.dm +++ b/code/controllers/verbs.dm @@ -19,7 +19,7 @@ feedback_add_details("admin_verb","RFailsafe") if("Lighting") new /datum/controller/lighting() - lighting_controller.process() + //lighting_controller.process() feedback_add_details("admin_verb","RLighting") if("Supply Shuttle") supply_shuttle.process() diff --git a/code/game/area/areas.dm b/code/game/area/areas.dm index f69b2a35e3..9161ac9570 100644 --- a/code/game/area/areas.dm +++ b/code/game/area/areas.dm @@ -24,20 +24,16 @@ // lighting_state = 4 //has_gravity = 0 // Space has gravity. Because.. because. - if(requires_power) - luminosity = 0 - else + if(!requires_power) power_light = 0 //rastaf0 power_equip = 0 //rastaf0 power_environ = 0 //rastaf0 - luminosity = 1 lighting_use_dynamic = 0 ..() // spawn(15) power_change() // all machines set to current power level, also updates lighting icon - InitializeLighting() /area/proc/poweralert(var/state, var/obj/source as obj) diff --git a/code/game/gamemodes/gameticker.dm b/code/game/gamemodes/gameticker.dm index 371db0de19..f0361f2245 100644 --- a/code/game/gamemodes/gameticker.dm +++ b/code/game/gamemodes/gameticker.dm @@ -148,7 +148,7 @@ var/global/datum/controller/gameticker/ticker supply_shuttle.process() //Start the supply shuttle regenerating points -- TLE master_controller.process() //Start master_controller.process() - lighting_controller.process() //Start processing DynamicAreaLighting updates + //lighting_controller.process() //Start processing DynamicAreaLighting updates for(var/obj/multiz/ladder/L in world) L.connect() //Lazy hackfix for ladders. TODO: move this to an actual controller. ~ Z diff --git a/code/game/objects/items/blueprints.dm b/code/game/objects/items/blueprints.dm index 5c5b1b6fd8..92ed4e9244 100644 --- a/code/game/objects/items/blueprints.dm +++ b/code/game/objects/items/blueprints.dm @@ -133,9 +133,6 @@ move an amendment to the drawing.

move_turfs_to_area(turfs, A) A.always_unpowered = 0 - for(var/turf/T in A.contents) - T.lighting_changed = 1 - lighting_controller.changed_turfs += T spawn(5) //ma = A.master ? "[A.master]" : "(null)" diff --git a/code/game/turfs/turf.dm b/code/game/turfs/turf.dm index 57e9aab94c..04aa40318c 100644 --- a/code/game/turfs/turf.dm +++ b/code/game/turfs/turf.dm @@ -195,6 +195,8 @@ if(L) del L +var/turf_light_data/old_lights = new + //Creates a new turf /turf/proc/ChangeTurf(var/turf/N) if (!N) @@ -214,10 +216,10 @@ return W ///// Z-Level Stuff - var/old_lumcount = lighting_lumcount - initial(lighting_lumcount) - //world << "Replacing [src.type] with [N]" + old_lights.copy_from(src) + if(connections) connections.erase_all() if(istype(src,/turf/simulated)) @@ -238,10 +240,7 @@ var/turf/simulated/W = new N( locate(src.x, src.y, src.z) ) //W.Assimilate_Air() - W.lighting_lumcount += old_lumcount - if(old_lumcount != W.lighting_lumcount) - W.lighting_changed = 1 - lighting_controller.changed_turfs += W + old_lights.copy_to(W) if (istype(W,/turf/simulated/floor)) W.RemoveLattice() @@ -259,10 +258,8 @@ // zone.SetStatus(ZONE_ACTIVE) var/turf/W = new N( locate(src.x, src.y, src.z) ) - W.lighting_lumcount += old_lumcount - if(old_lumcount != W.lighting_lumcount) - W.lighting_changed = 1 - lighting_controller.changed_turfs += W + + old_lights.copy_to(W) if(air_master) air_master.mark_for_update(src) diff --git a/code/modules/mob/living/carbon/human/life.dm b/code/modules/mob/living/carbon/human/life.dm index a9680785f6..26fa2378e6 100644 --- a/code/modules/mob/living/carbon/human/life.dm +++ b/code/modules/mob/living/carbon/human/life.dm @@ -897,7 +897,7 @@ var/turf/T = loc var/area/A = T.loc if(A) - if(A.lighting_use_dynamic) light_amount = min(10,T.lighting_lumcount) - 5 //hardcapped so it's not abused by having a ton of flashlights + if(A.lighting_use_dynamic) light_amount = min(10,T.lit_value) - 5 //hardcapped so it's not abused by having a ton of flashlights else light_amount = 5 nutrition += light_amount traumatic_shock -= light_amount @@ -917,7 +917,7 @@ var/turf/T = loc var/area/A = T.loc if(A) - if(A.lighting_use_dynamic) light_amount = T.lighting_lumcount + if(A.lighting_use_dynamic) light_amount = T.lit_value else light_amount = 10 if(light_amount > 2) //if there's enough light, start dying take_overall_damage(1,1) @@ -1072,7 +1072,7 @@ E = get_visible_implants(0) if(!E.len) embedded_flag = 0 - + //Eyes if(sdisabilities & BLIND) //disabled-blind, doesn't get better on its own @@ -1393,7 +1393,7 @@ //0.1% chance of playing a scary sound to someone who's in complete darkness if(isturf(loc) && rand(1,1000) == 1) var/turf/currentTurf = loc - if(!currentTurf.lighting_lumcount) + if(!currentTurf.lit_value) playsound_local(src,pick(scarySounds),50, 1, -1) proc/handle_virus_updates() diff --git a/code/modules/mob/living/carbon/monkey/life.dm b/code/modules/mob/living/carbon/monkey/life.dm index 4ec4d41306..30cd98d444 100644 --- a/code/modules/mob/living/carbon/monkey/life.dm +++ b/code/modules/mob/living/carbon/monkey/life.dm @@ -446,7 +446,7 @@ var/turf/T = loc var/area/A = T.loc if(A) - if(A.lighting_use_dynamic) light_amount = min(10,T.lighting_lumcount) - 5 //hardcapped so it's not abused by having a ton of flashlights + if(A.lighting_use_dynamic) light_amount = min(10,T.lit_value) - 5 //hardcapped so it's not abused by having a ton of flashlights else light_amount = 5 nutrition += light_amount diff --git a/code/modules/power/lighting.dm b/code/modules/power/lighting.dm index 0a3a4d3794..76f486e4c4 100644 --- a/code/modules/power/lighting.dm +++ b/code/modules/power/lighting.dm @@ -604,8 +604,8 @@ #define LIGHTING_POWER_FACTOR 20 //20W per unit luminosity /obj/machinery/light/process()//TODO: remove/add this from machines to save on processing as needed ~Carn PRIORITY - if(on) - use_power(luminosity * LIGHTING_POWER_FACTOR, LIGHT) + if(on && light) + use_power(light.radius * LIGHTING_POWER_FACTOR, LIGHT) // called when area power state changes /obj/machinery/light/power_change()