@ives_xxz/framework 1.5.14 → 1.5.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/expand/FWDecorator.ts +49 -0
- package/manager/FWBundleManager.ts +15 -11
- package/manager/FWLayerManager.ts +3 -0
- package/manager/FWResManager.ts +55 -1
- package/package.json +1 -1
package/expand/FWDecorator.ts
CHANGED
|
@@ -367,3 +367,52 @@ export function AutoRegisterFWEvent(eventName: any) {
|
|
|
367
367
|
};
|
|
368
368
|
};
|
|
369
369
|
}
|
|
370
|
+
|
|
371
|
+
export function PerformanceMonitor(operationName?: string) {
|
|
372
|
+
return function (
|
|
373
|
+
target: any,
|
|
374
|
+
propertyKey: string,
|
|
375
|
+
descriptor: PropertyDescriptor
|
|
376
|
+
) {
|
|
377
|
+
const originalMethod = descriptor.value;
|
|
378
|
+
|
|
379
|
+
descriptor.value = async function (...args: any[]) {
|
|
380
|
+
const startTime = Date.now();
|
|
381
|
+
const moduleName = target.constructor.name;
|
|
382
|
+
let methodName = propertyKey;
|
|
383
|
+
|
|
384
|
+
if (args && args[0].type) {
|
|
385
|
+
methodName = `${methodName}->${args[0]?.type?.name}`;
|
|
386
|
+
} else {
|
|
387
|
+
methodName = operationName || propertyKey;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
try {
|
|
391
|
+
const result = await originalMethod.apply(this, args);
|
|
392
|
+
const duration = Date.now() - startTime;
|
|
393
|
+
|
|
394
|
+
FW.Entry.performanceMgr?.recordOperationMetric(
|
|
395
|
+
moduleName,
|
|
396
|
+
methodName,
|
|
397
|
+
duration
|
|
398
|
+
);
|
|
399
|
+
|
|
400
|
+
if (duration > 100) {
|
|
401
|
+
FWLog.warn(`[${moduleName}] ${methodName} took ${duration}ms`);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
return result;
|
|
405
|
+
} catch (error) {
|
|
406
|
+
const duration = Date.now() - startTime;
|
|
407
|
+
FW.Entry.performanceMgr?.recordOperationMetric(
|
|
408
|
+
moduleName,
|
|
409
|
+
`${methodName}_error`,
|
|
410
|
+
duration
|
|
411
|
+
);
|
|
412
|
+
throw error;
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
return descriptor;
|
|
417
|
+
};
|
|
418
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { FWManager } from
|
|
2
|
-
import FWLog from
|
|
3
|
-
import Framework from
|
|
4
|
-
import { FWSystemConfig } from
|
|
1
|
+
import { FWManager } from "./FWManager";
|
|
2
|
+
import FWLog from "../log/FWLog";
|
|
3
|
+
import Framework from "../Framework";
|
|
4
|
+
import { FWSystemConfig } from "../config/FWSystemConfig";
|
|
5
|
+
import { FWLodash } from "../utils/FWLodash";
|
|
5
6
|
|
|
6
7
|
export class FWBundleManager extends FWManager implements FW.BundleManager {
|
|
7
8
|
bundleMap: Map<string, cc.AssetManager.Bundle>;
|
|
@@ -35,25 +36,28 @@ export class FWBundleManager extends FWManager implements FW.BundleManager {
|
|
|
35
36
|
return await this.invoke(
|
|
36
37
|
FW.Entry.promiseMgr.execute((resolve, reject, signal) => {
|
|
37
38
|
const remote = this.remoteBundleConfigMap.get(bundleName);
|
|
38
|
-
const url = remote ? remote.url :
|
|
39
|
+
const url = remote ? remote.url : "";
|
|
39
40
|
const path = `${url}${bundleName}`;
|
|
40
41
|
cc.assetManager.loadBundle(
|
|
41
42
|
path,
|
|
42
|
-
{
|
|
43
|
-
|
|
43
|
+
{
|
|
44
|
+
version: this.remoteBundleConfigMap.get(bundleName)?.version || "",
|
|
45
|
+
},
|
|
46
|
+
async (err: Error, bundle: cc.AssetManager.Bundle) => {
|
|
44
47
|
if (err || !bundle) {
|
|
45
48
|
FWLog.error(`"加载bundle失败:"${bundleName}!`);
|
|
46
49
|
reject(err);
|
|
47
50
|
}
|
|
48
|
-
this.bundleMap.set(bundleName, bundle);
|
|
49
51
|
|
|
50
52
|
Framework.createRegistry(bundleName)?.register();
|
|
51
53
|
|
|
54
|
+
this.bundleMap.set(bundleName, bundle);
|
|
55
|
+
|
|
52
56
|
resolve(bundle);
|
|
53
|
-
}
|
|
57
|
+
}
|
|
54
58
|
);
|
|
55
59
|
}, FWSystemConfig.PromiseConfig.loadBundle).promise,
|
|
56
|
-
`loadBundle -> ${bundleName}
|
|
60
|
+
`loadBundle -> ${bundleName}`
|
|
57
61
|
);
|
|
58
62
|
}
|
|
59
63
|
|
|
@@ -64,7 +68,7 @@ export class FWBundleManager extends FWManager implements FW.BundleManager {
|
|
|
64
68
|
*/
|
|
65
69
|
get(bundleName: string): cc.AssetManager.Bundle {
|
|
66
70
|
if (!this.has(bundleName)) {
|
|
67
|
-
FWLog.error(
|
|
71
|
+
FWLog.error("获取bundle失败,请先加载!");
|
|
68
72
|
return undefined;
|
|
69
73
|
}
|
|
70
74
|
return this.bundleMap.get(bundleName);
|
|
@@ -11,6 +11,7 @@ import FWSocketSender from "../service/socket/FWSocketSender";
|
|
|
11
11
|
import FWSocketHandle from "../service/socket/FWSocketHandle";
|
|
12
12
|
import Framework from "../Framework";
|
|
13
13
|
import { FrameworkBase } from "../FrameworkBase";
|
|
14
|
+
import { PerformanceMonitor } from "../expand/FWDecorator";
|
|
14
15
|
|
|
15
16
|
const ADD_EXTERNAL_REFERENCE: string = "addExternalReference";
|
|
16
17
|
|
|
@@ -43,6 +44,7 @@ export class FWLayerManager extends FWManager implements FW.LayerManager {
|
|
|
43
44
|
/**
|
|
44
45
|
* 异步打开Layer
|
|
45
46
|
*/
|
|
47
|
+
@PerformanceMonitor("openAsync")
|
|
46
48
|
async openAsync<Ctr extends FW.LayerController = FW.LayerController>(
|
|
47
49
|
data: FW.LayerOpenArgs
|
|
48
50
|
): Promise<Ctr> {
|
|
@@ -52,6 +54,7 @@ export class FWLayerManager extends FWManager implements FW.LayerManager {
|
|
|
52
54
|
/**
|
|
53
55
|
* 同步打开
|
|
54
56
|
*/
|
|
57
|
+
@PerformanceMonitor("openSync")
|
|
55
58
|
openSync<Ctr extends FW.LayerController = FW.LayerController>(
|
|
56
59
|
data: FW.LayerOpenArgs
|
|
57
60
|
): Ctr {
|
package/manager/FWResManager.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import FWAssetConfig from "../config/FWAssetConfig";
|
|
2
|
+
import { FWSystemConfig } from "../config/FWSystemConfig";
|
|
3
|
+
import { FWSystemDefine } from "../define/FWSystemDefine";
|
|
4
|
+
import FWLog from "../log/FWLog";
|
|
5
|
+
import { FWLodash } from "../utils/FWLodash";
|
|
1
6
|
import { FWAssetManager } from "./FWAssetManager";
|
|
2
7
|
import { FWBundleManager } from "./FWBundleManager";
|
|
3
8
|
import { FWManager } from "./FWManager";
|
|
@@ -19,7 +24,56 @@ export class FWResManager extends FWManager implements FW.ResManager {
|
|
|
19
24
|
* @returns
|
|
20
25
|
*/
|
|
21
26
|
async loadBundle(bundleName: string): Promise<cc.AssetManager.Bundle> {
|
|
22
|
-
return this.
|
|
27
|
+
return await this.invoke<cc.AssetManager.Bundle>(
|
|
28
|
+
FW.Entry.promiseMgr.execute(async (resolve, reject, signal) => {
|
|
29
|
+
const bundle = await this.bundleMgr.load(bundleName);
|
|
30
|
+
const depends = FWLodash.cloneDeep(FW.Entry.getDepend(bundleName));
|
|
31
|
+
try {
|
|
32
|
+
if (depends && depends.length > 0) {
|
|
33
|
+
for (const depend of depends) {
|
|
34
|
+
if (this.bundleMgr.has(depend)) continue;
|
|
35
|
+
|
|
36
|
+
await this.loadBundle(depend);
|
|
37
|
+
|
|
38
|
+
const config = FW.Entry.getComponent<FWAssetConfig>(
|
|
39
|
+
`${depend}${FWSystemDefine.FWBindTag.CONFIG}`
|
|
40
|
+
);
|
|
41
|
+
if (!config) continue;
|
|
42
|
+
const preLoad = config.preLoad;
|
|
43
|
+
const keys = Object.keys(preLoad);
|
|
44
|
+
|
|
45
|
+
if (keys.length > 0) {
|
|
46
|
+
const find = (o) => {
|
|
47
|
+
Object.keys(o).forEach(async (key) => {
|
|
48
|
+
const value: FW.AssetProperty = o[key];
|
|
49
|
+
const path: string = value.path;
|
|
50
|
+
const type: string = value.type;
|
|
51
|
+
const d: string = value.bundle || depend;
|
|
52
|
+
const priorityLoaded = value.priorityLoaded || false;
|
|
53
|
+
if (path) {
|
|
54
|
+
if (priorityLoaded) {
|
|
55
|
+
await this.assetMgr.load({
|
|
56
|
+
path: path,
|
|
57
|
+
bundle: d,
|
|
58
|
+
type: type,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
find(value);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
find(config.preLoad);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
resolve(bundle);
|
|
71
|
+
} catch (e) {
|
|
72
|
+
reject(e);
|
|
73
|
+
}
|
|
74
|
+
}, FWSystemConfig.PromiseConfig.loadBundle).promise,
|
|
75
|
+
`loadBundleDepend -> ${bundleName}`
|
|
76
|
+
);
|
|
23
77
|
}
|
|
24
78
|
/**
|
|
25
79
|
* 从远程加载spine动画
|