-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
77 lines (63 loc) · 1.53 KB
/
main.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
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"flag"
"fmt"
"os"
"os/signal"
"runtime"
"syscall"
"uk.ac.bris.cs/gameoflife/gol"
"uk.ac.bris.cs/gameoflife/sdl"
)
// main is the function called when starting Game of Life with 'go run .'
func main() {
runtime.LockOSThread()
var params gol.Params
flag.IntVar(
¶ms.Threads,
"t",
8,
"Specify the number of worker threads to use. Defaults to 8.")
flag.IntVar(
¶ms.ImageWidth,
"w",
512,
"Specify the width of the image. Defaults to 512.")
flag.IntVar(
¶ms.ImageHeight,
"h",
512,
"Specify the height of the image. Defaults to 512.")
flag.IntVar(
¶ms.Turns,
"turns",
10000000000,
"Specify the number of turns to process. Defaults to 10000000000.")
headless := flag.Bool(
"headless",
false,
"Disable the SDL window for running in a headless environment.")
flag.Parse()
fmt.Printf("%-10v %v\n", "Threads", params.Threads)
fmt.Printf("%-10v %v\n", "Width", params.ImageWidth)
fmt.Printf("%-10v %v\n", "Height", params.ImageHeight)
fmt.Printf("%-10v %v\n", "Turns", params.Turns)
keyPresses := make(chan rune, 10)
events := make(chan gol.Event, 1000)
go sigint(keyPresses)
go gol.Run(params, events, keyPresses)
if !(*headless) {
sdl.Run(params, events, keyPresses)
} else {
sdl.RunHeadless(events)
}
}
func sigint(keyPresses chan<- rune) {
sigint := make(chan os.Signal, 1)
signal.Notify(sigint, syscall.SIGINT, syscall.SIGTERM)
<-sigint
keyPresses <- 'q'
<-sigint
fmt.Println("\033[33mWARN\033[0m Force exit by the user with CTRL+C")
os.Exit(0)
}