Skip to content

Commit

Permalink
fix: load script packages before loading builtin assets (#16339)
Browse files Browse the repository at this point in the history
* fix: load script packages before loading builtin assets

* fix eslint

* fix ci

* Revert "fix ci"

This reverts commit 3858472.

* add errorID logID
  • Loading branch information
PPpro authored Oct 8, 2023
1 parent 3d65154 commit 7a8bde3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
8 changes: 8 additions & 0 deletions EngineErrorMap.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ Expected 'data' dict, but not found. Config file: %s

Please load the resource first : %s

### 1102

Effect settings not found, effects will not be imported.

### 1103

Success to load scene: %s

### 1200

cocos2d: Director: Error in gettimeofday
Expand Down
36 changes: 22 additions & 14 deletions cocos/game/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { findCanvas, loadJsFile } from 'pal/env';
import { Pacer } from 'pal/pacer';
import { ConfigOrientation } from 'pal/screen-adapter';
import assetManager, { IAssetManagerOptions } from '../asset/asset-manager/asset-manager';
import { EventTarget, AsyncDelegate, sys, macro, VERSION, cclegacy, screen, Settings, settings, assert, garbageCollectionManager, DebugMode, warn, log, _resetDebugSetting } from '../core';
import { EventTarget, AsyncDelegate, sys, macro, VERSION, cclegacy, screen, Settings, settings, assert, garbageCollectionManager, DebugMode, warn, log, _resetDebugSetting, errorID, logID } from '../core';
import { input } from '../input';
import { deviceManager, LegacyRenderMode } from '../gfx';
import { SplashScreen } from './splash-screen';
Expand Down Expand Up @@ -723,6 +723,7 @@ export class Game extends EventTarget {
})
.then((): void => {
if (DEBUG) {
// eslint-disable-next-line no-console
console.time('Init Base');
}
const debugMode = config.debugMode || DebugMode.NONE;
Expand All @@ -735,6 +736,7 @@ export class Game extends EventTarget {
.then((): Promise<void> => settings.init(config.settingsPath, config.overrideSettings))
.then((): Promise<void[]> => {
if (DEBUG) {
// eslint-disable-next-line no-console
console.timeEnd('Init Base');
}
this.emit(Game.EVENT_POST_BASE_INIT);
Expand All @@ -748,6 +750,7 @@ export class Game extends EventTarget {
})
.then((): void => {
if (DEBUG) {
// eslint-disable-next-line no-console
console.time('Init Infrastructure');
}
macro.init();
Expand All @@ -769,6 +772,7 @@ export class Game extends EventTarget {
Layers.init();
this.initPacer();
if (DEBUG) {
// eslint-disable-next-line no-console
console.timeEnd('Init Infrastructure');
}
})
Expand All @@ -795,27 +799,36 @@ export class Game extends EventTarget {
}
const data = effectSettings.data;
if (data === null) {
console.error('Effect settings not found, effects will not be imported.');
errorID(1102);
return;
}
cclegacy.rendering.init(deviceManager.gfxDevice, data);
})
.then((): Promise<any[]> => {
const scriptPackages = settings.querySettings<string[]>(Settings.Category.SCRIPTING, 'scriptPackages');
if (scriptPackages) {
return Promise.all(scriptPackages.map((pack): Promise<any> => import(pack)));
}
return Promise.resolve([]);
})
.then((): Promise<void> => {
if (DEBUG) {
// eslint-disable-next-line no-console
console.time('Init SubSystem');
}
director.init();
return builtinResMgr.loadBuiltinAssets();
})
.then((): Promise<void[]> => {
if (DEBUG) {
// eslint-disable-next-line no-console
console.timeEnd('Init SubSystem');
}
this.emit(Game.EVENT_POST_SUBSYSTEM_INIT);
return this.onPostSubsystemInitDelegate.dispatch();
})
.then((): void => {
console.log(`Cocos Creator v${VERSION}`);
log(`Cocos Creator v${VERSION}`);
this.emit(Game.EVENT_ENGINE_INITED);
this._engineInited = true;
})
Expand All @@ -827,6 +840,7 @@ export class Game extends EventTarget {
})
.then((): Promise<void> => {
if (DEBUG) {
// eslint-disable-next-line no-console
console.time('Init Project');
}
const jsList = settings.querySettings<string[]>(Settings.Category.PLUGINS, 'jsList');
Expand All @@ -838,13 +852,6 @@ export class Game extends EventTarget {
}
return promise;
})
.then((): Promise<any[]> => {
const scriptPackages = settings.querySettings<string[]>(Settings.Category.SCRIPTING, 'scriptPackages');
if (scriptPackages) {
return Promise.all(scriptPackages.map((pack): Promise<any> => import(pack)));
}
return Promise.resolve([]);
})
.then((): Promise<any[]> => this._loadProjectBundles())
.then((): Promise<void> => this._loadCCEScripts())
.then((): void | Promise<void> => this._setupRenderPipeline())
Expand All @@ -855,6 +862,7 @@ export class Game extends EventTarget {
})
.then((): Promise<void[]> => {
if (DEBUG) {
// eslint-disable-next-line no-console
console.timeEnd('Init Project');
}
this.emit(Game.EVENT_POST_PROJECT_INIT);
Expand Down Expand Up @@ -1013,11 +1021,11 @@ export class Game extends EventTarget {
SplashScreen.instance.update(this._calculateDT(false));
} else if (this._shouldLoadLaunchScene) {
this._shouldLoadLaunchScene = false;
const launchScene = settings.querySettings(Settings.Category.LAUNCH, 'launchScene');
const launchScene = settings.querySettings(Settings.Category.LAUNCH, 'launchScene') as string;
if (launchScene) {
// load scene
director.loadScene(launchScene, (): void => {
console.log(`Success to load scene: ${launchScene}`);
logID(1103, launchScene);
this._initTime = performance.now();
director.startAnimation();
this.onStart?.();
Expand Down Expand Up @@ -1098,7 +1106,7 @@ export class Game extends EventTarget {
}

private _setupRenderPipeline (): void | Promise<void> {
const renderPipeline = settings.querySettings(Settings.Category.RENDERING, 'renderPipeline');
const renderPipeline = settings.querySettings(Settings.Category.RENDERING, 'renderPipeline') as string;
if (!renderPipeline) {
return this._setRenderPipeline();
}
Expand All @@ -1124,7 +1132,7 @@ export class Game extends EventTarget {
this._safeEmit(Game.EVENT_RENDERER_INITED);
}

private _safeEmit (event): void {
private _safeEmit (event: string | number): void {
if (EDITOR) {
try {
this.emit(event);
Expand Down

0 comments on commit 7a8bde3

Please sign in to comment.