sd_DynamicAreaLighting

by Shadowdarke
Fast and easy dynamic lighting
ID:91659
 
The sd_DynamicAreaLighting library provides dynamic lighting with minimal cpu and bandwidth usage by shifting turfs between areas which represent varying shades of darkness.

Version 10: 5-27-08
  • Added support for custom darkness icons, including customization of how many shades of darkness there are.
  • Included several demo darkness icons and updated the demo program to allow you to switch them at runtime.


Version 9: 1-29-07
  • SetOpacity() no longer causes errors due to mob.sight settings.


Version 8: 4-6-05
  • Added some optimizations by Lummox JR.
  • Fixed a bug that caused outside areas to generate improperly. (Xooxer)


Version 7: 2-23-04
  • Added global sd_top_luminosity to cut down on the size of internally used lists.
  • Added the turf sd_LumReset() proc.
  • Changed area.New() to allow zeroing an area's sd_lighting var in the same tick it is created without the need to strip the darkness overlay manually. If you set sd_lighting after the first tick, you should be sure to remove the sd_darkimage from the area's overlays.


Version 6: 3-6-03
Extended the mob procs slightly to compensate for mob.sight settings. The old versions would allow the light to shine through opaque walls if a mob's sight was set to SEE_TURFS.

Version 5: 2-25-03
Changed the turf.sd_lumcount var to a tmp var, so sd_DAL works properly with save files.

Version 4: 12-21-02
Fixed a bug that prevented outside areas from lighting properly if sd_outside was set in the map editor.

Version 3:
Added support for daylight spilling indoors.
Fixed an error involving atoms moving into and out of the contents of non-turfs.

Version 2:
A major rehash of the internal workings. sd_DAL now works with the areas already in your game!

Anyone already using version 1 will need to make some changes. Please read the comments in the library file.
A great, easy-to-use lighting system. Very fast.
Looks like this guy is long gone but, an update does need to be made to the library to support mouse_opacity (like turning it off for dark area's that cover up atoms.)
How does one make a day/night cycle with this, i plugged it into a new game and it doesnt change the brightness
From the "readme" style comments in the library:

DAY/NIGHT CYCLES

sd_DynamicAreaLighting allows for separate indoor and outdoor
lighting. Areas used for outdoor light cycles should be
designated by setting the area's sd_outside var to 1. For example:

area/outside
sd_outside=1

You will need to write your own routine for the day/night
cycle so that you can control the timing and degree of lighting
changes. There is an example routine in lightingdemo.dm.

After your routine determines the amount of light outdoors,
call sd_OutsideLight(light_level) to update the light levels in
all outside areas. light_level should be a value from 0 to
sd_dark_shades, where 0 is darkest and sd_dark_shades is full
light.

The sd_OutsideLight() proc does not automatically detect a
range out of bounds in case you want to use nonstandard values
for interesting effects. For instance, you could use a negative
value to dampen light sources.


Basically, as the library says, it does not automatically give you a day/night cycle.

To set up a cycle, you need to write your own procedure to control the outside light level. You'll probably use some sort of constantly running loop.

But first, you need to make sure your map is set up properly. You'll need to define an /area for the outside, and set the area's sd_outside var to 1. This tells the library that this area is for the outside.

Then, you must fill all outside places on your map with this area.

Then, you've got to write a procedure that will change the light levels the way you want them to change. You just call sd_OutsideLight(n), where "n" is the light level you want to change to. This will probably be some loop that waits a certain length of time, then decreases the light level by 1, repeating until it gets to the lowest light you want, then reversing and getting brighter by 1 per loop, until it hits the brightest light level. You might even want to make it so it sticks at the lowest and brightest levels a little longer.

There's a demo file included in the library that has an example of how to write the loop to control the cycle.
yes, ive tried all that, but for some reason there is just me, a box of slight lighting around me and then complete blackness everywhere else
Well, at the very least, that means that you've got the lighting area placed on the map.

Did you set the outside area's sd_outside var?

area
outside_area //or whatever you named it
sd_outside=1


Also, maybe you should post your code that changes the outside light levels.
In response to SuperSaiyanGokuX
SuperSaiyanGokuX wrote:
Well, at the very least, that means that you've got the lighting area placed on the map.

Did you set the outside area's sd_outside var?

> area
> outside_area //or whatever you named it
> sd_outside=1
>

Also, maybe you should post your code that changes the outside light levels.

yeah, i have the whole area/outside/sd_outside = 1, also the code im trying to use is the DemoDayCycle from the library but its not really what i need...
Well, the demo procedure is just that, a demo. You'd have to tweak the cycle to match what you want (timing between light levels, basically, is what it boils down to)
var
daytime = "" // Used by mob/Stat() to disply the time of day

world
New()
..()
#if DM_VERSION>=400
// Only use the alpha blended icon if supported
sd_SetDarkIcon('sd_dark_alpha7.dmi',4)
#endif
// kick off the daylight cycles
spawn() DemoDayCycle()

proc/DemoDayCycle()
// a simple day/night cycle
var
time = 10 // how long it stays in this light state
light = 0 // how much light there is outside
d = 1 // amount of light increase
while(1) // keep doing until the program ends
sleep(time) // wait time ticks
time = 10 // set time to the default
light += d // shift the light amount

// if light level is outside the allowed range
if((light < 0) || (light > 4))
d = -d // switch the direction of light changes
light += d // put light back where it was
time = 100 // make this light period last longer

// just sets the time of day for the stat display
switch(d*light)
if(-4,4)
daytime = "Day"
if(-3,-2,-1)
daytime = "Dusk"
if(0)
daytime = "Night"
if(1,2,3)
daytime = "Dawn"

sd_OutsideLight(light)

I have changed it to use the alpha7, so what part of this needs to be changed/go , i know the daytime = "Dawn,night,dusk,day" goes
People still use this and not my own or FIREking's or Forum_Account's alternatives?
Murder Mansion still uses it. But mostly because it's tied into the game too tightly for me to easily replace it with something nicer. At least not until I get a lot more motivated.
I have a problem and I dont know what's going on. My head hurts trying to understand.. so here is a pic Image and video hosting by TinyPic

Little black spots everywhere!