Skip to content

Commit

Permalink
Force sounds to download even when "preload in cache" is unchecked (#…
Browse files Browse the repository at this point in the history
…5984)

- Don't show in changelog
  • Loading branch information
D8H authored Dec 1, 2023
1 parent 87fa0a3 commit 8830bb9
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 58 deletions.
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.
// 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
// 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);
}
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

0 comments on commit 8830bb9

Please sign in to comment.