first item, render order? redraw? broken

This commit is contained in:
thefish 2019-11-16 05:15:02 +03:00
parent 768426a316
commit 685dfeeeb1
4 changed files with 49 additions and 24 deletions

View File

@ -8,6 +8,7 @@ import (
"lab.zaar.be/thefish/alchemyst-go/engine/gamemap" "lab.zaar.be/thefish/alchemyst-go/engine/gamemap"
"lab.zaar.be/thefish/alchemyst-go/engine/gamemap/mapgens" "lab.zaar.be/thefish/alchemyst-go/engine/gamemap/mapgens"
"lab.zaar.be/thefish/alchemyst-go/engine/gamestate" "lab.zaar.be/thefish/alchemyst-go/engine/gamestate"
"lab.zaar.be/thefish/alchemyst-go/engine/items"
"lab.zaar.be/thefish/alchemyst-go/engine/mob" "lab.zaar.be/thefish/alchemyst-go/engine/mob"
"lab.zaar.be/thefish/alchemyst-go/engine/mob/movement" "lab.zaar.be/thefish/alchemyst-go/engine/mob/movement"
"lab.zaar.be/thefish/alchemyst-go/engine/screens" "lab.zaar.be/thefish/alchemyst-go/engine/screens"
@ -174,6 +175,18 @@ func main() {
controller.AddComponent(player, rooms[0].Center) //implicit Coords controller.AddComponent(player, rooms[0].Center) //implicit Coords
controller.AddComponent(player, moveable) controller.AddComponent(player, moveable)
potion := controller.CreateEntity([]ecs.Component{})
controller.AddComponent(potion, types.Appearance{
Glyph: types.PlainGlyphHolder{"!"},
ColorSet: types.TileColorSet{
Fg: types.PlainColorHolder{255, 55, 255, 222},
},
})
controller.AddComponent(potion, rooms[1].Center) //implicit Coords
controller.AddComponent(potion, items.Carried{})
controller.AddComponent(potion, items.Usable{})
controller.AddComponent(potion, items.Consumable{})
State.Player = player State.Player = player
State.Controller = controller State.Controller = controller

View File

@ -1,8 +1,8 @@
package systems package systems
import ( import (
"fmt"
"lab.zaar.be/thefish/alchemyst-go/engine/ecs" "lab.zaar.be/thefish/alchemyst-go/engine/ecs"
"lab.zaar.be/thefish/alchemyst-go/engine/fov"
"lab.zaar.be/thefish/alchemyst-go/engine/gamemap" "lab.zaar.be/thefish/alchemyst-go/engine/gamemap"
"lab.zaar.be/thefish/alchemyst-go/engine/types" "lab.zaar.be/thefish/alchemyst-go/engine/types"
"lab.zaar.be/thefish/alchemyst-go/ui/mainwindow" "lab.zaar.be/thefish/alchemyst-go/ui/mainwindow"
@ -12,26 +12,34 @@ type MobRenderSystem struct {
Controller *ecs.Controller Controller *ecs.Controller
Layer *mainwindow.Layer Layer *mainwindow.Layer
Viewport *mainwindow.ViewPort Viewport *mainwindow.ViewPort
Fov fov.Fov
*gamemap.Level *gamemap.Level
} }
func (mrs MobRenderSystem) Process(){ func (mrs MobRenderSystem) Process() {
for e := range mrs.Controller.GetEntities() { //if redraw {
if mrs.Controller.HasComponent(e, ecs.CoordsComponent) && for e := range mrs.Controller.GetEntities() {
mrs.Controller.HasComponent(e, ecs.AppearanceComponent) { if mrs.Controller.HasComponent(e, ecs.CoordsComponent) &&
mrs.Controller.HasComponent(e, ecs.AppearanceComponent) {
pos := mrs.Controller.GetComponent(e, ecs.CoordsComponent).(types.Coords) pos := mrs.Controller.GetComponent(e, ecs.CoordsComponent).(types.Coords)
appearance := mrs.Controller.GetComponent(e, ecs.AppearanceComponent).(types.Appearance) appearance := mrs.Controller.GetComponent(e, ecs.AppearanceComponent).(types.Appearance)
vpc, err := mrs.Viewport.ToVPCoords(pos) //fixme fov check
if err != nil { //if !mrs.Fov.IsInFov(pos) {
fmt.Printf("Err: " , err) // continue
//}
vpc, err := mrs.Viewport.ToVPCoords(pos)
if err != nil {
continue //we cant see it? no problem.
}
mrs.Layer.WithRawColor(appearance.ColorSet.Fg.GetColor()).Put(vpc.X, vpc.Y, appearance.Glyph.GetGlyph())
} }
mrs.Layer.WithRawColor(appearance.ColorSet.Fg.GetColor()).Put(vpc.X, vpc.Y, appearance.Glyph.GetGlyph())
} }
} //}
} }
func (mrs MobRenderSystem) SystemType() string { func (mrs MobRenderSystem) SystemType() string {
return ecs.MobRenderSystem return ecs.MobRenderSystem
} }

View File

@ -3,7 +3,6 @@ package systems
import ( import (
"lab.zaar.be/thefish/alchemyst-go/engine/ecs" "lab.zaar.be/thefish/alchemyst-go/engine/ecs"
"lab.zaar.be/thefish/alchemyst-go/engine/fov" "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/gamestate" "lab.zaar.be/thefish/alchemyst-go/engine/gamestate"
"lab.zaar.be/thefish/alchemyst-go/engine/types" "lab.zaar.be/thefish/alchemyst-go/engine/types"
"lab.zaar.be/thefish/alchemyst-go/ui/mainwindow" "lab.zaar.be/thefish/alchemyst-go/ui/mainwindow"
@ -18,34 +17,29 @@ type TerrainRenderSystem struct {
Viewport *mainwindow.ViewPort Viewport *mainwindow.ViewPort
state *gamestate.GameState state *gamestate.GameState
layer *mainwindow.Layer layer *mainwindow.Layer
animateTiles *time.Ticker
fov fov.Fov fov fov.Fov
animateTiles *time.Ticker
TorchRadius int TorchRadius int
redraw bool
fovRecompute bool
} }
func NewTerrainRenderSystem( func NewTerrainRenderSystem(
state *gamestate.GameState, state *gamestate.GameState,
vp *mainwindow.ViewPort, vp *mainwindow.ViewPort,
layer *mainwindow.Layer, layer *mainwindow.Layer,
fov fov.Fov,
) TerrainRenderSystem { ) TerrainRenderSystem {
trs := TerrainRenderSystem{ trs := TerrainRenderSystem{
Viewport:vp, Viewport:vp,
layer: layer, layer: layer,
state: state, state: state,
redraw: true, fov: fov,
fovRecompute: true,
} }
computedFov := precomputed_shade.NewPrecomputedShade(15)
computedFov.Init()
trs.TorchRadius = 12 //fixme move to sight component trs.TorchRadius = 12 //fixme move to sight component
trs.animateTiles = time.NewTicker(time.Second / 12) trs.animateTiles = time.NewTicker(time.Second / 12)
trs.fov = computedFov
return trs return trs
} }
@ -76,9 +70,9 @@ func (trs TerrainRenderSystem) Process() {
if fovRecompute { if fovRecompute {
trs.layer.ClearRect(trs.Viewport.Rect) trs.layer.ClearRect(trs.Viewport.Rect)
trs.fov.ComputeFov(trs.state.Level, playerCoords, trs.TorchRadius)
fovRecompute = false fovRecompute = false
redraw = true redraw = true
trs.fov.ComputeFov(trs.state.Level, playerCoords, trs.TorchRadius)
} }
if redraw { if redraw {

View File

@ -3,6 +3,8 @@ package screens
import ( import (
"lab.zaar.be/thefish/alchemyst-go/engine/ecs" "lab.zaar.be/thefish/alchemyst-go/engine/ecs"
"lab.zaar.be/thefish/alchemyst-go/engine/ecs/systems" "lab.zaar.be/thefish/alchemyst-go/engine/ecs/systems"
"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/gamestate" "lab.zaar.be/thefish/alchemyst-go/engine/gamestate"
"lab.zaar.be/thefish/alchemyst-go/engine/mob/movement" "lab.zaar.be/thefish/alchemyst-go/engine/mob/movement"
"lab.zaar.be/thefish/alchemyst-go/engine/types" "lab.zaar.be/thefish/alchemyst-go/engine/types"
@ -15,18 +17,26 @@ type GameScreen struct {
vp *mainwindow.ViewPort vp *mainwindow.ViewPort
controller *ecs.Controller controller *ecs.Controller
scm *types.ScreenManager scm *types.ScreenManager
fov fov.Fov
} }
func NewGameScreen(mw *mainwindow.MainWindow, state *gamestate.GameState, viewPort *mainwindow.ViewPort, controller *ecs.Controller, scm *types.ScreenManager) *GameScreen { func NewGameScreen(mw *mainwindow.MainWindow, state *gamestate.GameState, viewPort *mainwindow.ViewPort, controller *ecs.Controller, scm *types.ScreenManager) *GameScreen {
ts := &GameScreen{mw: mw, state: state, vp: viewPort, controller: controller, scm: scm} ts := &GameScreen{mw: mw, state: state, vp: viewPort, controller: controller, scm: scm}
//fixme move this to fov system
computedFov := precomputed_shade.NewPrecomputedShade(15)
computedFov.Init()
ts.fov = computedFov
renderMobs := systems.MobRenderSystem{ renderMobs := systems.MobRenderSystem{
Controller: ts.controller, Controller: ts.controller,
Layer: ts.mw.GetLayer("base"), Layer: ts.mw.GetLayer("base"),
Viewport: ts.vp, Viewport: ts.vp,
Level: state.Level, Level: state.Level,
Fov: ts.fov,
} }
ts.controller.AddSystem(renderMobs, 10) ts.controller.AddSystem(renderMobs, 10)
renderTerrain := systems.NewTerrainRenderSystem(state, viewPort, ts.mw.GetLayer("base")) renderTerrain := systems.NewTerrainRenderSystem(state, viewPort, ts.mw.GetLayer("base"), ts.fov)
go renderTerrain.Listen() go renderTerrain.Listen()
ts.controller.AddSystem(renderTerrain, 5) ts.controller.AddSystem(renderTerrain, 5)