Lighting code

How, what and why to code in BYOND.
Post Reply
mosquitoman
Joined: Fri May 01, 2015 7:52 pm
Byond Username: MosquitoMan

Lighting code

Post by mosquitoman » #105950

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.
Scott
Github User
Joined: Fri Apr 18, 2014 1:50 pm
Byond Username: Xxnoob
Github Username: xxalpha

Re: Lighting code

Post by Scott » #105957

MrPerson did it.
User avatar
Remie Richards
Joined: Thu Apr 17, 2014 7:11 pm
Byond Username: CrimsonVision
Location: England, UK, Earth, Sol, Milky Way, Local Group, Virgo Supercluster, Known Universe
Contact:

Re: Lighting code

Post by Remie Richards » #106066

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.
私は完璧
User avatar
MisterPerson
Board Moderator
Joined: Tue Apr 15, 2014 4:26 pm
Byond Username: MisterPerson

Re: Lighting code

Post by MisterPerson » #106159

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.
I code for the code project and moderate the code sections of the forums.

Feedback is dumb and it doesn't matter
mosquitoman
Joined: Fri May 01, 2015 7:52 pm
Byond Username: MosquitoMan

Re: Lighting code

Post by mosquitoman » #106168

Thanks a lot, that's much clearer now. What do the effects define? And how is lighting the non-turf objects handled?
User avatar
MisterPerson
Board Moderator
Joined: Tue Apr 15, 2014 4:26 pm
Byond Username: MisterPerson

Re: Lighting code

Post by MisterPerson » #106175

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.
I code for the code project and moderate the code sections of the forums.

Feedback is dumb and it doesn't matter
Post Reply

Who is online

Users browsing this forum: No registered users