添加内部属性标记

This commit is contained in:
宫欣海
2025-03-07 16:02:00 +08:00
parent b6551e9bbf
commit 897d618a0b
71 changed files with 909 additions and 220 deletions

View File

@@ -77,6 +77,10 @@ export default [
file: 'dist/kunpocc.d.ts',
format: 'es'
},
plugins: [dts()]
plugins: [dts({
compilerOptions: {
stripInternal: true
}
})]
}
];

View File

@@ -21,7 +21,10 @@ export interface IAssetConfig {
bundle?: string;
}
/** 资源加载的状态类型 */
/**
* 资源加载的状态类型
* @internal
*/
enum StateType {
Error,
Wait,
@@ -30,31 +33,77 @@ enum StateType {
}
export class AssetLoader {
/** 资源加载器名称 */
/**
* 资源加载器名称
* @internal
*/
private _name: string = "";
/** 资源总数 */
/**
* 资源总数
* @internal
*/
private _total: number = 0;
/** 最大并行加载数量 */
/**
* 最大并行加载数量
* @internal
*/
private _maxParallel: number = 10;
/** 当前并行加载数量 */
/**
* 当前并行加载数量
* @internal
*/
private _parallel: number = 0;
/** 失败重试次数 */
/**
* 失败重试次数
* @internal
*/
private _maxRetry: number = 3;
/** 失败重试次数 */
/**
* 失败重试次数
* @internal
*/
private _retry: number = 0;
/** 获取资源数量是否成功 */
/**
* 获取资源数量是否成功
* @internal
*/
private _initSuccess: boolean = false;
/**
* 加载进度回调
* @internal
*/
private _progress: (percent: number) => void;
/**
* 加载完成回调
* @internal
*/
private _complete: () => void;
/**
* 加载失败回调
* @internal
*/
private _fail: (msg: string, err: Error) => void;
/**
* 资源配置
* @internal
*/
private _configs: IAssetConfig[] = [];
/**
* 资源加载项
* @internal
*/
private _items: { type: typeof Asset, bundle: string, path: string, isFile?: boolean, status: StateType, count: number }[] = [];
/** load完成数量 */
/**
* 加载完成数量
* @internal
*/
private _completeCounts: Map<string, number> = new Map();
constructor(name?: string) {
this._name = name || "AssetLoader";
}
@@ -123,7 +172,10 @@ export class AssetLoader {
}
}
/** 重试开始 */
/**
* 重试开始
* @internal
*/
private retryStart(): void {
this._retry++;
this.start({
@@ -136,7 +188,10 @@ export class AssetLoader {
});
}
/** 重试加载资源 */
/**
* 重试加载资源
* @internal
*/
private retryLoad(): void {
this._retry++;
let count = this.resetErrorItem();
@@ -146,7 +201,10 @@ export class AssetLoader {
}
}
/** 初始化成功后,开始批量加载资源 */
/**
* 初始化成功后,开始批量加载资源
* @internal
*/
private initSuccess(): void {
this._initSuccess = true;
this._parallel = 0;
@@ -156,7 +214,10 @@ export class AssetLoader {
}
}
/** 加载下一个资源 */
/**
* 加载下一个资源
* @internal
*/
private loadNext(): void {
// 找到第一个等待中的资源
let index = this._items.findIndex(item => item.status == StateType.Wait);
@@ -170,7 +231,10 @@ export class AssetLoader {
}
}
/** 重置失败资源状态为等待中 */
/**
* 重置失败资源状态为等待中
* @internal
*/
private resetErrorItem(): number {
let count = 0;
for (const item of this._items) {
@@ -182,6 +246,10 @@ export class AssetLoader {
return count;
}
/**
* 加载资源
* @internal
*/
private async loadItem(index: number): Promise<void> {
let item = this._items[index];
item.status = StateType.Loading;
@@ -200,6 +268,10 @@ export class AssetLoader {
}
}
/**
* 加载资源
* @internal
*/
private loadDir(index: number, bundle: AssetManager.Bundle): void {
let item = this._items[index];
bundle.loadDir(item.path, item.type, (finish: number, total: number) => {
@@ -222,6 +294,10 @@ export class AssetLoader {
});
}
/**
* 加载资源
* @internal
*/
private loadFile(index: number, bundle: AssetManager.Bundle): void {
let item = this._items[index];
bundle.load(item.path, item.type, (error: Error, asset: Asset) => {
@@ -240,7 +316,10 @@ export class AssetLoader {
});
}
/** 更新进度 */
/**
* 更新进度
* @internal
*/
private updateProgress(): void {
let value = 0;
for (const count of this._completeCounts.values()) {

View File

@@ -9,7 +9,9 @@ import { log } from "../tool/log";
import { AssetUtils } from "./AssetUtils";
export class AssetPool {
/** @internal */
private static _assets: { [path: string]: Asset } = {};
/** @internal */
private static _uuidToName: Map<string, string> = new Map();
/** 批量添加资源 */
@@ -112,6 +114,10 @@ export class AssetPool {
this._uuidToName.clear();
}
/**
* 获取资源 key
* @internal
*/
private static getKey(path: string, bundlename: string = "resources"): string {
return `${bundlename}:${path}`;
}

View File

@@ -4,8 +4,11 @@ import { Ticker } from "./Ticker";
/** 代理 */
export class Agent {
/** 行为树 */
public tree: BehaviorTree;
/** 黑板 */
public blackboard: Blackboard;
/** 更新器 */
public ticker: Ticker;
/**
* constructor
@@ -18,6 +21,9 @@ export class Agent {
this.ticker = new Ticker(subject, this.blackboard, tree);
}
/**
* 执行
*/
public tick(): void {
this.tree.tick(this, this.blackboard, this.ticker);
if (this.blackboard.interrupt) {

View File

@@ -17,12 +17,18 @@ export abstract class Action extends BaseNode {
* 直接返回FAILURE
*/
export class Failure extends Action {
/** 执行函数 @internal */
private _func: () => void;
constructor(func: () => void) {
super();
this._func = func;
}
/**
* 执行
* @param {Ticker} ticker
* @returns {Status}
*/
public tick(ticker: Ticker): Status {
this._func();
return Status.FAILURE;
@@ -34,12 +40,18 @@ export class Failure extends Action {
* 直接返回RUNING
*/
export class Running extends Action {
/** 执行函数 @internal */
private _func: () => void;
constructor(func: () => void) {
super();
this._func = func;
}
/**
* 执行
* @param {Ticker} ticker
* @returns {Status}
*/
public tick(ticker: Ticker): Status {
this._func();
return Status.RUNNING;
@@ -51,12 +63,18 @@ export class Running extends Action {
* 直接返回SUCCESS
*/
export class Success extends Action {
/** 执行函数 @internal */
private _func: () => void;
constructor(func: () => void) {
super();
this._func = func;
}
/**
* 执行
* @param {Ticker} ticker
* @returns {Status}
*/
public tick(ticker: Ticker): Status {
this._func();
return Status.SUCCESS;
@@ -68,9 +86,9 @@ export class Success extends Action {
* 超次返回SUCCESS
*/
export class WaitTicks extends Action {
/** 最大次数 */
/** 最大次数 @internal */
private _maxTicks: number;
/** 经过的次数 */
/** 经过的次数 @internal */
private _elapsedTicks: number;
constructor(maxTicks: number = 0) {
super();
@@ -78,10 +96,19 @@ export class WaitTicks extends Action {
this._elapsedTicks = 0;
}
/**
* 打开
* @param {Ticker} ticker
*/
public open(ticker: Ticker): void {
this._elapsedTicks = 0;
}
/**
* 执行
* @param {Ticker} ticker
* @returns {Status}
*/
public tick(ticker: Ticker): Status {
if (++this._elapsedTicks >= this._maxTicks) {
this._elapsedTicks = 0;
@@ -96,18 +123,27 @@ export class WaitTicks extends Action {
* 时间到后返回SUCCESS否则返回RUNING
*/
export class WaitTime extends Action {
/** 等待时间(毫秒 ms) */
/** 等待时间(毫秒 ms) @internal */
private _duration: number;
constructor(duration: number = 0) {
super();
this._duration = duration * 1000;
}
/**
* 打开
* @param {Ticker} ticker
*/
public open(ticker: Ticker): void {
let startTime = new Date().getTime();
ticker.blackboard.set("startTime", startTime, ticker.tree.id, this.id);
}
/**
* 执行
* @param {Ticker} ticker
* @returns {Status}
*/
public tick(ticker: Ticker): Status {
let currTime = new Date().getTime();
let startTime = ticker.blackboard.get("startTime", ticker.tree.id, this.id);
@@ -124,6 +160,11 @@ export class WaitTime extends Action {
* 和 InterruptDefendCancel 必须成对出现
*/
export class InterruptDefend extends Action {
/**
* 执行
* @param {Ticker} ticker
* @returns {Status}
*/
public tick(ticker: Ticker): Status {
ticker.blackboard.interruptDefend = true;
return Status.SUCCESS;
@@ -136,6 +177,11 @@ export class InterruptDefend extends Action {
* 和 InterruptDefend 必须成对出现
*/
export class InterruptDefendCancel extends Action {
/**
* 执行
* @param {Ticker} ticker
* @returns {Status}
*/
public tick(ticker: Ticker): Status {
ticker.blackboard.interruptDefend = false;
return Status.SUCCESS;

View File

@@ -26,7 +26,11 @@ export abstract class BaseNode {
}
}
/** 执行节点 */
/**
* 执行节点
* @param ticker 更新器
* @returns {Status} 状态
*/
public _execute(ticker: Ticker): Status {
/* ENTER */
this._enter(ticker);
@@ -44,6 +48,7 @@ export abstract class BaseNode {
/**
* 进入节点
* @param ticker 更新器
* @internal
*/
public _enter(ticker: Ticker): void {
ticker.enterNode(this);
@@ -53,6 +58,7 @@ export abstract class BaseNode {
/**
* 打开节点
* @param ticker 更新器
* @internal
*/
public _open(ticker: Ticker): void {
ticker.openNode(this);
@@ -63,6 +69,7 @@ export abstract class BaseNode {
/**
* 更新节点
* @param ticker 更新器
* @internal
*/
public _tick(ticker: Ticker): Status {
ticker.tickNode(this);
@@ -72,6 +79,7 @@ export abstract class BaseNode {
/**
* 关闭节点
* @param ticker 更新器
* @internal
*/
public _close(ticker: Ticker): void {
ticker.closeNode(this);
@@ -82,6 +90,7 @@ export abstract class BaseNode {
/**
* 退出节点
* @param ticker 更新器
* @internal
*/
public _exit(ticker: Ticker): void {
ticker.exitNode(this);

View File

@@ -18,12 +18,21 @@ export abstract class Composite extends BaseNode {
* 任意一个Child Node返回不为 FAILURE, 本Node向自己的Parent Node也返回Child Node状态
*/
export class MemSelector extends Composite {
open(ticker: Ticker): void {
/**
* 打开
* @param {Ticker} ticker
*/
public open(ticker: Ticker): void {
super.open(ticker);
ticker.blackboard.set("runningChild", 0, ticker.tree.id, this.id);
}
tick(ticker: Ticker): Status {
/**
* 执行
* @param {Ticker} ticker
* @returns {Status}
*/
public tick(ticker: Ticker): Status {
let childIndex = ticker.blackboard.get("runningChild", ticker.tree.id, this.id) as number;
for (let i = childIndex; i < this.children.length; i++) {
@@ -49,12 +58,21 @@ export class MemSelector extends Composite {
* 所有节点都返回 SUCCESS, 本节点才返回 SUCCESS
*/
export class MemSequence extends Composite {
open(ticker: Ticker): void {
/**
* 打开
* @param {Ticker} ticker
*/
public open(ticker: Ticker): void {
super.open(ticker);
ticker.blackboard.set("runningChild", 0, ticker.tree.id, this.id);
}
tick(ticker: Ticker): Status {
/**
* 执行
* @param {Ticker} ticker
* @returns {Status}
*/
public tick(ticker: Ticker): Status {
let childIndex = ticker.blackboard.get("runningChild", ticker.tree.id, this.id) as number;
for (let i = childIndex; i < this.children.length; i++) {
let status = this.children[i]._execute(ticker);
@@ -74,7 +92,12 @@ export class MemSequence extends Composite {
* 从Child Node中随机选择一个执行
*/
export class RandomSelector extends Composite {
tick(ticker: Ticker): Status {
/**
* 执行
* @param {Ticker} ticker
* @returns {Status}
*/
public tick(ticker: Ticker): Status {
let childIndex = (Math.random() * this.children.length) | 0;
let child = this.children[childIndex];
let status = child._execute(ticker);
@@ -89,7 +112,12 @@ export class RandomSelector extends Composite {
* 如遇到一个Child Node执行后返回 SUCCESS 或者 RUNING那停止迭代本Node向自己的Parent Node也返回 SUCCESS 或 RUNING
*/
export class Selector extends Composite {
tick(ticker: Ticker): Status {
/**
* 执行
* @param {Ticker} ticker
* @returns {Status}
*/
public tick(ticker: Ticker): Status {
for (let i = 0; i < this.children.length; i++) {
let status = this.children[i]._execute(ticker);
if (status !== Status.FAILURE) {
@@ -107,6 +135,11 @@ export class Selector extends Composite {
* 所有节点都返回 SUCCESS, 本节点才返回 SUCCESS
*/
export class Sequence extends Composite {
/**
* 执行
* @param {Ticker} ticker
* @returns {Status}
*/
public tick(ticker: Ticker): Status {
for (let i = 0; i < this.children.length; i++) {
let status = this.children[i]._execute(ticker);
@@ -126,6 +159,11 @@ export class Sequence extends Composite {
* 所有节点都返回 SUCCESS, 本节点才返回 SUCCESS
*/
export class Parallel extends Composite {
/**
* 执行
* @param {Ticker} ticker
* @returns {Status}
*/
public tick(ticker: Ticker): Status {
let result = Status.SUCCESS;
for (let i = 0; i < this.children.length; i++) {
@@ -148,6 +186,11 @@ export class Parallel extends Composite {
* 否则返回 RUNNING
*/
export class ParallelAnySuccess extends Composite {
/**
* 执行
* @param {Ticker} ticker
* @returns {Status}
*/
public tick(ticker: Ticker): Status {
let result = Status.RUNNING;
for (let i = 0; i < this.children.length; i++) {

View File

@@ -6,13 +6,19 @@ import { Action } from "./Action";
* 条件节点
*/
export class Condition extends Action {
/** 执行函数 @internal */
private _func: (subject: any) => boolean = null;
constructor(func: (subject: any) => boolean) {
super();
this._func = func;
}
tick(ticker: Ticker): Status {
/**
* 执行
* @param {Ticker} ticker
* @returns {Status}
*/
public tick(ticker: Ticker): Status {
return this._func(ticker.subject) ? Status.SUCCESS : Status.FAILURE;
}
}

View File

@@ -19,6 +19,11 @@ export abstract class Decorator extends BaseNode {
* @extends Decorator
*/
export class Failer extends Decorator {
/**
* 执行
* @param {Ticker} ticker
* @returns {Status}
*/
public tick(ticker: Ticker): Status {
if (this.children.length !== 1) {
throw new Error("(Failer)节点必须包含一个子节点");
@@ -36,7 +41,12 @@ export class Failer extends Decorator {
* 第一个Child Node节点, 返回 SUCCESS, 本Node向自己的Parent Node也返回 FAILURE
*/
export class Inverter extends Decorator {
tick(ticker: Ticker): Status {
/**
* 执行
* @param {Ticker} ticker
* @returns {Status}
*/
public tick(ticker: Ticker): Status {
if (this.children.length !== 1) {
throw new Error("(Inverter)节点必须包含一个子节点");
}
@@ -58,9 +68,9 @@ export class Inverter extends Decorator {
* 次数超过后, 直接返回 FAILURE
*/
export class LimiterTicks extends Decorator {
/** 最大次数 */
/** 最大次数 @internal */
private _maxTicks: number;
/** 当前执行过的次数 */
/** 当前执行过的次数 @internal */
private _elapsedTicks: number;
/**
@@ -74,12 +84,21 @@ export class LimiterTicks extends Decorator {
this._elapsedTicks = 0;
}
open(ticker: Ticker): void {
/**
* 打开
* @param {Ticker} ticker
*/
public open(ticker: Ticker): void {
super.open(ticker);
this._elapsedTicks = 0;
}
tick(ticker: Ticker): Status {
/**
* 执行
* @param {Ticker} ticker
* @returns {Status}
*/
public tick(ticker: Ticker): Status {
if (this.children.length !== 1) {
throw new Error("(LimiterTicks)节点必须包含一个子节点");
}
@@ -99,7 +118,7 @@ export class LimiterTicks extends Decorator {
* 超时后, 直接返回 FAILURE
*/
export class LimiterTime extends Decorator {
/** 最大时间 (毫秒 ms) */
/** 最大时间 (毫秒 ms) @internal */
private _maxTime: number;
/**
@@ -112,13 +131,22 @@ export class LimiterTime extends Decorator {
this._maxTime = maxTime * 1000;
}
open(ticker: Ticker): void {
/**
* 打开
* @param {Ticker} ticker
*/
public open(ticker: Ticker): void {
super.open(ticker);
let startTime = new Date().getTime();
ticker.blackboard.set("startTime", startTime, ticker.tree.id, this.id);
}
tick(ticker: Ticker): Status {
/**
* 执行
* @param {Ticker} ticker
* @returns {Status}
*/
public tick(ticker: Ticker): Status {
if (this.children.length !== 1) {
throw new Error("(LimiterTime)节点必须包含一个子节点");
}
@@ -142,18 +170,33 @@ export class LimiterTime extends Decorator {
* 否则等待次数超过之后, 返回Child Node的结果RUNING的次数不计算在内
*/
export class Repeater extends Decorator {
maxLoop: number;
/** 最大循环次数 @internal */
private _maxLoop: number;
/**
* 创建
* @param child 子节点
* @param maxLoop 最大循环次数
*/
constructor(child: BaseNode, maxLoop: number = -1) {
super(child);
this.maxLoop = maxLoop;
this._maxLoop = maxLoop;
}
open(ticker: Ticker): void {
/**
* 打开
* @param {Ticker} ticker
*/
public open(ticker: Ticker): void {
ticker.blackboard.set("i", 0, ticker.tree.id, this.id);
}
tick(ticker: Ticker): Status {
/**
* 执行
* @param {Ticker} ticker
* @returns {Status}
*/
public tick(ticker: Ticker): Status {
if (this.children.length !== 1) {
throw new Error("(Repeater)节点必须包含一个子节点");
}
@@ -162,7 +205,7 @@ export class Repeater extends Decorator {
let i = ticker.blackboard.get("i", ticker.tree.id, this.id);
let status = Status.SUCCESS;
while (this.maxLoop < 0 || i < this.maxLoop) {
while (this._maxLoop < 0 || i < this._maxLoop) {
status = child._execute(ticker);
if (status === Status.SUCCESS || status === Status.FAILURE) {
@@ -185,18 +228,28 @@ export class Repeater extends Decorator {
* 循环次数大于等于maxLoop时, 返回Child Node的结果
*/
export class RepeatUntilFailure extends Decorator {
maxLoop: number;
/** 最大循环次数 @internal */
private _maxLoop: number;
constructor(child: BaseNode, maxLoop: number = -1) {
super(child);
this.maxLoop = maxLoop;
this._maxLoop = maxLoop;
}
open(ticker: Ticker): void {
/**
* 打开
* @param {Ticker} ticker
*/
public open(ticker: Ticker): void {
ticker.blackboard.set("i", 0, ticker.tree.id, this.id);
}
tick(ticker: Ticker): Status {
/**
* 执行
* @param {Ticker} ticker
* @returns {Status}
*/
public tick(ticker: Ticker): Status {
if (this.children.length !== 1) {
throw new Error("(RepeatUntilFailure)节点必须包含一个子节点");
}
@@ -205,7 +258,7 @@ export class RepeatUntilFailure extends Decorator {
let i = ticker.blackboard.get("i", ticker.tree.id, this.id);
let status = Status.SUCCESS;
while (this.maxLoop < 0 || i < this.maxLoop) {
while (this._maxLoop < 0 || i < this._maxLoop) {
status = child._execute(ticker);
if (status === Status.SUCCESS) {
@@ -227,17 +280,33 @@ export class RepeatUntilFailure extends Decorator {
* 循环次数大于等于maxLoop时, 返回Child Node的结果
*/
export class RepeatUntilSuccess extends Decorator {
/** 最大循环次数 @internal */
private _maxLoop: number;
/**
* 创建
* @param child 子节点
* @param maxLoop 最大循环次数
*/
constructor(child: BaseNode, maxLoop: number = -1) {
super(child);
this._maxLoop = maxLoop;
}
open(ticker: Ticker): void {
/**
* 打开
* @param {Ticker} ticker
*/
public open(ticker: Ticker): void {
ticker.blackboard.set("i", 0, ticker.tree.id, this.id);
}
tick(ticker: Ticker): Status {
/**
* 执行
* @param {Ticker} ticker
* @returns {Status}
*/
public tick(ticker: Ticker): Status {
if (this.children.length !== 1) {
throw new Error("(RepeatUntilSuccess)节点必须包含一个子节点");
}
@@ -262,6 +331,11 @@ export class RepeatUntilSuccess extends Decorator {
* 直接返回 RUNING
*/
export class Runner extends Decorator {
/**
* 执行
* @param {Ticker} ticker
* @returns {Status}
*/
public tick(ticker: Ticker): Status {
if (this.children.length !== 1) {
throw new Error("(Runner)节点必须包含一个子节点");
@@ -277,6 +351,11 @@ export class Runner extends Decorator {
* 直接返回 SUCCESS
*/
export class Succeeder extends Decorator {
/**
* 执行
* @param {Ticker} ticker
* @returns {Status}
*/
public tick(ticker: Ticker): Status {
if (this.children.length !== 1) {
throw new Error("(Succeeder)节点必须包含一个子节点");

View File

@@ -8,15 +8,25 @@ import { Ticker } from "./Ticker";
* 所有节点全部添加到树中
*/
export class BehaviorTree {
/** 行为树ID */
/** 行为树ID @internal */
private _id: string;
/** 行为树跟节点 */
/** 行为树跟节点 @internal */
private _root: BaseNode;
/**
* constructor
* @param root 根节点
*/
constructor(root: BaseNode) {
this._id = createUUID();
this._root = root;
}
/**
* 执行
* @param subject 主体
* @param blackboard 黑板
* @param ticker 更新器
*/
public tick(subject: any, blackboard: Blackboard, ticker?: Ticker): void {
ticker = ticker || new Ticker(subject, blackboard, this);
ticker.openNodes.length = 0;

View File

@@ -8,9 +8,13 @@ interface ITreeData {
/** 平台 */
export class Blackboard {
public interruptDefend: boolean = false; // 行为树打断保护
public interrupt: boolean = false; // 打断行为树的标记
/** 行为树打断保护 */
public interruptDefend: boolean = false;
/** 打断行为树的标记 */
public interrupt: boolean = false;
/** 基础记忆 @internal */
private _baseMemory: any;
/** 树记忆 @internal */
private _treeMemory: { [treeScope: string]: ITreeData };
constructor() {
@@ -18,21 +22,44 @@ export class Blackboard {
this._treeMemory = {};
}
clear(): void {
/**
* 清除
*/
public clear(): void {
this._baseMemory = {};
this._treeMemory = {};
}
set(key: string, value: any, treeScope?: string, nodeScope?: string): void {
/**
* 设置
* @param key 键
* @param value 值
* @param treeScope 树范围
* @param nodeScope 节点范围
*/
public set(key: string, value: any, treeScope?: string, nodeScope?: string): void {
let memory = this._getMemory(treeScope, nodeScope);
memory[key] = value;
}
get(key: string, treeScope?: string, nodeScope?: string): any {
/**
* 获取
* @param key 键
* @param treeScope 树范围
* @param nodeScope 节点范围
* @returns 值
*/
public get(key: string, treeScope?: string, nodeScope?: string): any {
let memory = this._getMemory(treeScope, nodeScope);
return memory[key];
}
/**
* 获取树记忆
* @param treeScope 树范围
* @returns 树记忆
* @internal
*/
private _getTreeMemory(treeScope: string): ITreeData {
if (!this._treeMemory[treeScope]) {
this._treeMemory[treeScope] = {
@@ -43,6 +70,13 @@ export class Blackboard {
return this._treeMemory[treeScope];
}
/**
* 获取节点记忆
* @param treeMemory 树记忆
* @param nodeScope 节点范围
* @returns 节点记忆
* @internal
*/
private _getNodeMemory(treeMemory: ITreeData, nodeScope: string): { [key: string]: any } {
let memory = treeMemory.nodeMemory;
if (!memory[nodeScope]) {
@@ -51,6 +85,13 @@ export class Blackboard {
return memory[nodeScope];
}
/**
* 获取记忆
* @param treeScope 树范围
* @param nodeScope 节点范围
* @returns 记忆
* @internal
*/
private _getMemory(treeScope?: string, nodeScope?: string): { [key: string]: any } {
let memory = this._baseMemory;
if (treeScope) {

View File

@@ -18,23 +18,38 @@ export class Ticker {
this.blackboard = blackboard;
}
/** 进入节点 */
enterNode(node: BaseNode): void {
/**
* 进入节点
* @param node 节点
*/
public enterNode(node: BaseNode): void {
this.nodeCount++;
this.openNodes.push(node);
}
/** 打开节点 */
openNode(node: BaseNode): void { }
/**
* 打开节点
* @param node 节点
*/
public openNode(node: BaseNode): void { }
/** 更新节点 */
tickNode(node: BaseNode): void { }
/**
* 更新节点
* @param node 节点
*/
public tickNode(node: BaseNode): void { }
/** 关闭节点 */
closeNode(node: BaseNode): void {
/**
* 关闭节点
* @param node 节点
*/
public closeNode(node: BaseNode): void {
this.openNodes.pop();
}
/** 退出节点 */
exitNode(node: BaseNode): void { }
/**
* 退出节点
* @param node 节点
*/
public exitNode(node: BaseNode): void { }
}

View File

@@ -4,6 +4,11 @@ export const enum Status {
RUNNING,
}
/**
* 创建UUID
* @returns UUID
* @internal
*/
export function createUUID(): string {
let s: string[] = Array(36);
let hexDigits = "0123456789abcdef";

View File

@@ -13,6 +13,7 @@ export class CocosAdapter extends Adapter {
/**
* 获取屏幕像素尺寸
* @returns {size}
* @internal
*/
protected getScreenSize(): size {
let windowSize = ccScreen.windowSize;
@@ -24,6 +25,7 @@ export class CocosAdapter extends Adapter {
/**
* 获取设计尺寸
* @returns {size}
* @internal
*/
protected getDesignSize(): size {
let designSize = view.getDesignResolutionSize();
@@ -32,7 +34,8 @@ export class CocosAdapter extends Adapter {
/**
* 设置尺寸发生变化的监听
* @param callback
* @param callback 回调
* @internal
*/
protected registerResizeCallback(callback: (...args: any) => void): void {
ccScreen.on("window-resize", (...args: any) => {

View File

@@ -33,6 +33,10 @@ export abstract class CocosEntry extends Component {
return {};
}
/**
* 开始初始化kunpo框架
* @internal
*/
protected start(): void {
info("开始初始化kunpo框架");
@@ -56,6 +60,10 @@ export abstract class CocosEntry extends Component {
this.onInit();
}
/**
* 初始化平台
* @internal
*/
private initPlatform(): void {
// 处理平台判断
Platform.isNative = sys.isNative;
@@ -105,10 +113,18 @@ export abstract class CocosEntry extends Component {
info(`platform: ${PlatformType[Platform.platform]}`);
}
/**
* 初始化事件
* @internal
*/
private initEvent(): void {
GlobalEvent._initGlobalEvent();
}
/**
* 初始化时间
* @internal
*/
private initTime(): void {
Time._configBoot();
InnerTimer.initTimer();
@@ -116,10 +132,18 @@ export abstract class CocosEntry extends Component {
this.schedule(this.tick.bind(this), 0, macro.REPEAT_FOREVER);
}
/**
* 初始化适配器
* @internal
*/
private initAdapter(): void {
new CocosAdapter().init();
}
/**
* 初始化模块
* @internal
*/
private initModule(): void {
info(`初始化模块`);
// 递归查找自身或所有子节点中指定类型的组件。
@@ -129,6 +153,11 @@ export abstract class CocosEntry extends Component {
}
}
/**
* 更新
* @param dt 时间间隔
* @internal
*/
private tick(dt: number): void {
InnerTimer.update(dt);
GlobalTimer.update(dt);

View File

@@ -19,7 +19,7 @@ const { ccclass, menu, property } = _decorator;
export class CocosUIModule extends ModuleBase {
/** 模块名称 */
public moduleName: string = "UI模块";
/** 模块初始化 (内部使用) */
/** 模块初始化 (内部使用) @internal */
public init(): void {
/** 初始化窗口管理系统 */
WindowManager._init(new WindowResPool());

View File

@@ -19,6 +19,7 @@ export class CocosWindowContainer extends Component {
@property({ displayName: "底部遮罩透明度", tooltip: "底部半透明遮罩的默认透明度", min: 0, max: 1, step: 0.01 }) bgAlpha: number = 0.75;
/**
* 初始化窗口容器
* @internal
*/
public init(): void {
let name = this.node.name;

View File

@@ -4,7 +4,7 @@
* @Description: 条件装饰器
*/
export namespace _conditionDecorator {
/** 用来存储条件注册信息 */
/** 用来存储条件注册信息 @internal */
const cdClassMap: Map<number, any> = new Map();
/** 获取组件注册信息 */

View File

@@ -9,20 +9,20 @@ import { ConditionMode } from "./ConditionMode";
import { ConditionBase } from "./node/ConditionBase";
import { ConditionNode } from "./node/ConditionNode";
export class ConditionManager {
/** 注册的 条件类型对应条件的信息 */
/** 注册的 条件类型对应条件的信息 @internal */
private static readonly _typeToCondition: Map<number, ConditionBase> = new Map<number, ConditionBase>();
/** 条件类型 对应 条件节点 */
/** 条件类型 对应 条件节点 @internal */
private static readonly _typeToNotifyNodes: Map<number, Set<ConditionNode>> = new Map<number, Set<ConditionNode>>();
/** 条件节点 对应 条件类型 */
/** 条件节点 对应 条件类型 @internal */
private static readonly _nodeToConditionTypes: Map<ConditionNode, Set<number>> = new Map<ConditionNode, Set<number>>();
/** 需要更新的条件 */
/** 需要更新的条件 @internal */
private static readonly _needUpdateConditions: Set<ConditionBase> = new Set<ConditionBase>();
/** 需要更新的节点 */
/** 需要更新的节点 @internal */
private static readonly _needUpdateNodes: Set<ConditionNode> = new Set<ConditionNode>();
/** 是否正在更新 */
/** 是否正在更新 @internal */
private static _updating: boolean = false;
/** 初始化所有条件,并全部更新一次 */
@@ -44,6 +44,7 @@ export class ConditionManager {
/**
* 添加条件
* @param {IConditionBase} condition 条件
* @internal
*/
private static _addCondition(condition: ConditionBase): void {
if (this._updating) {
@@ -54,7 +55,10 @@ export class ConditionManager {
this._needUpdateConditions.add(condition);
}
/**
* 刷新所有条件
* @internal
*/
private static _refreshAllConditions(): void {
let allCondition = this._typeToCondition;
for (const condition of allCondition.values()) {
@@ -65,6 +69,7 @@ export class ConditionManager {
/**
* 添加到更新列表中
* @param conditionType 条件类型
* @internal
*/
public static _addUpdateCondition(conditionType: number): void {
if (this._updating) {
@@ -81,6 +86,7 @@ export class ConditionManager {
* 添加条件节点
* @param notifyNode 条件节点
* @param conditionType 条件类型
* @internal
*/
public static _addConditionNode(conditionNode: ConditionNode, conditionType: number): void {
const condition = this._typeToCondition.get(conditionType);
@@ -108,6 +114,7 @@ export class ConditionManager {
* 移除条件节点
* @param conditionNode 条件节点
* @param conditionType 条件类型
* @internal
*/
public static _removeConditionNode(conditionNode: ConditionNode): void {
let types = this._nodeToConditionTypes.get(conditionNode);
@@ -121,12 +128,16 @@ export class ConditionManager {
/**
* 立即更新条件节点(内部使用)
* @param conditionNode 条件节点
* @internal
*/
public static _nowUpdateConditionNode(conditionNode: ConditionNode): void {
this._tryUpdateConditionNode(conditionNode);
}
/** 更新函数(内部使用)*/
/**
* 更新函数(内部使用)
* @internal
*/
public static _update(): void {
this._updating = true;
// 更新条件
@@ -150,7 +161,8 @@ export class ConditionManager {
/**
* 更新条件节点,如果状态改变,收集需要更新的通知节点(内部使用)
* @param {ConditionNode} conditionNode 条件节点
* @param {ConditionBase} condition 条件
* @internal
*/
private static _tryUpdateCondition(condition: ConditionBase): void {
// 更新条件
@@ -172,6 +184,7 @@ export class ConditionManager {
/**
* 更新条件节点(内部使用)
* @param {ConditionNode} conditionNode 条件节点
* @internal
*/
private static _tryUpdateConditionNode(conditionNode: ConditionNode): void {
if (!this._nodeToConditionTypes.has(conditionNode)) {

View File

@@ -24,6 +24,7 @@ export class ConditionModule extends ModuleBase {
/** 模块名称 */
public moduleName: string = "条件显示模块";
/** 计时器 @internal */
private _timer: number = 0;
public init(): void {
this.onInit();

View File

@@ -7,7 +7,7 @@
import { ConditionManager } from "../ConditionManager";
export abstract class ConditionBase {
/** 初始化 */
/** 初始化 @internal */
public _init(): void {
this.onInit();
}
@@ -15,6 +15,7 @@ export abstract class ConditionBase {
/** 条件类型 */
public type: number;
/** 是否可以通知 @internal */
private _canNotify: boolean;
/**
* 是否可以通知

View File

@@ -14,9 +14,11 @@ export class ConditionFGUINode extends ConditionNode {
* @protected
* @type {GObject | Node} fgui节点 或 node节点
* @memberof NotityFGUINode
* @internal
*/
protected node: GObject;
/** 旧的移除父节点 @internal */
private _oldRemoveFromParent: () => void;
/**
@@ -46,6 +48,10 @@ export class ConditionFGUINode extends ConditionNode {
}
}
/**
* 通知
* @param {boolean} visible 是否显示
*/
public notify(visible: boolean): void {
this.node.visible = visible;
}

View File

@@ -8,7 +8,7 @@ import { ConditionManager } from "../ConditionManager";
import { ConditionMode } from "../ConditionMode";
export abstract class ConditionNode {
/** 条件类型 */
/** 条件类型 @internal */
public _modeType: ConditionMode;
/**

View File

@@ -18,28 +18,28 @@ export abstract class Component extends ObjectBase {
/** 所属组件管理器 */
public componentManager: ComponentManager;
/** 是否需要销毁 */
/** 是否需要销毁 @internal */
public _needDestroy: boolean;
/** 更新ID */
/** 更新ID @internal */
public _updateId: number = -1;
/** 是否更新中 */
/** 是否更新中 @internal */
public get _updating(): boolean {
return this._updateId != -1;
}
/** 生命周期函数 添加到实体 */
/** 生命周期函数 添加到实体 @internal */
public _add(): void {
this.onAdd();
}
/** 生命周期函数 销毁 */
/** 生命周期函数 销毁 @internal */
public _destroy(): void {
this.onDestroy();
}
/** 生命周期函数 添加到实体后 在这个函数中可以获取其他组件 */
/** 生命周期函数 添加到实体后 在这个函数中可以获取其他组件 @internal */
public _enter(): void {
// 自动开启更新
if (this.needUpdate) {
@@ -48,14 +48,14 @@ export abstract class Component extends ObjectBase {
this.onEnter();
}
/** 生命周期函数 从实体中移除 */
/** 生命周期函数 从实体中移除 @internal */
public _remove(): void {
this.stopUpdate();
this.onRemove();
this.componentManager._destroyComponent(this);
}
/** 更新 */
/** 更新 @internal */
public _update(dt: number): void {
this.onUpdate(dt);
}

View File

@@ -3,18 +3,16 @@ import { ComponentPool } from "./ComponentPool";
/**
* 组件更新信息
*
* @export
* @class ComponentUpdate
* @internal
*/
export class ComponentUpdate {
/** 组件更新类型 */
public componentType: number;
/** 组件更新列表 */
/** 组件更新列表 @internal */
private readonly _components: Component[] = [];
/** create constructor */
/** create constructor @internal */
public constructor(componentType: number) {
this.componentType = componentType;
}
@@ -22,6 +20,7 @@ export class ComponentUpdate {
/**
* 添加要更新的组件
* @param component 组件
* @internal
*/
public addComponent(component: Component): void {
this._components.push(component);
@@ -31,6 +30,7 @@ export class ComponentUpdate {
/**
* 删除要更新的组件
* @param {Component} component 组件
* @internal
*/
public removeComponent(component: Component): void {
const components = this._components;
@@ -52,7 +52,7 @@ export class ComponentUpdate {
components.pop();
}
/** 更新 */
/** 更新 @internal */
public _update(dt: number): void {
const components = this._components;
const componentCount = components.length;
@@ -73,24 +73,28 @@ export class ComponentManager {
/**
* 组件池
* @type {ComponentPool}
* @internal
*/
protected componentPool: ComponentPool;
/** 更新组件池 */
/** 更新组件池 @internal */
protected readonly updatingComponents: ComponentUpdate[] = [];
/** 组件更新顺序 @internal */
protected readonly componentUpdateOrderList: number[] = [];
/** 新添加的或者新停止更新的组件池 */
/** 新添加的或者新停止更新的组件池 @internal */
private readonly _toUpdateComponents: Component[] = [];
/** 新停止更新的组件池 @internal */
private readonly _toStopComponents: Component[] = [];
/** 当前更新的组件类型 */
/** 当前更新的组件类型 @internal */
private _currentUpdateComponentType: number = -1;
/**
*Creates an instance of ComponentManager.
* @param {ComponentPool} componentPool 组件池
* @param {number[]} componentUpdateOrderList 组件更新顺序
* @internal
*/
constructor(componentPool: ComponentPool, componentUpdateOrderList: number[]) {
this.componentPool = componentPool;
@@ -101,6 +105,10 @@ export class ComponentManager {
}
}
/**
* 销毁组件管理器
* @internal
*/
public destroy(): void {
this.componentPool.clear();
this.updatingComponents.length = 0;
@@ -114,6 +122,7 @@ export class ComponentManager {
* @template T
* @param {string} componentName 组件名
* @returns {T} 创建的组件
* @internal
*/
public createComponent<T extends Component>(componentName: string): T {
const component = this.componentPool.get(componentName) as T;
@@ -158,6 +167,7 @@ export class ComponentManager {
/**
* 销毁组件(内部使用)
* @param {Component} component
* @internal
*/
public _destroyComponent(component: Component): void {
if (!component._updating) {
@@ -168,7 +178,11 @@ export class ComponentManager {
}
}
/** 更新所有组件(内部使用) */
/**
* 更新所有组件(内部使用)
* @param {number} dt 时间间隔
* @internal
*/
public _update(dt: number): void {
this._updateAllComponents(dt);
this._currentUpdateComponentType = -1;
@@ -180,6 +194,8 @@ export class ComponentManager {
/**
* 添加组件更新顺序,先添加的先更新
* @param {number} componentType 组件类型
* @returns {ComponentManager} 组件管理器
* @internal
*/
private _addComponentUpdateOrder(componentType: number): ComponentManager {
this.componentUpdateOrderList.push(componentType);
@@ -194,7 +210,11 @@ export class ComponentManager {
return this;
}
/** 添加组件到组件更新列表 */
/**
* 添加组件到组件更新列表
* @param {Component} component 组件
* @internal
*/
private _addComponentToUpdateList(component: Component): void {
if (component.type >= this.updatingComponents.length || !this.updatingComponents[component.type]) {
throw new Error(`组件(${component.constructor.name}没有添加到组件更新列表请使用addComponentUpdateOrder添加更新`);
@@ -202,12 +222,20 @@ export class ComponentManager {
this.updatingComponents[component.type].addComponent(component);
}
/** 组件更新列表中删除组件 */
/**
* 组件更新列表中删除组件
* @param {Component} component 组件
* @internal
*/
private _removeComponentToUpdateList(component: Component): void {
this.updatingComponents[component.type].removeComponent(component);
}
/** 更新所有组件 */
/**
* 更新所有组件
* @param {number} dt 时间间隔
* @internal
*/
private _updateAllComponents(dt: number): void {
// 按优先级更新所有组件
const updateList = this.componentUpdateOrderList;
@@ -221,6 +249,10 @@ export class ComponentManager {
}
}
/**
* 清除停止更新的组件
* @internal
*/
private _clearStopComponents(): void {
const toStopComponents = this._toStopComponents;
const l = toStopComponents.length;
@@ -238,6 +270,10 @@ export class ComponentManager {
}
}
/**
* 添加更新组件
* @internal
*/
private _addUpdateComponents(): void {
const toUpdateComponents = this._toUpdateComponents;
const l = toUpdateComponents.length;

View File

@@ -3,9 +3,11 @@ import { ObjectBase } from "./ObjectBase";
import { ObjectFactory } from "./ObjectFactory";
export class ComponentPool {
/** 组件对象类型到组件类型转换 */
/** 组件对象类型到组件类型转换 @internal */
private readonly _objectTypeToComponentType: number[] = new Array<number>(128);
/** 组件池 @internal */
private _pools: Map<number, ObjectFactory> = new Map();
/** 组件名称到组件对象类型转换 @internal */
private _nameToObjectType: Map<string, number> = new Map();
/**
* 注册组件
@@ -13,6 +15,7 @@ export class ComponentPool {
* @param {number} componentType 组件类型
* @param {string} name 组件名称
* @param {new () => Component} ctor 构造函数
* @internal
*/
public register(componentObjectType: number, componentType: number, name: string, ctor: new () => ObjectBase): void {
if (this._pools.has(componentObjectType)) {
@@ -28,6 +31,11 @@ export class ComponentPool {
objectTypeToComponentType[componentObjectType] = componentType;
}
/**
* 通过组件名称获取组件对象类型
* @param {string} componentName 组件名称
* @returns {number} 组件对象类型
*/
public getObjectTypeByName(componentName: string): number {
return this._nameToObjectType.get(componentName);
}
@@ -36,6 +44,8 @@ export class ComponentPool {
* 创建组件
* @param {number} componentName 组件名
* @returns {T} 创建的组件
* @template T
* @internal
*/
public get<T extends Component>(componentName: string): T {
let objectType = this.getObjectTypeByName(componentName);
@@ -54,6 +64,7 @@ export class ComponentPool {
* 通过组件对象类型获取组件类名
* @param {number} componentObjectType 组件类型
* @returns {string}
* @internal
*/
public className(componentObjectType: number): string {
const factory = this._pools.get(componentObjectType);
@@ -69,13 +80,17 @@ export class ComponentPool {
* 回收组件
* @param {BaseComponent} component 要回收的组件
* @memberof ComponentPool
* @internal
*/
public recycle(component: Component): void {
const objectFactory = this._pools.get(component.objectType);
objectFactory.recycle(component);
}
/** 清理缓存 */
/**
* 清理缓存
* @internal
*/
public clear(): void {
for (const factory of this._pools.values()) {
factory._clear();

View File

@@ -8,7 +8,7 @@ import { Component } from "./Component";
* @Description:
*/
export class ECDataHelper {
/** 组件池 */
/** 组件池 @internal */
public static _componentPool: ComponentPool = new ComponentPool();
/** 注册所有组件 */
public static registerComponents(): void {

View File

@@ -9,6 +9,7 @@ import { ObjectHelper } from "../tool/helper/ObjectHelper";
export namespace _ecdecorator {
/** @internal */
const ECPropMeta = "__ecpropmeta__"
type ECPropType = "int" | "float" | "string" | "boolean" | "size" | "vec2" | "vec3" | "color" | "asset" | "spriteframe" | "jsonAsset" | "particle" | "animation" | "audio" | "prefab" | "skeleton" | "enum" | "array" | "object" | "entity";

View File

@@ -21,9 +21,9 @@ interface IWorldConfig {
}
export class ECManager {
/** 实体管理器 */
/** 实体管理器 @internal */
private static _worlds: Map<string, IWorldConfig> = new Map();
/** 实体配置信息 */
/** 实体配置信息 @internal */
private static _entityList: { [name: string]: Record<string, any> } = {};
/** 注册所有组件 如果GameEntry因分包导致组件的代码注册晚于 CocosEntry的 onInit函数, 则需要在合适的时机手动调用此方法 */
@@ -130,6 +130,13 @@ export class ECManager {
return entity;
}
/**
* 添加组件到实体
* @param {EntityManager} world 实体管理器
* @param {Entity} entity 实体
* @param {Record<string, any>} componentsData 组件数据
* @internal
*/
private static _addComponentToEntity(world: EntityManager, entity: Entity, componentsData: Record<string, any>): void {
for (const componentName in componentsData) {
let component = world.createComponent(componentName);

View File

@@ -9,8 +9,11 @@
*/
import { Stack } from "../tool/DataStruct/Stack";
/** 实体索引位数 @internal */
export const EntityIndexBits = 16;
/** 实体索引掩码 @internal */
export const EntityIndexMask = (1 << EntityIndexBits) - 1;
/** 最大实体数量 @internal */
export const MaxEntityCount = 1 << EntityIndexBits;
export type EntityId = number;
@@ -18,6 +21,7 @@ export type EntityId = number;
* 2进制转10进制 (不支持小数和负数)
* @param {number} bitNumber 二进制数
* @return {number} 十进制数
* @internal
*/
export function bit2Decimal(bitNumber: number): number {
let bitString = String(bitNumber);
@@ -34,6 +38,7 @@ export function bit2Decimal(bitNumber: number): number {
* 10进制转2进制 (不支持小数和负数)
* @param {number} num 十进制数
* @return {number} 二进制数
* @internal
*/
export function decimal2Bit(num: number): number {
let stack = new Stack<number>();
@@ -54,6 +59,8 @@ export function decimal2Bit(num: number): number {
/**
* 通过实体id获取实体index
* @param id 实体id
* @return {number} 实体index
* @internal
*/
export function getEntityIndex(id: EntityId): number {
return id & EntityIndexMask;
@@ -61,7 +68,9 @@ export function getEntityIndex(id: EntityId): number {
/**
* 通过实体id获取实体版本
* @param id
* @param id 实体id
* @return {number} 实体版本
* @internal
*/
export function getEntityVersion(id: EntityId): number {
return id >>> EntityIndexBits;
@@ -70,6 +79,8 @@ export function getEntityVersion(id: EntityId): number {
/**
* 实体描述
* @param id 实体id
* @return {string} 实体描述
* @internal
*/
export function entityIdString(id: EntityId): string {
return `${getEntityIndex(id)}:${getEntityVersion(id)}`;

View File

@@ -51,8 +51,8 @@ export class Entity {
/**
* 实体被添加到EntityManager
* @internal
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
public _add(): void {
this.active = true;
for (const component of this.components.values()) {
@@ -62,9 +62,8 @@ export class Entity {
/**
* 实体销毁,不要手动调用
* @memberof Entity
* @internal
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
public _destroy(): void {
this.removeAllComponents();
this.tags && this.tags.clear();

View File

@@ -16,12 +16,14 @@ export class EntityManager {
/**
* 单例实体
* @type {Entity}
* @internal
*/
public readonly insEntity: Entity = new Entity();
/**
* 单例实体激活状态
* @type {boolean}
* @internal
*/
public insActive: boolean = false;
@@ -34,30 +36,32 @@ export class EntityManager {
/**
* 普通实体事件容器
* @type {EventManager}
* @internal
*/
private _eventManager: EventManager;
/**
* 单例实体消息监听容器
* @type {EventManager}
* @internal
*/
private _insEventManager: EventManager;
/** 实体池 */
/** 实体池 @internal */
private readonly _entityPool: Entity[] = [];
/** tag标记池 */
/** tag标记池 @internal */
private readonly _tagToEntity: Map<number, Set<EntityId>> = new Map<number, Set<EntityId>>();
/** 实体回收池 */
/** 实体回收池 @internal */
private _recyclePool: Entity[] = [];
/** 实体回收池最大容量 */
/** 实体回收池最大容量 @internal */
private _maxCapacityInPool: number;
/** 实体回收版本 */
/** 实体回收版本 @internal */
private _entityVersion: number[] = [];
/** 回收实体ID */
/** 回收实体ID @internal */
private _recycleEntityIds: EntityId[] = [];
/** 世界是否删除 */
/** 世界是否删除 @internal */
private _isDestroyed: boolean;
/** 是否正在更新 */
/** 是否正在更新 @internal */
private _updating: boolean;
/**
* 实体池最大容量,回收的多余的实体不会缓存
@@ -67,7 +71,6 @@ export class EntityManager {
* @param {number} [maxCapacityInPool=128] 实体回收池最大容量
* @param {number} [preloadEntityCount=32] 预加载Entity数量
*/
// eslint-disable-next-line prettier/prettier
constructor(name: string, componentPool: ComponentPool, componentUpdateOrderList: number[], maxCapacityInPool: number = 128, preloadEntityCount: number = 32) {
this.name = name;
if (preloadEntityCount >= MaxEntityCount) {
@@ -90,8 +93,8 @@ export class EntityManager {
* 添加实体标签(内部使用)
* @param {EntityId} entityId 实体Id
* @param {number} tag 标签
* @internal
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
public _addEntityTag(entityId: EntityId, tag: number): void {
this._validateEntityById(entityId);
let entitiesByTag = this._tagToEntity.get(tag);
@@ -106,8 +109,8 @@ export class EntityManager {
* 删除实体Tag内部使用
* @param {Entity} entity 实体
* @param {number} tag 标签
* @internal
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
public _removeEntityTag(entity: Entity, tag: number): void {
this._removeEntityTagById(entity.id, tag);
}
@@ -116,8 +119,8 @@ export class EntityManager {
* 通过实体ID删除实体Tag内部使用
* @param {EntityId} entityId 实体Id
* @param {number} tag 标签
* @internal
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
public _removeEntityTagById(entityId: EntityId, tag: number): void {
this._validateEntityById(entityId);
const entitiesByTag = this._tagToEntity.get(tag);
@@ -331,6 +334,7 @@ export class EntityManager {
* @param callback 事件回调
* @param entityId 实体ID
* @param once 是否单次事件
* @internal
*/
public _addEvent(eventName: string, callback: (...args: any[]) => void, entity: Entity, once: boolean = false): void {
if (entity == this.insEntity) {
@@ -347,6 +351,7 @@ export class EntityManager {
* @param eventName 消息名
* @param entityId 实体ID
* @param args 发送参数
* @internal
*/
public _sendEvent(eventName: string, entity: Entity, ...args: any[]): void {
if (entity == this.insEntity) {
@@ -356,6 +361,13 @@ export class EntityManager {
this._eventManager && this._eventManager.send(eventName, entity, ...args);
}
/**
* 移除消息监听 (内部使用)
* @param eventName 消息名
* @param entity 实体
* @param callback 事件回调
* @internal
*/
public _removeEvent(eventName: string, entity: Entity, callback?: (...args: any[]) => void): void {
if (entity == this.insEntity) {
this._insEventManager && this._insEventManager.remove(eventName, callback, entity);
@@ -364,7 +376,10 @@ export class EntityManager {
this._eventManager && this._eventManager.remove(eventName, callback, entity);
}
/** 更新 */
/**
* 更新
* @param {number} dt 时间间隔
*/
public update(dt: number): void {
this._updating = true;
this.componentManager._update(dt);
@@ -374,6 +389,7 @@ export class EntityManager {
/**
* 回收Entity
* @param {Entity} entity 要回收的Entity
* @internal
*/
private _recycleEntity(entity: Entity): void {
// 回收实体Id
@@ -388,8 +404,8 @@ export class EntityManager {
/**
* 销毁实体
* @param {Entity} entity
* @internal
*/
// eslint-disable-next-line @typescript-eslint/member-ordering
private _destroyEntity(entity: Entity): void {
entity._destroy();
if (this._recyclePool.length < this._maxCapacityInPool) {
@@ -400,6 +416,7 @@ export class EntityManager {
/**
* 实体根据tag添加到tag列表中
* @param entity
* @internal
*/
private _addEntityToTag(entity: Entity): void {
const tags = entity.tags;
@@ -412,6 +429,11 @@ export class EntityManager {
}
}
/**
* 验证实体ID是否存在
* @param {EntityId} entityId 实体ID
* @internal
*/
private _validateEntityById(entityId: EntityId): void {
if (!this.exists(entityId)) {
throw new Error(`实体(${entityId})不存在`);

View File

@@ -5,12 +5,12 @@ export class ObjectBase {
/** 对象类型 */
public objectType: number;
/** 回收 */
/** 回收 @internal */
public _recycle(): void {
this.recycled = true;
}
/** 重新利用 */
/** 重新利用 @internal */
public _reuse(): void {
this.recycled = false;
}

View File

@@ -1,5 +1,6 @@
import { ObjectBase } from "./ObjectBase";
/** @internal */
export class ObjectFactory {
/** 对象类 */
private _ctor: new () => ObjectBase;

View File

@@ -4,6 +4,7 @@
* @Description:
*/
/** @internal */
export class Event {
public id: number;
public name: string;

View File

@@ -6,6 +6,7 @@
import { Event } from "./Event";
/** @internal */
export class EventFactory {
private _id: number = 0;
private _stack: Event[] = [];

View File

@@ -8,9 +8,13 @@ import { Event } from "./Event";
import { EventFactory } from "./EventFactory";
export class EventManager {
/** @internal */
private _idToEvent: Map<number, Event> = new Map<number, Event>();
/** @internal */
private _nameToIds: Map<string, Set<number>> = new Map<string, Set<number>>();
/** @internal */
private _targetToIds: Map<any, Set<number>> = new Map<any, Set<number>>();
/** @internal */
private _factroy: EventFactory = new EventFactory(64, Event);
/**
* 添加事件监听器。
@@ -158,6 +162,7 @@ export class EventManager {
this._targetToIds.clear();
}
/** @internal */
public _addEvent(name: string, callback: (...arg: any[]) => void, once: boolean, target: any): void {
let listener = this._factroy.allocate<Event>();
listener.name = name;
@@ -188,6 +193,7 @@ export class EventManager {
}
}
/** @internal */
private _remove(id: number): void {
if (!this._idToEvent.has(id)) {
return;

View File

@@ -19,13 +19,15 @@ export abstract class WindowBase extends GComponent implements IWindow {
public adapterType: AdapterType = AdapterType.Full;
/** 底部遮罩的透明度 */
public bgAlpha: number;
/** header (内部使用) */
/** header (内部使用) @internal */
private _header: IWindowHeader = null;
/** 窗口是否被遮挡了 */
/** 窗口是否被遮挡了 @internal */
private _isCover: boolean = false;
/**
* 初始化方法 (框架内部使用)
* @param swallowTouch 是否吞噬触摸事件
* @param bgAlpha 底部遮罩的透明度
* @internal
*/
public _init(swallowTouch: boolean, bgAlpha: number): void {
if (swallowTouch) {
@@ -46,6 +48,10 @@ export abstract class WindowBase extends GComponent implements IWindow {
this.onInit();
}
/**
* 适配窗口
* @internal
*/
public _adapted(): void {
this.setPosition(Screen.ScreenWidth * 0.5, Screen.ScreenHeight * 0.5);
this.setPivot(0.5, 0.5, true);
@@ -64,6 +70,7 @@ export abstract class WindowBase extends GComponent implements IWindow {
/**
* 窗口关闭 (框架内部使用)
* @internal
*/
public _close(): void {
this.onClose();
@@ -72,6 +79,7 @@ export abstract class WindowBase extends GComponent implements IWindow {
/**
* 显示窗口 (框架内部使用)
* @param userdata 用户自定义数据
* @internal
*/
public _show(userdata?: any): void {
this.visible = true;
@@ -79,6 +87,7 @@ export abstract class WindowBase extends GComponent implements IWindow {
}
/**
* 隐藏窗口 (框架内部使用)
* @internal
*/
public _hide(): void {
this.visible = false;
@@ -86,6 +95,7 @@ export abstract class WindowBase extends GComponent implements IWindow {
}
/**
* 从隐藏状态恢复显示
* @internal
*/
public _showFromHide(): void {
this.visible = true;
@@ -94,6 +104,7 @@ export abstract class WindowBase extends GComponent implements IWindow {
/**
* 遮挡窗口 被同组或者不同组的其他窗口覆盖 (框架内部使用)
* @internal
*/
public _cover(): void {
this._isCover = true;
@@ -101,12 +112,18 @@ export abstract class WindowBase extends GComponent implements IWindow {
}
/**
* 遮挡恢复窗口 被同组或者不同组的其他窗口覆盖恢复 (框架内部使用)
* @internal
*/
public _recover(): void {
this._isCover = false;
this.onRecover();
}
/**
* 设置窗口深度
* @param depth 深度
* @internal
*/
public _setDepth(depth: number): void {
this.parent.setChildIndex(this, depth);
}
@@ -119,6 +136,7 @@ export abstract class WindowBase extends GComponent implements IWindow {
return this._isCover;
}
/** @internal */
public screenResize(): void {
this._adapted();
}
@@ -135,6 +153,7 @@ export abstract class WindowBase extends GComponent implements IWindow {
return this._header as T;
}
/** @internal */
public _setHeader<T extends IWindowHeader>(header: T): void {
this._header = header;
}

View File

@@ -15,7 +15,7 @@ import { IWindowHeader } from "../ui/IWindowHeader";
export abstract class WindowHeader extends GComponent implements IWindowHeader {
/** 窗口适配类型 */
public adapterType: AdapterType = AdapterType.Full;
/** 引用计数 */
/** 引用计数 @internal */
public _refCount: number = 0;
protected abstract onInit(): void;
@@ -31,6 +31,7 @@ export abstract class WindowHeader extends GComponent implements IWindowHeader {
/**
* 初始化 (内部方法)
* @internal
*/
public _init(): void {
this.onInit();
@@ -38,6 +39,7 @@ export abstract class WindowHeader extends GComponent implements IWindowHeader {
/**
* 窗口适配 (内部方法)
* @internal
*/
public _adapted(): void {
this.setPosition(Screen.ScreenWidth * 0.5, Screen.ScreenHeight * 0.5);
@@ -58,6 +60,7 @@ export abstract class WindowHeader extends GComponent implements IWindowHeader {
/**
* 显示 (内部方法)
* @param {IWindow} window 所属窗口
* @internal
*/
public _show(window: IWindow): void {
this.visible = true;
@@ -66,6 +69,7 @@ export abstract class WindowHeader extends GComponent implements IWindowHeader {
/**
* 隐藏 (内部方法)
* @internal
*/
public _hide(): void {
this.visible = false;
@@ -74,23 +78,33 @@ export abstract class WindowHeader extends GComponent implements IWindowHeader {
/**
* 关闭 (内部方法)
* @internal
*/
public _close(): void {
this.onClose();
this.dispose();
}
/** 增加引用计数 (内部方法) */
/**
* 增加引用计数 (内部方法)
* @internal
*/
public _addRef(): void {
this._refCount++;
}
/** 减少引用计数 (内部方法) */
/**
* 减少引用计数 (内部方法)
* @internal
*/
public _decRef(): number {
return --this._refCount;
}
/** 屏幕大小改变时被调用 (内部方法) */
/**
* 屏幕大小改变时被调用 (内部方法)
* @internal
*/
public _screenResize(): void {
this._adapted();
}

View File

@@ -11,6 +11,7 @@ import { Screen } from "./Screen";
import { size } from "./header";
export abstract class Adapter {
/** @internal */
public init() {
// 设计尺寸 不会变化
let designSize = this.getDesignSize();
@@ -25,6 +26,7 @@ export abstract class Adapter {
});
}
/** @internal */
protected resize(): void {
Screen.SafeAreaHeight = 60;
// 屏幕像素尺寸
@@ -55,6 +57,7 @@ export abstract class Adapter {
this.printScreen();
}
/** @internal */
private printScreen() {
info(`设计分辨率: ${Screen.DesignWidth}x${Screen.DesignHeight}`);
info(`屏幕分辨率: ${Screen.ScreenWidth}x${Screen.ScreenHeight}`);

View File

@@ -7,6 +7,7 @@
import { EventManager } from "../event/EventManager";
export class GlobalEvent {
/** @internal */
private static _globalEvent: EventManager = null;
public static add(eventName: string, callback: (...args: any[]) => void, target: any): void {
this._globalEvent.addEvent(eventName, callback, target);
@@ -36,6 +37,7 @@ export class GlobalEvent {
this._globalEvent.removeList(target);
}
/** @internal */
public static _initGlobalEvent(): void {
if (!this._globalEvent) {
this._globalEvent = new EventManager();

View File

@@ -7,10 +7,12 @@
import { Timer } from "../tool/timer/Timer";
export class GlobalTimer {
/** @internal */
private static _timer: Timer = null;
/**
* 初始化全局定时器设置定时器间隔为16毫秒。
* 此方法用于启动一个定时器实例,以便在整个应用程序中跟踪时间相关的操作。
* @internal
*/
public static initTimer(): void {
this._timer = new Timer(16);
@@ -19,6 +21,7 @@ export class GlobalTimer {
/**
* 获取全局定时器实例。如果定时器尚未初始化,则进行初始化。
* @returns {Timer} 全局定时器实例
* @internal
*/
public static get Timer(): Timer {
if (this._timer) {
@@ -70,6 +73,11 @@ export class GlobalTimer {
this.Timer.clear();
}
/**
* 更新定时器
* @param dt - 时间间隔
* @internal
*/
public static update(dt: number): void {
this._timer?.update(dt);
}

View File

@@ -5,6 +5,7 @@
*/
import { Timer } from "../tool/timer/Timer";
/** @internal */
export class InnerTimer {
private static _timer: Timer = null;
/**

View File

@@ -12,7 +12,7 @@ export abstract class ModuleBase extends Component implements IModule {
/** 模块名称 */
public moduleName: string;
/** 模块初始化 (内部使用) */
/** 模块初始化 (内部使用) @internal */
public init(): void { }
/** 模块初始化完成后调用的函数 */

View File

@@ -80,6 +80,7 @@ export class HttpManager {
* @param {IHttpEvent} netEvent 网络事件
* @param {any[]} headers 请求头 [key1, value1, key2, value2, ...] 形式
* @param {number} timeout (单位s) 请求超时时间 默认0 (0表示不超时)
* @internal
*/
private static _send(method: HttpRequestMethod, url: string, data: any, responseType: HttpResponseType, netEvent?: IHttpEvent, headers?: any[], timeout?: number): HttpRequest {
let http = new HttpRequest()

View File

@@ -11,7 +11,7 @@ import { IHttpResponse } from "./IHttpResponse";
export class HttpRequest implements IHttpRequest, IHttpResponse {
/** 请求方法 */
public method: HttpRequestMethod;
/** xhr实例 */
/** xhr实例 @internal */
private _xhr: XMLHttpRequest;
/** 请求超时时间 (s) */
public timeout: number;
@@ -22,7 +22,7 @@ export class HttpRequest implements IHttpRequest, IHttpResponse {
/** 响应数据 */
public data: HttpResponseDataType;
/** 网络事件回调 */
/** 网络事件回调 @internal */
private _callback: (result: "succeed" | "fail", response: IHttpResponse) => void;
/**
@@ -85,18 +85,25 @@ export class HttpRequest implements IHttpRequest, IHttpResponse {
/**
* 请求中断
*
* @internal
*/
private _onHttpAbort(): void {
this.message = "request aborted by user";
this.onError();
}
/**
* 请求错误
* @internal
*/
private _onHttpError(): void {
this.message = "request error";
this.onError();
}
/**
* @internal
*/
private _onHttpLoad(): void {
const xhr = this._xhr;
const status = xhr.status !== undefined ? xhr.status : 200;
@@ -108,6 +115,10 @@ export class HttpRequest implements IHttpRequest, IHttpResponse {
}
}
/**
* 请求超时
* @internal
*/
private _onHttpTimeout(): void {
this.message = "request timeout";
this.onError();
@@ -115,6 +126,7 @@ export class HttpRequest implements IHttpRequest, IHttpResponse {
/**
* 请求发生错误
* @internal
*/
private onError(): void {
this._callback?.("fail", this);
@@ -123,6 +135,7 @@ export class HttpRequest implements IHttpRequest, IHttpResponse {
/**
* 请求完成
* @internal
*/
private onComplete(): void {
try {
@@ -141,6 +154,10 @@ export class HttpRequest implements IHttpRequest, IHttpResponse {
}
}
/**
* 清除请求
* @internal
*/
private _clear(): void {
this._xhr.onabort = null;
this._xhr.onerror = null;

View File

@@ -22,6 +22,7 @@ export class Circle extends Shape {
return this.boundingBox;
}
/** @internal */
public drawShape(draw: Graphics): void {
draw && draw.circle(this.position.x, this.position.y, this.radius * this.scale);
}

View File

@@ -83,6 +83,7 @@ export class Polygon extends Shape {
}
}
/** @internal */
public drawShape(draw: Graphics): void {
if (draw) {
let points = this.points;

View File

@@ -50,11 +50,17 @@ export const QTConfig = {
}
export class QuadTree {
/** @internal */
private _draw: Graphics;
/** @internal */
private _shapes_map: Map<number, Shape[]>; // 根据类型存储形状对象
/** @internal */
private _trees: QuadTree[] = []; // 存储四个子节点
/** @internal */
private _level: number; // 树的深度
/** @internal */
private _bounds: Rect; // 树的外框
/** @internal */
private _ignore_shapes: Shape[] = []; // 不在树中的形状
/**
* 创建一个四叉树
@@ -107,6 +113,7 @@ export class QuadTree {
}
}
/** @internal */
private _insert(shape: Shape): void {
if (!this._shapes_map.has(shape.tag)) {
this._shapes_map.set(shape.tag, []);
@@ -177,7 +184,7 @@ export class QuadTree {
this._trees.length = 0;
}
/** 当前形状是否包含在象限内 */
/** 当前形状是否包含在象限内 @internal */
private _isInner(shape: Shape, bounds: Rect): boolean {
let rect = shape.getBoundingBox();
return (
@@ -195,6 +202,7 @@ export class QuadTree {
* 左上:象限二
* 左下:象限三
* 右下:象限四
* @internal
*/
private _getQuadrant(shape: Shape): Quadrant {
let bounds = this._bounds;
@@ -226,6 +234,7 @@ export class QuadTree {
* 如果某一个象限节点内存储的物体数量超过了MAX_OBJECTS最大数量
* 则需要对这个节点进行划分
* 它的工作就是将一个象限看作一个屏幕,将其划分为四个子象限
* @internal
*/
private _split(): void {
let bounds = this._bounds;
@@ -242,7 +251,7 @@ export class QuadTree {
);
}
/** 删除子树 */
/** 删除子树 @internal */
private _removeChildTree(): void {
if (this._trees.length > 0) {
if (this._totalSize() <= 0) {
@@ -251,7 +260,7 @@ export class QuadTree {
}
}
/** 更新忽略掉的形状 */
/** 更新忽略掉的形状 @internal */
private _updateIgnoreShapes(root: QuadTree): void {
let len = this._ignore_shapes.length;
if (len <= 0) {
@@ -270,7 +279,7 @@ export class QuadTree {
}
}
/** 更新有效的形状 */
/** 更新有效的形状 @internal */
private _updateShapes(root: QuadTree): void {
for (const shapes of this._shapes_map.values()) {
let len = shapes.length;
@@ -295,7 +304,7 @@ export class QuadTree {
}
}
/** 当前树以及子树中所有的形状数量 */
/** 当前树以及子树中所有的形状数量 @internal */
private _totalSize(): number {
let size = this._size();
for (const tree of this._trees) {
@@ -304,6 +313,7 @@ export class QuadTree {
return size;
}
/** 当前树中所有的形状数量 @internal */
private _size(): number {
let size = 0;
for (const shapes of this._shapes_map.values()) {
@@ -312,7 +322,7 @@ export class QuadTree {
return size + this._ignore_shapes.length;
}
/** 画出当前树的边界 */
/** 画出当前树的边界 @internal */
private _drawTreeBound(root: QuadTree): void {
if (!this._draw) {
return;
@@ -335,6 +345,7 @@ export class QuadTree {
}
}
/** 清除绘制 @internal */
private _strokeClear(): void {
this._draw && this._draw.clear();
}

View File

@@ -20,16 +20,16 @@ export abstract class Shape {
/** 缩放 */
public scale: number; // 缩放
/** 脏标记 用来重置包围盒 */
/** 脏标记 用来重置包围盒 @internal */
protected isDirty: boolean;
/** 包围盒 */
/** 包围盒 @internal */
protected boundingBox: Rect;
/** 位置 */
/** 位置 @internal */
protected _position: Vec2;
/** 旋转角度 */
/** 旋转角度 @internal */
protected _rotation: number;
constructor(tag: number) {
@@ -64,6 +64,7 @@ export abstract class Shape {
/** 包围盒 子类重写 */
public abstract getBoundingBox(): Rect;
/** @internal */
public drawShape(draw: Graphics): void {
}

View File

@@ -80,6 +80,7 @@ export class Binary {
* @param view DataView对象
* @param offset 当前偏移量
* @returns 下一个数据的偏移量
* @internal
*/
private static validateBinaryFormat(view: DataView, offset: number): number {
const type = view.getUint8(offset);
@@ -118,6 +119,7 @@ export class Binary {
}
}
/** @internal */
private static readValue(view: DataView, offset: number): any {
const type = view.getUint8(offset++);
@@ -166,6 +168,7 @@ export class Binary {
}
}
/** @internal */
private static writeValue(value: any, chunks: Uint8Array[]): void {
if (value === null) {
chunks.push(new Uint8Array([0]));
@@ -235,6 +238,7 @@ export class Binary {
}
}
/** @internal */
private static getNextOffset(view: DataView, offset: number): number {
const type = view.getUint8(offset);
switch (type) {

View File

@@ -11,8 +11,11 @@ export abstract class HeapNode {
export class BinaryHeap<T extends HeapNode> {
/** @internal */
private _nodes: Array<T>;
/** @internal */
private _size: number;
/** @internal */
private _capacity: number;
constructor(capacity: number) {
@@ -132,6 +135,7 @@ export class BinaryHeap<T extends HeapNode> {
return true;
}
/** @internal */
private _parent(index: number): number {
return (index - 1) >> 1;
}
@@ -144,6 +148,7 @@ export class BinaryHeap<T extends HeapNode> {
return this._size == 0;
}
/** @internal */
private _sortUp(node: T, index: number): void {
let parentIndex = this._parent(index);
const nodes = this._nodes;
@@ -159,6 +164,7 @@ export class BinaryHeap<T extends HeapNode> {
nodes[index] = node;
}
/** @internal */
private _sortDown(node: T, index: number): void {
let childIndex = (index << 1) + 1;
const nodes = this._nodes;

View File

@@ -25,8 +25,11 @@ export class DoublyNode<T> extends LinkedNode<T> {
/** 单向链表 */
export class LinkedList<T> {
/** @internal */
protected _equalsFn: (a: T, b: T) => boolean;
/** @internal */
protected _count: number;
/** @internal */
protected _head: LinkedNode<T>;
/**
* create
@@ -172,7 +175,9 @@ export class LinkedList<T> {
/** 双向链表 */
export class DoublyLinkedList<T> extends LinkedList<T> {
/** @internal */
protected _head: DoublyNode<T>; // 重新定义 head 类型
/** @internal */
protected _tail: DoublyNode<T>;
/**
* create

View File

@@ -1,6 +1,7 @@
import { DoublyLinkedList } from "./LinkedList";
export class Stack<T> {
/** @internal */
private _items: DoublyLinkedList<T>;
constructor(equalsFn?: (a: T, b: T) => boolean) {
this._items = new DoublyLinkedList<T>(equalsFn);

View File

@@ -44,4 +44,27 @@ export class MathTool {
}
return out;
}
/**
* 内部使用的辅助方法,用于计算平滑过渡的因子
* @internal
*/
public static calculateSmoothFactor(elapsedTime: number, responseTime: number): number {
return elapsedTime / (elapsedTime + responseTime);
}
/**
* 内部使用的工具方法,不应该在库外部使用
* @internal
*/
public static internalRoundToDecimal(value: number, decimals: number): number {
const factor = Math.pow(10, decimals);
return Math.round(value * factor) / factor;
}
/**
* 内部使用的辅助常量
* @internal
*/
public static readonly INTERNAL_EPSILON = 0.00001;
}

View File

@@ -11,16 +11,28 @@ import { log } from "./log";
let TimeCache: Date = null;
export class Time {
/** 游戏系统启动时间戳 */
/**
* 游戏系统启动时间戳
* @internal
*/
private static _osBootTime: number = 0;
/** 主动设置的网络时间 单位ms */
/**
* 主动设置的网络时间 单位ms
* @internal
*/
private static _netTime: number = 0;
/** 本地时间与网路时间的偏移量 单位ms */
/**
* 本地时间与网路时间的偏移量 单位ms
* @internal
*/
private static _netTimeDiff: number = 0;
/** 获取当前毫秒时间戳 */
/**
* 获取当前毫秒时间戳
* @internal
*/
private static _nowTimestamp: () => number;
/** 获取游戏系统启动时间戳 */

View File

@@ -1,7 +0,0 @@
/**
* @Author: Gongxh
* @Date: 2024-12-14
* @Description: tools 导出
*/

View File

@@ -4,6 +4,13 @@
* @Description: 对象帮助类
*/
export class ObjectHelper {
/**
* 获取对象属性
* @param obj 对象
* @param key 属性名
* @returns 属性值
* @internal
*/
public static getObjectProp(obj: Record<string, any>, key: string): any {
if (obj.hasOwnProperty(key)) {
return obj[key];

View File

@@ -9,15 +9,18 @@ import { TimerNode } from "./TimerNode";
import { TimerNodePool } from "./TimerNodePool";
export class Timer {
/** @internal */
private _timerNodeOrder: number = 0;
/** 经过的时间 */
/** 经过的时间 @internal */
private _elapsedTime: number = 0;
/** @internal */
private _pool: TimerNodePool;
/** @internal */
private _heap: BinaryHeap<TimerNode>;
/** 暂停的计时器 */
/** 暂停的计时器 @internal */
private _pausedTimers: Map<number, TimerNode>;
/**
@@ -31,9 +34,7 @@ export class Timer {
/**
* 定时器管理类
*
* @param {number} initTimerCapacity 初始定时器容量
* @memberof Timer
*/
public constructor(initTimerCapacity: number) {
this._heap = new BinaryHeap<TimerNode>(initTimerCapacity);
@@ -56,7 +57,6 @@ export class Timer {
/**
* 删除指定计时器
*
* @param {number} timerId 定时器ID
* @memberof Timer
*/
@@ -106,34 +106,10 @@ export class Timer {
}
}
// /**
// * 根据回调更新定时器
// *
// * @param {number} timerId 定时器ID
// * @param {number} interval 回调间隔
// * @param {number} loop 重复次数
// * @param {boolean} [resetTime=false] 是否更新下次回调时间(从当前时间开始计时)
// * @returns {boolean} 如果TimerID存在则返回true
// * @memberof Timer
// */
// public updateTimer(timerId: number, interval: number, loop: number, resetTime: boolean = false): boolean {
// const timerNode = this._pool.get(timerId);
// if (!timerNode) {
// return false;
// }
// timerNode.interval = interval;
// timerNode.loop = loop;
// if (resetTime) {
// timerNode.expireTime = this._elapsedTime + interval;
// }
// return this._heap.update(timerNode);
// }
/**
* 更新时钟
*
* @param {number} deltaTime 更新间隔
* @memberof Timer
* @internal
*/
public update(deltaTime: number): void {
const elapsedTime = (this._elapsedTime += deltaTime);
@@ -170,8 +146,6 @@ export class Timer {
/**
* 清空所有定时器
*
* @memberof Timer
*/
public clear(): void {
this._heap.clear();
@@ -180,6 +154,7 @@ export class Timer {
this._timerNodeOrder = 0;
}
/** @internal */
private _getTimerNode(callback: () => void, interval: number, loop: number): TimerNode {
const timerNode = this._pool.allocate();
@@ -193,6 +168,7 @@ export class Timer {
return timerNode;
}
/** @internal */
private _recycle(timerNode: TimerNode): void {
this._pool.recycle(timerNode.id);
}

View File

@@ -5,6 +5,7 @@
*/
import { HeapNode } from "../DataStruct/BinaryHeap";
/** @internal */
export class TimerNode extends HeapNode {
/** 定时器ID */
public id: number;

View File

@@ -11,12 +11,15 @@ const TimerVersionMask = (1 << TimerIdBit) - 1;
const TimerMaxVersion = TimerVersionMask;
export class TimerNodePool {
/** @internal */
private _pool: Array<TimerNode> = new Array<TimerNode>();
/** @internal */
private _freeIndices: Array<number> = new Array<number>();
/**
* 定时器池
* @param {number} capacity 初始容量
* @internal
*/
public constructor(capacity: number) {
for (let i = 0; i < capacity; ++i) {
@@ -31,6 +34,7 @@ export class TimerNodePool {
/**
* 分配定时器节点
* @returns {TimerNode} 定时器节点
* @internal
*/
public allocate(): TimerNode {
let timerNode: TimerNode;
@@ -59,6 +63,7 @@ export class TimerNodePool {
/**
* 回收定时器节点
* @param {number} timerId 定时器ID
* @internal
*/
public recycle(timerId: number): void {
const index = timerId >>> TimerIdBit;
@@ -82,6 +87,7 @@ export class TimerNodePool {
* 根据TimerID获取定时器节点
* @param {number} timerId 定时器ID
* @returns {TimerNode}
* @internal
*/
public get(timerId: number): TimerNode | undefined {
const index = timerId >>> TimerIdBit;
@@ -107,6 +113,7 @@ export class TimerNodePool {
/**
* 清空正在使用的Timer
* @internal
*/
public clear(): void {
const pools = this._pool;

View File

@@ -19,6 +19,7 @@ export class ComponentExtendHelper {
/**
* 注册自定义组件信息
* @param info
* @internal
*/
private static registerComponent(ctor: any, pkg: string, name: string): void {
// 自定义组件扩展

View File

@@ -17,43 +17,52 @@ export interface IWindow {
bgAlpha: number;
/**
* 窗口适配 (框架内部使用)
* @internal
*/
_adapted(): void;
/**
* 初始化方法 (框架内部使用)
* @param swallowTouch 是否吞噬触摸事件
* @internal
*/
_init(swallowTouch: boolean, bgAlpha: number): void;
/**
* 窗口关闭 (框架内部使用)
* @internal
*/
_close(): void;
/**
* 显示窗口 (框架内部使用)
* @param userdata 用户自定义数据
* @internal
*/
_show(userdata?: any): void;
/**
* 从隐藏状态恢复显示
* @internal
*/
_showFromHide(): void;
/**
* 隐藏窗口 (框架内部使用)
* @internal
*/
_hide(): void;
/**
* 窗口被遮挡 被同组或者不同组的其他窗口覆盖 (框架内部使用)
* @internal
*/
_cover(): void;
/**
* 恢复窗口遮挡 被同组或者不同组的其他窗口覆盖恢复 (框架内部使用)
* @internal
*/
_recover(): void;
/**
* 调整窗口的显示层级
* @param depth
* @internal
*/
_setDepth(depth: number): void;
@@ -75,5 +84,6 @@ export interface IWindow {
/** 获取资源栏数据 */
getHeaderInfo(): WindowHeaderInfo;
/** @internal */
_setHeader(header: IWindowHeader): void;
}

View File

@@ -11,35 +11,49 @@ export interface IWindowHeader {
name: string;
/** 窗口适配类型 */
adapterType: AdapterType;
/** 引用计数 */
/** 引用计数 @internal */
_refCount: number;
/**
* 初始化 (内部方法)
* @internal
*/
_init(): void;
/**
* 窗口适配 (内部方法)
* @internal
*/
_adapted(): void;
/**
* 显示 (内部方法)
* @param {IWindow} window 所属窗口
* @internal
*/
_show(window: IWindow): void;
/**
* 隐藏 (内部方法)
* @internal
*/
_hide(): void;
/**
* 关闭 (内部方法)
* @internal
*/
_close(): void;
/** 增加引用计数 (内部方法) */
/**
* 增加引用计数 (内部方法)
* @internal
*/
_addRef(): void;
/** 减少引用计数 (内部方法) */
/**
* 减少引用计数 (内部方法)
* @internal
*/
_decRef(): number;
/** 屏幕大小改变时被调用 (内部方法) */
/**
* 屏幕大小改变时被调用 (内部方法)
* @internal
*/
_screenResize(): void;
}

View File

@@ -16,13 +16,16 @@ interface IPropsInfo {
callbacks: (string | number)[];
}
/** @internal */
export class PropsHelper {
/** @internal */
private static _config: IPropsConfig = {};
/** @internal */
public static setConfig(config: IPropsConfig): void {
this._config = config;
}
/** 序列化属性 */
/** 序列化属性 @internal */
public static serializeProps(component: GComponent, packageName: string): void {
if (!this._config) {
return;
@@ -45,7 +48,7 @@ export class PropsHelper {
this.serializationCallbacksNode(component, callbacks);
}
/** 给界面中定义的属性赋值 */
/** 给界面中定义的属性赋值 @internal */
private static serializationPropsNode(component: GComponent, props: (string | number)[]) {
const propsCount = props.length;
// [name1, len, ...props1, name2, len, ...props2, ...]
@@ -65,6 +68,7 @@ export class PropsHelper {
}
}
/** 给界面中定义的回调赋值 @internal */
private static serializationCallbacksNode(component: GComponent, callbacks: (string | number)[]) {
const propsCount = callbacks.length;
// [name1, len, ...props1, name2, len, ...props2, ...]

View File

@@ -6,9 +6,13 @@
import { ObjectHelper } from "../tool/helper/ObjectHelper";
export namespace _uidecorator {
/** @internal */
const UIPropMeta = "__uipropmeta__"
/** @internal */
const UICBMeta = "__uicbmeta__"
/** @internal */
interface IUIInfoBase {
/** 构造函数 */
ctor: any;
@@ -20,6 +24,7 @@ export namespace _uidecorator {
/**
* 窗口属性注册数据结构
* @internal
*/
interface UIWindowInfo extends IUIInfoBase {
/** 配置信息 */
@@ -32,7 +37,7 @@ export namespace _uidecorator {
name: string;
};
}
/** 用来存储窗口注册信息 */
/** 用来存储窗口注册信息 @internal */
const uiclassMap: Map<any, UIWindowInfo> = new Map();
/** 获取窗口注册信息 */
@@ -67,6 +72,7 @@ export namespace _uidecorator {
/**
* 组件属性注册数据结构
* @internal
*/
interface IUIComInfo extends IUIInfoBase {
/** 配置信息 */
@@ -77,7 +83,7 @@ export namespace _uidecorator {
name: string;
};
}
/** 用来存储组件注册信息 */
/** 用来存储组件注册信息 @internal */
let uicomponentMap: Map<string, IUIComInfo> = new Map();
/** 获取组件注册信息 */
@@ -107,6 +113,7 @@ export namespace _uidecorator {
/**
* header属性注册数据结构
* @internal
*/
interface IUIHeaderInfo extends IUIInfoBase {
/** 配置信息 */
@@ -117,7 +124,7 @@ export namespace _uidecorator {
name: string;
};
}
/** 用来存储组件注册信息 */
/** 用来存储组件注册信息 @internal */
let uiheaderMap: Map<string, IUIHeaderInfo> = new Map();
/** 获取header注册信息 */

View File

@@ -16,23 +16,23 @@ import { WindowManager } from "./WindowManager";
import { WindowInfo } from "./WindowResPool";
export class WindowGroup {
/** 窗口组的名字 */
/** 窗口组的名字 @internal */
private _name: string = "";
/** 窗口组的根节点 */
/** 窗口组的根节点 @internal */
private _root: GComponent;
/** 忽略顶部窗口查询 */
/** 忽略顶部窗口查询 @internal */
private _ignoreQuery: boolean = false;
/** 吞噬触摸事件 */
/** 吞噬触摸事件 @internal */
private _swallowTouch: boolean = false;
/** 窗口容器中的窗口名列表 */
/** 窗口容器中的窗口名列表 @internal */
private _windowNames: string[] = [];
/** 窗口顶部资源栏 */
/** 窗口顶部资源栏 @internal */
private _headers: Map<string, WindowHeader> = new Map();
/** 半透明遮罩的透明度 */
/** 半透明遮罩的透明度 @internal */
private _bgAlpha: number = 0;
/** 半透明节点 */
/** 半透明节点 @internal */
private _alphaGraph: GGraph;
/** 半透明遮罩的颜色 */
/** 半透明遮罩的颜色 @internal */
private _color: Color = new Color(0, 0, 0, 255);
/**
@@ -65,6 +65,8 @@ export class WindowGroup {
* @param root 窗口组的根节点 一个fgui的组件
* @param ignoreQuery 是否忽略顶部窗口查询
* @param swallowTouch 是否吞掉触摸事件
* @param bgAlpha 半透明遮罩的透明度
* @internal
*/
constructor(name: string, root: GComponent, ignoreQuery: boolean, swallowTouch: boolean, bgAlpha: number) {
this._name = name;
@@ -86,6 +88,7 @@ export class WindowGroup {
/**
* 根据窗口名创建窗口 并添加到显示节点
* @param windowName 窗口名
* @internal
*/
private _createWindow(pkg: string, name: string): WindowBase {
let window = UIPackage.createObject(pkg, name) as WindowBase;
@@ -99,6 +102,11 @@ export class WindowGroup {
return window;
}
/**
* 添加窗口到显示节点
* @param window 窗口
* @internal
*/
private _addWindow(window: WindowBase): void {
this._root.addChild(window);
WindowManager._addWindow(window.name, window);
@@ -125,6 +133,7 @@ export class WindowGroup {
/**
* 移除指定名称的窗口。
* @param name 窗口的名称。
* @internal
*/
public _removeWindow(name: string): void {
let index = this._windowNames.lastIndexOf(name);
@@ -162,6 +171,7 @@ export class WindowGroup {
/**
* 将指定名称的窗口移动到窗口组的最顶层。
* @param name 窗口的名称。
* @internal
*/
public _moveWindowToTop(name: string): boolean {
let isMoved = false;
@@ -198,6 +208,7 @@ export class WindowGroup {
* 处理index下层窗口的隐藏状态的私有方法。递归调用
* @param index - 窗口索引
* @param isRecursion - 是否递归调用
* @internal
*/
private _processWindowHideStatus(index: number, isRecursion: boolean = true): void {
if (index < 0) {
@@ -237,6 +248,8 @@ export class WindowGroup {
/**
* 新创建窗口时,根据新创建的窗口类型
* 处理上一个窗口或者所有窗口的关闭
* @param window 新创建的窗口
* @internal
*/
private _processWindowCloseStatus(window: IWindow): void {
// 新创建窗口 如果需要关闭窗口或者关闭所有窗口 处理窗口的关闭
@@ -263,7 +276,10 @@ export class WindowGroup {
}
}
/** 处理header的显示状态 并调整层级 */
/**
* 处理header的显示状态 并调整层级
* @internal
*/
private _processHeaderStatus(): void {
// 找到第一个要显示的header
let firstHeader: WindowHeader = null;
@@ -303,6 +319,7 @@ export class WindowGroup {
/**
* 调整指定窗口的透明度图形。并根据窗口的背景透明度绘制半透明遮罩。
* @param window - 需要调整透明度的窗口对象。
* @internal
*/
private _adjustAlphaGraph(window: IWindow): void {
this._root.setChildIndex(this._alphaGraph, this._root.numChildren - 1);
@@ -329,7 +346,7 @@ export class WindowGroup {
}
/** 根据窗口 创建顶部资源栏 (内部方法) */
/** 根据窗口 创建顶部资源栏 (内部方法) @internal */
private _createHeader(window: IWindow): void {
// 只有创建界面的时候, 才会尝试创建顶部资源栏
let headerInfo = window.getHeaderInfo();
@@ -362,6 +379,7 @@ export class WindowGroup {
/**
* 顶部资源栏窗口 从管理器中移除 (内部方法)
* @param header 资源栏
* @internal
*/
public _removeHeader(header: WindowHeader): void {
if (this._headers.has(header.name)) {
@@ -376,12 +394,13 @@ export class WindowGroup {
/**
* 获取顶部资源栏 (内部方法)
* @param name 资源栏的名称
* @internal
*/
public _getHeader<T extends WindowHeader>(name: string): T | null {
return this._headers.get(name) as T;
}
/** 屏幕大小改变时被调用 (内部方法) */
/** 屏幕大小改变时被调用 (内部方法) @internal */
public _screenResize(): void {
this._headers.forEach((header) => {
header._screenResize();

View File

@@ -7,7 +7,7 @@
export class WindowHeaderInfo {
/** header名字 */
name: string;
/** 自定义数据 用于Header窗口 onShow方法的自定义参数 */
/** 自定义数据 用于Header窗口 onShow方法的自定义参数 @internal */
userdata: any;
/**

View File

@@ -13,13 +13,13 @@ import { WindowGroup } from "./WindowGroup";
import { WindowResPool } from "./WindowResPool";
export class WindowManager {
/** 窗口组 */
/** 窗口组 @internal */
private static _groups: Map<string, WindowGroup> = new Map();
/** 不忽略查询的窗口组名 */
/** 不忽略查询的窗口组名 @internal */
private static _queryGroupNames: string[] = [];
/** 所有窗口全部放到这个map中 */
/** 所有窗口全部放到这个map中 @internal */
private static _windows: Map<string, IWindow> = new Map();
/** 初始化时传入实例 */
/** 初始化时传入实例 @internal */
private static _resPool: WindowResPool;
/** 配置UI包的一些信息 (可以不配置 完全手动管理) */
@@ -175,6 +175,7 @@ export class WindowManager {
/**
* 初始化窗口管理器,设置资源池。 (框架内部使用)
* @param resPool - 窗口资源池实例。
* @internal
*/
public static _init(resPool: WindowResPool): void {
this._resPool = resPool;
@@ -184,6 +185,7 @@ export class WindowManager {
* 向窗口管理器添加一个新窗口。 (框架内部使用)
* @param name 窗口的唯一标识符。
* @param window 要添加的窗口对象,需实现 IWindow 接口。
* @internal
*/
public static _addWindow(name: string, window: IWindow): void {
this._windows.set(name, window);
@@ -192,6 +194,7 @@ export class WindowManager {
/**
* 移除指定名称的窗口。 (框架内部使用)
* @param name 窗口的名称。
* @internal
*/
public static _removeWindow(name: string): void {
if (this.hasWindow(name)) {
@@ -225,6 +228,7 @@ export class WindowManager {
/**
* 向窗口管理器添加一个窗口组 如果窗口组名称已存在,则抛出错误. (内部方法)
* @param group 要添加的窗口组
* @internal
*/
public static _addWindowGroup(group: WindowGroup): void {
if (this._groups.has(group.name)) {
@@ -237,6 +241,7 @@ export class WindowManager {
/**
* 屏幕大小改变时 调用所有窗口的screenResize方法 (内部方法)
* @internal
*/
public static _screenResize(): void {
this._windows.forEach((window: IWindow) => {
@@ -247,6 +252,11 @@ export class WindowManager {
});
}
/**
* 获取资源池实例 (内部方法)
* @returns {WindowResPool} 资源池实例
* @internal
*/
public static _getResPool(): WindowResPool {
return this._resPool;
}

View File

@@ -24,28 +24,34 @@ export interface HeaderInfo {
pkg: string;
}
/** @internal */
export class WindowResPool {
/** 窗口信息池 */
/** 窗口信息池 @internal */
protected _windowInfos: Map<string, WindowInfo> = new Map<string, any>();
/** 窗口header信息池 */
/** 窗口header信息池 @internal */
protected _headerInfos: Map<string, HeaderInfo> = new Map<string, any>();
/** 是否设置过配置内容 */
/** 是否设置过配置内容 @internal */
private _isInit: boolean = false;
/** 窗口名对应的包名列表 */
/** 窗口名对应的包名列表 @internal */
private _windowPkgs: Map<string, string[]> = new Map();
/** 包的引用计数 */
/** 包的引用计数 @internal */
private _pkgRefs: { [pkg: string]: number } = {};
/** UI包路径 @internal */
private _uipath: string = "";
/** 手动管理的包 @internal */
private _manualPackages: Set<string> = new Set();
/** 立即释放的包 @internal */
private _imReleasePackages: Set<string> = new Set();
/** 注册的回调函数 */
/** 注册的回调函数 @internal */
private _showWaitWindow: () => void = null;
/** 隐藏等待窗口的回调函数 @internal */
private _hideWaitWindow: () => void = null;
/** 加载失败回调函数 @internal */
private _fail: (windowName: string, errmsg: string, pkgs: string[]) => void = null;
/** 等待窗口的引用计数 */
/** 等待窗口的引用计数 @internal */
private _waitRef: number = 0;
/**

View File

@@ -8,6 +8,7 @@
"moduleResolution": "Node",
"skipLibCheck": true,
"esModuleInterop": true,
"stripInternal": true,
"types": [
"@cocos/creator-types/engine",
"@cocos/creator-types/editor",