/
eg.go
87 lines (80 loc) · 2.56 KB
/
eg.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
78
79
80
81
82
83
84
85
86
87
// Copyright © 2013-2018 Galvanized Logic Inc.
// Use is governed by a BSD-style license found in the LICENSE file.
// Package eg is used to test and demonstrate different aspects of the
// vu (virtual universe) engine. Examples are used both to showcase a
// particular 3D capability and to act as high level test cases for
// the engine. The examples are run using:
// eg [example name]
// Invoking eg without parameters will list the examples that can be run.
// Please look at each examples source code for possible user actions like
// moving around or tabbing to show different scenes.
//
// The package subdirectories contain asset filess needed by the examples.
package main
import (
"fmt"
"log"
"os"
"runtime/debug"
)
// example combines example code with descriptions.
type example struct {
tag string // Example identifier.
description string // Short description of the example.
function func() // Function to run the example.
}
// Launch the requested example or list available examples.
// Examples are roughly ordered from simple/basic at the top of the list
// to more complex/interesting at the bottom of the list.
func main() {
log.SetFlags(log.Lshortfile | log.Lmicroseconds)
examples := []example{
{"dg", "Dump OpenGL Bindings", dg},
{"da", "Dump OpenAL Bindings", da},
{"tr", "Spinning Triangle", tr},
{"ld", "Load .obj model", ld},
{"sh", "Simple Shell", sh},
{"sz", "Screen Resize", sz},
{"kc", "Keyboard Controller", kc},
{"au", "Audio", au},
{"sf", "Shader Fire", sf},
{"bb", "Banners & Billboards", bb},
{"lt", "Lighting", lt},
{"rl", "Random Levels", rl},
{"hx", "Hex Grid", hx},
{"sg", "Scene Graph", sg},
{"cr", "Collision Resolution", cr},
{"tm", "Terrain Map", tm},
{"ps", "Particle System", ps},
{"rc", "Ray Cast", rc},
{"sd", "Sky Dome", sd},
{"ma", "Model Animation", ma},
{"ff", "Flow Field", ff},
{"rt", "Ray Trace", rt},
{"tt", "Render to Texture", tt},
{"sm", "Shadow Map", sm},
{"ss", "Super Shapes", ss},
}
// run the first matching example.
for _, arg := range os.Args {
for _, eg := range examples {
if arg == eg.tag {
eg.function()
os.Exit(0)
}
}
}
// print usage if nothing was run.
fmt.Printf("Usage: eg [example]\n")
fmt.Printf("Examples are:\n")
for _, example := range examples {
fmt.Printf(" %s: %s \n", example.tag, example.description)
}
}
// catchErrors is a utility method used by some examples to trap and
// dump runtime errors.
func catchErrors() {
if r := recover(); r != nil {
log.Printf("Panic %s: %s Shutting down.", r, debug.Stack())
}
}