From 191aec5afd432198cbeb7537ccb121f0ec809aa4 Mon Sep 17 00:00:00 2001 From: muzzik <45589707+1226085293@users.noreply.github.com> Date: Fri, 12 Apr 2024 18:52:49 +0800 Subject: [PATCH 1/4] Bump protobufjs from 7.2.4 to 7.2.5 (#16) (#17) Bumps [protobufjs](https://github.com/protobufjs/protobuf.js) from 7.2.4 to 7.2.5. - [Release notes](https://github.com/protobufjs/protobuf.js/releases) - [Changelog](https://github.com/protobufjs/protobuf.js/blob/master/CHANGELOG.md) - [Commits](https://github.com/protobufjs/protobuf.js/compare/protobufjs-v7.2.4...protobufjs-v7.2.5) --- updated-dependencies: - dependency-name: protobufjs dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package-lock.json | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 73bc0b9..d14571d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,7 @@ "name": "mk-framework", "version": "3.6.3", "dependencies": { - "protobufjs": "^7.2.4" + "protobufjs": "^7.2.5" }, "devDependencies": { "@typescript-eslint/eslint-plugin": "^5.34.0", @@ -2864,9 +2864,9 @@ } }, "node_modules/protobufjs": { - "version": "7.2.4", - "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.2.4.tgz", - "integrity": "sha512-AT+RJgD2sH8phPmCf7OUZR8xGdcJRga4+1cOaXJ64hvcSkVhNcRHOwIxUatPH15+nj59WAGTDv3LSGZPEQbJaQ==", + "version": "7.2.5", + "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.2.5.tgz", + "integrity": "sha512-gGXRSXvxQ7UiPgfw8gevrfRWcTlSbOFg+p/N+JVJEK5VhueL2miT6qTymqAmjr1Q5WbOCyJbyrk6JfWKwlFn6A==", "hasInstallScript": true, "dependencies": { "@protobufjs/aspromise": "^1.1.2", @@ -5729,9 +5729,9 @@ } }, "protobufjs": { - "version": "7.2.4", - "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.2.4.tgz", - "integrity": "sha512-AT+RJgD2sH8phPmCf7OUZR8xGdcJRga4+1cOaXJ64hvcSkVhNcRHOwIxUatPH15+nj59WAGTDv3LSGZPEQbJaQ==", + "version": "7.2.5", + "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.2.5.tgz", + "integrity": "sha512-gGXRSXvxQ7UiPgfw8gevrfRWcTlSbOFg+p/N+JVJEK5VhueL2miT6qTymqAmjr1Q5WbOCyJbyrk6JfWKwlFn6A==", "requires": { "@protobufjs/aspromise": "^1.1.2", "@protobufjs/base64": "^1.1.2", diff --git a/package.json b/package.json index b4c29c9..799f364 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,6 @@ "uuid": "0db88ab0-0e0d-4a27-98dc-7d2c966dad01", "version": "3.6.3", "dependencies": { - "protobufjs": "^7.2.4" + "protobufjs": "^7.2.5" } } From 1b88616f1189cc772990e2f1dbb8e2cf32574624 Mon Sep 17 00:00:00 2001 From: muzzik <1226085293@qq.com> Date: Sun, 14 Apr 2024 23:37:23 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=9F=B3=E9=A2=91=20add?= =?UTF-8?q?=20=E6=8E=A5=E5=8F=A3=E7=B1=BB=E5=9E=8B=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/@framework/audio/mk_audio_base.ts | 39 ++++++++++-------------- declare/mk.d.ts | 19 +++++------- 2 files changed, 24 insertions(+), 34 deletions(-) diff --git a/assets/@framework/audio/mk_audio_base.ts b/assets/@framework/audio/mk_audio_base.ts index e81b665..6bb6b3c 100644 --- a/assets/@framework/audio/mk_audio_base.ts +++ b/assets/@framework/audio/mk_audio_base.ts @@ -50,29 +50,17 @@ abstract class mk_audio_base extends mk_instance_base { /** * 添加音频单元 - * @param url_s_ 音频资源路径 + * @param url_ 音频资源路径 | 音频资源路径列表 * @param target_ 跟随释放对象 * @param config_ 添加配置 */ - add( - url_s_: string, + async add( + url_: T, target_: mk_asset_.follow_release_object, - config_?: mk_audio_base_.add_config - ): Promise<(mk_audio_base_.unit & mk_audio_base_.unit[]) | null>; - /** - * 添加音频单元 - * @param url_ss_ 音频资源路径列表 - * @param target_ 跟随释放对象 - * @param config_ 添加配置 - */ - add(url_ss_: string[], target_: mk_asset_.follow_release_object, config_?: mk_audio_base_.add_config): Promise; - async add( - url_: string | string[], - target_: mk_asset_.follow_release_object, - config_?: mk_audio_base_.add_config - ): Promise { + config_?: mk_audio_base_.add_config + ): Promise { if (EDITOR) { - return null; + return null!; } /** 路径列表 */ @@ -85,8 +73,8 @@ abstract class mk_audio_base extends mk_instance_base { url_ss = url_; } - const audio_as: mk_audio_base_._unit[] = []; - let result: mk_audio_base_._unit | mk_audio_base_._unit[]; + const audio_as: (mk_audio_base_._unit | null)[] = []; + let result: mk_audio_base_._unit | (mk_audio_base_._unit | null)[]; if (config_?.dir_b) { for (const v_s of url_ss) { @@ -108,6 +96,7 @@ abstract class mk_audio_base extends mk_instance_base { const asset = await mk_asset.get(v_s, cc.AudioClip, target_, config_?.load_config); if (!asset) { + audio_as.push(null!); continue; } @@ -119,11 +108,15 @@ abstract class mk_audio_base extends mk_instance_base { audio_as.push(audio); } - result = audio_as.length === 1 ? audio_as[0] : audio_as; + result = (!Array.isArray(url_) ? audio_as[0] : audio_as) as any; } // 添加音频 audio_as.forEach((v) => { + if (!v) { + return; + } + this._add(v, config_?.group_ns); }); @@ -315,13 +308,13 @@ export namespace mk_audio_base_ { } /** add 配置 */ - export interface add_config { + export interface add_config { /** 类型 */ type?: global_config.audio.type; /** 分组 */ group_ns?: number[]; /** 文件夹 */ - dir_b?: boolean; + dir_b?: T; /** 加载配置 */ load_config?: mk_asset_.get_config; } diff --git a/declare/mk.d.ts b/declare/mk.d.ts index 29d65e6..38256da 100644 --- a/declare/mk.d.ts +++ b/declare/mk.d.ts @@ -117,13 +117,13 @@ declare namespace mk { clone(value_n_: number): T[]; } /** add 配置 */ - export interface add_config { + export interface add_config { /** 类型 */ type?: global_config.audio.type; /** 分组 */ group_ns?: number[]; /** 文件夹 */ - dir_b?: boolean; + dir_b?: T; /** 加载配置 */ load_config?: asset_.get_config; } @@ -1083,18 +1083,15 @@ declare namespace mk { get_group(group_n_: number): audio_.group; /** * 添加音频单元 - * @param url_s_ 音频资源路径 + * @param url_ 音频资源路径 | 音频资源路径列表 * @param target_ 跟随释放对象 * @param config_ 添加配置 */ - add(url_s_: string, target_: asset_.follow_release_object, config_?: audio_.add_config): Promise<(audio_.unit & audio_.unit[]) | null>; - /** - * 添加音频单元 - * @param url_ss_ 音频资源路径列表 - * @param target_ 跟随释放对象 - * @param config_ 添加配置 - */ - add(url_ss_: string[], target_: asset_.follow_release_object, config_?: audio_.add_config): Promise; + add( + url_: T, + target_: asset_.follow_release_object, + config_?: audio_.add_config + ): Promise; /** * 播放音效 * @param audio_ 音频单元 From 829b11d09c2d46f428059d5b1d0cff91f78b5c55 Mon Sep 17 00:00:00 2001 From: muzzik <1226085293@qq.com> Date: Mon, 15 Apr 2024 11:07:53 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=A4=BA=E4=BE=8B?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/resources/module/network/resources_network.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/assets/resources/module/network/resources_network.ts b/assets/resources/module/network/resources_network.ts index 0abe027..4ad24e9 100644 --- a/assets/resources/module/network/resources_network.ts +++ b/assets/resources/module/network/resources_network.ts @@ -42,16 +42,19 @@ export class resources_network extends mk.view_base { this._ws.event.on(this._ws.event.key.recv, this._network_recv, this); this._ws2.event.on(this._ws.event.key.recv, this._network_recv2, this); - // // 监听指定消息 - // this._ws2.message.on(test.test_c, (value) => { - // this.data.chat2_ss.push("网络 2 收到:" + value.data); - // }); + // // 发送消息 + // this._ws2.message.send(test.test_c.create()); // // 请求指定消息(等待返回、需在消息体添加消息序号并修改对应编解码) // this._ws2.message.request(test.test_c.create())?.then((value) => { // this._log.log("收到请求消息", value); // }); + // // 监听指定消息 + // this._ws2.message.on(test.test_c, (value) => { + // this.data.chat2_ss.push("网络 2 收到:" + value.data); + // }); + this.schedule(() => { if (this._ws.state === mk.network.base_.status.open) { this.data.chat_ss.push("网络 1 发送:123"); From 8490a974acd560dec3ab793b0f70225b814075e0 Mon Sep 17 00:00:00 2001 From: muzzik <1226085293@qq.com> Date: Mon, 15 Apr 2024 17:12:11 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=B0=86=E7=BD=91=E7=BB=9C=E4=BB=8E?= =?UTF-8?q?=E5=8D=95=E6=AC=A1=E6=94=B9=E4=B8=BA=E6=89=B9=E9=87=8F=E5=8F=91?= =?UTF-8?q?=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/@framework/network/mk_network_base.ts | 27 +++++++++++++++----- declare/mk.d.ts | 2 ++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/assets/@framework/network/mk_network_base.ts b/assets/@framework/network/mk_network_base.ts index 05d2a48..c6c630a 100644 --- a/assets/@framework/network/mk_network_base.ts +++ b/assets/@framework/network/mk_network_base.ts @@ -431,15 +431,23 @@ abstract class mk_network_base extends return; } - // 存在发送数据且上次发送已经结束,避免超出缓存 - if (this._write_as.length && !this._socket.bufferedAmount) { - const data = this.config.codec ? await this.config.codec.encode(this._write_as.pop()) : this._write_as.pop(); + // 发送完成进入睡眠 + if (this._write_as.length === 0) { + this._write_sleep_b = true; + + return; + } + + let data_as = this._write_as.splice(0, this._write_as.length); + + if (this.config.codec) { + data_as = await Promise.all(data_as.map((v) => this.config.codec!.encode(v))); + } - if ((data ?? null) !== null) { - this._socket.send(data); + for (const v of data_as) { + if ((v ?? null) !== null) { + this._socket.send(v); } - } else { - this._write_sleep_b = true; } } @@ -775,6 +783,11 @@ export namespace mk_network_base_ { } } + /** 清理所有未发送消息 */ + clear(): void { + this._mess_as.splice(0, this._mess_as.length); + } + /* ------------------------------- 全局事件 ------------------------------- */ private _event_restart(): void { clearInterval(this._send_timer); diff --git a/declare/mk.d.ts b/declare/mk.d.ts index 38256da..50e2bc9 100644 --- a/declare/mk.d.ts +++ b/declare/mk.d.ts @@ -2226,6 +2226,8 @@ declare namespace mk { send(data_: Parameters[0]): void; /** 触发发送 */ trigger(): void; + /** 清理所有未发送消息 */ + clear(): void; private _event_restart; } }