@ives_xxz/framework 1.4.16 → 1.5.0

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/FW.d.ts CHANGED
@@ -181,6 +181,10 @@ declare namespace FW {
181
181
 
182
182
  /** 销毁一个对象池 */
183
183
  destroyObjectPool(tag: string): void;
184
+ /** 获取对象池状态 */
185
+ getPoolStats(): { total: number; tags: string[] };
186
+ /** 清理所有对象池 */
187
+ clearAllPools(): void;
184
188
  };
185
189
 
186
190
  type ObjectPool = {
@@ -318,6 +322,7 @@ declare namespace FW {
318
322
  type Observer = {
319
323
  priority: number;
320
324
  intercept: boolean;
325
+ once: boolean;
321
326
  /**
322
327
  * 事件通知
323
328
  */
@@ -453,13 +458,52 @@ declare namespace FW {
453
458
  */
454
459
  register(
455
460
  eventName: string | number,
456
- cb: (any) => void,
461
+ cb: (
462
+ args1?: EventManagerArgs,
463
+ args2?: EventManagerArgs,
464
+ args3?: EventManagerArgs,
465
+ args4?: EventManagerArgs,
466
+ args5?: EventManagerArgs,
467
+ args6?: EventManagerArgs,
468
+ args7?: EventManagerArgs,
469
+ args8?: EventManagerArgs,
470
+ args9?: EventManagerArgs,
471
+ args10?: EventManagerArgs,
472
+ ) => void,
457
473
  target: TargetType,
458
474
  options?: {
459
475
  priority?: FWSystemDefine.FWPriorityOrder;
460
476
  intercept?: boolean;
461
477
  },
462
478
  );
479
+
480
+ registerOnce(
481
+ eventName: string | number,
482
+ cb: (
483
+ args1?: EventManagerArgs,
484
+ args2?: EventManagerArgs,
485
+ args3?: EventManagerArgs,
486
+ args4?: EventManagerArgs,
487
+ args5?: EventManagerArgs,
488
+ args6?: EventManagerArgs,
489
+ args7?: EventManagerArgs,
490
+ args8?: EventManagerArgs,
491
+ args9?: EventManagerArgs,
492
+ args10?: EventManagerArgs,
493
+ ) => void,
494
+ target: TargetType,
495
+ options?: {
496
+ priority?: number;
497
+ intercept?: boolean;
498
+ },
499
+ ): void;
500
+
501
+ /**
502
+ * 获取事件监听器数量
503
+ * @param eventName 事件名
504
+ * @returns 监听器数量
505
+ */
506
+ getListenerCount(eventName: string | number): number;
463
507
  /**
464
508
  * 派发事件
465
509
  * @param eventName
@@ -1579,48 +1623,11 @@ declare namespace FW {
1579
1623
  * @param mute
1580
1624
  */
1581
1625
  setSoundMute(mute: boolean): void;
1582
- /**
1583
- * 播放音效
1584
- * @param path
1585
- * @param loop
1586
- */
1587
- playEffect(path: string, loop?: boolean): Promise<number>;
1588
- /**
1589
- * 播放音效
1590
- * @param audio
1591
- * @param loop
1592
- */
1593
- playEffect(audio: cc.AudioClip, loop?: boolean): Promise<number>;
1594
- /**
1595
- * 播放音效
1596
- * @param assetProperty
1597
- * @param loop
1598
- */
1599
- playEffect(assetProperty: FW.AssetProperty, loop?: boolean): Promise<number>;
1600
- /**
1601
- * 停止音效
1602
- * @param audioID
1603
- */
1604
- stopEffect(audioID: number): void;
1605
- /**
1606
- * 设置音效音量
1607
- * @param volume
1608
- */
1609
- setEffectsVolume(volume: number): void;
1610
- /**
1611
- * 停止全部音效
1612
- */
1613
- stopAllEffects(): void;
1614
- /**
1615
- * 设置音效是否静音
1616
- * @param mute
1617
- */
1618
- setEffectsMute(mute: boolean): void;
1619
1626
  };
1620
1627
 
1621
1628
  type PerformanceManager = {
1622
1629
  recordOperationMetric(manager: string, operation: string, duration: number): void;
1623
- getManagerReport(manager: string): PerformanceReport;
1630
+ getModuleReport(manager: string): PerformanceReport;
1624
1631
  getAllReports(): Map<string, FW.PerformanceReport>;
1625
1632
  };
1626
1633
 
@@ -1950,7 +1957,7 @@ declare namespace FW {
1950
1957
  /**
1951
1958
  * 性能管理器配置
1952
1959
  */
1953
- type PerformanceManagerOptions = {
1960
+ type PerformanceModuleOptions = {
1954
1961
  /** 是否自动收集性能数据 */
1955
1962
  autoCollect?: boolean;
1956
1963
  /** 性能数据保留时间(毫秒) */
@@ -1965,7 +1972,7 @@ declare namespace FW {
1965
1972
  * 性能统计报告
1966
1973
  */
1967
1974
  type PerformanceReport = {
1968
- manager: string;
1975
+ module: string;
1969
1976
  totalOperations: number;
1970
1977
  averageDuration: number;
1971
1978
  minDuration: number;
@@ -1977,7 +1984,7 @@ declare namespace FW {
1977
1984
  * 性能指标数据
1978
1985
  */
1979
1986
  type PerformanceMetric = {
1980
- manager: string;
1987
+ module: string;
1981
1988
  operation: string;
1982
1989
  duration: number;
1983
1990
  timestamp: number;
@@ -0,0 +1,62 @@
1
+ import { FWEventDefine } from './define/FWEventDefine';
2
+ import FWLog from './log/FWLog';
3
+
4
+ export abstract class FrameworkBase {
5
+ public readonly entry: FW.Entry = FW.Entry;
6
+
7
+ constructor() {
8
+ this.initialize();
9
+
10
+ this.entry.evtMgr.register(FWEventDefine.SystemEvent.SYSTEM_RESTART, this.onRestart, this);
11
+ }
12
+
13
+ public abstract initialize?(): void;
14
+ public abstract onDestroy?(): void;
15
+
16
+ protected get moduleName(): string {
17
+ return this.constructor.name;
18
+ }
19
+ protected onRestart?(): void;
20
+
21
+ protected async invoke<T>(operation: Promise<T>, operationName: string = 'unknown'): Promise<T> {
22
+ const startTime = this.getCurrentTime();
23
+
24
+ try {
25
+ const result = await operation;
26
+ const duration = this.getCurrentTime() - startTime;
27
+ this.recordPerformanceMetric(operationName, duration);
28
+ return result;
29
+ } catch (error) {
30
+ this.handleError(operationName, error);
31
+ return undefined;
32
+ }
33
+ }
34
+
35
+ private recordPerformanceMetric(operationName: string, duration: number): void {
36
+ if (FW.Entry.performanceMgr) {
37
+ FW.Entry.performanceMgr.recordOperationMetric(this.moduleName, operationName, duration);
38
+ }
39
+
40
+ const shouldWarn = duration > 1000;
41
+
42
+ if (FW.Entry.engineMgr.debug || shouldWarn) {
43
+ const log = shouldWarn ? FWLog.warn : FWLog.debug;
44
+ log(`[${this.moduleName?.toUpperCase()}] Operation ${operationName} took ${duration}ms`);
45
+ }
46
+ }
47
+
48
+ protected handleError(operation: string, error: any): void {
49
+ const errorInfo = {
50
+ type: this.moduleName,
51
+ operation,
52
+ error: error?.message || error,
53
+ stack: error?.stack,
54
+ };
55
+
56
+ FWLog.error(`Error in ${this.moduleName}.${operation}:`, errorInfo);
57
+ }
58
+
59
+ protected getCurrentTime(): number {
60
+ return Date.now();
61
+ }
62
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "ver": "1.1.0",
3
+ "uuid": "abc42759-95e6-4156-a144-7ef424305eb6",
4
+ "importer": "typescript",
5
+ "isPlugin": false,
6
+ "loadPluginInWeb": true,
7
+ "loadPluginInNative": true,
8
+ "loadPluginInEditor": false,
9
+ "subMetas": {}
10
+ }
@@ -8,4 +8,22 @@ export namespace FWSystemConfig {
8
8
  protocolSymbol: null,
9
9
  protocolPollingTime: 10,
10
10
  };
11
+
12
+ export const PromiseConfig = {
13
+ loadAsset: {
14
+ retryCount: 3,
15
+ retryInterval: 5,
16
+ timeout: 10,
17
+ },
18
+ loadBundle: {
19
+ retryCount: 3,
20
+ retryInterval: 5,
21
+ timeout: 10,
22
+ },
23
+ http: {
24
+ retryCount: 3,
25
+ retryInterval: 5,
26
+ timeout: 10,
27
+ },
28
+ };
11
29
  }
@@ -2,7 +2,8 @@ import { FWSystemDefine } from '../define/FWSystemDefine';
2
2
  import FWLayer from '../layer/FWLayer';
3
3
  import { FWLayerData } from '../manager/FWLayerManager';
4
4
  import FWLog from '../log/FWLog';
5
- export abstract class FWLayerController implements FW.LayerController {
5
+ import { FrameworkBase } from '../FrameworkBase';
6
+ export abstract class FWLayerController extends FrameworkBase implements FW.LayerController {
6
7
  readonly entry: FW.Entry = FW.Entry;
7
8
  /** layer数据 */
8
9
  layerData: FWLayerData;
@@ -33,8 +34,8 @@ export abstract class FWLayerController implements FW.LayerController {
33
34
  onEnable?();
34
35
  onDisable?();
35
36
  onDestroy?();
36
- async onClose?();
37
37
  initialize() {}
38
+ async onClose?();
38
39
 
39
40
  async destroy() {
40
41
  FW.Entry.timeMgr?.unSchedule(this);
package/data/FWData.ts CHANGED
@@ -1,10 +1,7 @@
1
1
  import { injectable } from 'inversify';
2
+ import { FrameworkBase } from '../FrameworkBase';
2
3
  @injectable()
3
- export default class FWData implements FW.Data {
4
- constructor() {
5
- this.initialize?.();
6
- }
7
- public readonly entry: FW.Entry = FW.Entry;
4
+ export default class FWData extends FrameworkBase implements FW.Data {
8
5
  public initialize?(): void;
9
6
  public onDestroy?(): void;
10
7
  }
@@ -144,4 +144,9 @@ export namespace FWSystemDefine {
144
144
  OPENED = 'opened',
145
145
  CLOSING = 'closing',
146
146
  }
147
+
148
+ export enum FWAudioType {
149
+ MUSIC,
150
+ SOUND,
151
+ }
147
152
  }
package/entry/FWEntry.ts CHANGED
@@ -156,6 +156,10 @@ export default class FWEntry implements FW.Entry {
156
156
  cc.director.loadScene(this.getSceneName());
157
157
  }
158
158
 
159
+ restart() {
160
+ this.engineMgr?.restart();
161
+ }
162
+
159
163
  releaseBundle(bundleName: string) {
160
164
  this.resMgr.releaseBundle(bundleName);
161
165
  const depend = this.getDepend(bundleName);
@@ -208,10 +212,6 @@ export default class FWEntry implements FW.Entry {
208
212
  getComponents: <T>(serviceIdentifier?: FW.ServiceIdentifier<T>) => T[] = (serviceIdentifier) =>
209
213
  Framework.getComponents(serviceIdentifier);
210
214
 
211
- restart() {
212
- this.engineMgr?.restart();
213
- }
214
-
215
215
  update(dt: number) {
216
216
  this.timeMgr?.onUpdate(dt);
217
217
  }
package/logic/FWLogic.ts CHANGED
@@ -1,10 +1,7 @@
1
1
  import { injectable } from 'inversify';
2
+ import { FrameworkBase } from '../FrameworkBase';
2
3
  @injectable()
3
- export default class FWLogic implements FW.Logic {
4
- constructor() {
5
- this.initialize?.();
6
- }
7
- public readonly entry: FW.Entry = FW.Entry;
8
- public initialize?();
9
- public onDestroy?();
4
+ export default class FWLogic extends FrameworkBase implements FW.Logic {
5
+ initialize?();
6
+ onDestroy?();
10
7
  }
@@ -1,3 +1,4 @@
1
+ import { FWSystemConfig } from '../config/FWSystemConfig';
1
2
  import FWLog from '../log/FWLog';
2
3
  import { FWManager } from './FWManager';
3
4
 
@@ -41,19 +42,20 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
41
42
  bin?: boolean;
42
43
  }): Promise<sp.SkeletonData> {
43
44
  try {
44
- return new Promise((resolve) => {
45
- const bin = data.bin === undefined ? false : data.bin;
46
- const img = data.img;
47
- const ske = data.ske;
48
- const atlas = data.atlas;
49
- const type = bin ? '.bin' : '.txt';
50
- cc.assetManager.loadAny(
51
- [
52
- { url: atlas, ext: type },
53
- { url: ske, ext: type },
54
- ],
55
- (error, assets) => {
56
- cc.assetManager.loadRemote(img, (error, texture: cc.Texture2D) => {
45
+ return await this.invoke(
46
+ FW.Entry.promiseMgr.execute((resolve, reject, signal) => {
47
+ const bin = data.bin === undefined ? false : data.bin;
48
+ const img = data.img;
49
+ const ske = data.ske;
50
+ const atlas = data.atlas;
51
+ const type = bin ? '.bin' : '.txt';
52
+ cc.assetManager.loadAny(
53
+ [
54
+ { url: atlas, ext: type },
55
+ { url: ske, ext: type },
56
+ ],
57
+ async (error, assets) => {
58
+ const texture: cc.Texture2D = await this.loadRemote();
57
59
  var asset = new sp.SkeletonData();
58
60
  asset.skeletonJson = assets[1];
59
61
  asset.atlasText = assets[0];
@@ -61,29 +63,32 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
61
63
  asset['textureNames'] = [`${img}.png`];
62
64
  asset['_uuid'] = ske;
63
65
  resolve(asset);
64
- });
65
- },
66
- );
67
- });
66
+ },
67
+ );
68
+ }, FWSystemConfig.PromiseConfig.loadAsset).promise,
69
+ );
68
70
  } catch (e) {
69
71
  FWLog.error('从远程加载spine动画资源失败!');
70
72
  }
71
73
  }
72
74
 
73
75
  /** 加载远程资源 */
74
- loadRemote<T extends cc.Asset = cc.Asset>(
76
+ async loadRemote<T extends cc.Asset = cc.Asset>(
75
77
  url?: string,
76
78
  cb?: (asset: cc.Asset) => void,
77
79
  ): Promise<T> {
78
- return new Promise((resolve, reject) => {
79
- cc.assetManager.loadRemote(url, { cacheEnabled: true, maxRetryCount: 0 }, (err, asset) => {
80
- if (err || !asset) {
81
- reject(err);
82
- }
83
- cb?.(asset as T);
84
- resolve(asset as T);
85
- });
86
- });
80
+ return await this.invoke(
81
+ FW.Entry.promiseMgr.execute((resolve, reject, signal) => {
82
+ cc.assetManager.loadRemote(url, { cacheEnabled: true, maxRetryCount: 3 }, (err, asset) => {
83
+ if (err || !asset) {
84
+ reject(err);
85
+ }
86
+ cb?.(asset as T);
87
+ resolve(asset as T);
88
+ });
89
+ }, FWSystemConfig.PromiseConfig.loadAsset).promise,
90
+ `loadAssets -> ${url}`,
91
+ );
87
92
  }
88
93
 
89
94
  /**
@@ -132,43 +137,36 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
132
137
  assetData.loaded = false;
133
138
 
134
139
  return await this.invoke(
135
- FW.Entry.promiseMgr.execute(
136
- (resolve, reject, signal) => {
137
- const self = this;
138
-
139
- bundle.load(
140
- path,
141
- type,
142
- (finish: number, total: number, item: cc.AssetManager.RequestItem) => {
143
- progress?.(finish, total, item);
144
- },
145
- (err: Error, asset: cc.Asset) => {
146
- if (err || !asset) {
147
- reject(err);
148
- return;
149
- }
150
- assetData.loaded = true;
151
- assetData.dependentBundle = bundleName;
152
- assetData.uuid = asset['_uuid'];
153
- assetData.autoRelease = autoRelease;
154
- assetData.asset = asset;
155
- assetData.user = assetProperty.user;
156
- assetData.refCount = 1;
157
- assetData.assetProperty = assetProperty;
158
-
159
- self.assetsMap.set(key, assetData);
160
-
161
- cb?.(assetData);
162
- resolve(assetData);
163
- },
164
- );
165
- },
166
- {
167
- retryCount: 3,
168
- retryInterval: 1,
169
- timeout: 10,
170
- },
171
- ).promise,
140
+ FW.Entry.promiseMgr.execute((resolve, reject, signal) => {
141
+ const self = this;
142
+
143
+ bundle.load(
144
+ path,
145
+ type,
146
+ (finish: number, total: number, item: cc.AssetManager.RequestItem) => {
147
+ progress?.(finish, total, item);
148
+ },
149
+ (err: Error, asset: cc.Asset) => {
150
+ if (err || !asset) {
151
+ reject(err);
152
+ return;
153
+ }
154
+ assetData.loaded = true;
155
+ assetData.dependentBundle = bundleName;
156
+ assetData.uuid = asset['_uuid'];
157
+ assetData.autoRelease = autoRelease;
158
+ assetData.asset = asset;
159
+ assetData.user = assetProperty.user;
160
+ assetData.refCount = 1;
161
+ assetData.assetProperty = assetProperty;
162
+
163
+ self.assetsMap.set(key, assetData);
164
+
165
+ cb?.(assetData);
166
+ resolve(assetData);
167
+ },
168
+ );
169
+ }, FWSystemConfig.PromiseConfig.loadAsset).promise,
172
170
  `loadAssets -> ${assetProperty.path}`,
173
171
  );
174
172
  }
@@ -322,9 +320,6 @@ export class FWAssetManager extends FWManager implements FW.AssetManager {
322
320
  * @returns
323
321
  */
324
322
  public getReferenceCount(assetProperty: FW.AssetProperty): number {
325
- const bundleName = assetProperty.bundle || FW.Entry.bundleName;
326
- const path = assetProperty.path;
327
- const type = assetProperty.type;
328
323
  const key = this.createAssetMapKey(assetProperty);
329
324
  return this.assetsMap.get(key)?.refCount || 0;
330
325
  }