-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.go
66 lines (54 loc) · 1.25 KB
/
core.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
59
60
61
62
63
64
65
66
package main
import (
al "github.com/tapir/allegro5"
"github.com/tapir/allegro5/imageio"
"runtime"
"log"
)
func init() {
// Lock the main thread
runtime.LockOSThread()
}
func main() {
// Prepare channels
alpha := make(chan float64) // Logic-render interpolation value
input := make(chan uint) // Input data
display := make(chan *al.Display) // Display created
// Start Allegro
if !al.Init() {
log.Fatalln("Could not start Allegro.")
}
//defer al.UninstallSystem()
// Load image addon
if !imageio.Init() {
log.Fatalln("Could not start image IO addon.")
}
imageio.Shutdown()
// Create an event queue
queue := al.CreateEventQueue()
if queue == nil {
log.Fatalln("Could not create event queue.")
}
defer queue.Destroy()
// Process logic
go processLogic(alpha, input)
// Process render
go render(alpha, display)
// Get display created in render goroutine
d := <-display
// Register event sources
queue.RegisterEventSource(d.GetEventSource())
// Start timer and process input
done := false
for !done {
ok, event := queue.GetNextEvent()
if ok {
// Handle all allegro events here
if event.Type == al.EventDisplayClose {
done = true
}
}
// Switch context to logic goroutine by sending input data
input <- 0
}
}