/
scene.go
59 lines (50 loc) · 960 Bytes
/
scene.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
package gira
import (
"context"
"reflect"
"log"
"golang.org/x/sync/errgroup"
)
type Scene struct {
object *Object
cancelCtx context.Context
cancelFunc context.CancelFunc
errCtx context.Context
errGroup *errgroup.Group
}
func CreateScene() *Scene {
//app := App()
cancelCtx, cancel := context.WithCancel(context.TODO())
errGroup, errCtx := errgroup.WithContext(cancelCtx)
scene := &Scene{
cancelCtx: cancelCtx,
cancelFunc: cancel,
errCtx: errCtx,
errGroup: errGroup,
}
scene.object = scene.CreateObject()
return scene
}
func (s *Scene) CreateObject() *Object {
object := &Object{
componentDict: make(map[reflect.Type][]Component),
scene: s,
}
return object
}
func (s *Scene) forver() error {
select {
case <-s.cancelCtx.Done():
{
log.Println("scene done")
break
}
}
return nil
}
func (s *Scene) Cancel() {
s.cancelFunc()
}
func (s *Scene) Go(f func() error) {
s.errGroup.Go(f)
}