MCPcopy Create free account
hub / github.com/EasyRPG/Player / MainFunction

Method MainFunction

src/scene.cpp:145–212  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

143}
144
145void Scene::MainFunction() {
146 static bool init = false;
147
148 if (IsAsyncPending()) {
149 Player::Update(false);
150 return;
151 } else {
152 // This is used to provide a hook for Scene_Map to finish
153 // it's PreUpdate() and teleport logic after transition
154 // or asynchronous file load.
155 OnFinishAsync();
156 }
157
158 // The continuation could have caused a new async wait condition, or
159 // it could have changed the scene.
160 if (!IsAsyncPending() && Scene::instance.get() == this) {
161 if (!init) {
162 auto prev_scene = Graphics::UpdateSceneCallback();
163 auto prev_scene_type = prev_scene ? prev_scene->type : Null;
164
165 // Destroy the previous scene here, before any initialization logic / transition in occurs.
166 prev_scene.reset();
167
168 // Initialization after scene switch
169 switch (push_pop_operation) {
170 case ScenePushed:
171 Start();
172 initialized = true;
173 break;
174 case ScenePopped:
175 if (!initialized) {
176 Start();
177 initialized = true;
178 } else {
179 Continue(prev_scene_type);
180 }
181 break;
182 default:;
183 }
184
185 push_pop_operation = 0;
186
187 ScheduleTransitionIn(prev_scene_type);
188
189 init = true;
190 return;
191 } else {
192 Player::Update();
193 }
194 }
195
196 if (Scene::instance.get() != this) {
197 // Shutdown after scene switch
198 assert(Scene::instance == instances.back() &&
199 "Don't set Scene::instance directly, use Push instead!");
200
201 Graphics::Update();
202

Callers 1

MainLoopMethod · 0.80

Calls 4

UpdateFunction · 0.70
getMethod · 0.45
resetMethod · 0.45
IsActiveMethod · 0.45

Tested by

no test coverage detected