MCPcopy
hub / github.com/4ian/GDevelop / prioritize

Method prioritize

GDJS/Runtime/ResourceLoader.ts:1179–1216  ·  view source on GitHub ↗

* Put a given scene at the end of the queue. * * When the scene that is currently loading in background is done, * this scene will be the next to be loaded.

(taskIdentifier: string)

Source from the content-addressed store, hash-verified

1177 * this scene will be the next to be loaded.
1178 */
1179 prioritize(taskIdentifier: string): LoadingTask | null {
1180 const loadingState = this.loadingStates.get(taskIdentifier);
1181 if (!loadingState) return null;
1182 if (loadingState.status === 'loaded' || loadingState.status === 'ready') {
1183 debugLogger.log(
1184 `Scene ${taskIdentifier} is already loaded. Skipping prioritization.`
1185 );
1186
1187 // The scene is already loaded, nothing to do.
1188 return null;
1189 }
1190
1191 // The scene is not loaded: either prioritize it or add it to the loading queue.
1192 const taskIndex = this.loadingTaskQueue.findIndex(
1193 (task) => task.identifier === taskIdentifier
1194 );
1195 let task: LoadingTask;
1196 if (taskIndex !== -1) {
1197 // There is already a task for this scene in the queue.
1198 // Move it so that it's loaded first.
1199 task = this.loadingTaskQueue[taskIndex];
1200 this.loadingTaskQueue.splice(taskIndex, 1);
1201 this.loadingTaskQueue.push(task);
1202 } else {
1203 // There is no task for this scene in the queue.
1204 // It might be because the scene was unloaded or never loaded.
1205 // In this case, we need to add a new task to the queue.
1206 task = new LoadingTask(taskIdentifier);
1207 this.loadingTaskQueue.push(task);
1208 }
1209
1210 // Re-start the loading process in the background. While at the beginning of the game
1211 // it's not needed because already launched, a scene might be unloaded. This means
1212 // that we then need to relaunch the loading process.
1213 this.loadAllTasksInBackground();
1214
1215 return task;
1216 }
1217
1218 registerResources(
1219 taskIdentifier: string,

Callers 1

loadSceneResourcesMethod · 0.80

Calls 4

getMethod · 0.65
logMethod · 0.65
pushMethod · 0.65

Tested by

no test coverage detected