add root api doc (#4619)

This commit is contained in:
Weiliang Wang
2019-06-14 10:50:03 +08:00
committed by GitHub
parent 28b18223da
commit 2ce2bbf402
+132
View File
@@ -10,60 +10,120 @@ import { UI } from '../renderer/ui/ui';
export let _createSceneFun;
export let _createViewFun;
/**
* @zh
* Root描述信息
*/
export interface IRootInfo {
enableHDR?: boolean;
}
/**
* @zh
* 场景描述信息
*/
export interface ISceneInfo {
name: string;
}
/**
* @zh
* Root类
*/
export class Root {
/**
* @zh
* GFX设备
*/
public get device (): GFXDevice {
return this._device;
}
/**
* @zh
* 主窗口
*/
public get mainWindow (): GFXWindow | null {
return this._mainWindow;
}
/**
* @zh
* 当前窗口
*/
public get curWindow (): GFXWindow | null {
return this._curWindow;
}
/**
* @zh
* 窗口列表
*/
public get windows (): GFXWindow[] {
return this._windows;
}
/**
* @zh
* 渲染管线
*/
public get pipeline (): RenderPipeline {
return this._pipeline!;
}
/**
* @zh
* UI实例
*/
public get ui (): UI {
return this._ui as UI;
}
/**
* @zh
* 场景列表
*/
public get scenes (): RenderScene[] {
return this._scenes;
}
/**
* @zh
* 渲染视图列表
*/
public get views (): RenderView[] {
return this._views;
}
/**
* @zh
* 累计时间(秒)
*/
public get cumulativeTime (): number {
return this._time;
}
/**
* @zh
* 帧时间(秒)
*/
public get frameTime (): number {
return this._frameTime;
}
/**
* @zh
* 一秒内的累计帧数
*/
public get frameCount (): number {
return this._frameCount;
}
/**
* @zh
* 每秒帧率
*/
public get fps (): number {
return this._fps;
}
@@ -85,6 +145,11 @@ export class Root {
private _frameCount: number = 0;
private _fps: number = 0;
/**
* @zh
* 构造函数
* @param device GFX设备
*/
constructor (device: GFXDevice) {
this._device = device;
@@ -92,6 +157,11 @@ export class Root {
RenderView.registerCreateFunc(this);
}
/**
* @zh
* 初始化函数
* @param info Root描述信息
*/
public initialize (info: IRootInfo): boolean {
if (!this._device.mainWindow) {
@@ -142,6 +212,12 @@ export class Root {
this._mainWindow = null;
}
/**
* @zh
* 重置大小
* @param width 屏幕宽度
* @param height 屏幕高度
*/
public resize (width: number, height: number) {
// const w = width / cc.view._devicePixelRatio;
// const h = height / cc.view._devicePixelRatio;
@@ -165,14 +241,28 @@ export class Root {
}
}
/**
* @zh
* 激活指定窗口为当前窗口
* @param window GFX窗口
*/
public activeWindow (window: GFXWindow) {
this._curWindow = window;
}
/**
* @zh
* 重置累计时间
*/
public resetCumulativeTime () {
this._time = 0;
}
/**
* @zh
* 每帧执行函数
* @param deltaTime 间隔时间
*/
public frameMove (deltaTime: number) {
this._frameTime = deltaTime;
@@ -194,6 +284,11 @@ export class Root {
this._device.present();
}
/**
* @zh
* 创建窗口
* @param info GFX窗口描述信息
*/
public createWindow (info: IGFXWindowInfo): GFXWindow | null {
if (this._device) {
const window = this._device.createWindow(info);
@@ -206,6 +301,11 @@ export class Root {
return null;
}
/**
* @zh
* 销毁指定的窗口
* @param window GFX窗口
*/
public destroyWindow (window: GFXWindow) {
for (let i = 0; i < this._windows.length; ++i) {
if (this._windows[i] === window) {
@@ -216,6 +316,10 @@ export class Root {
}
}
/**
* @zh
* 销毁全部窗口
*/
public destroyWindows () {
for (const window of this._windows) {
window.destroy();
@@ -223,6 +327,11 @@ export class Root {
this._windows = [];
}
/**
* @zh
* 创建渲染场景
* @param info 渲染场景描述信息
*/
public createScene (info: IRenderSceneInfo): RenderScene {
const scene: RenderScene = this._createSceneFun(this);
scene.initialize(info);
@@ -230,6 +339,11 @@ export class Root {
return scene;
}
/**
* @zh
* 销毁指定的渲染场景
* @param scene 渲染场景
*/
public destroyScene (scene: RenderScene) {
for (let i = 0; i < this._scenes.length; ++i) {
if (this._scenes[i] === scene) {
@@ -240,6 +354,10 @@ export class Root {
}
}
/**
* @zh
* 销毁全部场景
*/
public destroyScenes () {
for (const scene of this._scenes) {
scene.destroy();
@@ -247,6 +365,11 @@ export class Root {
this._scenes = [];
}
/**
* @zh
* 创建渲染视图
* @param info 渲染视图描述信息
*/
public createView (info: IRenderViewInfo): RenderView {
const view: RenderView = this._createViewFun(this, info.camera);
view.initialize(info);
@@ -260,6 +383,11 @@ export class Root {
return view;
}
/**
* @zh
* 销毁指定的渲染视图
* @param view 渲染视图
*/
public destroyView (view: RenderView) {
for (let i = 0; i < this._views.length; ++i) {
if (this._views[i] === view) {
@@ -270,6 +398,10 @@ export class Root {
}
}
/**
* @zh
* 销毁全部渲染视图
*/
public destroyViews () {
for (const view of this._views) {
view.destroy();