mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-02-13 12:06:31 -05:00
* added command line arg for launching ecs impl * removed render system tests, was causing gl context issues in tests * fixed all lint errors in d2systems
59 lines
1.1 KiB
Go
59 lines
1.1 KiB
Go
package d2systems
|
|
|
|
import (
|
|
"github.com/gravestench/akara"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2util"
|
|
)
|
|
|
|
const (
|
|
logPrefixUpdateCounter = "Update Counter"
|
|
)
|
|
|
|
// NewUpdateCounterSystem creates a new update counter system
|
|
func NewUpdateCounterSystem() *UpdateCounter {
|
|
uc := &UpdateCounter{
|
|
BaseSystem: &akara.BaseSystem{},
|
|
Logger: d2util.NewLogger(),
|
|
}
|
|
|
|
uc.SetPrefix(logPrefixUpdateCounter)
|
|
|
|
return uc
|
|
}
|
|
|
|
var _ akara.System = &UpdateCounter{}
|
|
|
|
// UpdateCounter is a utility system that logs the number of updates per second
|
|
type UpdateCounter struct {
|
|
*akara.BaseSystem
|
|
*d2util.Logger
|
|
secondsElapsed float64
|
|
count int
|
|
}
|
|
|
|
// Init initializes the update counter
|
|
func (u *UpdateCounter) Init(world *akara.World) {
|
|
u.World = world
|
|
|
|
if u.World == nil {
|
|
u.SetActive(false)
|
|
}
|
|
|
|
u.Info("initializing")
|
|
}
|
|
|
|
// Update the world update count in 1 second intervals
|
|
func (u *UpdateCounter) Update() {
|
|
u.count++
|
|
u.secondsElapsed += u.World.TimeDelta.Seconds()
|
|
|
|
if u.secondsElapsed < 1 {
|
|
return
|
|
}
|
|
|
|
u.Infof("%d updates per second", u.count)
|
|
u.secondsElapsed = 0
|
|
u.count = 0
|
|
}
|