Skip to content

Commit

Permalink
No more hard resource dependencies (#6)
Browse files Browse the repository at this point in the history
* no more hard resource dependencies, upgrade arche dependencies
* run CI also in PRs
  • Loading branch information
mlange-42 authored Apr 5, 2023
1 parent 24cafb3 commit 5575ea0
Showing 10 changed files with 56 additions and 22 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
name: Tests

on: [push]
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:

8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
2 changes: 2 additions & 0 deletions plot/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package plot provides live plotting systems.
package plot
20 changes: 10 additions & 10 deletions plot/time_series.go
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 2 additions & 0 deletions window/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package window provides an OpenGL window system for free drawing.
package window
5 changes: 3 additions & 2 deletions window/example_test.go
Original file line number Diff line number Diff line change
@@ -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
23 changes: 17 additions & 6 deletions window/window.go
Original file line number Diff line number Diff line change
@@ -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,14 +35,18 @@ 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
DrawInterval int
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 {

0 comments on commit 5575ea0

Please sign in to comment.