Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force sounds to download even when "preload in cache" is unchecked #5984

Merged
merged 12 commits into from
Dec 1, 2023
10 changes: 5 additions & 5 deletions Core/GDCore/Extensions/Builtin/SceneExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsSceneExtension(
_("Preload a scene resources as soon as possible in background."),
_("Preload scene _PARAM1_ in background"),
"",
"res/actions/replaceScene24.png",
"res/actions/replaceScene.png")
"res/actions/hourglass_black.svg",
"res/actions/hourglass_black.svg")
.SetHelpPath("/all-features/resources-loading")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("sceneName", _("Name of the new scene"))
Expand All @@ -184,7 +184,7 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsSceneExtension(
_("The progress of resources loading in background for a scene (between 0 and 1)."),
_("_PARAM0_ loading progress"),
_(""),
"res/actions/replaceScene24.png")
"res/actions/hourglass_black.svg")
.SetHelpPath("/all-features/resources-loading")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("sceneName", _("Scene name"))
Expand All @@ -197,8 +197,8 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsSceneExtension(
_("Check if scene resources have finished to load in background."),
_("Scene _PARAM1_ was preloaded in background"),
"",
"res/actions/replaceScene24.png",
"res/actions/replaceScene.png")
"res/actions/hourglass_black.svg",
"res/actions/hourglass_black.svg")
.SetHelpPath("/all-features/resources-loading")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("sceneName", _("Scene name"))
Expand Down
2 changes: 1 addition & 1 deletion Core/GDCore/Project/LoadingScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ LoadingScreen::LoadingScreen()
backgroundFadeInDuration(0.2),
minDuration(1.5),
logoAndProgressFadeInDuration(0.2),
logoAndProgressLogoFadeInDelay(0.2),
logoAndProgressLogoFadeInDelay(0),
showProgressBar(true),
progressBarMinWidth(40),
progressBarMaxWidth(200),
Expand Down
10 changes: 9 additions & 1 deletion GDJS/Runtime/howler-sound-manager/howler-sound-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,15 @@ namespace gdjs {
'There was an error while preloading an audio file: ' + error
);
}
} else if (resource.preloadInCache) {
} else if (
resource.preloadInCache ||
// Force downloading of sounds.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there a risk to download large files that have not been tagged as "preload as a music" by the user?

Copy link
Collaborator Author

@D8H D8H Dec 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, we have the choice between:

  • the previous behavior, the sound won't play the 1st times which sounds like a bug in the engine (pun intend)
  • the new behavior, the loading takes more time which is easy to understand for users to try and fix it

I didn't update the UI because we may make it asynchronous if it's a good trade off.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok! What do we do about the other TODO "Decide if sounds should be allowed to be downloaded after the scene starts"?

// TODO Decide if sounds should be allowed to be downloaded after the scene starts.
// - they should be requested automatically at the end of the scene loading
// - they will be downloaded while the scene is playing
// - other scenes will be pre-loaded only when all the sounds for the current scene are in cache
!resource.preloadAsMusic
) {
// preloading as sound already does a XHR request, hence "else if"
try {
await new Promise((resolve, reject) => {
Expand Down
24 changes: 19 additions & 5 deletions GDJS/Runtime/pixi-renderers/loadingscreen-pixi-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace gdjs {
}

const fadeIn = (
object: PIXI.DisplayObject | null,
object: { alpha: number } | null,
duration: float,
deltaTimeInMs: float
) => {
Expand Down Expand Up @@ -54,14 +54,12 @@ namespace gdjs {
return;
}
this._pixiRenderer.background.color = this._loadingScreenData.backgroundColor;
this._pixiRenderer.background.alpha = 0;

const backgroundTexture = imageManager.getOrLoadPIXITexture(
loadingScreenData.backgroundImageResourceName
);
if (
backgroundTexture !== imageManager.getInvalidPIXITexture() &&
isFirstScene
) {
if (backgroundTexture !== imageManager.getInvalidPIXITexture()) {
this._backgroundSprite = PIXI.Sprite.from(backgroundTexture);
this._backgroundSprite.alpha = 0;
this._backgroundSprite.anchor.x = 0.5;
Expand Down Expand Up @@ -173,6 +171,15 @@ namespace gdjs {
} else if (this._state == LoadingScreenState.STARTED) {
const backgroundFadeInDuration = this._loadingScreenData
.backgroundFadeInDuration;

this._pixiRenderer.clear();
if (!this._backgroundSprite) {
fadeIn(
this._pixiRenderer.background,
backgroundFadeInDuration,
deltaTimeInMs
);
}
fadeIn(this._backgroundSprite, backgroundFadeInDuration, deltaTimeInMs);

if (hasFadedIn(this._backgroundSprite)) {
Expand Down Expand Up @@ -245,6 +252,13 @@ namespace gdjs {
);
this._progressBarGraphics.endFill();
}
} else if (this._state === LoadingScreenState.FINISHED) {
// Display a black screen to avoid a stretched image of the loading
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, great polishing work.

// screen to appear.
this._pixiRenderer.background.color = 'black';
this._pixiRenderer.background.alpha = 1;
this._pixiRenderer.clear();
this._loadingScreenContainer.removeChildren();
}

this._pixiRenderer.render(this._loadingScreenContainer);
Expand Down
49 changes: 30 additions & 19 deletions GDJS/Runtime/runtimegame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -650,25 +650,36 @@ namespace gdjs {
progressCallback?: (progress: float) => void
): Promise<void> {
try {
await this._loadAssetsWithLoadingScreen(
/* isFirstScene = */ true,
async (onProgress) => {
// TODO Is a setting needed?
if (false) {
await this._resourcesLoader.loadAllResources(onProgress);
} else {
await this._resourcesLoader.loadGlobalAndFirstSceneResources(
firstSceneName,
onProgress
);
// Don't await as it must not block the first scene from starting.
this._resourcesLoader.loadAllSceneInBackground();
}
},
progressCallback
);
// TODO This is probably not necessary in case of hot reload.
await gdjs.getAllAsynchronouslyLoadingLibraryPromise();
// Download the loading screen background image first to be able to
// display the loading screen as soon as possible.
const backgroundImageResourceName = this._data.properties.loadingScreen
.backgroundImageResourceName;
if (backgroundImageResourceName) {
await this._resourcesLoader
.getImageManager()
.loadResource(backgroundImageResourceName);
}
D8H marked this conversation as resolved.
Show resolved Hide resolved
await Promise.all([
this._loadAssetsWithLoadingScreen(
/* isFirstScene = */ true,
async (onProgress) => {
// TODO Is a setting needed?
if (false) {
await this._resourcesLoader.loadAllResources(onProgress);
} else {
await this._resourcesLoader.loadGlobalAndFirstSceneResources(
firstSceneName,
onProgress
);
// Don't await as it must not block the first scene from starting.
this._resourcesLoader.loadAllSceneInBackground();
}
},
progressCallback
),
// TODO This is probably not necessary in case of hot reload.
gdjs.getAllAsynchronouslyLoadingLibraryPromise(),
]);
} catch (e) {
if (this._debuggerClient) this._debuggerClient.onUncaughtException(e);

Expand Down
10 changes: 10 additions & 0 deletions newIDE/app/public/res/actions/hourglass_black.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion newIDE/app/src/Profile/Subscription/SubscriptionChecker.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { isNativeMobileApp } from '../../Utils/Platform';

export type SubscriptionCheckerInterface = {|
checkUserHasSubscription: () => boolean,
hasUserSubscription: () => boolean,
|};

type Props = {|
Expand Down Expand Up @@ -68,7 +69,14 @@ const SubscriptionChecker = React.forwardRef<
return false;
};

React.useImperativeHandle(ref, () => ({ checkUserHasSubscription }));
const hasUserSubscription = () => {
return hasValidSubscriptionPlan(authenticatedUser.subscription);
};

React.useImperativeHandle(ref, () => ({
checkUserHasSubscription,
hasUserSubscription,
}));

return (
<Dialog
Expand Down
Loading