Add serialization support for btGeneric6DofSpring2Constraint

Attempt to re-order serialization data so it can be serialized in-memory (for deep copy)
This commit is contained in:
erwincoumans
2014-09-16 09:22:35 -07:00
parent 11ded54a04
commit 89aeae9102
6 changed files with 800 additions and 923 deletions

View File

@@ -57,7 +57,6 @@ typedef struct bInvalidHandle {
class btCompoundShapeChildData; class btCompoundShapeChildData;
class btCompoundShapeData; class btCompoundShapeData;
class btCylinderShapeData; class btCylinderShapeData;
class btConeShapeData;
class btCapsuleShapeData; class btCapsuleShapeData;
class btTriangleInfoData; class btTriangleInfoData;
class btTriangleInfoMapData; class btTriangleInfoMapData;
@@ -65,32 +64,18 @@ typedef struct bInvalidHandle {
class btConvexHullShapeData; class btConvexHullShapeData;
class btCollisionObjectDoubleData; class btCollisionObjectDoubleData;
class btCollisionObjectFloatData; class btCollisionObjectFloatData;
class btDynamicsWorldDoubleData;
class btDynamicsWorldFloatData;
class btRigidBodyFloatData; class btRigidBodyFloatData;
class btRigidBodyDoubleData; class btRigidBodyDoubleData;
class btConstraintInfo1; class btConstraintInfo1;
class btTypedConstraintFloatData;
class btTypedConstraintData; class btTypedConstraintData;
class btTypedConstraintDoubleData;
class btPoint2PointConstraintFloatData; class btPoint2PointConstraintFloatData;
class btPoint2PointConstraintDoubleData2;
class btPoint2PointConstraintDoubleData; class btPoint2PointConstraintDoubleData;
class btHingeConstraintDoubleData; class btHingeConstraintDoubleData;
class btHingeConstraintFloatData; class btHingeConstraintFloatData;
class btHingeConstraintDoubleData2;
class btConeTwistConstraintDoubleData;
class btConeTwistConstraintData; class btConeTwistConstraintData;
class btGeneric6DofConstraintData; class btGeneric6DofConstraintData;
class btGeneric6DofConstraintDoubleData2;
class btGeneric6DofSpringConstraintData; class btGeneric6DofSpringConstraintData;
class btGeneric6DofSpringConstraintDoubleData2;
class btSliderConstraintData; class btSliderConstraintData;
class btSliderConstraintDoubleData;
class btGearConstraintFloatData;
class btGearConstraintDoubleData;
class btContactSolverInfoDoubleData;
class btContactSolverInfoFloatData;
class SoftBodyMaterialData; class SoftBodyMaterialData;
class SoftBodyNodeData; class SoftBodyNodeData;
class SoftBodyLinkData; class SoftBodyLinkData;
@@ -436,16 +421,6 @@ typedef struct bInvalidHandle {
}; };
// -------------------------------------------------- //
class btConeShapeData
{
public:
btConvexInternalShapeData m_convexInternalShapeData;
int m_upIndex;
char m_padding[4];
};
// -------------------------------------------------- // // -------------------------------------------------- //
class btCapsuleShapeData class btCapsuleShapeData
{ {
@@ -528,7 +503,6 @@ typedef struct bInvalidHandle {
double m_contactProcessingThreshold; double m_contactProcessingThreshold;
double m_deactivationTime; double m_deactivationTime;
double m_friction; double m_friction;
double m_rollingFriction;
double m_restitution; double m_restitution;
double m_hitFraction; double m_hitFraction;
double m_ccdSweptSphereRadius; double m_ccdSweptSphereRadius;
@@ -560,7 +534,6 @@ typedef struct bInvalidHandle {
float m_contactProcessingThreshold; float m_contactProcessingThreshold;
float m_deactivationTime; float m_deactivationTime;
float m_friction; float m_friction;
float m_rollingFriction;
float m_restitution; float m_restitution;
float m_hitFraction; float m_hitFraction;
float m_ccdSweptSphereRadius; float m_ccdSweptSphereRadius;
@@ -572,25 +545,6 @@ typedef struct bInvalidHandle {
int m_activationState1; int m_activationState1;
int m_internalType; int m_internalType;
int m_checkCollideWith; int m_checkCollideWith;
char m_padding[4];
};
// -------------------------------------------------- //
class btDynamicsWorldDoubleData
{
public:
btContactSolverInfoDoubleData m_solverInfo;
btVector3DoubleData m_gravity;
};
// -------------------------------------------------- //
class btDynamicsWorldFloatData
{
public:
btContactSolverInfoFloatData m_solverInfo;
btVector3FloatData m_gravity;
}; };
@@ -660,26 +614,6 @@ typedef struct bInvalidHandle {
}; };
// -------------------------------------------------- //
class btTypedConstraintFloatData
{
public:
btRigidBodyFloatData *m_rbA;
btRigidBodyFloatData *m_rbB;
char *m_name;
int m_objectType;
int m_userConstraintType;
int m_userConstraintId;
int m_needsFeedback;
float m_appliedImpulse;
float m_dbgDrawSize;
int m_disableCollisionsBetweenLinkedBodies;
int m_overrideNumSolverIterations;
float m_breakingImpulseThreshold;
int m_isEnabled;
};
// -------------------------------------------------- // // -------------------------------------------------- //
class btTypedConstraintData class btTypedConstraintData
{ {
@@ -700,27 +634,6 @@ typedef struct bInvalidHandle {
}; };
// -------------------------------------------------- //
class btTypedConstraintDoubleData
{
public:
btRigidBodyDoubleData *m_rbA;
btRigidBodyDoubleData *m_rbB;
char *m_name;
int m_objectType;
int m_userConstraintType;
int m_userConstraintId;
int m_needsFeedback;
double m_appliedImpulse;
double m_dbgDrawSize;
int m_disableCollisionsBetweenLinkedBodies;
int m_overrideNumSolverIterations;
double m_breakingImpulseThreshold;
int m_isEnabled;
char padding[4];
};
// -------------------------------------------------- // // -------------------------------------------------- //
class btPoint2PointConstraintFloatData class btPoint2PointConstraintFloatData
{ {
@@ -731,16 +644,6 @@ typedef struct bInvalidHandle {
}; };
// -------------------------------------------------- //
class btPoint2PointConstraintDoubleData2
{
public:
btTypedConstraintDoubleData m_typeConstraintData;
btVector3DoubleData m_pivotInA;
btVector3DoubleData m_pivotInB;
};
// -------------------------------------------------- // // -------------------------------------------------- //
class btPoint2PointConstraintDoubleData class btPoint2PointConstraintDoubleData
{ {
@@ -791,44 +694,6 @@ typedef struct bInvalidHandle {
}; };
// -------------------------------------------------- //
class btHingeConstraintDoubleData2
{
public:
btTypedConstraintDoubleData m_typeConstraintData;
btTransformDoubleData m_rbAFrame;
btTransformDoubleData m_rbBFrame;
int m_useReferenceFrameA;
int m_angularOnly;
int m_enableAngularMotor;
double m_motorTargetVelocity;
double m_maxMotorImpulse;
double m_lowerLimit;
double m_upperLimit;
double m_limitSoftness;
double m_biasFactor;
double m_relaxationFactor;
char m_padding1[4];
};
// -------------------------------------------------- //
class btConeTwistConstraintDoubleData
{
public:
btTypedConstraintDoubleData m_typeConstraintData;
btTransformDoubleData m_rbAFrame;
btTransformDoubleData m_rbBFrame;
double m_swingSpan1;
double m_swingSpan2;
double m_twistSpan;
double m_limitSoftness;
double m_biasFactor;
double m_relaxationFactor;
double m_damping;
};
// -------------------------------------------------- // // -------------------------------------------------- //
class btConeTwistConstraintData class btConeTwistConstraintData
{ {
@@ -863,22 +728,6 @@ typedef struct bInvalidHandle {
}; };
// -------------------------------------------------- //
class btGeneric6DofConstraintDoubleData2
{
public:
btTypedConstraintDoubleData m_typeConstraintData;
btTransformDoubleData m_rbAFrame;
btTransformDoubleData m_rbBFrame;
btVector3DoubleData m_linearUpperLimit;
btVector3DoubleData m_linearLowerLimit;
btVector3DoubleData m_angularUpperLimit;
btVector3DoubleData m_angularLowerLimit;
int m_useLinearReferenceFrameA;
int m_useOffsetForConstraintFrame;
};
// -------------------------------------------------- // // -------------------------------------------------- //
class btGeneric6DofSpringConstraintData class btGeneric6DofSpringConstraintData
{ {
@@ -891,18 +740,6 @@ typedef struct bInvalidHandle {
}; };
// -------------------------------------------------- //
class btGeneric6DofSpringConstraintDoubleData2
{
public:
btGeneric6DofConstraintDoubleData2 m_6dofData;
int m_springEnabled[6];
double m_equilibriumPoint[6];
double m_springStiffness[6];
double m_springDamping[6];
};
// -------------------------------------------------- // // -------------------------------------------------- //
class btSliderConstraintData class btSliderConstraintData
{ {
@@ -919,103 +756,6 @@ typedef struct bInvalidHandle {
}; };
// -------------------------------------------------- //
class btSliderConstraintDoubleData
{
public:
btTypedConstraintDoubleData m_typeConstraintData;
btTransformDoubleData m_rbAFrame;
btTransformDoubleData m_rbBFrame;
double m_linearUpperLimit;
double m_linearLowerLimit;
double m_angularUpperLimit;
double m_angularLowerLimit;
int m_useLinearReferenceFrameA;
int m_useOffsetForConstraintFrame;
};
// -------------------------------------------------- //
class btGearConstraintFloatData
{
public:
btTypedConstraintFloatData m_typeConstraintData;
btVector3FloatData m_axisInA;
btVector3FloatData m_axisInB;
float m_ratio;
char m_padding[4];
};
// -------------------------------------------------- //
class btGearConstraintDoubleData
{
public:
btTypedConstraintDoubleData m_typeConstraintData;
btVector3DoubleData m_axisInA;
btVector3DoubleData m_axisInB;
double m_ratio;
};
// -------------------------------------------------- //
class btContactSolverInfoDoubleData
{
public:
double m_tau;
double m_damping;
double m_friction;
double m_timeStep;
double m_restitution;
double m_maxErrorReduction;
double m_sor;
double m_erp;
double m_erp2;
double m_globalCfm;
double m_splitImpulsePenetrationThreshold;
double m_splitImpulseTurnErp;
double m_linearSlop;
double m_warmstartingFactor;
double m_maxGyroscopicForce;
double m_singleAxisRollingFrictionThreshold;
int m_numIterations;
int m_solverMode;
int m_restingContactRestitutionThreshold;
int m_minimumSolverBatchSize;
int m_splitImpulse;
char m_padding[4];
};
// -------------------------------------------------- //
class btContactSolverInfoFloatData
{
public:
float m_tau;
float m_damping;
float m_friction;
float m_timeStep;
float m_restitution;
float m_maxErrorReduction;
float m_sor;
float m_erp;
float m_erp2;
float m_globalCfm;
float m_splitImpulsePenetrationThreshold;
float m_splitImpulseTurnErp;
float m_linearSlop;
float m_warmstartingFactor;
float m_maxGyroscopicForce;
float m_singleAxisRollingFrictionThreshold;
int m_numIterations;
int m_solverMode;
int m_restingContactRestitutionThreshold;
int m_minimumSolverBatchSize;
int m_splitImpulse;
char m_padding[4];
};
// -------------------------------------------------- // // -------------------------------------------------- //
class SoftBodyMaterialData class SoftBodyMaterialData
{ {

View File

@@ -144,6 +144,7 @@ typedef unsigned long uintptr_t;
#include "BulletDynamics/ConstraintSolver/btConeTwistConstraint.h" #include "BulletDynamics/ConstraintSolver/btConeTwistConstraint.h"
#include "BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.h" #include "BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.h"
#include "BulletDynamics/ConstraintSolver/btGeneric6DofSpringConstraint.h" #include "BulletDynamics/ConstraintSolver/btGeneric6DofSpringConstraint.h"
#include "BulletDynamics/ConstraintSolver/btGeneric6DofSpring2Constraint.h"
#include "BulletDynamics/ConstraintSolver/btSliderConstraint.h" #include "BulletDynamics/ConstraintSolver/btSliderConstraint.h"
#include "BulletDynamics/ConstraintSolver/btGearConstraint.h" #include "BulletDynamics/ConstraintSolver/btGearConstraint.h"
#include "BulletDynamics/ConstraintSolver/btContactSolverInfo.h" #include "BulletDynamics/ConstraintSolver/btContactSolverInfo.h"
@@ -192,6 +193,7 @@ char *includefiles[] = {
"../../../src/BulletDynamics/ConstraintSolver/btConeTwistConstraint.h", "../../../src/BulletDynamics/ConstraintSolver/btConeTwistConstraint.h",
"../../../src/BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.h", "../../../src/BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.h",
"../../../src/BulletDynamics/ConstraintSolver/btGeneric6DofSpringConstraint.h", "../../../src/BulletDynamics/ConstraintSolver/btGeneric6DofSpringConstraint.h",
"../../../src/BulletDynamics/ConstraintSolver/btGeneric6DofSpring2Constraint.h",
"../../../src/BulletDynamics/ConstraintSolver/btSliderConstraint.h", "../../../src/BulletDynamics/ConstraintSolver/btSliderConstraint.h",
"../../../src/BulletDynamics/ConstraintSolver/btGearConstraint.h", "../../../src/BulletDynamics/ConstraintSolver/btGearConstraint.h",
"../../../src/BulletDynamics/ConstraintSolver/btContactSolverInfo.h", "../../../src/BulletDynamics/ConstraintSolver/btContactSolverInfo.h",

View File

@@ -1512,15 +1512,6 @@ void btCollisionWorld::debugDrawWorld()
void btCollisionWorld::serializeCollisionObjects(btSerializer* serializer) void btCollisionWorld::serializeCollisionObjects(btSerializer* serializer)
{ {
int i; int i;
//serialize all collision objects
for (i=0;i<m_collisionObjects.size();i++)
{
btCollisionObject* colObj = m_collisionObjects[i];
if (colObj->getInternalType() == btCollisionObject::CO_COLLISION_OBJECT)
{
colObj->serializeSingleObject(serializer);
}
}
///keep track of shapes already serialized ///keep track of shapes already serialized
btHashMap<btHashPtr,btCollisionShape*> serializedShapes; btHashMap<btHashPtr,btCollisionShape*> serializedShapes;
@@ -1537,6 +1528,15 @@ void btCollisionWorld::serializeCollisionObjects(btSerializer* serializer)
} }
} }
//serialize all collision objects
for (i=0;i<m_collisionObjects.size();i++)
{
btCollisionObject* colObj = m_collisionObjects[i];
if (colObj->getInternalType() == btCollisionObject::CO_COLLISION_OBJECT)
{
colObj->serializeSingleObject(serializer);
}
}
} }

View File

@@ -1456,10 +1456,10 @@ void btDiscreteDynamicsWorld::serialize(btSerializer* serializer)
serializeDynamicsWorldInfo(serializer); serializeDynamicsWorldInfo(serializer);
serializeRigidBodies(serializer);
serializeCollisionObjects(serializer); serializeCollisionObjects(serializer);
serializeRigidBodies(serializer);
serializer->finishSerialization(); serializer->finishSerialization();
} }

File diff suppressed because it is too large Load Diff

View File

@@ -98,6 +98,9 @@ public:
virtual void setSerializationFlags(int flags) = 0; virtual void setSerializationFlags(int flags) = 0;
virtual int getNumChunks() const = 0;
virtual const btChunk* getChunk(int chunkIndex) const = 0;
}; };
@@ -134,11 +137,35 @@ struct btPointerUid
}; };
}; };
struct btBulletSerializedArrays
{
btBulletSerializedArrays()
:m_bulletDnaVersion(0)
{
}
btAlignedObjectArray<struct btQuantizedBvhDoubleData*> m_bvhsDouble;
btAlignedObjectArray<struct btQuantizedBvhFloatData*> m_bvhsFloat;
btAlignedObjectArray<struct btCollisionShapeData*> m_colShapeData;
btAlignedObjectArray<struct btDynamicsWorldDoubleData*> m_dynamicWorldInfoDataDouble;
btAlignedObjectArray<struct btDynamicsWorldFloatData*> m_dynamicWorldInfoDataFloat;
btAlignedObjectArray<struct btRigidBodyDoubleData*> m_rigidBodyDataDouble;
btAlignedObjectArray<struct btRigidBodyFloatData*> m_rigidBodyDataFloat;
btAlignedObjectArray<struct btCollisionObjectDoubleData*> m_collisionDataDouble;
btAlignedObjectArray<struct btCollisionObjectFloatData*> m_collisionDataFloat;
btAlignedObjectArray<struct btTypedConstraintFloatData*> m_constraintDataFloat;
btAlignedObjectArray<struct btTypedConstraintDoubleData*> m_constraintDataDouble;
btAlignedObjectArray<struct btTypedConstraintData*> m_constraintData;//for backwards compatibility
};
///The btDefaultSerializer is the main Bullet serialization class. ///The btDefaultSerializer is the main Bullet serialization class.
///The constructor takes an optional argument for backwards compatibility, it is recommended to leave this empty/zero. ///The constructor takes an optional argument for backwards compatibility, it is recommended to leave this empty/zero.
class btDefaultSerializer : public btSerializer class btDefaultSerializer : public btSerializer
{ {
protected:
btAlignedObjectArray<char*> mTypes; btAlignedObjectArray<char*> mTypes;
btAlignedObjectArray<short*> mStructs; btAlignedObjectArray<short*> mStructs;
@@ -631,7 +658,15 @@ public:
{ {
m_serializationFlags = flags; m_serializationFlags = flags;
} }
int getNumChunks() const
{
return m_chunkPtrs.size();
}
const btChunk* getChunk(int chunkIndex) const
{
return m_chunkPtrs[chunkIndex];
}
}; };