1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2025-07-26 11:24:38 -04:00
OpenDiablo2/d2core/d2systems/update_counter.go
gravestench 8b1b6b9adc more work on ecs implementation
* removed d2common/d2scene, was not the right way to go.
* added components for animation, scale, main viewport, viewport filter
* added interface for scenes, which are extensions of akara.System
* BootStrap is now AppBootstrap, common to game clients and headless
server
* added generic BasicScene struct for common scene functionality
* added game object factory as a system, with single sprite factory
* added update counter system, shows how many times the world updates
per second
* integration test is now the game client test
2020-12-07 12:44:11 -08:00

55 lines
875 B
Go

package d2systems
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2util"
"github.com/gravestench/akara"
)
const (
logPrefixUpdateCounter = "Update Counter"
)
func NewUpdateCounterSystem() *UpdateCounter {
uc := &UpdateCounter{
BaseSystem: &akara.BaseSystem{},
Logger: d2util.NewLogger(),
}
uc.SetPrefix(logPrefixUpdateCounter)
return uc
}
var _ akara.System = &UpdateCounter{}
type UpdateCounter struct {
*akara.BaseSystem
*d2util.Logger
secondsElapsed float64
count int
}
func (u *UpdateCounter) Init(world *akara.World) {
u.World = world
if u.World == nil {
u.SetActive(false)
}
u.Info("initializing")
}
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
}