MCPcopy
hub / github.com/EngoEngine/engo / SetScene

Function SetScene

scene.go:68–118  ·  view source on GitHub ↗

SetScene sets the currentScene to the given Scene, and optionally forcing to create a new ecs.World that goes with it.

(s Scene, forceNewWorld bool)

Source from the content-addressed store, hash-verified

66// SetScene sets the currentScene to the given Scene, and
67// optionally forcing to create a new ecs.World that goes with it.
68func SetScene(s Scene, forceNewWorld bool) {
69 // Break down currentScene
70 if currentScene != nil {
71 if hider, ok := currentScene.(Hider); ok {
72 hider.Hide()
73 }
74 }
75
76 // Register Scene if needed
77 sceneMutex.RLock()
78 wrapper, registered := scenes[s.Type()]
79 sceneMutex.RUnlock()
80
81 if !registered {
82 RegisterScene(s)
83
84 sceneMutex.RLock()
85 wrapper = scenes[s.Type()]
86 sceneMutex.RUnlock()
87 }
88
89 // Initialize new Scene / World if needed
90 var doSetup bool
91
92 if wrapper.update == nil || forceNewWorld {
93 t := reflect.Indirect(reflect.ValueOf(currentUpdater)).Type()
94 v := reflect.New(t)
95 wrapper.update = v.Interface().(Updater)
96 wrapper.mailbox = &MessageManager{}
97
98 doSetup = true
99 }
100
101 // Do the switch
102 currentScene = s
103 currentUpdater = wrapper.update
104 Mailbox = wrapper.mailbox
105
106 // doSetup is true whenever we're (re)initializing the Scene
107 if doSetup {
108 s.Preload()
109
110 wrapper.mailbox.listeners = make(map[string][]HandlerIDPair)
111
112 s.Setup(wrapper.update)
113 } else {
114 if shower, ok := currentScene.(Shower); ok {
115 shower.Show()
116 }
117 }
118}
119
120// RegisterScene registers the `Scene`, so it can later be used by `SetSceneByName`
121func RegisterScene(s Scene) {

Callers 9

RunPreparationFunction · 0.85
RunFunction · 0.85
RunPreparationFunction · 0.85
runLoopFunction · 0.85
RunPreparationFunction · 0.85
RunPreparationFunction · 0.85
RunPreparationFunction · 0.85
SetSceneByNameFunction · 0.85
RunPreparationFunction · 0.85

Calls 7

RegisterSceneFunction · 0.85
HideMethod · 0.65
TypeMethod · 0.65
PreloadMethod · 0.65
SetupMethod · 0.65
ShowMethod · 0.65
NewMethod · 0.45

Tested by

no test coverage detected