Code effeciency project: Sun datum

Because of the wrong direction of this sign, every single solar array was being checked for occlusion every tick.

This should fix that right up.

Trackers set to update their angle only when the sun does.

Solar panels set to calculate occlusion every minute (was every tick (though thought to be set to every 6 minutes (36 degrees)), now checks every 6 degrees of sun movement or so)
This commit is contained in:
Ccomp5950
2014-02-14 11:54:08 +01:00
committed by alex-gh
parent 2655c9b341
commit 1c9271d218
+19 -17
View File
@@ -6,6 +6,7 @@
var/rate
var/list/solars // for debugging purposes, references solars_list at the constructor
var/nexttime = 3600 // Replacement for var/counter to force the sun to move every X IC minutes
var/lastAngleUpdate
/datum/sun/New()
@@ -24,15 +25,25 @@
counter = 0 */
angle = ((rate*world.time/100)%360 + 360)%360
/*
Yields a 45 - 75 IC minute rotational period
Rotation rate can vary from 4.8 deg/min to 8 deg/min (288 to 480 deg/hr)
*/
// To prevent excess server load the server only updates the sun's sight lines every 6 minutes
if(nexttime < world.time)
if(lastAngleUpdate != angle)
for(var/obj/machinery/power/tracker/T in solars_list)
if(!T.powernet)
solars_list.Remove(T)
continue
T.set_angle(angle)
lastAngleUpdate=angle
if(nexttime > world.time)
return
nexttime = nexttime + 3600 // 600 world.time ticks = 1 minute, 3600 = 6 minutes.
nexttime = nexttime + 600 // 600 world.time ticks = 1 minute
// now calculate and cache the (dx,dy) increments for line drawing
@@ -54,22 +65,13 @@
dy = c / abs(s)
for(var/obj/machinery/power/M in solars_list)
for(var/obj/machinery/power/solar/S in solars_list)
if(!M.powernet)
solars_list.Remove(M)
if(!S.powernet)
solars_list.Remove(S)
continue
// Solar Tracker
if(istype(M, /obj/machinery/power/tracker))
var/obj/machinery/power/tracker/T = M
T.set_angle(angle)
// Solar Panel
else if(istype(M, /obj/machinery/power/solar))
var/obj/machinery/power/solar/S = M
if(S.control)
occlusion(S)
if(S.control)
occlusion(S)