// LightMap builds a lighting map with given light sources. It returs a cached
// slice of lighted nodes. Values can also be consulted with At.
LightMap builds a lighting map with given light sources. It returs a cached
slice of lighted nodes. Values can also be consulted with At.
// LightMap builds a lighting map with given light sources . It returs a cached // slice of lighted nodes . Values can also be consulted with At .
func (fov *FOV) LightMap(lt Lighter, srcs []gruid.Point) []LightNode {
	if fov.Costs == nil {
		fov.Costs = make([]int, fov.Capacity)
	}
	for i := range fov.Costs {
		fov.Costs[i] = 0
	}
	for _, src := range srcs {
		if !src.In(fov.Rg) {
			continue
		}
		fov.Src = src
		fov.Costs[fov.idx(src)] = 1
		for d := 1; d <= lt.MaxCost(src); d++ {
			rg := fov.Rg.Intersect(gruid.NewRange(src.X-d, src.Y-d+1, src.X+d+1, src.Y+d))
			if src.Y+d < fov.Rg.Max.Y {
				for x := rg.Min.X; x < rg.Max.X; x++ {
					fov.lightUpdate(lt, src, gruid.Point{x, src.Y + d})
				}
			}
			if src.Y-d >= fov.Rg.Min.Y {
				for x := rg.Min.X; x < rg.Max.X; x++ {
					fov.lightUpdate(lt, src, gruid.Point{x, src.Y - d})
				}
			}
			if src.X+d < fov.Rg.Max.X {
				for y := rg.Min.Y; y < rg.Max.Y; y++ {
					fov.lightUpdate(lt, src, gruid.Point{src.X + d, y})
				}
			}
			if src.X-d >= fov.Rg.Min.X {
				for y := rg.Min.Y; y < rg.Max.Y; y++ {
					fov.lightUpdate(lt, src, gruid.Point{src.X - d, y})
				}
			}
		}
	}
	fov.computeLighted()
	return fov.Lighted
}
func ( fov * FOV ) LightMap ( lt Lighter , srcs [ ] gruid . Point ) [ ] LightNode { if fov . Costs == nil { fov . Costs = make ( [ ] int , fov . Capacity ) } for i := range fov . Costs { fov . Costs [ i ] = 0 } for _ , src := range srcs { if ! src . In ( fov . Rg ) { continue } fov . Src = src fov . Costs [ fov . idx ( src ) ] = 1 for d := 1 ; d <= lt . MaxCost ( src ) ; d ++ { rg := fov . Rg . Intersect ( gruid . NewRange ( src . X - d , src . Y - d + 1 , src . X + d + 1 , src . Y + d ) ) if src . Y + d < fov . Rg . Max . Y { for x := rg . Min . X ; x < rg . Max . X ; x ++ { fov . lightUpdate ( lt , src , gruid . Point { x , src . Y + d } ) } } if src . Y - d >= fov . Rg . Min . Y { for x := rg . Min . X ; x < rg . Max . X ; x ++ { fov . lightUpdate ( lt , src , gruid . Point { x , src . Y - d } ) } } if src . X + d < fov . Rg . Max . X { for y := rg . Min . Y ; y < rg . Max . Y ; y ++ { fov . lightUpdate ( lt , src , gruid . Point { src . X + d , y } ) } } if src . X - d >= fov . Rg . Min . X { for y := rg . Min . Y ; y < rg . Max . Y ; y ++ { fov . lightUpdate ( lt , src , gruid . Point { src . X - d , y } ) } } } } fov . computeLighted ( ) return fov . Lighted }
LightMap builds a lighting map with given light sources.
LightMap builds a lighting map with given light sources .