| 1 | // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics) |
| 2 | // SPDX-FileCopyrightText: 2021 Jorrit Rouwe |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | |
| 5 | #include <Jolt/Jolt.h> |
| 6 | |
| 7 | #include <Jolt/Physics/Character/CharacterBase.h> |
| 8 | #include <Jolt/Physics/StateRecorder.h> |
| 9 | |
| 10 | JPH_NAMESPACE_BEGIN |
| 11 | |
| 12 | CharacterBase::CharacterBase(const CharacterBaseSettings *inSettings, PhysicsSystem *inSystem) : |
| 13 | mSystem(inSystem), |
| 14 | mShape(inSettings->mShape), |
| 15 | mUp(inSettings->mUp), |
| 16 | mSupportingVolume(inSettings->mSupportingVolume) |
| 17 | { |
| 18 | // Initialize max slope angle |
| 19 | SetMaxSlopeAngle(inSettings->mMaxSlopeAngle); |
| 20 | } |
| 21 | |
| 22 | const char *CharacterBase::sToString(EGroundState inState) |
| 23 | { |
| 24 | switch (inState) |
| 25 | { |
| 26 | case EGroundState::OnGround: return "OnGround"; |
| 27 | case EGroundState::OnSteepGround: return "OnSteepGround"; |
| 28 | case EGroundState::NotSupported: return "NotSupported"; |
| 29 | case EGroundState::InAir: return "InAir"; |
| 30 | } |
| 31 | |
| 32 | JPH_ASSERT(false); |
| 33 | return "Unknown"; |
| 34 | } |
| 35 | |
| 36 | void CharacterBase::SaveState(StateRecorder &inStream) const |
| 37 | { |
| 38 | inStream.Write(mGroundState); |
| 39 | inStream.Write(mGroundBodyID); |
| 40 | inStream.Write(mGroundBodySubShapeID); |
| 41 | inStream.Write(mGroundPosition); |
| 42 | inStream.Write(mGroundNormal); |
| 43 | inStream.Write(mGroundVelocity); |
| 44 | // Can't save user data (may be a pointer) and material |
| 45 | } |
| 46 | |
| 47 | void CharacterBase::RestoreState(StateRecorder &inStream) |
| 48 | { |
| 49 | inStream.Read(mGroundState); |
| 50 | inStream.Read(mGroundBodyID); |
| 51 | inStream.Read(mGroundBodySubShapeID); |
| 52 | inStream.Read(mGroundPosition); |
| 53 | inStream.Read(mGroundNormal); |
| 54 | inStream.Read(mGroundVelocity); |
| 55 | mGroundUserData = 0; // Cannot restore user data |
| 56 | mGroundMaterial = PhysicsMaterial::sDefault; // Cannot restore material |
| 57 | } |
| 58 | |
| 59 | JPH_NAMESPACE_END |