Skip to content

Commit

Permalink
adjust initialization process (cocos#11143)
Browse files Browse the repository at this point in the history
* adjust init process

* fix bugs

* restructure

* tweak

* delete useless code

* fix ci

* support more platform and fix some bugs

* mark internal

* tweak

* add docs

* add docs and little adjustment

* fix bugs

* adjust decorator execute order

fix mesh error

* fix bugs

* revert some change

* revert auto-generated code

* revert auto-generated code
  • Loading branch information
SantyWang authored Jul 3, 2022
1 parent 8110169 commit 7bc135e
Show file tree
Hide file tree
Showing 199 changed files with 8,390 additions and 7,993 deletions.
4 changes: 4 additions & 0 deletions @types/pal/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module 'pal/env' {
export function findCanvas (): { frame: HTMLDivElement, container: HTMLDivElement, canvas: HTMLCanvasElement };
export function loadJsFile (path: string): Promise<void>;
}
1 change: 1 addition & 0 deletions @types/pal/minigame.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
declare module 'pal/minigame' {
export const minigame: IMiniGame;
export interface IMiniGame {
setPreferredFramesPerSecond(_targetFrameRate: number);
// platform related
wx?: WeChatAPI;
tt?: ByteDanceAPI;
Expand Down
10 changes: 10 additions & 0 deletions @types/pal/pacer.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
declare module 'pal/pacer' {

export class Pacer {
get targetFrameRate (): number;
set targetFrameRate (val: number);
onTick: (() => void) | null;
start (): void;
stop (): void;
}
}
102 changes: 89 additions & 13 deletions cc.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,60 @@
"$schema": "./cc.config.schema.json",

"features": {
"base": { "modules": [ "base", "native" ] },
"base": { "modules": [ "base", "native" ], "dependentAssets": [
"ff9be190-20a4-4e48-b68c-76e3c7cff085",
"970b0598-bcb0-4714-91fb-2e81440dccd8",
"bcd64cc6-2dd9-43f6-abbe-66318d332032",
"d930590d-bb92-4cc8-8bd1-23cd027f9edf",
"a3cd009f-0ab0-420d-9278-b9fdab939bbc"
]},
"gfx-webgl": { "modules": [ "gfx-webgl" ] },
"gfx-webgl2": { "modules": [ "gfx-webgl2" ] },
"3d": { "modules": [ "3d" ] },
"3d": {
"modules": [ "3d" ],
"dependentAssets": [
"1baf0fc9-befa-459c-8bdd-af1a450a0319",
"d9937e59-61fe-4ec6-92ab-7ac5a19c89b0",
"9361fd90-ba52-4f84-aa93-6e878fd576ca",
"511d2633-09a7-4bdd-ac42-f778032124b3",
"5d45aa00-e064-4938-b314-4265f0c2258c",
"28d6d6b8-3f66-4a73-9795-17a0852ba2d4",
"ec8106fe-05bf-4e94-943c-e0d3b7bb5e45",
"620b6bf3-0369-4560-837f-2a2c00b73c26"
]
},
"animation": { "modules": ["animation"] },
"skeletal-animation": { "modules": ["animation", "skeletal-animation"] },
"2d": { "modules": [ "2d" ] },
"2d": {
"modules": [ "2d" ],
"dependentAssets": [
"60f7195c-ec2a-45eb-ba94-8955f60e81d0",
"1c02ae6f-4492-4915-b8f8-7492a3b1e4cd",
"810e96e4-e456-4468-9b59-f4e8f39732c0",
"efe8e2a3-eace-427b-b4f1-cb8a937ec77d",
"e9aa9a3e-5b2b-4ac7-a2c7-073de2b2b24f",
"8bbdbcdd-5cd4-4100-b6d5-b7c9625b6107",
"50f4348b-c883-4e2f-8f11-ce233b859fa1",
"fda095cb-831d-4601-ad94-846013963de8",
"f92806d7-1768-443f-afe8-12bcde84d0f0",
"dd3a144d-ab7f-41f0-82b8-2e43a090d496",
"f0416e68-0200-4b77-a926-4f9d16e494da"
]
},
"ui": { "modules": [ "ui", "2d" ] },
"particle": { "modules": [ "particle" ] },
"particle": {
"modules": [ "particle" ],
"dependentAssets": [
"d1346436-ac96-4271-b863-1f4fdead95b0",
"971bdb23-3ff6-43eb-b422-1c30165a3663",
"17debcc3-0a6b-4b8a-b00b-dc58b885581e",
"711ebe11-f673-4cd9-9a83-63c60ba54c5b",
"c0143906-9aed-447e-9436-2ae8512d1b6e",
"14da1725-c4c2-42b4-ab08-ee0aeb6898b3",
"081cab31-dccd-428e-8652-f2404cc81c47",
"78e0584a-4343-4727-8f37-e14e65c2a2db"
]
},
"particle-2d": { "modules": [ "particle-2d" ] },
"physics-framework": { "modules": [ "physics-framework" ] },
"physics-cannon": { "modules": [ "physics-cannon", "physics-framework" ] },
Expand All @@ -22,16 +67,39 @@
"physics-2d-builtin": { "modules": [ "physics-2d-builtin", "physics-2d-framework" ] },
"intersection-2d": { "modules": [ "intersection-2d" ] },
"primitive": { "modules": [ "primitive" ] },
"profiler": { "modules": [ "profiler" ] },
"geometry-renderer": { "modules": [ "geometry-renderer" ] },
"debug-renderer": { "modules": [ "debug-renderer" ], "dependentAssets": ["0835f102-5471-47a3-9a76-01c07ac9cdb2", "b5475517-23b9-4873-bc1a-968d96616081", "0ed97c56-390e-4dd1-96b7-e7f2d93a98ed", "b23391b6-52eb-46a6-8da1-6244d9d315fb"] },
"profiler": {
"modules": [ "profiler" ],
"dependentAssets": [ "871c3b6c-7379-419d-bda3-794b239ab90d" ]
},
"geometry-renderer": {
"modules": [ "geometry-renderer" ],
"dependentAssets": [ "4bb480dd-8384-4bc9-987f-de67cc53052a" ]
},
"debug-renderer": {
"modules": [ "debug-renderer" ],
"dependentAssets": [
"0835f102-5471-47a3-9a76-01c07ac9cdb2",
"b5475517-23b9-4873-bc1a-968d96616081",
"0ed97c56-390e-4dd1-96b7-e7f2d93a98ed",
"b23391b6-52eb-46a6-8da1-6244d9d315fb"
]
},
"audio": { "modules": [ "audio" ] },
"video": { "modules": [ "video" ] },
"terrain": { "modules": [ "terrain" ] },
"terrain": {
"modules": [ "terrain" ],
"dependentAssets": [ "1d08ef62-a503-4ce2-8b9a-46c90873f7d3" ]
},
"webview": { "modules": [ "webview" ] },
"tween": { "modules": [ "tween" ] },
"tiled-map": { "modules": [ "tiled-map" ] },
"spine": { "modules": [ "spine" ] },
"spine": {
"modules": [ "spine" ],
"dependentAssets":[
"c27215d8-6835-4b68-bfbb-bdeac6100c04",
"b5d6115f-0370-4d7c-aad3-c194cc71cf98"
]
},
"dragon-bones": { "modules": [ "dragon-bones" ] },
"marionette": {
"modules": [],
Expand Down Expand Up @@ -116,7 +184,9 @@
"pal/audio": "pal/audio/web/player.ts",
"pal/system-info": "pal/system-info/web/system-info.ts",
"pal/screen-adapter": "pal/screen-adapter/web/screen-adapter.ts",
"pal/input": "pal/input/web/index.ts"
"pal/input": "pal/input/web/index.ts",
"pal/env": "pal/env/web/env.ts",
"pal/pacer": "pal/pacer/pacer-web.ts"
}
},
{
Expand All @@ -127,7 +197,9 @@
"pal/audio": "pal/audio/native/player.ts",
"pal/system-info": "pal/system-info/native/system-info.ts",
"pal/screen-adapter": "pal/screen-adapter/native/screen-adapter.ts",
"pal/input": "pal/input/native/index.ts"
"pal/input": "pal/input/native/index.ts",
"pal/env": "pal/env/native/env.ts",
"pal/pacer": "pal/pacer/pacer-native.ts"
}
},
{
Expand All @@ -138,7 +210,9 @@
"pal/audio": "pal/audio/minigame/player.ts",
"pal/system-info": "pal/system-info/minigame/system-info.ts",
"pal/screen-adapter": "pal/screen-adapter/minigame/screen-adapter.ts",
"pal/input": "pal/input/minigame/index.ts"
"pal/input": "pal/input/minigame/index.ts",
"pal/env": "pal/env/minigame/env.ts",
"pal/pacer": "pal/pacer/pacer-minigame.ts"
}
},
{
Expand All @@ -149,7 +223,9 @@
"pal/audio": "pal/audio/minigame/player.ts",
"pal/system-info": "pal/system-info/minigame/system-info.ts",
"pal/screen-adapter": "pal/screen-adapter/minigame/screen-adapter.ts",
"pal/input": "pal/input/minigame/index.ts"
"pal/input": "pal/input/minigame/index.ts",
"pal/env": "pal/env/runtime/env.ts",
"pal/pacer": "pal/pacer/pacer-minigame.ts"
}
},
{
Expand Down
4 changes: 2 additions & 2 deletions cocos/2d/components/graphics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { IBatcher } from '../renderer/i-batcher';
import { LineCap, LineJoin } from '../assembler/graphics/types';
import { Impl } from '../assembler/graphics/webgl/impl';
import { RenderingSubMesh } from '../../core/assets';
import { Format, PrimitiveMode, Attribute, Device, BufferUsageBit, BufferInfo, MemoryUsageBit } from '../../core/gfx';
import { Format, PrimitiveMode, Attribute, Device, BufferUsageBit, BufferInfo, MemoryUsageBit, deviceManager } from '../../core/gfx';
import { vfmtPosColor, getAttributeStride, getComponentPerVertex } from '../renderer/vertex-format';
import { legacyCC } from '../../core/global-exports';
import { warnID } from '../../core/platform/debug';
Expand Down Expand Up @@ -618,7 +618,7 @@ export class Graphics extends UIRenderer {
}

if (this.model.subModels.length <= idx) {
const gfxDevice: Device = legacyCC.director.root.device;
const gfxDevice: Device = deviceManager.gfxDevice;
const vertexBuffer = gfxDevice.createBuffer(new BufferInfo(
BufferUsageBit.VERTEX | BufferUsageBit.TRANSFER_DST,
MemoryUsageBit.DEVICE,
Expand Down
4 changes: 2 additions & 2 deletions cocos/2d/components/mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { Graphics } from './graphics';
import { TransformBit } from '../../core/scene-graph/node-enum';
import { SpriteFrame } from '../assets/sprite-frame';
import { Game, Material, builtinResMgr, director, CCObject } from '../../core';
import { Device, BufferInfo, BufferUsageBit, MemoryUsageBit, PrimitiveMode } from '../../core/gfx';
import { Device, BufferInfo, BufferUsageBit, MemoryUsageBit, PrimitiveMode, deviceManager } from '../../core/gfx';
import { legacyCC } from '../../core/global-exports';
import { MaterialInstance, scene } from '../../core/renderer';
import { Model } from '../../core/renderer/scene';
Expand Down Expand Up @@ -541,7 +541,7 @@ export class Mask extends UIRenderer {
this._clearModel = director.root!.createModel(scene.Model);
this._clearModel.node = this._clearModel.transform = this.node;
const stride = getAttributeStride(vfmt);
const gfxDevice: Device = legacyCC.director.root.device;
const gfxDevice: Device = deviceManager.gfxDevice;
const vertexBuffer = gfxDevice.createBuffer(new BufferInfo(
BufferUsageBit.VERTEX | BufferUsageBit.TRANSFER_DST,
MemoryUsageBit.DEVICE,
Expand Down
1 change: 0 additions & 1 deletion cocos/2d/framework/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { ccclass, help, disallowMultiple, executeInEditMode,
import { EDITOR } from 'internal:constants';
import { Camera } from '../../core/components/camera-component';
import { Widget } from '../../ui/widget';
import { game } from '../../core/game';
import { Vec3 } from '../../core/math';
import { view } from '../../core/platform/view';
import { legacyCC } from '../../core/global-exports';
Expand Down
16 changes: 8 additions & 8 deletions cocos/2d/renderer/batcher-2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import type { UIStaticBatch } from '../components/ui-static-batch';
import { Material } from '../../core/assets/material';
import { RenderRoot2D, UIRenderer } from '../framework';
import { Texture, Device, Attribute, Sampler, DescriptorSetInfo, Buffer,
BufferInfo, BufferUsageBit, MemoryUsageBit, DescriptorSet, InputAssembler } from '../../core/gfx';
BufferInfo, BufferUsageBit, MemoryUsageBit, DescriptorSet, InputAssembler, deviceManager } from '../../core/gfx';
import { Pool } from '../../core/memop';
import { CachedArray } from '../../core/memop/cached-array';
import { Root } from '../../core/root';
Expand Down Expand Up @@ -722,7 +722,7 @@ class LocalDescriptorSet {
}

constructor () {
const device = legacyCC.director.root.device;
const device = deviceManager.gfxDevice;
this._localData = new Float32Array(UBOLocal.COUNT);
this._localBuffer = device.createBuffer(new BufferInfo(
BufferUsageBit.UNIFORM | BufferUsageBit.TRANSFER_DST,
Expand All @@ -733,17 +733,17 @@ class LocalDescriptorSet {
}

public initialize (batch) {
const device = legacyCC.director.root.device;
const device = deviceManager.gfxDevice;
this._transform = batch.useLocalData;
this._textureHash = batch.textureHash;
this._samplerHash = batch.samplerHash;
_dsInfo.layout = batch.passes[0].localSetLayout;
this._descriptorSet = device.createDescriptorSet(_dsInfo);
this._descriptorSet!.bindBuffer(UBOLocal.BINDING, this._localBuffer!);
this._descriptorSet.bindBuffer(UBOLocal.BINDING, this._localBuffer!);
const binding = ModelLocalBindings.SAMPLER_SPRITE;
this._descriptorSet!.bindTexture(binding, batch.texture!);
this._descriptorSet!.bindSampler(binding, batch.sampler!);
this._descriptorSet!.update();
this._descriptorSet.bindTexture(binding, batch.texture!);
this._descriptorSet.bindSampler(binding, batch.sampler!);
this._descriptorSet.update();
this._transformUpdate = true;
}

Expand Down Expand Up @@ -838,7 +838,7 @@ class DescriptorSetCache {
return this._descriptorSetCache.get(hash)!;
} else {
_dsInfo.layout = batch.passes[0].localSetLayout;
const descriptorSet = root.device.createDescriptorSet(_dsInfo) as DescriptorSet;
const descriptorSet = deviceManager.gfxDevice.createDescriptorSet(_dsInfo);
const binding = ModelLocalBindings.SAMPLER_SPRITE;
descriptorSet.bindTexture(binding, batch.texture!);
descriptorSet.bindSampler(binding, batch.sampler!);
Expand Down
13 changes: 12 additions & 1 deletion cocos/2d/utils/dynamic-atlas/atlas-manager.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { EDITOR } from 'internal:constants';
import { director, System } from '../../../core';
import { Filter } from '../../../core/assets/asset-enum';
import { legacyCC } from '../../../core/global-exports';
import { macro } from '../../../core/platform';
import { js } from '../../../core/utils/js';
import { Atlas } from './atlas';

export class DynamicAtlasManager {
export class DynamicAtlasManager extends System {
public static instance: DynamicAtlasManager;

private _atlases: Atlas[] = [];
Expand Down Expand Up @@ -121,6 +123,13 @@ export class DynamicAtlasManager {
this.reset();
}

/**
* @internal
*/
public init () {
this.enabled = !macro.CLEANUP_IMAGE_CACHE;
}

/**
* @en
* Append a sprite frame into the dynamic atlas.
Expand Down Expand Up @@ -244,4 +253,6 @@ export class DynamicAtlasManager {

export const dynamicAtlasManager: DynamicAtlasManager = DynamicAtlasManager.instance = new DynamicAtlasManager();

director.registerSystem('dynamicAtlasManager', dynamicAtlasManager, 0);

legacyCC.internal.dynamicAtlasManager = dynamicAtlasManager;
Loading

0 comments on commit 7bc135e

Please sign in to comment.