From 5575ea026d60e43a3ea2b336d5cef309845e8f14 Mon Sep 17 00:00:00 2001 From: Martin Lange <44003176+mlange-42@users.noreply.github.com> Date: Wed, 5 Apr 2023 12:23:49 +0200 Subject: [PATCH] No more hard resource dependencies (#6) * no more hard resource dependencies, upgrade arche dependencies * run CI also in PRs --- .github/workflows/tests.yml | 8 +++++++- CHANGELOG.md | 8 ++++++++ doc.go | 2 +- go.mod | 4 ++-- go.sum | 4 ++++ plot/doc.go | 2 ++ plot/time_series.go | 20 ++++++++++---------- window/doc.go | 2 ++ window/example_test.go | 5 +++-- window/window.go | 23 +++++++++++++++++------ 10 files changed, 56 insertions(+), 22 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 plot/doc.go create mode 100644 window/doc.go diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8e4a85e..11c3106 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,6 +1,12 @@ name: Tests -on: [push] +on: + push: + branches: + - main + pull_request: + branches: + - main jobs: diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..260ef18 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,8 @@ +# Changelog + +## [[v0.0.2]](https://github.com/mlange-42/arche-pixel/compare/v0.0.1...v0.0.2) + +### Other + +* Remove hard dependencies on resources `Tick` and `Termination` (#6) +* Upgrade dependency to Arche v0.6.1 and Arche-Model v0.0.2 (#6) diff --git a/doc.go b/doc.go index 45ed6ff..14d205b 100644 --- a/doc.go +++ b/doc.go @@ -1,6 +1,6 @@ // Package archepixel provides OpenGL graphics and plots for the Arche ECS using the Pixel] game engine. // // See the sub-packages: -// - OpenGL window system for free drawing -- [github.com/mlange-42/arche-pixel/window] // - Live plotting systems -- [github.com/mlange-42/arche-pixel/plot] +// - OpenGL window system for free drawing -- [github.com/mlange-42/arche-pixel/window] package archepixel diff --git a/go.mod b/go.mod index 287ba70..04a48c6 100644 --- a/go.mod +++ b/go.mod @@ -4,8 +4,8 @@ go 1.20 require ( github.com/faiface/pixel v0.10.0 - github.com/mlange-42/arche v0.6.0 - github.com/mlange-42/arche-model v0.0.1 + github.com/mlange-42/arche v0.6.1 + github.com/mlange-42/arche-model v0.0.2 golang.org/x/image v0.5.0 gonum.org/v1/plot v0.12.0 ) diff --git a/go.sum b/go.sum index dafa2ce..5742862 100644 --- a/go.sum +++ b/go.sum @@ -46,8 +46,12 @@ github.com/jung-kurt/gofpdf v1.0.0/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/mlange-42/arche v0.6.0 h1:xF/jlJeSjX1Yt7JdiGcPIS0q20ATqwbegU5cIP0/j4g= github.com/mlange-42/arche v0.6.0/go.mod h1:cgOiMHWCbNAb5L5mCihS2yzdk1Zll1IoBJL+3wVm0AM= +github.com/mlange-42/arche v0.6.1 h1:MA0VTHvlGxw44MRfj8qbHLnB5QQFAXueGYRiQgLGPVc= +github.com/mlange-42/arche v0.6.1/go.mod h1:cgOiMHWCbNAb5L5mCihS2yzdk1Zll1IoBJL+3wVm0AM= github.com/mlange-42/arche-model v0.0.1 h1:jcJLHC1Zfka/qDasLYIvarmznnhkaa35rmFTm+VbzwY= github.com/mlange-42/arche-model v0.0.1/go.mod h1:L0raAVjpLe7LpDuSCkbFwZ2p2uNkwE63bX3DBRYvwG8= +github.com/mlange-42/arche-model v0.0.2 h1:o1ijU+3Md0mYPq9x9NOXsBk7k7JPnQ6eovEm7n4inqs= +github.com/mlange-42/arche-model v0.0.2/go.mod h1:/qrG4sg+rUgwcxMQ7i6R8+K507SLm2QKlQpKs9ggYs4= github.com/phpdave11/gofpdf v1.4.2/go.mod h1:zpO6xFn9yxo3YLyMvW8HcKWVdbNqgIfOOp2dXMnm1mY= github.com/phpdave11/gofpdi v1.0.12/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI= github.com/phpdave11/gofpdi v1.0.13/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI= diff --git a/plot/doc.go b/plot/doc.go new file mode 100644 index 0000000..7abb84a --- /dev/null +++ b/plot/doc.go @@ -0,0 +1,2 @@ +// Package plot provides live plotting systems. +package plot diff --git a/plot/time_series.go b/plot/time_series.go index 4143c75..726ad1c 100644 --- a/plot/time_series.go +++ b/plot/time_series.go @@ -8,7 +8,6 @@ import ( "github.com/mlange-42/arche-model/model" "github.com/mlange-42/arche-pixel/window" "github.com/mlange-42/arche/ecs" - "github.com/mlange-42/arche/generic" "golang.org/x/image/colornames" "gonum.org/v1/plot" "gonum.org/v1/plot/plotter" @@ -27,19 +26,22 @@ var defaultColors = []color.Color{ } // TimeSeries plot reporter. +// +// If the world contains a resource of type [github.com/mlange-42/arche-model/resource.Termination], +// the model is terminated when the window is closed. type TimeSeries struct { Bounds window.Bounds Observer model.Observer UpdateInterval int DrawInterval int window.Window - drawer timeSeriesDrawer - timeRes generic.Resource[model.Time] + drawer timeSeriesDrawer + step int64 } // Initialize the system. func (s *TimeSeries) Initialize(w *ecs.World) { - s.timeRes = generic.NewResource[model.Time](w) + s.step = 0 } // InitializeUI the system. @@ -57,13 +59,11 @@ func (s *TimeSeries) InitializeUI(w *ecs.World) { // Update the system. func (s *TimeSeries) Update(w *ecs.World) { - time := s.timeRes.Get() - - if s.UpdateInterval > 1 && time.Tick%int64(s.UpdateInterval) != 0 { - return + if s.UpdateInterval <= 1 || s.step%int64(s.UpdateInterval) == 0 { + s.Observer.Update(w) + s.drawer.append(float64(s.step), s.Observer.Values(w)) } - s.Observer.Update(w) - s.drawer.append(float64(time.Tick), s.Observer.Values(w)) + s.step++ } // Finalize the system. diff --git a/window/doc.go b/window/doc.go new file mode 100644 index 0000000..9024cd9 --- /dev/null +++ b/window/doc.go @@ -0,0 +1,2 @@ +// Package window provides an OpenGL window system for free drawing. +package window diff --git a/window/example_test.go b/window/example_test.go index 959e77a..3331be0 100644 --- a/window/example_test.go +++ b/window/example_test.go @@ -7,6 +7,7 @@ import ( "github.com/faiface/pixel/imdraw" "github.com/faiface/pixel/pixelgl" "github.com/mlange-42/arche-model/model" + "github.com/mlange-42/arche-model/resource" "github.com/mlange-42/arche-model/system" "github.com/mlange-42/arche-pixel/window" "github.com/mlange-42/arche/ecs" @@ -53,8 +54,8 @@ func (d *RectDrawer) Initialize(w *ecs.World, win *pixelgl.Window) { // Draw the RectDrawer's stuff. func (d *RectDrawer) Draw(w *ecs.World, win *pixelgl.Window) { // Get a resource from the world. - time := ecs.GetResource[model.Time](w) - offset := float64(time.Tick) + tick := ecs.GetResource[resource.Tick](w) + offset := float64(tick.Tick) // Create a white rectangle that moves with progressing model tick. d.dr.Color = color.White diff --git a/window/window.go b/window/window.go index 22927c7..879197d 100644 --- a/window/window.go +++ b/window/window.go @@ -1,4 +1,3 @@ -// Package window provides an OpenGL window system for free drawing. package window import ( @@ -7,7 +6,7 @@ import ( "github.com/faiface/pixel" "github.com/faiface/pixel/pixelgl" - "github.com/mlange-42/arche-model/model" + "github.com/mlange-42/arche-model/resource" "github.com/mlange-42/arche/ecs" "github.com/mlange-42/arche/generic" "golang.org/x/image/colornames" @@ -36,6 +35,9 @@ type Drawer interface { // Window provides an OpenGL window for drawing. // +// If the world contains a resource of type [github.com/mlange-42/arche-model/resource/Termination], +// the model is terminated when the window is closed. +// // See the example for [window] package. type Window struct { Bounds Bounds @@ -43,7 +45,8 @@ type Window struct { window *pixelgl.Window drawers []Drawer step int - timeRes generic.Resource[model.Time] + isClosed bool + termRes generic.Resource[resource.Termination] } // Add adds a drawer @@ -83,14 +86,22 @@ func (s *Window) InitializeUI(w *ecs.World) { for _, d := range s.drawers { d.Initialize(w, s.window) } - s.timeRes = generic.NewResource[model.Time](w) + + s.termRes = generic.NewResource[resource.Termination](w) + s.step = 0 + s.isClosed = false } // UpdateUI the system func (s *Window) UpdateUI(w *ecs.World) { if s.window.Closed() { - time := s.timeRes.Get() - time.Finished = true + if !s.isClosed { + term := s.termRes.Get() + if term != nil { + term.Terminate = true + } + s.isClosed = true + } return } if s.DrawInterval <= 1 || s.step%s.DrawInterval == 0 {