/
world.go
58 lines (45 loc) · 1.11 KB
/
world.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package gameblocks
import (
"time"
mgl "github.com/go-gl/mathgl/mgl32"
"github.com/shazow/go-gameblocks/control"
"github.com/shazow/go-gameblocks/loader"
)
type Vector interface {
Position() mgl.Vec3
Direction() mgl.Vec3
}
type WorldContext struct {
Bindings control.Bindings
Shaders loader.Shaders
Textures loader.Textures
}
type World interface {
Scene
Reset()
Tick(time.Duration) error
Focus() Vector
Start(WorldContext) error
}
func FixedVector(position mgl.Vec3, direction mgl.Vec3) Vector {
return &fixedVector{
position: position,
direction: direction,
}
}
type fixedVector struct {
position mgl.Vec3
direction mgl.Vec3
}
func (v fixedVector) Position() mgl.Vec3 { return v.position }
func (v fixedVector) Direction() mgl.Vec3 { return v.direction }
type stubWorld struct {
Scene
}
func (w stubWorld) Reset() {}
func (w stubWorld) Tick(d time.Duration) error { return nil }
func (w stubWorld) Focus() Vector { return fixedVector{} }
func (w stubWorld) Start(_ WorldContext) error { return nil }
func StubWorld(scene Scene) World {
return stubWorld{scene}
}