Page 1 of 1
Lighting code
Posted: Mon Jul 20, 2015 9:18 pm
by mosquitoman
Hi
Is there anybody here who knows how the lighting system works? Is it area or tile based? What's the actual algorithm doing?
I tried looking through the code but a lot of it is very hard to follow, with many dependent classes in separate files and whatnot.
Re: Lighting code
Posted: Mon Jul 20, 2015 9:55 pm
by Scott
MrPerson did it.
Re: Lighting code
Posted: Tue Jul 21, 2015 3:31 am
by Remie Richards
it's tile based lighting, there is a lighting object (/atom/movable/light iirc) on every turf, and they do all the work of brightening and dimming the turf.
a lot of it is just calculating differences in light, finding out if it needs an update, and then redrawing it.
Re: Lighting code
Posted: Tue Jul 21, 2015 10:37 am
by MisterPerson
mosquitoman wrote:Hi
Is there anybody here who knows how the lighting system works? Is it area or tile based? What's the actual algorithm doing?
I tried looking through the code but a lot of it is very hard to follow, with many dependent classes in separate files and whatnot.
It's a tile-based system adapted from an area-based system.
I tried to keep everything in two files: The single file in the lighting module folder and the lighting subsystem in the subsystem folder. I would focus on the lighting datums themselves; they do all the heavy lifting like which tiles are affected and calculating how much light is affecting each tile. They don't manually do any of this; they only recalculate their effects when told to. Basically when a light's effect needs updating, something makes the light datum call changed(), which eventually calls check(). check() clears the current effect and applies a new one. Then all the turfs which were changed by any light call redraw_lighting(). All this one does is tell the lighting object (the visual object on the map) to change its appearance to match how bright the tile is supposed to be.
Most of the rest of the stuff is either setting up the light datums or setting up the lighting objects on the map or handling ChangeTurf() or telling the light datums when to call changed().
And yes, I know having a light datum and a lighting object is confusing.
Re: Lighting code
Posted: Tue Jul 21, 2015 11:03 am
by mosquitoman
Thanks a lot, that's much clearer now. What do the effects define? And how is lighting the non-turf objects handled?
Re: Lighting code
Posted: Tue Jul 21, 2015 11:42 am
by MisterPerson
The effects list is an associative list stored for each light datum where the keys are turfs being affected and the values associated with each turf is how much light is being applied (ie turf1 = 10, turf2 = 9.1, etc). The actual strength values are completely arbitrary but for every light, the origin is fully lit and the "strength"/luminosity is actually range. One of my eventual plans is to separate strength and range so 1-tile lights don't look like ass because that tile is fully lit and the surrounding tiles are fully dark.
The actual lighting is just a mask on top of everything on the map. It darkens everything lower, including the turf and all the objects on the map.