precomputed shade algo, viewport basic render

This commit is contained in:
anton.gurov
2019-10-30 17:56:30 +03:00
parent 4a77323aab
commit 3958951cd5
15 changed files with 924 additions and 26 deletions

View File

@ -36,10 +36,14 @@ func (layer *Layer) WithColor(colorName string) *Layer {
func (layer *Layer) PutWithRawBackground(x,y int, symbol interface{}, bgColor uint32) {
layer.before()
prevColor := uint32(blt.State(blt.TK_COLOR))
prevCompMode := blt.State(blt.TK_COMPOSITION)
blt.Color(bgColor)
blt.Composition(1)
layer.Put(x,y,"█")
blt.Color(prevColor)
layer.Put(x,y, symbol)
blt.Composition(prevCompMode)
}
func (layer *Layer) PutWithBackground(x,y int, symbol interface{}, bgColorName string) {

View File

@ -2,25 +2,40 @@ package mainwindow
import (
"errors"
"lab.zaar.be/thefish/alchemyst-go/engine/fov"
"lab.zaar.be/thefish/alchemyst-go/engine/fov/precomputed_shade"
"lab.zaar.be/thefish/alchemyst-go/engine/gamemap"
"lab.zaar.be/thefish/alchemyst-go/engine/types"
)
var NotInViewError = errors.New("not in ViewPort")
const FPS_LIMIT = 60
type ViewPort struct {
*types.Rect
level *gamemap.Level
layer *Layer
Fov fov.Fov
playerCoords types.Coords
playerTorchRadius int
}
func NewViewPort(x, y, w, h int, level *gamemap.Level, layer *Layer) *ViewPort {
return &ViewPort{
//fixme
fov := precomputed_shade.NewPrecomputedShade(15)
fov.Init()
vp := ViewPort{
Rect: &types.Rect{x, y, w, h},
level: level,
layer: layer,
Fov: fov,
}
vp.playerCoords = types.Coords{10,10}
vp.playerTorchRadius = 10
return &vp
}
func (vp *ViewPort) Move(c *types.Coords) {
@ -52,34 +67,35 @@ func (vp *ViewPort) ToVPCoords(c *types.Coords) (newCoords *types.Coords, err er
return &types.Coords{x, y}, nil
}
//call only from main thread
////call only from main thread
//func (vp *ViewPort) Render() {
// //fixme get these from state chan(s)
// var fpsTicker int
// var fovRecompute bool
// var fovRecompute bool = true
// redraw := false
// //fixme get player instance
//
// vp.Move(player.Coords)
// vp.Move(&vp.playerCoords)
// //fixme detect fovRecompute
// if fovRecompute {
// vp.layer.Clear(vp.Rect)
// fovRecompute = false
// redraw = true
// //fixme
// vp.level.ComputeFov(FovMap, player.Coords, player.TorchRadius, FovLightWalls, FovAlgo)
//
// vp.Fov.ComputeFov(vp.level, vp.playerCoords, vp.playerTorchRadius)
// }
// //increase ticker
// fpsTicker++
//
// if redraw || fpsTicker % (FPS_LIMIT / 10) == 0 {
// fpsTicker := 0
// if redraw || fpsTicker%(FPS_LIMIT/10) == 0 {
// fpsTicker = 0
//
// for y:=0; y < vp.H; y++ {
// for x:=0; x<vp.W; x++ {
// for y := 0; y < vp.H; y++ {
// for x := 0; x < vp.W; x++ {
// mapCoords := types.Coords{vp.X + x, vp.Y + y}
// tile := vp.level.Tiles[mapCoords.X][mapCoords.Y]
// visible := vp.IsInFov(mapCoords)
// visible := vp.Fov.IsInFov(mapCoords)
// if !visible {
// if tile.MustDraw {
// //darkened version of landscape
@ -98,4 +114,19 @@ func (vp *ViewPort) ToVPCoords(c *types.Coords) (newCoords *types.Coords, err er
// }
//
// }
//}
//}
func (vp *ViewPort) Render() {
for y := 0; y < vp.H; y++ {
for x := 0; x < vp.W; x++ {
mapCoords := types.Coords{vp.X + x, vp.Y + y}
tile := vp.level.Tiles[mapCoords.X][mapCoords.Y]
fg := tile.ColorSet.Fg()
bg := tile.ColorSet.Bg()
vp.layer.WithRawColor(fg).
PutWithRawBackground(mapCoords.X, mapCoords.Y, tile.Char, bg)
}
}
}