@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/manager/FWManager.ts
CHANGED
|
@@ -1,65 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import FWLog from '../log/FWLog';
|
|
3
|
-
|
|
4
|
-
export abstract class FWManager implements FW.Manager {
|
|
5
|
-
public readonly entry: FW.Entry = FW.Entry;
|
|
6
|
-
public readonly managerName: string = this.constructor.name;
|
|
1
|
+
import { FrameworkBase } from '../FrameworkBase';
|
|
7
2
|
|
|
3
|
+
export abstract class FWManager extends FrameworkBase implements FW.Manager {
|
|
8
4
|
public abstract initialize(): void;
|
|
9
5
|
public abstract onDestroy(): void;
|
|
10
6
|
|
|
11
|
-
constructor() {
|
|
12
|
-
this.initialize();
|
|
13
|
-
this.entry.evtMgr.register(FWEventDefine.SystemEvent.SYSTEM_RESTART, this.onRestart, this);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
7
|
protected onRestart() {
|
|
17
8
|
this.onDestroy();
|
|
18
9
|
this.initialize();
|
|
19
10
|
}
|
|
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
|
-
|
|
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.managerName, operationName, duration);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (duration > 1000) {
|
|
42
|
-
FWLog.warn(`Operation ${operationName} took ${duration}ms`);
|
|
43
|
-
} else if (FW.Entry.engineMgr.debug) {
|
|
44
|
-
FWLog.debug(`Operation ${operationName} took ${duration}ms`);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
protected handleError(operation: string, error: any): void {
|
|
49
|
-
const errorInfo = {
|
|
50
|
-
manager: this.managerName,
|
|
51
|
-
operation,
|
|
52
|
-
error: error?.message || error,
|
|
53
|
-
stack: error?.stack,
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
FWLog.error(`Manager error in ${this.managerName}.${operation}:`, errorInfo);
|
|
57
|
-
|
|
58
|
-
if (CC_DEBUG && FW.Entry.engineMgr.debug) {
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
protected getCurrentTime(): number {
|
|
63
|
-
return Date.now();
|
|
64
|
-
}
|
|
65
11
|
}
|
|
@@ -1,17 +1,29 @@
|
|
|
1
1
|
import { FWSystemDefine } from '../define/FWSystemDefine';
|
|
2
|
-
import Framework from '../Framework';
|
|
3
2
|
import FWObject from '../utils/FWObject';
|
|
4
3
|
import { FWObjectPool } from '../utils/FWObjectPool';
|
|
5
4
|
import { FWManager } from './FWManager';
|
|
5
|
+
import FWLog from '../log/FWLog';
|
|
6
6
|
|
|
7
7
|
export default class FWObjectManager extends FWManager implements FW.ObjectManager {
|
|
8
8
|
public initialize(): void {
|
|
9
9
|
this.poolMap = new Map<string, FWObjectPool>();
|
|
10
|
+
this.poolIdCounter = 0;
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
+
|
|
13
|
+
public onDestroy(): void {
|
|
14
|
+
this.poolMap.forEach((pool, tag) => {
|
|
15
|
+
try {
|
|
16
|
+
pool.onDestroy();
|
|
17
|
+
} catch (error) {
|
|
18
|
+
FWLog.error(`销毁对象池失败: ${tag}`, error);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
this.poolMap.clear();
|
|
22
|
+
}
|
|
23
|
+
|
|
12
24
|
private poolMap: Map<string, FWObjectPool>;
|
|
25
|
+
private poolIdCounter: number = 0;
|
|
13
26
|
|
|
14
|
-
/** 创建一个对象池 */
|
|
15
27
|
async createObjectPool<T extends FWObject = FWObject>(
|
|
16
28
|
node: cc.Node,
|
|
17
29
|
parent: cc.Node,
|
|
@@ -43,49 +55,104 @@ export default class FWObjectManager extends FWManager implements FW.ObjectManag
|
|
|
43
55
|
type?: number,
|
|
44
56
|
): Promise<FWObjectPool>;
|
|
45
57
|
async createObjectPool<T extends FWObject = FWObject>(): Promise<FWObjectPool> {
|
|
58
|
+
if (arguments.length < 2 || arguments.length > 3) {
|
|
59
|
+
FWLog.error('createObjectPool 参数数量错误,需要2-3个参数');
|
|
60
|
+
throw new Error('Invalid arguments count');
|
|
61
|
+
}
|
|
62
|
+
|
|
46
63
|
let objectNode: cc.Node = null;
|
|
47
64
|
let objectPrefab: cc.Prefab = null;
|
|
48
65
|
let objectAssetProperty: FW.AssetProperty = null;
|
|
49
66
|
let objectParent: cc.Node;
|
|
50
67
|
let objectTag: string;
|
|
51
68
|
let objectType: FWSystemDefine.FWObjectType;
|
|
52
|
-
if (arguments.length > 3) return;
|
|
53
|
-
if (arguments[0] instanceof cc.Node) {
|
|
54
|
-
objectNode = arguments[0];
|
|
55
|
-
} else if (arguments[0] instanceof cc.Prefab) {
|
|
56
|
-
objectPrefab = arguments[0];
|
|
57
|
-
objectNode = cc.instantiate(objectPrefab);
|
|
58
|
-
} else {
|
|
59
|
-
objectAssetProperty = arguments[0];
|
|
60
|
-
objectPrefab = await FW.Entry.resMgr.loadAsset<cc.Prefab>(objectAssetProperty);
|
|
61
|
-
objectNode = cc.instantiate(objectPrefab);
|
|
62
|
-
}
|
|
63
|
-
objectParent = arguments[1];
|
|
64
|
-
if (arguments[2] && typeof arguments[2] === 'string') {
|
|
65
|
-
objectTag = arguments[2];
|
|
66
|
-
objectType = FWSystemDefine.FWObjectType.OPACITY;
|
|
67
|
-
} else {
|
|
68
|
-
objectTag = this.poolMap.size?.toString() || '';
|
|
69
|
-
objectType = arguments[2];
|
|
70
|
-
}
|
|
71
69
|
|
|
72
|
-
|
|
70
|
+
try {
|
|
71
|
+
const resources = arguments[0];
|
|
72
|
+
if (resources instanceof cc.Node) {
|
|
73
|
+
objectNode = resources;
|
|
74
|
+
} else if (resources instanceof cc.Prefab) {
|
|
75
|
+
objectPrefab = resources;
|
|
76
|
+
objectNode = cc.instantiate(objectPrefab);
|
|
77
|
+
} else {
|
|
78
|
+
objectAssetProperty = resources;
|
|
79
|
+
objectPrefab = await FW.Entry.resMgr.loadAsset<cc.Prefab>(objectAssetProperty);
|
|
80
|
+
if (!objectPrefab) {
|
|
81
|
+
throw new Error(`加载预制体失败: ${objectAssetProperty.path}`);
|
|
82
|
+
}
|
|
83
|
+
objectNode = cc.instantiate(objectPrefab);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
objectParent = arguments[1];
|
|
87
|
+
if (!(objectParent instanceof cc.Node)) {
|
|
88
|
+
throw new Error('第二个参数必须是 cc.Node 类型');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const arg = arguments[2];
|
|
92
|
+
if (typeof arg === 'string') {
|
|
93
|
+
objectTag = arg;
|
|
94
|
+
objectType = FWSystemDefine.FWObjectType.OPACITY;
|
|
95
|
+
} else if (typeof arg === 'number') {
|
|
96
|
+
objectTag = `pool_${this.poolIdCounter++}`;
|
|
97
|
+
objectType = arg;
|
|
98
|
+
} else {
|
|
99
|
+
objectTag = `pool_${this.poolIdCounter++}`;
|
|
100
|
+
objectType = FWSystemDefine.FWObjectType.OPACITY;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (this.poolMap.has(objectTag)) {
|
|
104
|
+
this.destroyObjectPool(objectTag);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const pool = new FWObjectPool<T>(objectNode, objectParent, objectType);
|
|
108
|
+
this.poolMap.set(objectTag, pool);
|
|
73
109
|
|
|
74
|
-
|
|
110
|
+
return pool;
|
|
111
|
+
} catch (error) {
|
|
112
|
+
FWLog.error('创建对象池失败:', error);
|
|
75
113
|
|
|
76
|
-
|
|
114
|
+
if (objectNode && objectNode.isValid) {
|
|
115
|
+
objectNode.destroy();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
77
120
|
}
|
|
78
121
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
122
|
+
getObjectPool(tag: string): FWObjectPool | undefined {
|
|
123
|
+
if (!this.poolMap.has(tag)) {
|
|
124
|
+
FWLog.warn(`对象池不存在: ${tag}`);
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
82
127
|
return this.poolMap.get(tag);
|
|
83
128
|
}
|
|
84
129
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
130
|
+
destroyObjectPool(tag: string): boolean {
|
|
131
|
+
if (!this.poolMap.has(tag)) {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
try {
|
|
136
|
+
const pool = this.poolMap.get(tag);
|
|
137
|
+
pool.onDestroy();
|
|
138
|
+
this.poolMap.delete(tag);
|
|
139
|
+
return true;
|
|
140
|
+
} catch (error) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
getPoolStats(): { total: number; tags: string[] } {
|
|
146
|
+
return {
|
|
147
|
+
total: this.poolMap.size,
|
|
148
|
+
tags: Array.from(this.poolMap.keys()),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
clearAllPools(): void {
|
|
153
|
+
const tags = Array.from(this.poolMap.keys());
|
|
154
|
+
tags.forEach((tag) => {
|
|
155
|
+
this.destroyObjectPool(tag);
|
|
156
|
+
});
|
|
90
157
|
}
|
|
91
158
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// FWPerformanceManager.ts
|
|
2
|
-
|
|
3
1
|
import FWLog from '../log/FWLog';
|
|
4
2
|
import { FWManager } from './FWManager';
|
|
5
3
|
|
|
@@ -8,7 +6,7 @@ import { FWManager } from './FWManager';
|
|
|
8
6
|
*/
|
|
9
7
|
export class FWPerformanceManager extends FWManager implements FW.PerformanceManager {
|
|
10
8
|
private metrics: FW.PerformanceMetric[] = [];
|
|
11
|
-
private
|
|
9
|
+
private moduleStats: Map<
|
|
12
10
|
string,
|
|
13
11
|
{
|
|
14
12
|
totalDuration: number;
|
|
@@ -18,7 +16,7 @@ export class FWPerformanceManager extends FWManager implements FW.PerformanceMan
|
|
|
18
16
|
}
|
|
19
17
|
> = new Map();
|
|
20
18
|
|
|
21
|
-
private performanceOptions: FW.
|
|
19
|
+
private performanceOptions: FW.PerformanceModuleOptions;
|
|
22
20
|
|
|
23
21
|
public async initialize(): Promise<void> {
|
|
24
22
|
this.performanceOptions = {
|
|
@@ -28,13 +26,13 @@ export class FWPerformanceManager extends FWManager implements FW.PerformanceMan
|
|
|
28
26
|
warningThreshold: 1000,
|
|
29
27
|
};
|
|
30
28
|
if (this.performanceOptions.autoCollect) {
|
|
31
|
-
this.
|
|
29
|
+
this.autoClear();
|
|
32
30
|
}
|
|
33
31
|
}
|
|
34
32
|
|
|
35
33
|
public onDestroy(): void {
|
|
36
34
|
this.metrics = [];
|
|
37
|
-
this.
|
|
35
|
+
this.moduleStats.clear();
|
|
38
36
|
}
|
|
39
37
|
|
|
40
38
|
protected onCleanup(): void {}
|
|
@@ -42,38 +40,38 @@ export class FWPerformanceManager extends FWManager implements FW.PerformanceMan
|
|
|
42
40
|
/**
|
|
43
41
|
* 记录操作性能指标
|
|
44
42
|
*/
|
|
45
|
-
public recordOperationMetric(
|
|
43
|
+
public recordOperationMetric(module: string, operation: string, duration: number): void {
|
|
46
44
|
if (Math.random() > this.performanceOptions.samplingRate!) {
|
|
47
45
|
return;
|
|
48
46
|
}
|
|
49
47
|
const metric: FW.PerformanceMetric = {
|
|
50
|
-
|
|
48
|
+
module,
|
|
51
49
|
operation,
|
|
52
50
|
duration,
|
|
53
51
|
timestamp: Date.now(),
|
|
54
52
|
};
|
|
55
53
|
|
|
56
54
|
this.metrics.push(metric);
|
|
57
|
-
this.
|
|
55
|
+
this.updateModuleStats(module, duration);
|
|
58
56
|
|
|
59
57
|
if (duration > this.performanceOptions.warningThreshold!) {
|
|
60
|
-
FWLog.warn(`Performance warning: ${
|
|
58
|
+
FWLog.warn(`Performance warning: ${module}.${operation} took ${duration}ms`);
|
|
61
59
|
}
|
|
62
60
|
}
|
|
63
61
|
|
|
64
62
|
/**
|
|
65
|
-
*
|
|
63
|
+
* 获取指定模块的性能报告
|
|
66
64
|
*/
|
|
67
|
-
public
|
|
68
|
-
const stats = this.
|
|
65
|
+
public getModuleReport(module: string): FW.PerformanceReport | null {
|
|
66
|
+
const stats = this.moduleStats.get(module);
|
|
69
67
|
if (!stats) {
|
|
70
68
|
return null;
|
|
71
69
|
}
|
|
72
70
|
|
|
73
|
-
const recentMetrics = this.metrics.filter((m) => m.
|
|
71
|
+
const recentMetrics = this.metrics.filter((m) => m.module === module).slice(-500);
|
|
74
72
|
|
|
75
73
|
return {
|
|
76
|
-
|
|
74
|
+
module,
|
|
77
75
|
totalOperations: stats.operationCount,
|
|
78
76
|
averageDuration: stats.totalDuration / stats.operationCount,
|
|
79
77
|
minDuration: stats.minDuration,
|
|
@@ -88,10 +86,10 @@ export class FWPerformanceManager extends FWManager implements FW.PerformanceMan
|
|
|
88
86
|
public getAllReports(): Map<string, FW.PerformanceReport> {
|
|
89
87
|
const reports = new Map<string, FW.PerformanceReport>();
|
|
90
88
|
|
|
91
|
-
this.
|
|
92
|
-
const recentMetrics = this.metrics.filter((m) => m.
|
|
93
|
-
reports.set(
|
|
94
|
-
|
|
89
|
+
this.moduleStats.forEach((stats, module) => {
|
|
90
|
+
const recentMetrics = this.metrics.filter((m) => m.module === module).slice(-500);
|
|
91
|
+
reports.set(module, {
|
|
92
|
+
module,
|
|
95
93
|
totalOperations: stats.operationCount,
|
|
96
94
|
averageDuration: stats.totalDuration / stats.operationCount,
|
|
97
95
|
minDuration: stats.minDuration,
|
|
@@ -109,37 +107,37 @@ export class FWPerformanceManager extends FWManager implements FW.PerformanceMan
|
|
|
109
107
|
public getPerformanceSummary(): {
|
|
110
108
|
totalOperations: number;
|
|
111
109
|
averageOperationTime: number;
|
|
112
|
-
|
|
113
|
-
|
|
110
|
+
slowestModule: string;
|
|
111
|
+
mostActiveModule: string;
|
|
114
112
|
} {
|
|
115
113
|
let totalOperations = 0;
|
|
116
114
|
let totalDuration = 0;
|
|
117
|
-
let
|
|
115
|
+
let slowestModule = '';
|
|
118
116
|
let maxAvgDuration = 0;
|
|
119
|
-
let
|
|
117
|
+
let mostActiveModule = '';
|
|
120
118
|
let maxOperations = 0;
|
|
121
119
|
|
|
122
|
-
this.
|
|
120
|
+
this.moduleStats.forEach((stats, module) => {
|
|
123
121
|
totalOperations += stats.operationCount;
|
|
124
122
|
totalDuration += stats.totalDuration;
|
|
125
123
|
|
|
126
124
|
const avgDuration = stats.totalDuration / stats.operationCount;
|
|
127
125
|
if (avgDuration > maxAvgDuration) {
|
|
128
126
|
maxAvgDuration = avgDuration;
|
|
129
|
-
|
|
127
|
+
slowestModule = module;
|
|
130
128
|
}
|
|
131
129
|
|
|
132
130
|
if (stats.operationCount > maxOperations) {
|
|
133
131
|
maxOperations = stats.operationCount;
|
|
134
|
-
|
|
132
|
+
mostActiveModule = module;
|
|
135
133
|
}
|
|
136
134
|
});
|
|
137
135
|
|
|
138
136
|
return {
|
|
139
137
|
totalOperations,
|
|
140
138
|
averageOperationTime: totalOperations > 0 ? totalDuration / totalOperations : 0,
|
|
141
|
-
|
|
142
|
-
|
|
139
|
+
slowestModule: slowestModule,
|
|
140
|
+
mostActiveModule: mostActiveModule,
|
|
143
141
|
};
|
|
144
142
|
}
|
|
145
143
|
|
|
@@ -167,15 +165,15 @@ export class FWPerformanceManager extends FWManager implements FW.PerformanceMan
|
|
|
167
165
|
*/
|
|
168
166
|
public resetAllData(): void {
|
|
169
167
|
this.metrics = [];
|
|
170
|
-
this.
|
|
168
|
+
this.moduleStats.clear();
|
|
171
169
|
}
|
|
172
170
|
|
|
173
171
|
/**
|
|
174
172
|
* 更新管理器统计信息
|
|
175
173
|
*/
|
|
176
|
-
private
|
|
177
|
-
if (!this.
|
|
178
|
-
this.
|
|
174
|
+
private updateModuleStats(module: string, duration: number): void {
|
|
175
|
+
if (!this.moduleStats.has(module)) {
|
|
176
|
+
this.moduleStats.set(module, {
|
|
179
177
|
totalDuration: 0,
|
|
180
178
|
operationCount: 0,
|
|
181
179
|
minDuration: Infinity,
|
|
@@ -183,7 +181,7 @@ export class FWPerformanceManager extends FWManager implements FW.PerformanceMan
|
|
|
183
181
|
});
|
|
184
182
|
}
|
|
185
183
|
|
|
186
|
-
const stats = this.
|
|
184
|
+
const stats = this.moduleStats.get(module)!;
|
|
187
185
|
stats.totalDuration += duration;
|
|
188
186
|
stats.operationCount++;
|
|
189
187
|
stats.minDuration = Math.min(stats.minDuration, duration);
|
|
@@ -193,7 +191,7 @@ export class FWPerformanceManager extends FWManager implements FW.PerformanceMan
|
|
|
193
191
|
/**
|
|
194
192
|
* 启动自动清理任务
|
|
195
193
|
*/
|
|
196
|
-
private
|
|
194
|
+
private autoClear(): void {
|
|
197
195
|
FW.Entry.timeMgr.schedule(() => {
|
|
198
196
|
this.clearPerformanceData();
|
|
199
197
|
}, 300);
|
package/manager/FWResManager.ts
CHANGED
|
@@ -75,7 +75,7 @@ export class FWResManager extends FWManager implements FW.ResManager {
|
|
|
75
75
|
* @returns
|
|
76
76
|
*/
|
|
77
77
|
async loadAssetData<T extends cc.Asset>(assetProperty: FW.AssetProperty) {
|
|
78
|
-
return this.
|
|
78
|
+
return this.process<T>(await this.assetMgr.load(assetProperty));
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
81
|
* 加载资源
|
|
@@ -84,7 +84,7 @@ export class FWResManager extends FWManager implements FW.ResManager {
|
|
|
84
84
|
*/
|
|
85
85
|
async loadAsset<T extends cc.Asset>(assetProperty: FW.AssetProperty): Promise<T> {
|
|
86
86
|
const res = await this.assetMgr.load(assetProperty);
|
|
87
|
-
return this.
|
|
87
|
+
return this.process<T>(res).asset as T;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
/**
|
|
@@ -102,7 +102,7 @@ export class FWResManager extends FWManager implements FW.ResManager {
|
|
|
102
102
|
* @returns
|
|
103
103
|
*/
|
|
104
104
|
getAssetData<T extends cc.Asset>(assetProperty: FW.AssetProperty) {
|
|
105
|
-
return this.
|
|
105
|
+
return this.process<T>(this.assetMgr.get(assetProperty));
|
|
106
106
|
}
|
|
107
107
|
/**
|
|
108
108
|
* 获取资源
|
|
@@ -110,7 +110,7 @@ export class FWResManager extends FWManager implements FW.ResManager {
|
|
|
110
110
|
* @returns
|
|
111
111
|
*/
|
|
112
112
|
getAsset<T extends cc.Asset>(assetProperty: FW.AssetProperty): T {
|
|
113
|
-
return this.
|
|
113
|
+
return this.process<T>(this.assetMgr.get(assetProperty)).asset as T;
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
/**
|
|
@@ -141,7 +141,7 @@ export class FWResManager extends FWManager implements FW.ResManager {
|
|
|
141
141
|
* @param res
|
|
142
142
|
* @returns
|
|
143
143
|
*/
|
|
144
|
-
private
|
|
144
|
+
private process<T extends cc.Asset>(res: FW.AssetData) {
|
|
145
145
|
let asset: cc.Asset;
|
|
146
146
|
|
|
147
147
|
if (res.asset instanceof cc.Texture2D) {
|
package/manager/FWTimeManager.ts
CHANGED
|
@@ -133,46 +133,18 @@ export class FWTimeManager extends FWManager implements FW.TimeManager {
|
|
|
133
133
|
let cb: () => void;
|
|
134
134
|
let tag: string;
|
|
135
135
|
let target: any;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
if (typeof
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
} else if (typeof arguments[0] === 'function') {
|
|
150
|
-
cb = arguments[0];
|
|
151
|
-
if (typeof arguments[1] === 'string') {
|
|
152
|
-
tag = arguments[1];
|
|
153
|
-
} else if (typeof arguments[1] === 'number') {
|
|
154
|
-
time = arguments[1];
|
|
155
|
-
} else {
|
|
156
|
-
target = arguments[1];
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
} else if (arguments.length == 3) {
|
|
160
|
-
if (typeof arguments[0] === 'number') {
|
|
161
|
-
time = arguments[0];
|
|
162
|
-
cb = arguments[1];
|
|
163
|
-
if (typeof arguments[2] === 'string') {
|
|
164
|
-
tag = arguments[2];
|
|
165
|
-
} else {
|
|
166
|
-
target = arguments[2];
|
|
167
|
-
}
|
|
168
|
-
} else if (typeof arguments[0] === 'function') {
|
|
169
|
-
cb = arguments[0];
|
|
170
|
-
time = arguments[1];
|
|
171
|
-
if (typeof arguments[2] === 'string') {
|
|
172
|
-
tag = arguments[2];
|
|
173
|
-
} else {
|
|
174
|
-
target = arguments[2];
|
|
175
|
-
}
|
|
136
|
+
|
|
137
|
+
const config: any = {};
|
|
138
|
+
|
|
139
|
+
for (const arg of arguments) {
|
|
140
|
+
if (typeof arg === 'function') {
|
|
141
|
+
cb = arg;
|
|
142
|
+
} else if (typeof arg === 'number') {
|
|
143
|
+
time = arg;
|
|
144
|
+
} else if (typeof arg === 'string') {
|
|
145
|
+
tag = arg;
|
|
146
|
+
} else if (arg) {
|
|
147
|
+
target = arg;
|
|
176
148
|
}
|
|
177
149
|
}
|
|
178
150
|
|
package/package.json
CHANGED
package/service/FWService.ts
CHANGED
|
@@ -1,57 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import FWLog from '../log/FWLog';
|
|
1
|
+
import { FrameworkBase } from '../FrameworkBase';
|
|
3
2
|
|
|
4
|
-
export default abstract class FWService {
|
|
5
|
-
constructor() {
|
|
6
|
-
this.initialize();
|
|
7
|
-
this.entry.evtMgr.register(FWEventDefine.SystemEvent.SYSTEM_RESTART, this.onDestroy, this);
|
|
8
|
-
}
|
|
9
|
-
public entry: FW.Entry = FW.Entry;
|
|
3
|
+
export default abstract class FWService extends FrameworkBase {
|
|
10
4
|
public abstract initialize(): void;
|
|
11
5
|
public abstract onDestroy(): void;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const startTime = this.getCurrentTime();
|
|
16
|
-
|
|
17
|
-
try {
|
|
18
|
-
const result = await operation;
|
|
19
|
-
const duration = this.getCurrentTime() - startTime;
|
|
20
|
-
|
|
21
|
-
this.recordPerformanceMetric(operationName, duration);
|
|
22
|
-
return result;
|
|
23
|
-
} catch (error) {
|
|
24
|
-
this.handleError(operationName, error);
|
|
25
|
-
return undefined;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
private recordPerformanceMetric(operationName: string, duration: number): void {
|
|
30
|
-
if (FW.Entry.performanceMgr) {
|
|
31
|
-
FW.Entry.performanceMgr.recordOperationMetric(this.serviceName, operationName, duration);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (FW.Entry.engineMgr.debug) {
|
|
35
|
-
const log = duration > 1000 ? FWLog.warn : FWLog.debug;
|
|
36
|
-
log(`Operation ${operationName} took ${duration}ms`);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
protected getCurrentTime(): number {
|
|
41
|
-
return Date.now();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
protected handleError(operation: string, error: any): void {
|
|
45
|
-
const errorInfo = {
|
|
46
|
-
manager: this.serviceName,
|
|
47
|
-
operation,
|
|
48
|
-
error: error?.message || error,
|
|
49
|
-
stack: error?.stack,
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
FWLog.error(`Manager error in ${this.serviceName}.${operation}:`, errorInfo);
|
|
53
|
-
|
|
54
|
-
if (FW.Entry.engineMgr.debug) {
|
|
55
|
-
}
|
|
6
|
+
protected onRestart() {
|
|
7
|
+
this.onDestroy();
|
|
8
|
+
this.initialize();
|
|
56
9
|
}
|
|
57
10
|
}
|
package/service/http/FWHttp.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { FWSystemConfig } from '../../config/FWSystemConfig';
|
|
1
2
|
import { FWSystemDefine } from '../../define/FWSystemDefine';
|
|
2
3
|
import FWLog from '../../log/FWLog';
|
|
3
4
|
import FWService from '../FWService';
|
|
4
5
|
|
|
5
6
|
export default class FWHttp extends FWService {
|
|
6
|
-
public serviceName: string = 'http';
|
|
7
7
|
public initialize(): void {}
|
|
8
8
|
public onDestroy(): void {}
|
|
9
9
|
|
|
@@ -13,7 +13,7 @@ export default class FWHttp extends FWService {
|
|
|
13
13
|
cb?: (response: string) => void,
|
|
14
14
|
tag?: string,
|
|
15
15
|
): Promise<string> {
|
|
16
|
-
return this.
|
|
16
|
+
return this.process(url, params, cb, tag, FWSystemDefine.FWHttpRequestType.GET);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
protected async postMessage(
|
|
@@ -22,10 +22,10 @@ export default class FWHttp extends FWService {
|
|
|
22
22
|
cb?: (response: string) => void,
|
|
23
23
|
tag?: string,
|
|
24
24
|
): Promise<string> {
|
|
25
|
-
return this.
|
|
25
|
+
return this.process(url, params, cb, tag, FWSystemDefine.FWHttpRequestType.POST);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
private async
|
|
28
|
+
private async process(
|
|
29
29
|
url: string,
|
|
30
30
|
params: string,
|
|
31
31
|
cb: (response: any) => void,
|
|
@@ -47,12 +47,12 @@ export default class FWHttp extends FWService {
|
|
|
47
47
|
|
|
48
48
|
xhr.onerror = (err: any) => {
|
|
49
49
|
FWLog.error(err);
|
|
50
|
-
this.onError(err);
|
|
50
|
+
this.onError?.(err);
|
|
51
51
|
reject(`http request error:${err}`);
|
|
52
52
|
};
|
|
53
53
|
|
|
54
54
|
xhr.ontimeout = () => {
|
|
55
|
-
this.onTimeout();
|
|
55
|
+
this.onTimeout?.();
|
|
56
56
|
reject(`http request timeout!`);
|
|
57
57
|
};
|
|
58
58
|
|
|
@@ -60,7 +60,7 @@ export default class FWHttp extends FWService {
|
|
|
60
60
|
xhr.send(params);
|
|
61
61
|
},
|
|
62
62
|
{
|
|
63
|
-
|
|
63
|
+
...FWSystemConfig.PromiseConfig.http,
|
|
64
64
|
retryCondition(error, retryCount) {
|
|
65
65
|
return xhr.readyState != 4 || (xhr.status !== 200 && retryCount < 3);
|
|
66
66
|
},
|
|
@@ -8,7 +8,6 @@ import FWSocketSender from './FWSocketSender';
|
|
|
8
8
|
* TODO 犹豫socket没有改版暂时已老的cmd字符串映射方式做,后期优化
|
|
9
9
|
*/
|
|
10
10
|
export default class FWSocket extends FWService implements FW.Socket {
|
|
11
|
-
public serviceName: string = 'socket';
|
|
12
11
|
/** 发送心跳时间抽 */
|
|
13
12
|
private sendHeartTimestamp: number;
|
|
14
13
|
/** 接收心跳时间戳 */
|