mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
95a76235b6
`cocos/core` should not depend other modules, so move some files out of `cocos/core`: - move some files from `cocos/core` to `cocos/game` - director.ts - splash-screen.ts - game.ts - move `cocos/core/root.ts` to `cocos/root.ts` as there is not better module to contain `root.ts`. - move `cocos/core/platform/view.ts` to `cocos/ui/view.ts` as screen related logic is moved to `cocos/core/platform/screen.ts`
51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
import { Vec3 } from "../../cocos/core";
|
|
import { physics } from "../../exports/physics-framework";
|
|
import { Node } from "../../cocos/scene-graph";
|
|
import { director } from "../../cocos/game";
|
|
|
|
/**
|
|
* This function is used to test automatic sleep
|
|
*/
|
|
export default function (parent: Node, steps = 300) {
|
|
const nodeDynamicA = new Node('DynamicA');
|
|
parent.addChild(nodeDynamicA);
|
|
nodeDynamicA.worldPosition = new Vec3(0, 10, 0);
|
|
nodeDynamicA.addComponent(physics.SphereCollider);
|
|
const bodyA = nodeDynamicA.addComponent(physics.RigidBody) as physics.RigidBody;
|
|
|
|
const nodeDynamicB = new Node('DynamicB');
|
|
parent.addChild(nodeDynamicB);
|
|
nodeDynamicB.worldPosition = new Vec3(0, 5, 0);
|
|
const bodyB = nodeDynamicB.addComponent(physics.RigidBody) as physics.RigidBody;
|
|
nodeDynamicB.addComponent(physics.BoxCollider);
|
|
|
|
const nodeStatic = new Node('StaticB');
|
|
parent.addChild(nodeStatic);
|
|
nodeStatic.addComponent(physics.BoxCollider);
|
|
nodeStatic.worldScale = new Vec3(10, 1, 10);
|
|
|
|
expect(bodyA.isSleeping).toBe(false);
|
|
expect(bodyB.isSleeping).toBe(false);
|
|
expect(bodyA.isAwake).toBe(true);
|
|
expect(bodyB.isAwake).toBe(true);
|
|
|
|
const dt = physics.PhysicsSystem.instance.fixedTimeStep;
|
|
const middle = Math.floor(steps / 2);
|
|
for (let i = 0; i < steps; i++) {
|
|
if (i === middle) {
|
|
bodyA.wakeUp();
|
|
expect(bodyA.isSleeping).toBe(false);
|
|
expect(bodyA.isAwake).toBe(true);
|
|
}
|
|
director.tick(dt);
|
|
}
|
|
|
|
expect(bodyA.isSleeping).toBe(true);
|
|
expect(bodyB.isSleeping).toBe(true);
|
|
expect(bodyA.isAwake).toBe(false);
|
|
expect(bodyB.isAwake).toBe(false);
|
|
|
|
parent.destroyAllChildren();
|
|
parent.removeAllChildren();
|
|
}
|