Browse Source

Rename statistics functions

main
Trevor Slocum 1 month ago
parent
commit
21d6f53dcc
  1. 4
      entity.go
  2. 12
      entity_test.go
  3. 2
      examples/twinstick/system/printinfo.go
  4. 16
      world.go

4
entity.go

@ -55,8 +55,8 @@ func (w *World) RemoveEntity(entity Entity) bool {
var numEntities int
var numEntitiesT time.Time
// ActiveEntities returns the number of currently active entities.
func (w *World) ActiveEntities() int {
// CurrentEntities returns the number of currently active entities.
func (w *World) CurrentEntities() int {
if time.Since(numEntitiesT) >= w.cacheTime {
numEntities = len(w.allEntities)
numEntitiesT = time.Now()

12
entity_test.go

@ -8,12 +8,12 @@ func TestActiveEntities(t *testing.T) {
w := NewWorld()
w.cacheTime = 0
active := w.ActiveEntities()
active := w.CurrentEntities()
if active != 0 {
t.Fatalf("expected 0 active entities, got %d", active)
}
active = w.ActiveEntities()
active = w.CurrentEntities()
if active != 0 {
t.Fatalf("expected 0 active entities, got %d", active)
}
@ -21,7 +21,7 @@ func TestActiveEntities(t *testing.T) {
// Create entity.
e1 := w.NewEntity()
active = w.ActiveEntities()
active = w.CurrentEntities()
if active != 1 {
t.Fatalf("expected 1 active entities, got %d", active)
}
@ -29,21 +29,21 @@ func TestActiveEntities(t *testing.T) {
// Create entity.
e2 := w.NewEntity()
active = w.ActiveEntities()
active = w.CurrentEntities()
if active != 2 {
t.Fatalf("expected 2 active entities, got %d", active)
}
w.RemoveEntity(e1)
active = w.ActiveEntities()
active = w.CurrentEntities()
if active != 1 {
t.Fatalf("expected 1 active entities, got %d", active)
}
w.RemoveEntity(e2)
active = w.ActiveEntities()
active = w.CurrentEntities()
if active != 0 {
t.Fatalf("expected 0 active entities, got %d", active)
}

2
examples/twinstick/system/printinfo.go

@ -47,7 +47,7 @@ func (s *printInfoSystem) Draw(_ *gohan.Context, screen *ebiten.Image) error {
w := world.World
s.img.Clear()
ebitenutil.DebugPrint(s.img, fmt.Sprintf("KEY WASD+MOUSE\nENT %d\nUPD %d\nDRA %d\nTPS %0.0f\nFPS %0.0f", w.ActiveEntities(), w.UpdatedEntities(), w.DrawnEntities(), ebiten.CurrentTPS(), ebiten.CurrentFPS()))
ebitenutil.DebugPrint(s.img, fmt.Sprintf("KEY WASD+MOUSE\nENT %d\nUPD %d\nDRA %d\nTPS %0.0f\nFPS %0.0f", w.CurrentEntities(), w.CurrentUpdates(), w.CurrentDraws(), ebiten.CurrentTPS(), ebiten.CurrentFPS()))
screen.DrawImage(s.img, s.op)
return nil
}

16
world.go

@ -278,10 +278,10 @@ func (w *World) Update() error {
return nil
}
// UpdatedEntities returns the total number of Entities handled by System Update
// calls. Because each Entity may be handled by more than one System, this
// number may be higher than the number of active entities.
func (w *World) UpdatedEntities() int {
// CurrentUpdates returns the number of System Update calls required to update
// the game state. Because entities may be handled by more than one System,
// this number may be higher than the number of active entities.
func (w *World) CurrentUpdates() int {
if time.Since(w.systemUpdatedEntitiesT) >= w.cacheTime {
w.systemUpdatedEntitiesV = w.systemUpdatedEntities
w.systemUpdatedEntitiesT = time.Now()
@ -346,10 +346,10 @@ func (w *World) Draw(screen *ebiten.Image) error {
return nil
}
// DrawnEntities returns the total number of Entities handled by System Draw
// calls. Because each Entity may be handled by more than one System, this
// number may be higher than the number of active entities.
func (w *World) DrawnEntities() int {
// CurrentDraws returns the number of System Draw calls required to draw the
// game on to the screen. Because entities may be handled by more than one
// System, this number may be higher than the number of active entities.
func (w *World) CurrentDraws() int {
if time.Since(w.systemDrawnEntitiesT) >= w.cacheTime {
w.systemDrawnEntitiesV = w.systemDrawnEntities
w.systemDrawnEntitiesT = time.Now()

Loading…
Cancel
Save