bruteforce
This commit is contained in:
parent
657af45eb1
commit
c22c4d890f
@ -5,6 +5,6 @@
|
|||||||
"sizeY": 47,
|
"sizeY": 47,
|
||||||
"fpsLimit": 60,
|
"fpsLimit": 60,
|
||||||
"font": "./resources/fonts-ttf/LiberationMono-Bold.ttf",
|
"font": "./resources/fonts-ttf/LiberationMono-Bold.ttf",
|
||||||
"fontSize": "8x12",
|
"fontSize": "9x14",
|
||||||
"verbosity": "debug"
|
"verbosity": "debug"
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,9 @@ Pre-Computed Visiblity Trees on RogueBasin
|
|||||||
Adam Milazzo's FOV Method Roundup where a similar method described as 'permissive' is detailed
|
Adam Milazzo's FOV Method Roundup where a similar method described as 'permissive' is detailed
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const MIN_LIT_TO_BE_VISIBLE = 1
|
||||||
|
const MIN_WALL_LIT_TO_BE_VISIBLE = 4
|
||||||
|
|
||||||
var errNotFoundCell = errors.New("Cell not found")
|
var errNotFoundCell = errors.New("Cell not found")
|
||||||
var errOutOfBounds = errors.New("Cell out of bounds")
|
var errOutOfBounds = errors.New("Cell out of bounds")
|
||||||
|
|
||||||
@ -163,9 +166,9 @@ func (ps *precomputedShade) PrecomputeFovMap() {
|
|||||||
|
|
||||||
//Bresanham lines / Raycast
|
//Bresanham lines / Raycast
|
||||||
var lineX, lineY float64
|
var lineX, lineY float64
|
||||||
for i := 0; i < 360; i++ {
|
for i := 0; i < 720; i++ { // 1/2 of angles
|
||||||
dx := math.Sin(float64(i) / (float64(180) / math.Pi))
|
dx := math.Sin(float64(i) / (float64(360) / math.Pi)) //1/2 of angles
|
||||||
dy := math.Cos(float64(i) / (float64(180) / math.Pi))
|
dy := math.Cos(float64(i) / (float64(360) / math.Pi))
|
||||||
|
|
||||||
lineX = 0
|
lineX = 0
|
||||||
lineY = 0
|
lineY = 0
|
||||||
@ -204,11 +207,11 @@ func (ps *precomputedShade) recalc(level *gamemap.Level, initCoords types.Coords
|
|||||||
|
|
||||||
level.GetTile(initCoords).Visible = true
|
level.GetTile(initCoords).Visible = true
|
||||||
|
|
||||||
var fullShade = make([]byte, 360)
|
var fullShade = make([]byte, 720) // 1/2 of angles
|
||||||
for i := range fullShade {
|
for i := range fullShade {
|
||||||
fullShade[i] = 1
|
fullShade[i] = 1
|
||||||
}
|
}
|
||||||
var emptyShade = make([]byte, 360)
|
var emptyShade = make([]byte, 720) // 1/2 of angles
|
||||||
currentShade := emptyShade
|
currentShade := emptyShade
|
||||||
nextShade := emptyShade
|
nextShade := emptyShade
|
||||||
|
|
||||||
@ -236,7 +239,11 @@ func (ps *precomputedShade) recalc(level *gamemap.Level, initCoords types.Coords
|
|||||||
//fmt.Printf("\n level coords: %v", lc)
|
//fmt.Printf("\n level coords: %v", lc)
|
||||||
for _, angle := range cell.occludedAngles {
|
for _, angle := range cell.occludedAngles {
|
||||||
|
|
||||||
if level.GetTile(lc).BlocksSight {
|
if level.GetTile(lc).BlocksSight && ps.LightWalls {
|
||||||
|
if (nextShade[angle] == 0 && currentShade[angle] == 0) {
|
||||||
|
level.GetTile(lc).Visible = true
|
||||||
|
level.GetTile(lc).Explored = true
|
||||||
|
}
|
||||||
nextShade[angle] = 1
|
nextShade[angle] = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,7 +263,7 @@ func (ps *precomputedShade) ComputeFov(level *gamemap.Level, initCoords types.Co
|
|||||||
for _, cell := range ps.CellList {
|
for _, cell := range ps.CellList {
|
||||||
//fmt.Printf("\n coords: %v, distance: %f, lit: %d", cell.Coords, cell.distance, cell.lit)
|
//fmt.Printf("\n coords: %v, distance: %f, lit: %d", cell.Coords, cell.distance, cell.lit)
|
||||||
cs, err := ps.toLevelCoords(level, initCoords, cell.Coords)
|
cs, err := ps.toLevelCoords(level, initCoords, cell.Coords)
|
||||||
if cell.lit > 2 {
|
if cell.lit > MIN_LIT_TO_BE_VISIBLE {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -265,21 +272,25 @@ func (ps *precomputedShade) ComputeFov(level *gamemap.Level, initCoords types.Co
|
|||||||
}
|
}
|
||||||
|
|
||||||
//light walls, crutch
|
//light walls, crutch
|
||||||
if level.GetTile(cs).BlocksSight && ps.LightWalls {
|
//if level.GetTile(cs).BlocksSight && ps.LightWalls {
|
||||||
if cell.IsAdjacentTo(&types.Coords{0,0}) {
|
// if cell.IsAdjacentTo(&types.Coords{0,0}) {
|
||||||
level.GetTile(cs).Visible = true
|
// level.GetTile(cs).Visible = true
|
||||||
} else {
|
// } else {
|
||||||
for _, maybeNb := range ps.CellList {
|
// maybeLit := false
|
||||||
if //int(maybeNb.distance) == int(cell.distance-1) &&
|
// for _, maybeNb := range ps.CellList {
|
||||||
maybeNb.IsAdjacentTo(&cell.Coords) &&
|
// if //int(maybeNb.distance) == int(cell.distance-1) &&
|
||||||
//(maybeNb.X == cell.X || maybeNb.Y == cell.Y) &&
|
// maybeNb.IsAdjacentTo(&cell.Coords) &&
|
||||||
maybeNb.lit > 5 { //magic constant!
|
// (maybeNb.X == cell.X || maybeNb.Y == cell.Y) &&
|
||||||
level.GetTile(cs).Visible = true
|
// maybeNb.lit > MIN_WALL_LIT_TO_BE_VISIBLE { //magic constant!
|
||||||
level.GetTile(cs).Explored = true
|
// maybeLit = true
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// if maybeLit {
|
||||||
}
|
// level.GetTile(cs).Visible = true
|
||||||
|
// level.GetTile(cs).Explored = true
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user