mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-02-10 02:26:29 -05:00
* removed position,scale,rotation components * added Transform component that contains position, rotation, and scale * scene graph update now regenerates the local mat4 using the transform component * akara bugfix: adding new subscriptions will process existing entities * added `--testscene` arg for testing individual scenes in isolation * added rotation support to d2interface.Surface
74 lines
1.7 KiB
Go
74 lines
1.7 KiB
Go
package d2systems
|
|
|
|
import (
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2components"
|
|
"time"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2util"
|
|
|
|
"github.com/gravestench/akara"
|
|
)
|
|
|
|
const (
|
|
defaultScale float64 = 1
|
|
)
|
|
|
|
const (
|
|
logPrefixTimeScaleSystem = "Time Scale"
|
|
)
|
|
|
|
// static check that TimeScaleSystem implements the System interface
|
|
var _ akara.System = &TimeScaleSystem{}
|
|
|
|
// TimeScaleSystem should be the first system added to the world, and whose only job is to
|
|
// apply a scalar the world's TimeDelta between frames. It's useful for slowing down or speeding
|
|
// up the game time without affecting the render rate.
|
|
type TimeScaleSystem struct {
|
|
akara.BaseSystem
|
|
*d2util.Logger
|
|
scale float64
|
|
d2components.DirtyFactory
|
|
d2components.CommandRegistrationFactory
|
|
}
|
|
|
|
// Init will initialize the TimeScale system
|
|
func (t *TimeScaleSystem) Init(world *akara.World) {
|
|
t.World = world
|
|
|
|
t.Logger = d2util.NewLogger()
|
|
t.SetPrefix(logPrefixTimeScaleSystem)
|
|
|
|
t.Info("initializing ...")
|
|
|
|
t.InjectComponent(&d2components.CommandRegistration{}, &t.CommandRegistration)
|
|
t.InjectComponent(&d2components.Dirty{}, &t.Dirty)
|
|
|
|
t.registerCommands()
|
|
|
|
t.scale = defaultScale
|
|
}
|
|
|
|
// Update scales the worlds time delta for this frame
|
|
func (t *TimeScaleSystem) Update() {
|
|
if !t.Active() {
|
|
return
|
|
}
|
|
|
|
t.World.TimeDelta = time.Duration(float64(t.World.TimeDelta) * t.scale)
|
|
}
|
|
|
|
func (t *TimeScaleSystem) registerCommands() {
|
|
e := t.NewEntity()
|
|
|
|
reg := t.AddCommandRegistration(e)
|
|
|
|
t.AddDirty(e)
|
|
|
|
reg.Name = "timescale"
|
|
reg.Description = "set the time scale of the game (default is 1.0)"
|
|
reg.Callback = func(scale float64) {
|
|
t.Infof("setting time scale to %.1f", scale)
|
|
t.scale = scale
|
|
}
|
|
}
|