| 930 | } |
| 931 | |
| 932 | void PhysicsWorld::update(float delta, bool userCall /* = false*/) |
| 933 | { |
| 934 | |
| 935 | if (_preUpdateCallback) |
| 936 | _preUpdateCallback(); // fix #11154 |
| 937 | |
| 938 | if (!_delayAddBodies.empty()) |
| 939 | { |
| 940 | updateBodies(); |
| 941 | } |
| 942 | else if (!_delayRemoveBodies.empty()) |
| 943 | { |
| 944 | updateBodies(); |
| 945 | } |
| 946 | |
| 947 | auto sceneToWorldTransform = _scene->getNodeToParentTransform(); |
| 948 | beforeSimulation(_scene, sceneToWorldTransform, 1.f, 1.f, 0.f); |
| 949 | |
| 950 | if (!_delayAddJoints.empty() || !_delayRemoveJoints.empty()) |
| 951 | { |
| 952 | updateJoints(); |
| 953 | } |
| 954 | |
| 955 | if (delta < FLT_EPSILON) |
| 956 | { |
| 957 | return; |
| 958 | } |
| 959 | |
| 960 | if (userCall) |
| 961 | { |
| 962 | # if AX_TARGET_PLATFORM == AX_PLATFORM_WIN32 |
| 963 | cpSpaceStep(_cpSpace, delta); |
| 964 | # else |
| 965 | cpHastySpaceStep(_cpSpace, delta); |
| 966 | # endif |
| 967 | } |
| 968 | else |
| 969 | { |
| 970 | _updateTime += delta; |
| 971 | if (_fixedRate) |
| 972 | { |
| 973 | const float step = 1.0f / _fixedRate; |
| 974 | const float dt = step * _speed; |
| 975 | while (_updateTime > step) |
| 976 | { |
| 977 | _updateTime -= step; |
| 978 | for (auto&& body : _bodies) |
| 979 | { |
| 980 | body->fixedUpdate(dt); |
| 981 | } |
| 982 | _scene->fixedUpdate(dt); |
| 983 | |
| 984 | # if AX_TARGET_PLATFORM == AX_PLATFORM_WIN32 |
| 985 | cpSpaceStep(_cpSpace, dt); |
| 986 | # else |
| 987 | cpHastySpaceStep(_cpSpace, dt); |
| 988 | # endif |
| 989 | } |
nothing calls this directly
no test coverage detected