50 lines
605 B
Go
50 lines
605 B
Go
package txflow
|
|
|
|
import "sync"
|
|
|
|
type Position struct {
|
|
X, Y, Z float64
|
|
World string
|
|
}
|
|
|
|
type World interface {
|
|
Name() string
|
|
Exec(func(Tx))
|
|
}
|
|
|
|
type Tx interface {
|
|
World() World
|
|
}
|
|
|
|
type Entity interface {
|
|
Teleport(Position)
|
|
}
|
|
|
|
type Handle interface {
|
|
Entity(tx Tx) (Entity, bool)
|
|
ExecWorld(func(tx Tx, e Entity))
|
|
}
|
|
|
|
type WorldResolver interface {
|
|
Resolve(name string) (World, error)
|
|
}
|
|
|
|
type SafeBox[T any] struct {
|
|
mu sync.RWMutex
|
|
v T
|
|
}
|
|
|
|
func (s *SafeBox[T]) Set(v T) {
|
|
s.mu.Lock()
|
|
s.v = v
|
|
s.mu.Unlock()
|
|
}
|
|
|
|
func (s *SafeBox[T]) Get() T {
|
|
s.mu.RLock()
|
|
v := s.v
|
|
s.mu.RUnlock()
|
|
return v
|
|
}
|
|
|