From 768426a31616bb6795572c03c3a9f1ce2920aa05 Mon Sep 17 00:00:00 2001 From: thefish Date: Sat, 16 Nov 2019 04:43:56 +0300 Subject: [PATCH] move render to systems --- cmd/game/main.go | 2 +- engine/ecs/systems/mob_render_system.go | 27 --------------------- engine/ecs/systems/terrain_render_system.go | 20 +++++++++------ ui/mainwindow/viewport.go | 2 +- 4 files changed, 14 insertions(+), 37 deletions(-) diff --git a/cmd/game/main.go b/cmd/game/main.go index 373201e..8865de0 100644 --- a/cmd/game/main.go +++ b/cmd/game/main.go @@ -80,7 +80,7 @@ func main() { sidebarWidth := 0 //Set up viewport - vp := mainwindow.NewViewPort(sidebarWidth, 0, (mw.W - sidebarWidth), (mw.H - 0), mw.GetLayer("base")) + vp := mainwindow.NewViewPort(sidebarWidth, 0, (mw.W - sidebarWidth), (mw.H - 0)) //set up controller diff --git a/engine/ecs/systems/mob_render_system.go b/engine/ecs/systems/mob_render_system.go index 5b05b3d..41bc99e 100644 --- a/engine/ecs/systems/mob_render_system.go +++ b/engine/ecs/systems/mob_render_system.go @@ -23,38 +23,11 @@ func (mrs MobRenderSystem) Process(){ pos := mrs.Controller.GetComponent(e, ecs.CoordsComponent).(types.Coords) appearance := mrs.Controller.GetComponent(e, ecs.AppearanceComponent).(types.Appearance) - //fixme - // if vp.Rect.InBounds(pos) { - // Clear the cell this entity occupies, so it is the only glyph drawn there - - //for i := 0; i <= 2; i++ { - //mrs.Layer.ClearArea(pos.X, pos.Y,1,1) //WHY?! - //gogue.ClearArea(pos.X, pos.Y, 1, 1, i) - //} - - //fixme - //for y := 0; y < mrs.Viewport.H; y++ { - // for x := 0; x < mrs.Viewport.W; x++ { - // mapCoords := types.Coords{mrs.Viewport.CameraCoords.X + x, mrs.Viewport.CameraCoords.Y + y} - // if mrs.Level.InBounds(mapCoords) { - // mrs.Layer.WithRawColor(appearance.ColorSet.Fg.GetColor()).Put( - // x+mrs.Viewport.X, - // y+mrs.Viewport.Y, - // appearance.Glyph.GetGlyph(), - // ) - // } - // } - //} - vpc, err := mrs.Viewport.ToVPCoords(pos) if err != nil { fmt.Printf("Err: " , err) } - mrs.Layer.WithRawColor(appearance.ColorSet.Fg.GetColor()).Put(vpc.X, vpc.Y, appearance.Glyph.GetGlyph()) - //gogue.PrintGlyph(pos.X, pos.Y, appearance.Glyph, "", appearance.Layer) - - //} } } } diff --git a/engine/ecs/systems/terrain_render_system.go b/engine/ecs/systems/terrain_render_system.go index 2a267a0..bfdf4b3 100644 --- a/engine/ecs/systems/terrain_render_system.go +++ b/engine/ecs/systems/terrain_render_system.go @@ -10,6 +10,10 @@ import ( "time" ) +var fovRecompute = true +var redraw = false + + type TerrainRenderSystem struct { Viewport *mainwindow.ViewPort state *gamestate.GameState @@ -56,11 +60,11 @@ func (trs TerrainRenderSystem) Listen() { for { select { case <-trs.state.FovRecompute: - trs.fovRecompute = true + fovRecompute = true case <-trs.state.Redraw: - trs.redraw = true + redraw = true case <-trs.animateTiles.C: - trs.redraw = true + redraw = true } } } @@ -70,14 +74,14 @@ func (trs TerrainRenderSystem) Process() { trs.Viewport.Move(trs.state, playerCoords) - if trs.fovRecompute { + if fovRecompute { trs.layer.ClearRect(trs.Viewport.Rect) - trs.fovRecompute = false - trs.redraw = true + fovRecompute = false + redraw = true trs.fov.ComputeFov(trs.state.Level, playerCoords, trs.TorchRadius) } - if trs.redraw { + if redraw { //terrain for y := 0; y < trs.Viewport.H; y++ { for x := 0; x < trs.Viewport.W; x++ { @@ -97,7 +101,7 @@ func (trs TerrainRenderSystem) Process() { } } } - trs.redraw = false + redraw = false } } diff --git a/ui/mainwindow/viewport.go b/ui/mainwindow/viewport.go index 9570540..48f1010 100644 --- a/ui/mainwindow/viewport.go +++ b/ui/mainwindow/viewport.go @@ -11,7 +11,7 @@ type ViewPort struct { CameraCoords types.Coords } -func NewViewPort(x, y, w, h int, layer *Layer) *ViewPort { +func NewViewPort(x, y, w, h int) *ViewPort { vp := ViewPort{ Rect: types.Rect{x, y, w, h}, }