From 3d2c385b7a1d633d520e0d658a9f5b7e929b138d Mon Sep 17 00:00:00 2001 From: "jiaxin.lai" Date: Mon, 1 Jul 2019 09:34:31 +0800 Subject: [PATCH] adjust physics system interface (#4759) --- cocos/3d/framework/physics/physics-system.ts | 81 +++++++++++++++----- 1 file changed, 61 insertions(+), 20 deletions(-) diff --git a/cocos/3d/framework/physics/physics-system.ts b/cocos/3d/framework/physics/physics-system.ts index f4135b811f..349a56052e 100644 --- a/cocos/3d/framework/physics/physics-system.ts +++ b/cocos/3d/framework/physics/physics-system.ts @@ -11,9 +11,11 @@ import { createPhysicsWorld } from '../../physics/instance'; */ export class PhysicsSystem { private _world: PhysicsWorldBase; - private _paused = false; - private _singleStep = false; + private _enable = true; private _deltaTime = 1.0 / 60.0; + private _maxSubStep = 2; + // private _frameRate = 60; + // private _singleStep = false; constructor () { this._world = createPhysicsWorld(); @@ -21,40 +23,79 @@ export class PhysicsSystem { /** * @zh - * 设置是否只运行一步。 - * @param b - 布尔值 + * 获取或设置是否启用物理系统,可以用于暂停或继续运行物理系统。 */ - public setSingleStep (b: boolean) { - this._singleStep = b; + public get enable (): boolean { + return this._enable; + } + + public set enable (value: boolean) { + this._enable = value; + } + + // shielding for alpha version + // /** + // * @zh + // * 获取或设置是否只运行一步。 + // * @param {boolean} b + // */ + // public get singleStep () { + // return this._singleStep; + // } + + // public set singleStep (b: boolean) { + // this._singleStep = b; + // } + + /** + * @zh + * 获取或设置每帧模拟的最大子步数。 + */ + public get maxSubStep () { + return this._maxSubStep; + } + + public set maxSubStep (value: number) { + this._maxSubStep = value; } /** * @zh - * 继续。 + * 获取或设置每步模拟消耗的固定时间。 */ - public resume () { - this._paused = false; + public get deltaTime () { + return this._deltaTime; } - /** - * @zh - * 暂停。 - */ - public pause () { - this._paused = true; + public set deltaTime (value: number) { + this._deltaTime = value; } + // shielding for alpha version + // /** + // * @zh + // * 获取或设置物理每秒模拟的帧率。 + // */ + // public get frameRate () { + // return this._frameRate; + // } + + // public set frameRate (value: number) { + // this._frameRate = value; + // this._deltaTime = 1 / this._frameRate; + // } + public update (deltaTime: number) { if (CC_EDITOR) { return; } - if (this._paused) { + if (!this._enable) { return; } - this._world.step(this._deltaTime); - if (this._singleStep) { - this._paused = true; - } + this._world.step(this._deltaTime, deltaTime, this._maxSubStep); + // if (this._singleStep) { + // this._enable = false; + // } } get world () {