-
Notifications
You must be signed in to change notification settings - Fork 0
/
engine.go
49 lines (39 loc) · 1.38 KB
/
engine.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
package game
import (
ray "github.com/gen2brain/raylib-go/raylib"
"github.com/jordanbrauer/rpgo/game/component"
"github.com/jordanbrauer/rpgo/game/system"
lua "github.com/yuin/gopher-lua"
luar "layeh.com/gopher-luar"
)
func EnableRendering(world World) *system.Rendering {
textures := component.Texture{}.Name()
models := component.Model{}.Name()
positioning := component.Position{}.Name()
world.RegisterComponent(textures)
world.RegisterComponent(models)
world.RegisterComponent(positioning)
camera := &ray.Camera3D{
Position: ray.NewVector3(4.0, 2.0, 4.0),
Target: ray.NewVector3(0.0, 1.8, 0.0),
Up: ray.NewVector3(0.0, 1.0, 0.0),
Fovy: 60.0,
Projection: ray.CameraPerspective,
}
rendering := &system.Rendering{Camera: camera}
// TODO: implement custom camera mode
ray.SetCameraMode(*camera, ray.CameraFirstPerson)
world.RegisterSystem(rendering, textures, positioning, models)
return rendering
}
func EnableScripting(world World) (*system.Scripting, *lua.LState) {
library := Library{World: world}
script := lua.NewState()
behaviour := component.Scriptable{}.Name()
scripting := &system.Scripting{Global: script}
script.SetGlobal("configuration", luar.New(script, config))
script.SetGlobal("spawn", script.NewFunction(library.Spawn))
world.RegisterComponent(behaviour)
world.RegisterSystem(scripting, behaviour)
return scripting, script
}