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

Start games without loading screen if assets are ready before half the fade-in #6025

Merged
merged 5 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions GDJS/Runtime/pixi-renderers/loadingscreen-pixi-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ namespace gdjs {
_lastFrameTimeInMs: float = 0;
_progressPercent: float = 0;

private _isWatermarkEnabled: boolean;

constructor(
runtimeGamePixiRenderer: gdjs.RuntimeGamePixiRenderer,
imageManager: gdjs.PixiImageManager,
loadingScreenData: LoadingScreenData,
isWatermarkEnabled: boolean,
isFirstScene: boolean
) {
this._loadingScreenData = loadingScreenData;
this._isWatermarkEnabled = isWatermarkEnabled;
this._isFirstLayout = isFirstScene;
this._loadingScreenContainer = new PIXI.Container();
this._pixiRenderer = runtimeGamePixiRenderer.getPIXIRenderer();
Expand Down Expand Up @@ -267,16 +271,40 @@ namespace gdjs {

unload(): Promise<void> {
const totalElapsedTime = (performance.now() - this._startTimeInMs) / 1000;
const remainingTime =
(this._isFirstLayout ? this._loadingScreenData.minDuration : 0) -
totalElapsedTime;
this.setPercent(100);

// Ensure we have shown the loading screen for at least minDuration.
if (remainingTime <= 0) {
/**
* The duration before something bright may appear on screen at 100%
* opacity.
*/
const fadeInDuration = Math.min(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm really struggling to understand this logic, had to read it multiple times.
Could we split each side of the Math.min into named variables like fadeInDurationIfShowingGDevelopSplash and fadeInDurationIfUsingBackgroundColor ?

Also, I don't understand the Positive_infinity. Will this make a fade_in infinite if no splash or background color?

this._loadingScreenData.showGDevelopSplash
? this._loadingScreenData.logoAndProgressLogoFadeInDelay +
this._loadingScreenData.logoAndProgressFadeInDuration
: Number.POSITIVE_INFINITY,
this._loadingScreenData.backgroundImageResourceName ||
this._loadingScreenData.backgroundColor
? this._loadingScreenData.backgroundFadeInDuration
: Number.POSITIVE_INFINITY
);

if (
// Intermediate loading screens can be skipped as soon as possible.
!this._isFirstLayout ||
// Skip the 1st loading screen if nothing is too much visible yet to
// avoid flashing users eyes.
// This will likely only happen when the game is played a 2nd time
// and resources are already in cache.
(this._isWatermarkEnabled && totalElapsedTime < fadeInDuration / 2) ||
// Otherwise, display the loading screen at least the minimal duration
// set in game settings.
totalElapsedTime > this._loadingScreenData.minDuration
) {
this._state = LoadingScreenState.FINISHED;
return Promise.resolve();
}
const remainingTime =
this._loadingScreenData.minDuration - totalElapsedTime;
this.setPercent(100);
return new Promise((resolve) =>
setTimeout(() => {
this._state = LoadingScreenState.FINISHED;
Expand Down
1 change: 1 addition & 0 deletions GDJS/Runtime/runtimegame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@ namespace gdjs {
this.getRenderer(),
this._resourcesLoader.getImageManager(),
this._data.properties.loadingScreen,
this._data.properties.watermark.showWatermark,
isFirstScene
);

Expand Down