feat: westworldwithmessaging. add entitymanager, telegram, messagehandlers, delayedmessages, expand baseentity

This commit is contained in:
jonas committed 2026-09-03 21:57:52 +02:00
1 parent 0e7482e04c
commit 129dd5d8b8
18 files changed
+505 -19

No files matched your search

@@ -0,0 +1,40 @@
package westworldwithmessaging
import (
"sync"
"time"
)
// clockSingleton is our own stand-in for whatever timer/clock utility
// class the book uses elsewhere (it only shows up here as
// "Clock->GetCurrentTime()" - the book hasn't shown us that class's
// actual source, likely a separate timer file). All DispatchMessage
// and DispatchDelayedMessages actually need is a steadily increasing
// number of seconds, so this just measures time elapsed since the
// clock was first used.
type clockSingleton struct {
start time.Time
}
var (
clockInstance *clockSingleton
clockOnce sync.Once
)
func newClock() *clockSingleton {
clockOnce.Do(func() {
clockInstance = &clockSingleton{start: time.Now()}
})
return clockInstance
}
// Clock is a shorthand for the clock singleton, same "#define"-style
// convenience pattern as EntityMgr and Dispatch.
var Clock = newClock()
// GetCurrentTime returns the number of seconds elapsed since the
// clock started, matching the book's
// "double CurrentTime = Clock->GetCurrentTime();".
func (c *clockSingleton) GetCurrentTime() float64 {
return time.Since(c.start).Seconds()
}