ID:141237
 
Code:
world/New()
..()
spawn() Repopper()
spawn() Delete()
spawn() DAYNIGHT()



proc/Repopper()
while(world)
sleep(HOUR*2)
world.Repop()
world<<"<b><font color=red>AutoRepop the world has been restored!</b></font>"

proc/Delete()
while(world)
sleep(HOUR*2)
for(var/obj/Grave/G in world) del(G)
for(var/mob/Suiryuudan/S in world) del(S)
for(var/obj/Mirror/M in world) del(M)
for(var/obj/Mist/M2 in world) del(M2)
for(var/obj/projc/Kunai/k in world) del(k)
for(var/obj/projc/Shuriken/ss in world) del(ss)
for(var/obj/projc/Needle/N in world) del(N)
for(var/obj/projc/NoteKunai/NK in world) del(NK)
proc/DAYNIGHT()
while(world)
sleep(HOUR*3)
var/obj/Night/O = new /obj/Night
world<<"<b><font color=red>Night falls over the land covering it in darkness.</b></font>"
for(var/turf/T in world)
if(!T.weatherProof) T.overlays += O
else
if(istype(T,/turf/LAMPZ))
T.overlays -= O
T.icon='turfs.dmi'
T.icon_state="lit"
sleep(HOUR*3)
for(var/turf/T in world)
if(!T.weatherProof) T.overlays -= O
if(istype(T,/turf/LAMPZ))
T.overlays -= O
T.icon='turfs.dmi'
T.icon_state="lamp1"
world<<"<b><font color=yellow>The sun rises above the sky and gleams over and lights up the land.</b></font>"

obj/Night
icon='mist.dmi'
icon_state="night"
layer = MOB_LAYER+52
turf/LAMP/Area
luminosity=6
weatherProof=1


Problem description:
When night system changed over it had a lag spike, but it works, what could i do to prevent or weakin this lag spike?
Its cause your going over every turf in the world, its better to use areas like ShadowDarkes day/night system does.
In response to Bakasensei
so that would double the size of the map, cant u like add only specific turfs that can become dark? like grass and step stones,ect?
Instead of adding an overlay, you could just make it a different icon state of an /area. Just put everywhere that is outside in the night time area. Then to change the graphics, all you have to do is change the icon state of the area. (Have a blank icon state for the day time.)
In response to Louisthe10
No it wouldn't. Your map is already covered in an area, everything is. So making a new area, maybe called outside, that would change to an icon so its just 1 area changing instead of maybe 10 thousand turfs.
In response to Bakasensei
Definately go with the area idea. We have that implemented into NFF and it works flawlessly...on the two maps we actually have it on anyways but it works very well.

No lag to speak of when it changes from day to night or vice versa. Though I should mention we have a dedicated linux server thats only purpose in life is to host our game and has 5 gb of RAM, 240 GB of Harddrive space, 3.6 g/h processor and...lots of other stuff thats probably not necessary.
In response to DemonicK
but wouldnt a new area turf just make the map bigger? Could i just do something if(turf/grass&&turf/stepstones/ect) ect only the outside icons.
Easiest thing I can think of you to do is create an icon file called 'area.dmi' with two icon_states in it. One blank for day (with no name for the icon_state) and another black icon_state with an alpha of 150-180 named "night".

Then all you have to do is the following.

area
icon='area.dmi'
New()
..()
while(1)
sleep(600) //Every minute it changes
if(icon_state=="night") icon_state=""
else icon_state="night"


And it'll change it automatically. It only creates one single loop, so you don't have to worry about it being a resource hog or anything. It will affect every square on your map, without you actually having to put anything on the map itself.

Play around with it, it's rather simple.
how would i put this code if i added a var for outside for turfs i want to become dark, in the turf code itself, and make it go over anything that is ouside. how would i code it going over an outside turf?(outside is a var)
In response to Louisthe10
Don't alter the turfs at all. The best way to go about it is by adding an area over the turfs that should become dark, you define it this way.

var/area/outside/outside_area
//This way the var name is outside_area which you will alter

area/outside
invisibility=1
layer=20 //You can change this to higher or lower, but you want it above turf_layer
icon='area.dmi'
/*Create a .dmi file named 'area.dmi' with one icon_state.
Fill it with a black color with an alpha of 100-180 depending on how dark you want it. */


New()
..()
outside_area=src


Now that it's defined and you made the icon, to change from day to night all you have to do is the following.

mob/verb/test_day_and_night()
if(outside_area.invisibility)
outside_area.invisibility=0
world<<"Night time!!!"
else
outside_area.invisibility=1
world<<"Day time!!!"


Just play with it. Go to the map editor and under area you'll see a [+]. Simply place the "outside" over whatever you deem to be changed by day and night, and run the program. Play with the verb, it's actually rather simple.

What you don't wanna do is change the turfs, that will lag out your game every cycle. Find a way to incorporate this method instead. You'll find that alphas can do a lot of justice to an icon if you give it a chance. There is no way to smoothly change every turf in the game at a given time. Unless of course you're playing on a 10x10x1 map.
In response to The Naked Ninja
Are you 100% that i have to use a outside area or outside turf, i made this originally to avoid making the map bigger. Could i just have it apply to just turfs that i code in. For example grass, stones, ect. all my outside turfs are not used inside so i should be good if there is a way to do it like a planned.
In response to Louisthe10
Area won't make the map bigger. It seems you're thinking of area in the sense of creating a whole new "area".

Area is the 'A' in ATOM. (Area, Turf, Obj, Mob) and you won't make the map any bigger than it is. All you are doing is adding an ATOM atop your map, which will alter the map in no other way than providing another visible layer that already existed in the first place.