@ives_xxz/framework 1.4.16 → 1.5.1
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 +49 -42
- package/FrameworkBase.ts +63 -0
- package/FrameworkBase.ts.meta +10 -0
- package/config/FWSystemConfig.ts +18 -0
- package/controller/FWLayerController.ts +3 -2
- package/data/FWData.ts +2 -5
- package/define/FWSystemDefine.ts +5 -0
- package/entry/FWEntry.ts +4 -4
- package/logic/FWLogic.ts +4 -7
- package/manager/FWAssetManager.ts +62 -67
- package/manager/FWAudioManager.ts +230 -185
- package/manager/FWBundleManager.ts +5 -6
- package/manager/FWEventManager.ts +91 -2
- package/manager/FWManager.ts +2 -56
- package/manager/FWObjectManager.ts +100 -33
- package/manager/FWPerformanceManager.ts +32 -34
- package/manager/FWPromiseManager.ts +0 -1
- package/manager/FWResManager.ts +5 -5
- package/manager/FWTimeManager.ts +12 -40
- package/package.json +1 -1
- package/service/FWService.ts +5 -52
- package/service/http/FWHttp.ts +7 -7
- package/service/socket/FWSocket.ts +0 -1
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: (
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
1987
|
+
module: string;
|
|
1981
1988
|
operation: string;
|
|
1982
1989
|
duration: number;
|
|
1983
1990
|
timestamp: number;
|
package/FrameworkBase.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { injectable } from 'inversify';
|
|
2
|
+
import { FWEventDefine } from './define/FWEventDefine';
|
|
3
|
+
import FWLog from './log/FWLog';
|
|
4
|
+
@injectable()
|
|
5
|
+
export abstract class FrameworkBase {
|
|
6
|
+
public readonly entry: FW.Entry = FW.Entry;
|
|
7
|
+
|
|
8
|
+
constructor() {
|
|
9
|
+
this.initialize?.();
|
|
10
|
+
|
|
11
|
+
this.entry.evtMgr.register(FWEventDefine.SystemEvent.SYSTEM_RESTART, this.onRestart, this);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public abstract initialize?(): void;
|
|
15
|
+
public abstract onDestroy?(): void;
|
|
16
|
+
|
|
17
|
+
protected get moduleName(): string {
|
|
18
|
+
return this.constructor.name;
|
|
19
|
+
}
|
|
20
|
+
protected onRestart?(): void;
|
|
21
|
+
|
|
22
|
+
protected async invoke<T>(operation: Promise<T>, operationName: string = 'unknown'): Promise<T> {
|
|
23
|
+
const startTime = this.getCurrentTime();
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
const result = await operation;
|
|
27
|
+
const duration = this.getCurrentTime() - startTime;
|
|
28
|
+
this.recordPerformanceMetric(operationName, duration);
|
|
29
|
+
return result;
|
|
30
|
+
} catch (error) {
|
|
31
|
+
this.handleError(operationName, error);
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
private recordPerformanceMetric(operationName: string, duration: number): void {
|
|
37
|
+
if (FW.Entry.performanceMgr) {
|
|
38
|
+
FW.Entry.performanceMgr.recordOperationMetric(this.moduleName, operationName, duration);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const shouldWarn = duration > 1000;
|
|
42
|
+
|
|
43
|
+
if (FW.Entry.engineMgr.debug || shouldWarn) {
|
|
44
|
+
const log = shouldWarn ? FWLog.warn : FWLog.debug;
|
|
45
|
+
log(`[${this.moduleName?.toUpperCase()}] Operation ${operationName} took ${duration}ms`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
protected handleError(operation: string, error: any): void {
|
|
50
|
+
const errorInfo = {
|
|
51
|
+
type: this.moduleName,
|
|
52
|
+
operation,
|
|
53
|
+
error: error?.message || error,
|
|
54
|
+
stack: error?.stack,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
FWLog.error(`Error in ${this.moduleName}.${operation}:`, errorInfo);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
protected getCurrentTime(): number {
|
|
61
|
+
return Date.now();
|
|
62
|
+
}
|
|
63
|
+
}
|
package/config/FWSystemConfig.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
}
|
package/define/FWSystemDefine.ts
CHANGED
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
|
-
|
|
5
|
-
|
|
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
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
(finish
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
(err
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
}
|