func NewStateMachine(initial StateMachineState) *StateMachine { sm := &StateMachine{ timer: timer.NewTimer(), } sm.initialState = initial return sm }
func (w *World) worldTick() { var gameTime float64 var accumulator float64 var frameTime float64 dt := 0.01 timer := timer.NewTimer() currentTime := timer.Seconds() for { newTime := timer.Seconds() frameTime = newTime - currentTime currentTime = newTime accumulator += frameTime for accumulator >= dt { // Individual entities w.entityManager.Update(w, dt) accumulator -= (dt) gameTime += dt } // world AI w.director.Update(w, dt, gameTime) // tell the event manager to dispatch all queued events events.DispatchEvents() } }