• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mlange-42 / arche-model / 6698858792

30 Oct 2023 09:19PM CUT coverage: 98.208% (+0.8%) from 97.455%
6698858792

push

github

web-flow
Fix full CPU load when paused (#47)

As reported in mlange-42/arche#304, systems spin at maximum speed when paused.

This PR fixes the issue by calculating the theoretical next update time even when paused (assuming 30 TPS). Also, UI system update logic needs to be performed even when there are no UI systems.

Fixes mlange-42/arche#304

Changes:

* prevent paused spinning by still calculating next update
* add a test for pausing the model/Systems
* limit FPS/TPS when paused
* execute UI system update logic also when there are no UI systems
* update changelog

30 of 30 new or added lines in 1 file covered. (100.0%)

548 of 558 relevant lines covered (98.21%)

124.11 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/observer/layers_to_layers.go
1
package observer
2

3
import (
4
        "github.com/mlange-42/arche/ecs"
5
)
6

7
// LayersToLayers creates an observer that serves as adapter from a [MatrixLayers] observer to a [GridLayers] observer.
8
func LayersToLayers(obs MatrixLayers, origin *[2]float64, cellsize *[2]float64) GridLayers {
2✔
9
        m := layersToLayers{
2✔
10
                Observer: obs,
2✔
11
        }
2✔
12
        if origin != nil {
3✔
13
                m.Origin = *origin
1✔
14
        }
1✔
15
        if cellsize == nil {
3✔
16
                m.CellSize = [2]float64{1, 1}
1✔
17
        } else {
2✔
18
                m.CellSize = *cellsize
1✔
19
        }
1✔
20
        return &m
2✔
21
}
22

23
// layersToLayers is an observer that serves as adapter from a [MatrixLayers] observer to a [GridLayers] observer.
24
type layersToLayers struct {
25
        Observer MatrixLayers // The wrapped MatrixLayers observers.
26
        Origin   [2]float64   // Origin. Optional, defaults to (0, 0)
27
        CellSize [2]float64   // CellSize. Optional, defaults to (1, 1).
28
}
29

30
// Initialize the child observer.
31
func (o *layersToLayers) Initialize(w *ecs.World) {
1✔
32
        o.Observer.Initialize(w)
1✔
33
}
1✔
34

35
// Update the child observer.
36
func (o *layersToLayers) Update(w *ecs.World) {
1✔
37
        o.Observer.Update(w)
1✔
38
}
1✔
39

40
// Dims returns the matrix dimensions.
41
func (o *layersToLayers) Dims() (int, int) {
1✔
42
        return o.Observer.Dims()
1✔
43
}
1✔
44

45
// Layers returns the number of layers.
46
func (o *layersToLayers) Layers() int {
1✔
47
        return o.Observer.Layers()
1✔
48
}
1✔
49

50
// Values for the current model tick.
51
func (o *layersToLayers) Values(w *ecs.World) [][]float64 {
1✔
52
        return o.Observer.Values(w)
1✔
53
}
1✔
54

55
// X axis coordinates.
56
func (o *layersToLayers) X(c int) float64 {
1✔
57
        return o.Origin[0] + o.CellSize[0]*float64(c)
1✔
58
}
1✔
59

60
// Y axis coordinates.
61
func (o *layersToLayers) Y(r int) float64 {
1✔
62
        return o.Origin[1] + o.CellSize[1]*float64(r)
1✔
63
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc