Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
1226085293 committed Apr 15, 2024
2 parents caba85d + 8490a97 commit f715542
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 45 deletions.
39 changes: 16 additions & 23 deletions assets/@framework/audio/mk_audio_base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends string | string[], T2 extends true | false = false>(
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<mk_audio_base_.unit[] | null>;
async add(
url_: string | string[],
target_: mk_asset_.follow_release_object,
config_?: mk_audio_base_.add_config
): Promise<mk_audio_base_.unit | mk_audio_base_.unit[] | null> {
config_?: mk_audio_base_.add_config<T2>
): Promise<T2 extends true ? (mk_audio_base_.unit | null)[] : T extends string ? mk_audio_base_.unit | null : (mk_audio_base_.unit | null)[]> {
if (EDITOR) {
return null;
return null!;
}

/** 路径列表 */
Expand All @@ -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) {
Expand All @@ -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;
}

Expand All @@ -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);
});

Expand Down Expand Up @@ -315,13 +308,13 @@ export namespace mk_audio_base_ {
}

/** add 配置 */
export interface add_config {
export interface add_config<T extends boolean> {
/** 类型 */
type?: global_config.audio.type;
/** 分组 */
group_ns?: number[];
/** 文件夹 */
dir_b?: boolean;
dir_b?: T;
/** 加载配置 */
load_config?: mk_asset_.get_config<cc.AudioClip>;
}
Expand Down
27 changes: 20 additions & 7 deletions assets/@framework/network/mk_network_base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,15 +431,23 @@ abstract class mk_network_base<CT extends mk_codec_base = mk_codec_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;
}
}

Expand Down Expand Up @@ -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);
Expand Down
11 changes: 7 additions & 4 deletions assets/resources/module/network/resources_network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
21 changes: 10 additions & 11 deletions declare/mk.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ declare namespace mk {
clone<T extends this>(value_n_: number): T[];
}
/** add 配置 */
export interface add_config {
export interface add_config<T extends boolean> {
/** 类型 */
type?: global_config.audio.type;
/** 分组 */
group_ns?: number[];
/** 文件夹 */
dir_b?: boolean;
dir_b?: T;
/** 加载配置 */
load_config?: asset_.get_config<cc_2.AudioClip>;
}
Expand Down Expand Up @@ -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<audio_.unit[] | null>;
add<T extends string | string[], T2 extends true | false = false>(
url_: T,
target_: asset_.follow_release_object,
config_?: audio_.add_config<T2>
): Promise<T2 extends true ? (audio_.unit | null)[] : T extends string ? audio_.unit | null : (audio_.unit | null)[]>;
/**
* 播放音效
* @param audio_ 音频单元
Expand Down Expand Up @@ -2229,6 +2226,8 @@ declare namespace mk {
send(data_: Parameters<CT["encode"]>[0]): void;
/** 触发发送 */
trigger(): void;
/** 清理所有未发送消息 */
clear(): void;
private _event_restart;
}
}
Expand Down

0 comments on commit f715542

Please sign in to comment.