colordance
This commit is contained in:
@ -37,7 +37,7 @@ CurrentShade variable with the contents of the NextShade variable.
|
||||
If the tested cell is opaque – for each angle in the range occludedAngles by the cell, place a 1 at the position
|
||||
determined by angle%360 in the NextShade string.
|
||||
|
||||
For each angle in the range occludedAngles by the cell, add 1 to the shade value for that cell for each 0 encountered
|
||||
For each angle in the range occludedAngles by the cell, add 1 to the lit value for that cell for each 0 encountered
|
||||
at the position determined by angle%360 in the CurrentShade string.
|
||||
|
||||
Notes
|
||||
@ -75,7 +75,8 @@ type Cell struct {
|
||||
types.Coords
|
||||
distance float64
|
||||
occludedAngles []int //indexes of cells in CellList
|
||||
shade int //shade value
|
||||
lit int //lit value
|
||||
wasOccluded bool
|
||||
}
|
||||
|
||||
type CellList []*Cell
|
||||
@ -116,7 +117,7 @@ func (ps *precomputedShade) IsInFov(coords types.Coords) bool {
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return cell.shade > 0
|
||||
return cell.lit > 0
|
||||
}
|
||||
|
||||
func (ps *precomputedShade) SetLightWalls(value bool) {
|
||||
@ -141,7 +142,7 @@ func (ps *precomputedShade) PrecomputeFovMap() {
|
||||
iterCoords := types.Coords{x, y}
|
||||
distance := zeroCoords.DistanceTo(iterCoords)
|
||||
if distance <= float64(max) {
|
||||
ps.CellList = append(ps.CellList, &Cell{iterCoords, distance, nil, 0})
|
||||
ps.CellList = append(ps.CellList, &Cell{iterCoords, distance, nil, 0, false})
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -223,19 +224,22 @@ func (ps *precomputedShade) recalc(level *gamemap.Level, initCoords types.Coords
|
||||
}
|
||||
|
||||
//fmt.Printf("\n level coords: %v", lc)
|
||||
if level.Tiles[lc.X][lc.Y].BlocksSight {
|
||||
level.Tiles[lc.X][lc.Y].Visible = true
|
||||
for _, angle := range cell.occludedAngles {
|
||||
for _, angle := range cell.occludedAngles {
|
||||
|
||||
if level.Tiles[lc.X][lc.Y].BlocksSight {
|
||||
nextShade[angle] = 1
|
||||
}
|
||||
}
|
||||
|
||||
for _, angle := range cell.occludedAngles {
|
||||
if currentShade[angle] == 0 {
|
||||
cell.shade = cell.shade + 1
|
||||
cell.lit = cell.lit + 1
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if level.Tiles[lc.X][lc.Y].BlocksSight {
|
||||
level.Tiles[lc.X][lc.Y].Visible = true
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -244,8 +248,8 @@ func (ps *precomputedShade) ComputeFov(level *gamemap.Level, initCoords types.Co
|
||||
ps.recalc(level, initCoords, radius)
|
||||
|
||||
for _, cell := range ps.CellList {
|
||||
//fmt.Printf("\n coords: %v, distance: %f, shade: %d", cell.Coords, cell.distance, cell.shade)
|
||||
if cell.shade > 0 {
|
||||
//fmt.Printf("\n coords: %v, distance: %f, lit: %d", cell.Coords, cell.distance, cell.lit)
|
||||
if cell.lit > 0 {
|
||||
cs, err := ps.toLevelCoords(level, initCoords, cell.Coords)
|
||||
if err != nil {
|
||||
continue
|
||||
|
@ -59,7 +59,7 @@ func TestPrecompShade(t *testing.T) {
|
||||
level.Tiles[10][11] = gamemap.NewWall()
|
||||
level.Tiles[11][10] = gamemap.NewWall()
|
||||
|
||||
ppFov.ComputeFov(level, playerCoords, 15)
|
||||
ppFov.ComputeFov(level, playerCoords, 12)
|
||||
|
||||
fmt.Printf("\n\n")
|
||||
|
||||
|
Reference in New Issue
Block a user