first commit
This commit is contained in:
49
txflow/interfaces.go
Normal file
49
txflow/interfaces.go
Normal file
@@ -0,0 +1,49 @@
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user