merge master

This commit is contained in:
thefish 2024-04-22 13:55:13 +03:00
commit 4913b0a567
2 changed files with 15 additions and 13 deletions

View File

@ -46,7 +46,7 @@ func NewLevelRenderSystem(
return trs
}
//fixme add to screens/game Exit()
// fixme add to screens/game Exit()
func (trs LevelRenderSystem) Close() {
trs.animateTiles.Stop()
trs.animateTiles = nil //zero pointer to ticker
@ -93,7 +93,7 @@ func (trs LevelRenderSystem) Process() {
//terrain
for y := 0; y < trs.Viewport.H; y++ {
for x := 0; x < trs.Viewport.W; x++ {
mapCoords := types.Coords{trs.Viewport.CameraCoords.X + x, trs.Viewport.CameraCoords.Y + y}
mapCoords := types.Coords{X: trs.Viewport.CameraCoords.X + x, Y: trs.Viewport.CameraCoords.Y + y}
if trs.state.Level.InBounds(mapCoords) {
tile := trs.state.Level.GetTile(mapCoords)

View File

@ -124,7 +124,9 @@ func (ps *precomputedShade) FindByCoords(c types.Coords) (int, *Cell, error) {
func (ps *precomputedShade) IsInFov(coords types.Coords) bool {
rc := ps.fromLevelCoords(coords)
if rc.X == 0 && rc.Y ==0 {return true}
if rc.X == 0 && rc.Y == 0 {
return true
}
_, cell, err := ps.FindByCoords(rc)
if err != nil {
return false
@ -143,15 +145,15 @@ func (ps *precomputedShade) Init() {
func (ps *precomputedShade) PrecomputeFovMap() {
max := ps.MaxTorchRadius
minusMax := (-1) * max
zeroCoords := types.Coords{0, 0}
zeroCoords := types.Coords{X: 0, Y: 0}
var x, y int
//fill list
for x = minusMax; x < max+1; x++ {
for y = minusMax; y < max+1; y++ {
if x == 0 && y == 0 {
continue;
continue
}
iterCoords := types.Coords{x, y}
iterCoords := types.Coords{X: x, Y: y}
distance := zeroCoords.DistanceTo(iterCoords)
if distance <= float64(max) {
ps.CellList = append(ps.CellList, &Cell{iterCoords, distance, nil, 0})
@ -180,11 +182,11 @@ func (ps *precomputedShade) PrecomputeFovMap() {
roundedX := int(basic.Round(lineX))
roundedY := int(basic.Round(lineY))
_, cell, err := ps.FindByCoords(types.Coords{roundedX, roundedY})
_, cell, err := ps.FindByCoords(types.Coords{X: roundedX, Y: roundedY})
if err != nil {
//inexistent coord found
break;
break
}
cell.occludedAngles = unique(append(cell.occludedAngles, i))
}
@ -219,7 +221,7 @@ func (ps *precomputedShade) recalc(level *gamemap.Level, initCoords types.Coords
i := 0
prevDistance := 0.0
for !bytes.Equal(currentShade, fullShade) {
if (i == len(ps.CellList)-1) {
if i == len(ps.CellList)-1 {
break
}
cell := ps.CellList[i]
@ -242,7 +244,7 @@ func (ps *precomputedShade) recalc(level *gamemap.Level, initCoords types.Coords
if level.GetTile(lc).BlocksSight && ps.LightWalls {
//if (nextShade[angle] == 0 && currentShade[angle] == 0) {
if (nextShade[angle] == 0) {
if nextShade[angle] == 0 {
level.GetTile(lc).Visible = true
level.GetTile(lc).Explored = true
}
@ -266,7 +268,7 @@ func (ps *precomputedShade) ComputeFov(level *gamemap.Level, initCoords types.Co
//fmt.Printf("\n coords: %v, distance: %f, lit: %d", cell.Coords, cell.distance, cell.lit)
cs, err := ps.toLevelCoords(level, initCoords, cell.Coords)
if cell.lit > 0 && cell.lit > MIN_LIT_TO_BE_VISIBLE {
//if cell.lit > 0 && cell.lit / (ps.MaxTorchRadius - int(cell.distance - 0.4) - 1) > MIN_LIT_TO_BE_VISIBLE {
//if cell.lit > 0 && cell.lit / (ps.MaxTorchRadius - int(cell.distance - 0.4) - 1) > MIN_LIT_TO_BE_VISIBLE {
if err != nil {
continue
}
@ -298,7 +300,7 @@ func (ps *precomputedShade) ComputeFov(level *gamemap.Level, initCoords types.Co
}
func (ps *precomputedShade) toLevelCoords(level *gamemap.Level, initCoords, relativeCoords types.Coords) (types.Coords, error) {
realCoords := types.Coords{initCoords.X + relativeCoords.X, initCoords.Y + relativeCoords.Y}
realCoords := types.Coords{X: initCoords.X + relativeCoords.X, Y: initCoords.Y + relativeCoords.Y}
if !level.InBounds(realCoords) {
return types.Coords{}, errOutOfBounds
}
@ -306,7 +308,7 @@ func (ps *precomputedShade) toLevelCoords(level *gamemap.Level, initCoords, rela
}
func (ps *precomputedShade) fromLevelCoords(lc types.Coords) types.Coords {
relativeCoords := types.Coords{lc.X - ps.originCoords.X, lc.Y - ps.originCoords.Y}
relativeCoords := types.Coords{X: lc.X - ps.originCoords.X, Y: lc.Y - ps.originCoords.Y}
return relativeCoords
}