The Light System
I'm making this post because I have a funny feeling that I need to re-evaluate the design of the system, and possibly rewrite it from scratch. Here's how it works:
- All lighting is handled via /lighting obj's placed on every tile*
- The distance light is cast is done via a variable called
incandescence
- Lighting objects are updated every time a client moves, an incandescent object moves within view of a client.mob, an object in view of a client.mob changes incandescence, or a door/window is open/closed
- atom/light() - all of the logic for acquiring lighting objects within the range of the light source and
src
's affect on their overall intensity - lighting/update() - all of the logic for adjusting the intensity of the lighting object, and assigning it's
icon_state
accordingly
* I know this is far from the most efficient way to handle it, which I think is where I can improve the performance here drastically.
Screenshots
Shadowcasting
//-----------------------------------------//
// //
// This system uses AbyssDragon.BasicMath //
// //
//-----------------------------------------//
lighting
proc
// update the light level of the lighting object
update()
var/global_light = event_lighting.global_light // light level of the world
var/result = tile_light + global_light // resultant light level
var
light // light is the light level of the light source being referenced
distance // distance of light to src
for(var/atom/l in lights) // loop through the light sources affecting the lighting object
light = lights[l]
for(var/turf/o in getline(src, l))
// IF TURFS EVER END UP CASTING SHADOWS, ADD LOGIC HERE
for(var/atom/movable/a in o)
if(a == l) continue
if(a.shadowcast)
distance = distance(src, a)
if(!distance(a, l))
result -= light
else if(distance && distance <= pi)
result -= (( (light) / (distance * distance(src, l)) ) * pi)
result = min(230, max(global_light, round(result)))
if(icon_state != "[result]")
icon_state = "[result]"
I'd like to hear what I can do differently here. Any relevant snippets can be posted, but (for obvious reasons) I'm against putting too much code up on the site for all eyes. That being said, let me know what you need to look at in order to help out, and I'll gladly share it.
Looking forward to your help
- F0lak