refactor: 渲染端初始化移动至主插件

This commit is contained in:
AncTe committed 2026-10-16 00:41:58 +08:00
1 parent 7fde97ff1e
commit 0a133058ca
12 files changed
+118 -187

No files matched your search

+6 -35
View File
@@ -35,19 +35,10 @@ import {
} from '@user/client-base';
import {
ExcitationDivider,
ExcitationVariator,
IExcitation,
IExcitationDivider,
RafExcitation
} from '@motajs/animate';
import {
DEBUG_DIVIDER,
DEBUG_VARIATOR,
DIVIDER_DEBUG_DIVIDER,
MAIN_HEIGHT,
MAIN_WIDTH,
VARIATOR_DEBUG_SPEED
} from './shared';
import { IRendererUsing, RendererUsing } from '@motajs/render-vue';
import { IUIController, UIController } from '@motajs/system';
import { createApp } from './render';
@@ -71,7 +62,7 @@ export class ClientCore extends CoreState implements IClientCore {
readonly sceneController: IUIController<IGameUIPropsBase>;
readonly mainUIController: IUIController<IGameUIPropsBase>;
// Layer 5 渲染顶层
// Layer 5 渲染顶层 - 目前没东西
/** 已注册的渲染端插件 */
private readonly clientPlugins: Map<
@@ -85,10 +76,7 @@ export class ClientCore extends CoreState implements IClientCore {
constructor(config: IClientCoreConfig) {
super(config);
//#region Layer 4
this.save = new SaveSystem();
this.save.init('');
this.audioContext = new MotaAudioContext();
this.soundPlayer = new SoundPlayer(this.audioContext);
this.bgmPlayer = new BGMPlayer(this.audioContext);
@@ -98,30 +86,15 @@ export class ClientCore extends CoreState implements IClientCore {
config.tilesetUnit
);
const rafExcitation = new RafExcitation();
const excitationDivider = new ExcitationDivider<number>();
this.rafExcitation = rafExcitation;
this.excitationDivider = excitationDivider;
if (DEBUG_VARIATOR) {
const variator = new ExcitationVariator();
variator.bindExcitation(rafExcitation);
variator.setSpeed(VARIATOR_DEBUG_SPEED);
excitationDivider.bindExcitation(variator);
} else {
excitationDivider.bindExcitation(rafExcitation);
}
if (DEBUG_DIVIDER) {
excitationDivider.setDivider(DIVIDER_DEBUG_DIVIDER);
}
this.rafExcitation = new RafExcitation();
this.excitationDivider = new ExcitationDivider<number>();
this.renderer = new MotaRenderer({
canvas: '#render-main',
width: MAIN_WIDTH,
height: MAIN_HEIGHT,
width: config.renderWidth,
height: config.renderHeight,
// 使用分频器,用户可以在设置中调整,如果设备性能较差调高分频有助于提高性能表现
excitaion: excitationDivider
excitaion: this.excitationDivider
});
this.using = new RendererUsing(this.renderer);
this.mainMapRenderer = new MapRenderer(this.materials);
@@ -133,8 +106,6 @@ export class ClientCore extends CoreState implements IClientCore {
this.sceneController.setPropsBaseCreator(pbCreator);
this.mainUIController.setPropsBaseCreator(pbCreator);
//#endregion
this.loader.addCoreConfig('client', config.clientURL);
// 渲染端插件注册表
@@ -2,25 +2,6 @@ import { ElementLocator, Font } from '@motajs/render';
// 本文件为 UI 配置文件,你可以修改下面的每个常量来控制 UI 的显示参数,每个常量都有注释说明
//#region 调试用参数
/**
* 渲染器的激励源是否使用变速器,使用后可以通过 {@link VARIATOR_DEBUG_SPEED} 调整激励源速度,
* 从而调整动画等内容的执行速度,方便调试
*/
export const DEBUG_VARIATOR = false;
/** 当使用变速器作为激励源调试时,变速器的速度 */
export const VARIATOR_DEBUG_SPEED = 0.2;
/**
* 是否使用分频器调试,使用后可以通过 {@link DIVIDER_DEBUG_DIVIDER} 调整分配比例,
* 降低画面刷新频率及每帧执行函数的执行频率,方便调试
*/
export const DEBUG_DIVIDER = false;
/** 当使用分频器调试时,分频比例 */
export const DIVIDER_DEBUG_DIVIDER = 60;
//#endregion
//#region 地图
/** 每个格子的默认宽度,现阶段用处不大 */
@@ -60,6 +60,10 @@ export interface IClientCoreConfig extends ICoreStateConfig {
readonly tilesetUnit: number;
/** 渲染器挂载至的画布元素 */
readonly rendererCanvas: string;
/** 渲染器的渲染宽度 */
readonly renderWidth: number;
/** 渲染器的渲染高度 */
readonly renderHeight: number;
/** 渲染端插件列表 */
readonly clientPlugins: IClientPluginDefine[];
}