Skip to content

Commit

Permalink
Use less concurrency in background.
Browse files Browse the repository at this point in the history
  • Loading branch information
D8H committed Dec 6, 2023
1 parent 14b08b4 commit 9937986
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 12 additions & 4 deletions GDJS/Runtime/ResourceLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ namespace gdjs {
);
};

const maxConcurrency = 20;
const maxForegroundConcurrency = 20;
const maxBackgroundConcurrency = 5;
const maxAttempt = 3;

/**
Expand Down Expand Up @@ -132,6 +133,7 @@ namespace gdjs {
* Only used by events.
*/
private currentSceneLoadingProgress: float = 0;
private _isLoadingScreenShown = false;

/**
* @param runtimeGame The game.
Expand Down Expand Up @@ -217,13 +219,17 @@ namespace gdjs {
}
}

onLoadingScreenShown(isLoadingScreenShown: boolean) {
this._isLoadingScreenShown = isLoadingScreenShown;
}

async loadAllResources(
onProgress: (loadingCount: integer, totalCount: integer) => void
): Promise<void> {
let loadedCount = 0;
await promisePoolAndRetry(
[...this._resources.values()],
maxConcurrency,
maxForegroundConcurrency,
maxAttempt,
async (resource) => {
await this._loadResource(resource);
Expand Down Expand Up @@ -254,7 +260,7 @@ namespace gdjs {
const resources = [...this._globalResources, ...sceneResources.values()];
await promisePoolAndRetry(
resources,
maxConcurrency,
maxForegroundConcurrency,
maxAttempt,
async (resourceName) => {
const resource = this._resources.get(resourceName);
Expand Down Expand Up @@ -318,7 +324,9 @@ namespace gdjs {
let loadedCount = 0;
await promisePoolAndRetry(
[...sceneResources.values()],
maxConcurrency,
this._isLoadingScreenShown
? maxForegroundConcurrency
: maxBackgroundConcurrency,
maxAttempt,
async (resourceName) => {
const resource = this._resources.get(resourceName);
Expand Down
2 changes: 2 additions & 0 deletions GDJS/Runtime/runtimegame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@ namespace gdjs {
progressCallback?: (progress: float) => void
): Promise<void> {
this.pause(true);
this._resourcesLoader.onLoadingScreenShown(true);
const loadingScreen = new gdjs.LoadingScreenRenderer(
this.getRenderer(),
this._resourcesLoader.getImageManager(),
Expand All @@ -739,6 +740,7 @@ namespace gdjs {
await loadAssets(onProgress);

await loadingScreen.unload();
this._resourcesLoader.onLoadingScreenShown(false);
this.pause(false);
}

Expand Down

0 comments on commit 9937986

Please sign in to comment.