More work on serialization and BulletFileLoader
This commit is contained in:
17
Extras/Serialize/BulletFileLoader/CMakeLists.txt
Normal file
17
Extras/Serialize/BulletFileLoader/CMakeLists.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
)
|
||||
|
||||
ADD_LIBRARY(
|
||||
BulletFileLoader
|
||||
bChunk.cpp
|
||||
bChunk.h
|
||||
bCommon.h
|
||||
bDefines.h
|
||||
bDNA.cpp
|
||||
bDNA.h
|
||||
bFile.cpp
|
||||
bFile.h
|
||||
btBulletFile.cpp
|
||||
btBulletFile.h
|
||||
)
|
||||
32
Extras/Serialize/BulletFileLoader/autogenerated/bullet.h
Normal file
32
Extras/Serialize/BulletFileLoader/autogenerated/bullet.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/* Copyright (C) 2006-2009 Erwin Coumans & Charlie C
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
// Auto generated from makesdna dna.c
|
||||
#ifndef __BULLET_H__
|
||||
#define __BULLET_H__
|
||||
#include "bullet_PointerArray.h"
|
||||
#include "bullet_btPhysicsSystem.h"
|
||||
#include "bullet_ListBase.h"
|
||||
#include "bullet_btVector3Data.h"
|
||||
#include "bullet_btMatrix3x3Data.h"
|
||||
#include "bullet_btTransformData.h"
|
||||
#include "bullet_btCollisionShapeData.h"
|
||||
#include "bullet_btConvexInternalShapeData.h"
|
||||
#include "bullet_btCollisionObjectData.h"
|
||||
#include "bullet_btRigidBodyData.h"
|
||||
#endif//__BULLET_H__
|
||||
@@ -0,0 +1,40 @@
|
||||
/* Copyright (C) 2006-2009 Erwin Coumans & Charlie C
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
// Auto generated from makesdna dna.c
|
||||
#ifndef __BULLETCOMMON_H__
|
||||
#define __BULLETCOMMON_H__
|
||||
|
||||
// put an empty struct in the case
|
||||
typedef struct bInvalidHandle {
|
||||
int unused;
|
||||
}bInvalidHandle;
|
||||
|
||||
namespace Bullet {
|
||||
class PointerArray;
|
||||
class btPhysicsSystem;
|
||||
class ListBase;
|
||||
class btVector3Data;
|
||||
class btMatrix3x3Data;
|
||||
class btTransformData;
|
||||
class btCollisionShapeData;
|
||||
class btConvexInternalShapeData;
|
||||
class btCollisionObjectData;
|
||||
class btRigidBodyData;
|
||||
}
|
||||
#endif//__BULLETCOMMON_H__
|
||||
@@ -0,0 +1,40 @@
|
||||
/* Copyright (C) 2006-2009 Erwin Coumans & Charlie C
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
// Auto generated from makesdna dna.c
|
||||
#ifndef __BULLET_LISTBASE__H__
|
||||
#define __BULLET_LISTBASE__H__
|
||||
|
||||
|
||||
// -------------------------------------------------- //
|
||||
#include "bullet_Common.h"
|
||||
|
||||
namespace Bullet {
|
||||
|
||||
|
||||
// ---------------------------------------------- //
|
||||
class ListBase
|
||||
{
|
||||
public:
|
||||
void *first;
|
||||
void *last;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif//__BULLET_LISTBASE__H__
|
||||
@@ -0,0 +1,41 @@
|
||||
/* Copyright (C) 2006-2009 Erwin Coumans & Charlie C
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
// Auto generated from makesdna dna.c
|
||||
#ifndef __BULLET_POINTERARRAY__H__
|
||||
#define __BULLET_POINTERARRAY__H__
|
||||
|
||||
|
||||
// -------------------------------------------------- //
|
||||
#include "bullet_Common.h"
|
||||
|
||||
namespace Bullet {
|
||||
|
||||
|
||||
// ---------------------------------------------- //
|
||||
class PointerArray
|
||||
{
|
||||
public:
|
||||
int m_size;
|
||||
int m_capacity;
|
||||
void *m_data;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif//__BULLET_POINTERARRAY__H__
|
||||
@@ -0,0 +1,63 @@
|
||||
/* Copyright (C) 2006-2009 Erwin Coumans & Charlie C
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
// Auto generated from makesdna dna.c
|
||||
#ifndef __BULLET_BTCOLLISIONOBJECTDATA__H__
|
||||
#define __BULLET_BTCOLLISIONOBJECTDATA__H__
|
||||
|
||||
|
||||
// -------------------------------------------------- //
|
||||
#include "bullet_Common.h"
|
||||
#include "bullet_btTransformData.h"
|
||||
#include "bullet_btVector3Data.h"
|
||||
|
||||
namespace Bullet {
|
||||
|
||||
|
||||
// ---------------------------------------------- //
|
||||
class btCollisionObjectData
|
||||
{
|
||||
public:
|
||||
btTransformData m_worldTransform;
|
||||
btTransformData m_interpolationWorldTransform;
|
||||
btVector3Data m_interpolationLinearVelocity;
|
||||
btVector3Data m_interpolationAngularVelocity;
|
||||
btVector3Data m_anisotropicFriction;
|
||||
int m_hasAnisotropicFriction;
|
||||
btScalar m_contactProcessingThreshold;
|
||||
void *m_broadphaseHandle;
|
||||
void *m_collisionShape;
|
||||
btCollisionShapeData *m_rootCollisionShape;
|
||||
int m_collisionFlags;
|
||||
int m_islandTag1;
|
||||
int m_companionId;
|
||||
int m_activationState1;
|
||||
btScalar m_deactivationTime;
|
||||
btScalar m_friction;
|
||||
btScalar m_restitution;
|
||||
int m_internalType;
|
||||
void *m_userObjectPointer;
|
||||
btScalar m_hitFraction;
|
||||
btScalar m_ccdSweptSphereRadius;
|
||||
btScalar m_ccdMotionThreshold;
|
||||
int m_checkCollideWith;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif//__BULLET_BTCOLLISIONOBJECTDATA__H__
|
||||
@@ -0,0 +1,41 @@
|
||||
/* Copyright (C) 2006-2009 Erwin Coumans & Charlie C
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
// Auto generated from makesdna dna.c
|
||||
#ifndef __BULLET_BTCOLLISIONSHAPEDATA__H__
|
||||
#define __BULLET_BTCOLLISIONSHAPEDATA__H__
|
||||
|
||||
|
||||
// -------------------------------------------------- //
|
||||
#include "bullet_Common.h"
|
||||
|
||||
namespace Bullet {
|
||||
|
||||
|
||||
// ---------------------------------------------- //
|
||||
class btCollisionShapeData
|
||||
{
|
||||
public:
|
||||
void *m_userPointer;
|
||||
int m_shapeType;
|
||||
char m_padding[4];
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif//__BULLET_BTCOLLISIONSHAPEDATA__H__
|
||||
@@ -0,0 +1,45 @@
|
||||
/* Copyright (C) 2006-2009 Erwin Coumans & Charlie C
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
// Auto generated from makesdna dna.c
|
||||
#ifndef __BULLET_BTCONVEXINTERNALSHAPEDATA__H__
|
||||
#define __BULLET_BTCONVEXINTERNALSHAPEDATA__H__
|
||||
|
||||
|
||||
// -------------------------------------------------- //
|
||||
#include "bullet_Common.h"
|
||||
#include "bullet_btCollisionShapeData.h"
|
||||
#include "bullet_btVector3Data.h"
|
||||
|
||||
namespace Bullet {
|
||||
|
||||
|
||||
// ---------------------------------------------- //
|
||||
class btConvexInternalShapeData
|
||||
{
|
||||
public:
|
||||
btCollisionShapeData m_collisionShapeData;
|
||||
btVector3Data m_localScaling;
|
||||
btVector3Data m_implicitShapeDimensions;
|
||||
btScalar m_collisionMargin;
|
||||
char m_padding[4];
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif//__BULLET_BTCONVEXINTERNALSHAPEDATA__H__
|
||||
@@ -0,0 +1,40 @@
|
||||
/* Copyright (C) 2006-2009 Erwin Coumans & Charlie C
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
// Auto generated from makesdna dna.c
|
||||
#ifndef __BULLET_BTMATRIX3X3DATA__H__
|
||||
#define __BULLET_BTMATRIX3X3DATA__H__
|
||||
|
||||
|
||||
// -------------------------------------------------- //
|
||||
#include "bullet_Common.h"
|
||||
#include "bullet_btVector3Data.h"
|
||||
|
||||
namespace Bullet {
|
||||
|
||||
|
||||
// ---------------------------------------------- //
|
||||
class btMatrix3x3Data
|
||||
{
|
||||
public:
|
||||
btVector3Data m_el[3];
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif//__BULLET_BTMATRIX3X3DATA__H__
|
||||
@@ -0,0 +1,42 @@
|
||||
/* Copyright (C) 2006-2009 Erwin Coumans & Charlie C
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
// Auto generated from makesdna dna.c
|
||||
#ifndef __BULLET_BTPHYSICSSYSTEM__H__
|
||||
#define __BULLET_BTPHYSICSSYSTEM__H__
|
||||
|
||||
|
||||
// -------------------------------------------------- //
|
||||
#include "bullet_Common.h"
|
||||
#include "bullet_PointerArray.h"
|
||||
|
||||
namespace Bullet {
|
||||
|
||||
|
||||
// ---------------------------------------------- //
|
||||
class btPhysicsSystem
|
||||
{
|
||||
public:
|
||||
PointerArray m_collisionShapes;
|
||||
PointerArray m_collisionObjects;
|
||||
PointerArray m_constraints;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif//__BULLET_BTPHYSICSSYSTEM__H__
|
||||
@@ -0,0 +1,62 @@
|
||||
/* Copyright (C) 2006-2009 Erwin Coumans & Charlie C
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
// Auto generated from makesdna dna.c
|
||||
#ifndef __BULLET_BTRIGIDBODYDATA__H__
|
||||
#define __BULLET_BTRIGIDBODYDATA__H__
|
||||
|
||||
|
||||
// -------------------------------------------------- //
|
||||
#include "bullet_Common.h"
|
||||
#include "bullet_btCollisionObjectData.h"
|
||||
#include "bullet_btMatrix3x3Data.h"
|
||||
#include "bullet_btVector3Data.h"
|
||||
|
||||
namespace Bullet {
|
||||
|
||||
|
||||
// ---------------------------------------------- //
|
||||
class btRigidBodyData
|
||||
{
|
||||
public:
|
||||
btCollisionObjectData m_collisionObjectData;
|
||||
btMatrix3x3Data m_invInertiaTensorWorld;
|
||||
btVector3Data m_linearVelocity;
|
||||
btVector3Data m_angularVelocity;
|
||||
btScalar m_inverseMass;
|
||||
btVector3Data m_angularFactor;
|
||||
btVector3Data m_linearFactor;
|
||||
btVector3Data m_gravity;
|
||||
btVector3Data m_gravity_acceleration;
|
||||
btVector3Data m_invInertiaLocal;
|
||||
btVector3Data m_totalForce;
|
||||
btVector3Data m_totalTorque;
|
||||
btScalar m_linearDamping;
|
||||
btScalar m_angularDamping;
|
||||
int m_additionalDamping;
|
||||
btScalar m_additionalDampingFactor;
|
||||
btScalar m_additionalLinearDampingThresholdSqr;
|
||||
btScalar m_additionalAngularDampingThresholdSqr;
|
||||
btScalar m_additionalAngularDampingFactor;
|
||||
btScalar m_linearSleepingThreshold;
|
||||
btScalar m_angularSleepingThreshold;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif//__BULLET_BTRIGIDBODYDATA__H__
|
||||
@@ -0,0 +1,42 @@
|
||||
/* Copyright (C) 2006-2009 Erwin Coumans & Charlie C
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
// Auto generated from makesdna dna.c
|
||||
#ifndef __BULLET_BTTRANSFORMDATA__H__
|
||||
#define __BULLET_BTTRANSFORMDATA__H__
|
||||
|
||||
|
||||
// -------------------------------------------------- //
|
||||
#include "bullet_Common.h"
|
||||
#include "bullet_btMatrix3x3Data.h"
|
||||
#include "bullet_btVector3Data.h"
|
||||
|
||||
namespace Bullet {
|
||||
|
||||
|
||||
// ---------------------------------------------- //
|
||||
class btTransformData
|
||||
{
|
||||
public:
|
||||
btMatrix3x3Data m_basis;
|
||||
btVector3Data m_origin;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif//__BULLET_BTTRANSFORMDATA__H__
|
||||
@@ -0,0 +1,39 @@
|
||||
/* Copyright (C) 2006-2009 Erwin Coumans & Charlie C
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
// Auto generated from makesdna dna.c
|
||||
#ifndef __BULLET_BTVECTOR3DATA__H__
|
||||
#define __BULLET_BTVECTOR3DATA__H__
|
||||
|
||||
|
||||
// -------------------------------------------------- //
|
||||
#include "bullet_Common.h"
|
||||
|
||||
namespace Bullet {
|
||||
|
||||
|
||||
// ---------------------------------------------- //
|
||||
class btVector3Data
|
||||
{
|
||||
public:
|
||||
btScalar m_floats[4];
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif//__BULLET_BTVECTOR3DATA__H__
|
||||
188
Extras/Serialize/BulletFileLoader/bChunk.cpp
Normal file
188
Extras/Serialize/BulletFileLoader/bChunk.cpp
Normal file
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
bParse
|
||||
Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include <memory.h>
|
||||
#include "bChunk.h"
|
||||
#include "bDefines.h"
|
||||
#include "bFile.h"
|
||||
|
||||
using namespace bParse;
|
||||
|
||||
|
||||
// ----------------------------------------------------- //
|
||||
short ChunkUtils::swapShort(short sht)
|
||||
{
|
||||
SWITCH_SHORT(sht);
|
||||
return sht;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------- //
|
||||
int ChunkUtils::swapInt(int inte)
|
||||
{
|
||||
SWITCH_INT(inte);
|
||||
return inte;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------- //
|
||||
long64 ChunkUtils::swapLong64(long64 lng)
|
||||
{
|
||||
SWITCH_LONGINT(lng);
|
||||
return lng;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------- //
|
||||
int ChunkUtils::getOffset(int flags)
|
||||
{
|
||||
// if the file is saved in a
|
||||
// different format, get the
|
||||
// file's chunk size
|
||||
int res = CHUNK_HEADER_LEN;
|
||||
|
||||
if (VOID_IS_8)
|
||||
{
|
||||
if (flags &FD_BITS_VARIES)
|
||||
res = sizeof(bChunkPtr4);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (flags &FD_BITS_VARIES)
|
||||
res = sizeof(bChunkPtr8);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------- //
|
||||
int ChunkUtils::getNextBlock(bChunkInd *dataChunk, char *dataPtr, const int flags)
|
||||
{
|
||||
bool swap = false;
|
||||
bool varies = false;
|
||||
|
||||
if (flags &FD_ENDIAN_SWAP) swap = true;
|
||||
if (flags &FD_BITS_VARIES) varies = true;
|
||||
|
||||
if (VOID_IS_8)
|
||||
{
|
||||
if (varies)
|
||||
{
|
||||
bChunkPtr4 head;
|
||||
memcpy(&head, dataPtr, sizeof(bChunkPtr4));
|
||||
|
||||
|
||||
bChunkPtr8 chunk;
|
||||
|
||||
chunk.code = head.code;
|
||||
chunk.len = head.len;
|
||||
chunk.old = head.old;
|
||||
chunk.dna_nr = head.dna_nr;
|
||||
chunk.nr = head.nr;
|
||||
|
||||
if (swap)
|
||||
{
|
||||
if ((chunk.code & 0xFFFF)==0)
|
||||
chunk.code >>=16;
|
||||
|
||||
SWITCH_INT(chunk.len);
|
||||
SWITCH_INT(chunk.dna_nr);
|
||||
SWITCH_INT(chunk.nr);
|
||||
}
|
||||
|
||||
|
||||
memcpy(dataChunk, &chunk, sizeof(bChunkInd));
|
||||
}
|
||||
else
|
||||
{
|
||||
bChunkPtr8 c;
|
||||
memcpy(&c, dataPtr, sizeof(bChunkPtr8));
|
||||
|
||||
if (swap)
|
||||
{
|
||||
if ((c.code & 0xFFFF)==0)
|
||||
c.code >>=16;
|
||||
|
||||
SWITCH_INT(c.len);
|
||||
SWITCH_INT(c.dna_nr);
|
||||
SWITCH_INT(c.nr);
|
||||
}
|
||||
|
||||
memcpy(dataChunk, &c, sizeof(bChunkInd));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (varies)
|
||||
{
|
||||
bChunkPtr8 head;
|
||||
memcpy(&head, dataPtr, sizeof(bChunkPtr8));
|
||||
|
||||
|
||||
bChunkPtr4 chunk;
|
||||
chunk.code = head.code;
|
||||
chunk.len = head.len;
|
||||
|
||||
long64 oldPtr =0;
|
||||
|
||||
memcpy(&oldPtr, &head.old, 8);
|
||||
chunk.old = (int)(oldPtr >> 3);
|
||||
|
||||
chunk.dna_nr = head.dna_nr;
|
||||
chunk.nr = head.nr;
|
||||
|
||||
if (swap)
|
||||
{
|
||||
if ((chunk.code & 0xFFFF)==0)
|
||||
chunk.code >>=16;
|
||||
|
||||
SWITCH_INT(chunk.len);
|
||||
SWITCH_INT(chunk.dna_nr);
|
||||
SWITCH_INT(chunk.nr);
|
||||
}
|
||||
|
||||
memcpy(dataChunk, &chunk, sizeof(bChunkInd));
|
||||
}
|
||||
else
|
||||
{
|
||||
bChunkPtr4 c;
|
||||
memcpy(&c, dataPtr, sizeof(bChunkPtr4));
|
||||
|
||||
if (swap)
|
||||
{
|
||||
if ((c.code & 0xFFFF)==0)
|
||||
c.code >>=16;
|
||||
|
||||
SWITCH_INT(c.len);
|
||||
SWITCH_INT(c.dna_nr);
|
||||
SWITCH_INT(c.nr);
|
||||
}
|
||||
memcpy(dataChunk, &c, sizeof(bChunkInd));
|
||||
}
|
||||
}
|
||||
|
||||
if (dataChunk->len < 0)
|
||||
return -1;
|
||||
|
||||
#if 0
|
||||
print ("----------");
|
||||
print (dataChunk->code);
|
||||
print (dataChunk->len);
|
||||
print (dataChunk->old);
|
||||
print (dataChunk->dna_nr);
|
||||
print (dataChunk->nr);
|
||||
#endif
|
||||
return (dataChunk->len+getOffset(flags));
|
||||
}
|
||||
|
||||
|
||||
|
||||
//eof
|
||||
85
Extras/Serialize/BulletFileLoader/bChunk.h
Normal file
85
Extras/Serialize/BulletFileLoader/bChunk.h
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
bParse
|
||||
Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef __BCHUNK_H__
|
||||
#define __BCHUNK_H__
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
#define long64 __int64
|
||||
#else
|
||||
#define long64 long long
|
||||
#endif
|
||||
|
||||
|
||||
namespace bParse {
|
||||
|
||||
|
||||
// ----------------------------------------------------- //
|
||||
class bChunkPtr4
|
||||
{
|
||||
public:
|
||||
bChunkPtr4(){}
|
||||
int code;
|
||||
int len;
|
||||
int old;
|
||||
int dna_nr;
|
||||
int nr;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------- //
|
||||
class bChunkPtr8
|
||||
{
|
||||
public:
|
||||
bChunkPtr8(){}
|
||||
int code, len;
|
||||
long64 old;
|
||||
int dna_nr, nr;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------- //
|
||||
class bChunkInd
|
||||
{
|
||||
public:
|
||||
bChunkInd(){}
|
||||
int code, len;
|
||||
void *oldPtr;
|
||||
int dna_nr, nr;
|
||||
};
|
||||
|
||||
|
||||
// ----------------------------------------------------- //
|
||||
class ChunkUtils
|
||||
{
|
||||
public:
|
||||
// buffer offset util
|
||||
static int getNextBlock(bChunkInd *dataChunk, char *dataPtr, const int flags);
|
||||
|
||||
// file chunk offset
|
||||
static int getOffset(int flags);
|
||||
|
||||
// endian utils
|
||||
static short swapShort(short sht);
|
||||
static int swapInt(int inte);
|
||||
static long64 swapLong64(long64 lng);
|
||||
|
||||
};
|
||||
|
||||
|
||||
const int CHUNK_HEADER_LEN = ((sizeof(bChunkInd)));
|
||||
const bool VOID_IS_8 = ((sizeof(void*)==8));
|
||||
}
|
||||
|
||||
#endif//__BCHUNK_H__
|
||||
39
Extras/Serialize/BulletFileLoader/bCommon.h
Normal file
39
Extras/Serialize/BulletFileLoader/bCommon.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
bParse
|
||||
Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef __BCOMMON_H__
|
||||
#define __BCOMMON_H__
|
||||
|
||||
|
||||
#include <assert.h>
|
||||
//#include "bLog.h"
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
#include "LinearMath/btHashMap.h"
|
||||
|
||||
namespace bParse {
|
||||
|
||||
class bMain;
|
||||
class bFileData;
|
||||
class bFile;
|
||||
class bDNA;
|
||||
|
||||
// delete void* undefined
|
||||
typedef struct bStructHandle {int unused;}bStructHandle;
|
||||
typedef btAlignedObjectArray<bStructHandle*> bListBasePtr;
|
||||
typedef btHashMap<btHashPtr, bStructHandle*> bPtrMap;
|
||||
}
|
||||
|
||||
|
||||
#endif//__BCOMMON_H__
|
||||
624
Extras/Serialize/BulletFileLoader/bDNA.cpp
Normal file
624
Extras/Serialize/BulletFileLoader/bDNA.cpp
Normal file
@@ -0,0 +1,624 @@
|
||||
/*
|
||||
bParse
|
||||
Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include <assert.h>
|
||||
|
||||
#include "bDNA.h"
|
||||
#include "bChunk.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace bParse;
|
||||
|
||||
|
||||
// ----------------------------------------------------- //
|
||||
bDNA::bDNA()
|
||||
: mPtrLen(0)
|
||||
{
|
||||
// --
|
||||
}
|
||||
|
||||
// ----------------------------------------------------- //
|
||||
bDNA::~bDNA()
|
||||
{
|
||||
// --
|
||||
}
|
||||
|
||||
// ----------------------------------------------------- //
|
||||
bool bDNA::lessThan(bDNA *file)
|
||||
{
|
||||
return ( m_Names.size() < file->m_Names.size());
|
||||
}
|
||||
|
||||
// ----------------------------------------------------- //
|
||||
char *bDNA::getName(int ind)
|
||||
{
|
||||
assert(ind <= (int)m_Names.size());
|
||||
return m_Names[ind].m_name;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------- //
|
||||
char *bDNA::getType(int ind)
|
||||
{
|
||||
assert(ind<= (int)mTypes.size());
|
||||
return mTypes[ind];
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------- //
|
||||
short *bDNA::getStruct(int ind)
|
||||
{
|
||||
assert(ind <= (int)mStructs.size());
|
||||
return mStructs[ind];
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------- //
|
||||
short bDNA::getLength(int ind)
|
||||
{
|
||||
assert(ind <= (int)mTlens.size());
|
||||
return mTlens[ind];
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------- //
|
||||
int bDNA::getReverseType(short type)
|
||||
{
|
||||
|
||||
int* intPtr = mStructReverse.find(type);
|
||||
if (intPtr)
|
||||
return *intPtr;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------- //
|
||||
int bDNA::getReverseType(const char *type)
|
||||
{
|
||||
|
||||
btHashString key(type);
|
||||
int* valuePtr = mTypeLookup.find(key);
|
||||
if (valuePtr)
|
||||
return *valuePtr;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------- //
|
||||
int bDNA::getNumStructs()
|
||||
{
|
||||
return (int)mStructs.size();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------- //
|
||||
bool bDNA::flagNotEqual(int dna_nr)
|
||||
{
|
||||
assert(dna_nr <= (int)mCMPFlags.size());
|
||||
return mCMPFlags[dna_nr] == FDF_STRUCT_NEQU;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------- //
|
||||
bool bDNA::flagEqual(int dna_nr)
|
||||
{
|
||||
assert(dna_nr <= (int)mCMPFlags.size());
|
||||
int flag = mCMPFlags[dna_nr];
|
||||
return flag == FDF_STRUCT_EQU;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------- //
|
||||
bool bDNA::flagNone(int dna_nr)
|
||||
{
|
||||
assert(dna_nr <= (int)mCMPFlags.size());
|
||||
return mCMPFlags[dna_nr] == FDF_NONE;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------- //
|
||||
int bDNA::getPointerSize()
|
||||
{
|
||||
return mPtrLen;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------- //
|
||||
void bDNA::initRecurseCmpFlags(int iter)
|
||||
{
|
||||
// iter is FDF_STRUCT_NEQU
|
||||
|
||||
short *oldStrc = mStructs[iter];
|
||||
short type = oldStrc[0];
|
||||
|
||||
for (int i=0; i<(int)mStructs.size(); i++)
|
||||
{
|
||||
if (i != iter && mCMPFlags[i] == FDF_STRUCT_EQU )
|
||||
{
|
||||
short *curStruct = mStructs[i];
|
||||
int eleLen = curStruct[1];
|
||||
curStruct+=2;
|
||||
|
||||
for (int j=0; j<eleLen; j++, curStruct+=2)
|
||||
{
|
||||
if (curStruct[0] == type)
|
||||
{
|
||||
//char *name = m_Names[curStruct[1]].m_name;
|
||||
//if (name[0] != '*')
|
||||
if (m_Names[curStruct[1]].m_isPointer)
|
||||
{
|
||||
mCMPFlags[i] = FDF_STRUCT_NEQU;
|
||||
initRecurseCmpFlags(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------- //
|
||||
void bDNA::initCmpFlags(bDNA *memDNA)
|
||||
{
|
||||
|
||||
// compare the file to memory
|
||||
// this ptr should be the file data
|
||||
|
||||
|
||||
assert(!m_Names.size() == 0 && "SDNA empty!");
|
||||
mCMPFlags.resize(mStructs.size(), FDF_NONE);
|
||||
|
||||
|
||||
|
||||
for (int i=0; i<(int)mStructs.size(); i++)
|
||||
{
|
||||
short *oldStruct = mStructs[i];
|
||||
|
||||
int oldLookup = getReverseType(oldStruct[0]);
|
||||
if (oldLookup == -1)
|
||||
{
|
||||
mCMPFlags[i] = FDF_NONE;
|
||||
continue;
|
||||
}
|
||||
//#define SLOW_FORWARD_COMPATIBLE 1
|
||||
#ifdef SLOW_FORWARD_COMPATIBLE
|
||||
char* typeName = mTypes[oldLookup];
|
||||
int newLookup = memDNA->getReverseType(typeName);
|
||||
if (newLookup == -1)
|
||||
{
|
||||
mCMPFlags[i] = FDF_NONE;
|
||||
continue;
|
||||
}
|
||||
short *curStruct = memDNA->mStructs[newLookup];
|
||||
#else
|
||||
// memory for file
|
||||
|
||||
if (oldLookup < memDNA->mStructs.size())
|
||||
{
|
||||
short *curStruct = memDNA->mStructs[oldLookup];
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
// rebuild...
|
||||
mCMPFlags[i] = FDF_STRUCT_NEQU;
|
||||
|
||||
#if 1
|
||||
if (curStruct[1] == oldStruct[1])
|
||||
{
|
||||
// type len same ...
|
||||
if (mTlens[oldStruct[0]] == memDNA->mTlens[curStruct[0]])
|
||||
{
|
||||
bool isSame = true;
|
||||
int elementLength = oldStruct[1];
|
||||
|
||||
|
||||
curStruct+=2;
|
||||
oldStruct+=2;
|
||||
|
||||
|
||||
for (int j=0; j<elementLength; j++, curStruct+=2, oldStruct+=2)
|
||||
{
|
||||
// type the same
|
||||
if (strcmp(mTypes[oldStruct[0]], memDNA->mTypes[curStruct[0]])!=0)
|
||||
{
|
||||
isSame=false;
|
||||
break;
|
||||
}
|
||||
|
||||
// name the same
|
||||
if (strcmp(m_Names[oldStruct[1]].m_name, memDNA->m_Names[curStruct[1]].m_name)!=0)
|
||||
{
|
||||
isSame=false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// flag valid ==
|
||||
if (isSame)
|
||||
mCMPFlags[i] = FDF_STRUCT_EQU;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// recurse in
|
||||
for (int i=0; i<(int)mStructs.size(); i++)
|
||||
{
|
||||
if (mCMPFlags[i] == FDF_STRUCT_NEQU)
|
||||
initRecurseCmpFlags(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static int name_is_array(char* name, int* dim1, int* dim2) {
|
||||
int len = strlen(name);
|
||||
/*fprintf(stderr,"[%s]",name);*/
|
||||
/*if (len >= 1) {
|
||||
if (name[len-1] != ']')
|
||||
return 1;
|
||||
}
|
||||
return 0;*/
|
||||
char *bp;
|
||||
int num;
|
||||
if (dim1) {
|
||||
*dim1 = 1;
|
||||
}
|
||||
if (dim2) {
|
||||
*dim2 = 1;
|
||||
}
|
||||
bp = strchr(name, '[');
|
||||
if (!bp) {
|
||||
return 0;
|
||||
}
|
||||
num = 0;
|
||||
while (++bp < name+len-1) {
|
||||
const char c = *bp;
|
||||
if (c == ']') {
|
||||
break;
|
||||
}
|
||||
if (c <= '9' && c >= '0') {
|
||||
num *= 10;
|
||||
num += (c - '0');
|
||||
} else {
|
||||
printf("array parse error.\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (dim2) {
|
||||
*dim2 = num;
|
||||
}
|
||||
|
||||
/* find second dim, if any. */
|
||||
bp = strchr(bp, '[');
|
||||
if (!bp) {
|
||||
return 1; /* at least we got the first dim. */
|
||||
}
|
||||
num = 0;
|
||||
while (++bp < name+len-1) {
|
||||
const char c = *bp;
|
||||
if (c == ']') {
|
||||
break;
|
||||
}
|
||||
if (c <= '9' && c >= '0') {
|
||||
num *= 10;
|
||||
num += (c - '0');
|
||||
} else {
|
||||
printf("array2 parse error.\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (dim1) {
|
||||
if (dim2) {
|
||||
*dim1 = *dim2;
|
||||
*dim2 = num;
|
||||
} else {
|
||||
*dim1 = num;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------- //
|
||||
void bDNA::init(char *data, int len, bool swap)
|
||||
{
|
||||
int *intPtr=0;short *shtPtr=0;
|
||||
char *cp = 0;int dataLen =0;long nr=0;
|
||||
intPtr = (int*)data;
|
||||
|
||||
/*
|
||||
SDNA (4 bytes) (magic number)
|
||||
NAME (4 bytes)
|
||||
<nr> (4 bytes) amount of names (int)
|
||||
<string>
|
||||
<string>
|
||||
*/
|
||||
|
||||
if (strncmp(data, "SDNA", 4)==0)
|
||||
{
|
||||
// skip ++ NAME
|
||||
intPtr++; intPtr++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Parse names
|
||||
if (swap) dataLen = ChunkUtils::swapInt(*intPtr);
|
||||
else dataLen = *intPtr;
|
||||
intPtr++;
|
||||
|
||||
cp = (char*)intPtr;
|
||||
for (int i=0; i<dataLen; i++)
|
||||
{
|
||||
bNameInfo info;
|
||||
info.m_name = cp;
|
||||
info.m_isPointer = (info.m_name[0] == '*') || (info.m_name[1] == '*');
|
||||
name_is_array(info.m_name,&info.m_dim0,&info.m_dim1);
|
||||
m_Names.push_back(info);
|
||||
while (*cp)cp++;
|
||||
cp++;
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
nr= (long)cp;
|
||||
long mask=3;
|
||||
nr= ((nr+3)&~3)-nr;
|
||||
while (nr--)
|
||||
{
|
||||
cp++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
TYPE (4 bytes)
|
||||
<nr> amount of types (int)
|
||||
<string>
|
||||
<string>
|
||||
*/
|
||||
|
||||
intPtr = (int*)cp;
|
||||
assert(strncmp(cp, "TYPE", 4)==0); intPtr++;
|
||||
|
||||
if (swap) dataLen = ChunkUtils::swapInt(*intPtr);
|
||||
else dataLen = *intPtr;
|
||||
intPtr++;
|
||||
|
||||
cp = (char*)intPtr;
|
||||
for (int i=0; i<dataLen; i++)
|
||||
{
|
||||
mTypes.push_back(cp);
|
||||
while (*cp)cp++;
|
||||
cp++;
|
||||
}
|
||||
|
||||
{
|
||||
nr= (long)cp;
|
||||
long mask=3;
|
||||
nr= ((nr+3)&~3)-nr;
|
||||
while (nr--)
|
||||
{
|
||||
cp++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
TLEN (4 bytes)
|
||||
<len> (short) the lengths of types
|
||||
<len>
|
||||
*/
|
||||
|
||||
// Parse type lens
|
||||
intPtr = (int*)cp;
|
||||
assert(strncmp(cp, "TLEN", 4)==0); intPtr++;
|
||||
|
||||
dataLen = (int)mTypes.size();
|
||||
|
||||
shtPtr = (short*)intPtr;
|
||||
for (int i=0; i<dataLen; i++, shtPtr++)
|
||||
{
|
||||
if (swap)
|
||||
shtPtr[0] = ChunkUtils::swapShort(shtPtr[0]);
|
||||
mTlens.push_back(shtPtr[0]);
|
||||
}
|
||||
|
||||
if (dataLen & 1) shtPtr++;
|
||||
|
||||
/*
|
||||
STRC (4 bytes)
|
||||
<nr> amount of structs (int)
|
||||
<typenr>
|
||||
<nr_of_elems>
|
||||
<typenr>
|
||||
<namenr>
|
||||
<typenr>
|
||||
<namenr>
|
||||
*/
|
||||
|
||||
intPtr = (int*)shtPtr;
|
||||
cp = (char*)intPtr;
|
||||
assert(strncmp(cp, "STRC", 4)==0); intPtr++;
|
||||
|
||||
if (swap) dataLen = ChunkUtils::swapInt(*intPtr);
|
||||
else dataLen = *intPtr;
|
||||
intPtr++;
|
||||
|
||||
|
||||
shtPtr = (short*)intPtr;
|
||||
for (int i=0; i<dataLen; i++)
|
||||
{
|
||||
mStructs.push_back (shtPtr);
|
||||
if (swap)
|
||||
{
|
||||
shtPtr[0]= ChunkUtils::swapShort(shtPtr[0]);
|
||||
shtPtr[1]= ChunkUtils::swapShort(shtPtr[1]);
|
||||
|
||||
int len = shtPtr[1];
|
||||
shtPtr+= 2;
|
||||
|
||||
for (int a=0; a<len; a++, shtPtr+=2)
|
||||
{
|
||||
shtPtr[0]= ChunkUtils::swapShort(shtPtr[0]);
|
||||
shtPtr[1]= ChunkUtils::swapShort(shtPtr[1]);
|
||||
}
|
||||
}
|
||||
else
|
||||
shtPtr+= (2*shtPtr[1])+2;
|
||||
}
|
||||
|
||||
|
||||
// build reverse lookups
|
||||
for (int i=0; i<(int)mStructs.size(); i++)
|
||||
{
|
||||
short *strc = mStructs.at(i);
|
||||
if (!mPtrLen && strcmp(mTypes[strc[0]],"ListBase")==0)
|
||||
{
|
||||
mPtrLen = mTlens[strc[0]]/2;
|
||||
}
|
||||
|
||||
mStructReverse.insert(strc[0], i);
|
||||
mTypeLookup.insert(btHashString(mTypes[strc[0]]),i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------- //
|
||||
int bDNA::getArraySize(char* string)
|
||||
{
|
||||
int ret = 1;
|
||||
int len = strlen(string);
|
||||
|
||||
|
||||
char* next = 0;
|
||||
for (int i=0; i<len; i++)
|
||||
{
|
||||
char c = string[i];
|
||||
|
||||
if (c == '[')
|
||||
next = &string[i+1];
|
||||
else if (c==']')
|
||||
if (next)
|
||||
ret *= atoi(next);
|
||||
}
|
||||
|
||||
// print (string << ' ' << ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void bDNA::dumpTypeDefinitions()
|
||||
{
|
||||
int i;
|
||||
|
||||
int numTypes = mTypes.size();
|
||||
|
||||
for (i=0;i<numTypes;i++)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
for (int i=0; i<(int)mStructs.size(); i++)
|
||||
{
|
||||
int totalBytes=0;
|
||||
short *oldStruct = mStructs[i];
|
||||
|
||||
int oldLookup = getReverseType(oldStruct[0]);
|
||||
if (oldLookup == -1)
|
||||
{
|
||||
mCMPFlags[i] = FDF_NONE;
|
||||
continue;
|
||||
}
|
||||
|
||||
short* newStruct = mStructs[oldLookup];
|
||||
char* typeName = mTypes[newStruct[0]];
|
||||
printf("%3d: %s ",i,typeName);
|
||||
|
||||
//char *name = mNames[oldStruct[1]];
|
||||
int len = oldStruct[1];
|
||||
printf(" (%d fields) ",len);
|
||||
oldStruct+=2;
|
||||
|
||||
printf("{");
|
||||
int j;
|
||||
for (j=0; j<len; ++j,oldStruct+=2) {
|
||||
const char* name = m_Names[oldStruct[1]].m_name;
|
||||
printf("%s %s", mTypes[oldStruct[0]],name);
|
||||
int elemNumBytes= 0;
|
||||
int arrayDimensions = getArraySizeNew(oldStruct[1]);
|
||||
|
||||
if (m_Names[oldStruct[1]].m_isPointer)
|
||||
{
|
||||
elemNumBytes = VOID_IS_8 ? 8 : 4;
|
||||
} else
|
||||
{
|
||||
elemNumBytes = getLength(oldStruct[0]);
|
||||
}
|
||||
printf(" /* %d bytes */",elemNumBytes*arrayDimensions);
|
||||
|
||||
if (j == len-1) {
|
||||
printf(";}");
|
||||
} else {
|
||||
printf("; ");
|
||||
}
|
||||
totalBytes+=elemNumBytes*arrayDimensions;
|
||||
}
|
||||
printf("\ntotalBytes=%d\n\n",totalBytes);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
/* dump out display of types and their sizes */
|
||||
for (i=0; i<bf->types_count; ++i) {
|
||||
/* if (!bf->types[i].is_struct)*/
|
||||
{
|
||||
printf("%3d: sizeof(%s%s)=%d",
|
||||
i,
|
||||
bf->types[i].is_struct ? "struct " : "atomic ",
|
||||
bf->types[i].name, bf->types[i].size);
|
||||
if (bf->types[i].is_struct) {
|
||||
int j;
|
||||
printf(", %d fields: { ", bf->types[i].fieldtypes_count);
|
||||
for (j=0; j<bf->types[i].fieldtypes_count; ++j) {
|
||||
printf("%s %s",
|
||||
bf->types[bf->types[i].fieldtypes[j]].name,
|
||||
bf->names[bf->types[i].fieldnames[j]]);
|
||||
if (j == bf->types[i].fieldtypes_count-1) {
|
||||
printf(";}");
|
||||
} else {
|
||||
printf("; ");
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("\n\n");
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//eof
|
||||
|
||||
|
||||
109
Extras/Serialize/BulletFileLoader/bDNA.h
Normal file
109
Extras/Serialize/BulletFileLoader/bDNA.h
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
bParse
|
||||
Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef __BDNA_H__
|
||||
#define __BDNA_H__
|
||||
|
||||
|
||||
#include "bCommon.h"
|
||||
|
||||
namespace bParse {
|
||||
|
||||
struct bNameInfo
|
||||
{
|
||||
char* m_name;
|
||||
bool m_isPointer;
|
||||
int m_dim0;
|
||||
int m_dim1;
|
||||
};
|
||||
|
||||
class bDNA
|
||||
{
|
||||
public:
|
||||
bDNA();
|
||||
~bDNA();
|
||||
|
||||
void init(char *data, int len, bool swap=false);
|
||||
|
||||
int getArraySize(char* str);
|
||||
int getArraySizeNew(short name)
|
||||
{
|
||||
const bNameInfo& nameInfo = m_Names[name];
|
||||
return nameInfo.m_dim0*nameInfo.m_dim1;
|
||||
}
|
||||
int getElementSize(short type, short name)
|
||||
{
|
||||
const bNameInfo& nameInfo = m_Names[name];
|
||||
int size = nameInfo.m_isPointer ? mPtrLen*nameInfo.m_dim0*nameInfo.m_dim1 : mTlens[type]*nameInfo.m_dim0*nameInfo.m_dim1;
|
||||
return size;
|
||||
}
|
||||
|
||||
int getNumNames() const
|
||||
{
|
||||
return m_Names.size();
|
||||
}
|
||||
|
||||
char *getName(int ind);
|
||||
char *getType(int ind);
|
||||
short *getStruct(int ind);
|
||||
short getLength(int ind);
|
||||
int getReverseType(short type);
|
||||
int getReverseType(const char *type);
|
||||
|
||||
|
||||
int getNumStructs();
|
||||
|
||||
//
|
||||
bool lessThan(bDNA* other);
|
||||
|
||||
void initCmpFlags(bDNA *memDNA);
|
||||
bool flagNotEqual(int dna_nr);
|
||||
bool flagEqual(int dna_nr);
|
||||
bool flagNone(int dna_nr);
|
||||
|
||||
|
||||
int getPointerSize();
|
||||
|
||||
void dumpTypeDefinitions();
|
||||
|
||||
|
||||
private:
|
||||
enum FileDNAFlags
|
||||
{
|
||||
FDF_NONE=0,
|
||||
FDF_STRUCT_NEQU,
|
||||
FDF_STRUCT_EQU
|
||||
};
|
||||
|
||||
void initRecurseCmpFlags(int i);
|
||||
|
||||
btAlignedObjectArray<int> mCMPFlags;
|
||||
|
||||
btAlignedObjectArray<bNameInfo> m_Names;
|
||||
btAlignedObjectArray<char*> mTypes;
|
||||
btAlignedObjectArray<short*> mStructs;
|
||||
btAlignedObjectArray<short> mTlens;
|
||||
btHashMap<btHashInt, int> mStructReverse;
|
||||
btHashMap<btHashString,int> mTypeLookup;
|
||||
|
||||
int mPtrLen;
|
||||
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif//__BDNA_H__
|
||||
140
Extras/Serialize/BulletFileLoader/bDefines.h
Normal file
140
Extras/Serialize/BulletFileLoader/bDefines.h
Normal file
@@ -0,0 +1,140 @@
|
||||
/* Copyright (C) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#ifndef __B_DEFINES_H__
|
||||
#define __B_DEFINES_H__
|
||||
|
||||
|
||||
// MISC defines, see BKE_global.h, BKE_utildefines.h
|
||||
#define SIZEOFBLENDERHEADER 12
|
||||
|
||||
|
||||
// ------------------------------------------------------------
|
||||
#if defined(__sgi) || defined (__sparc) || defined (__sparc__) || defined (__PPC__) || defined (__ppc__) || defined (__BIG_ENDIAN__)
|
||||
# define MAKE_ID(a,b,c,d) ( (int)(a)<<24 | (int)(b)<<16 | (c)<<8 | (d) )
|
||||
#else
|
||||
# define MAKE_ID(a,b,c,d) ( (int)(d)<<24 | (int)(c)<<16 | (b)<<8 | (a) )
|
||||
#endif
|
||||
|
||||
|
||||
// ------------------------------------------------------------
|
||||
#if defined(__sgi) || defined(__sparc) || defined(__sparc__) || defined (__PPC__) || defined (__ppc__) || defined (__BIG_ENDIAN__)
|
||||
# define MAKE_ID2(c, d) ( (c)<<8 | (d) )
|
||||
# define MOST_SIG_BYTE 0
|
||||
# define BBIG_ENDIAN
|
||||
#else
|
||||
# define MAKE_ID2(c, d) ( (d)<<8 | (c) )
|
||||
# define MOST_SIG_BYTE 1
|
||||
# define BLITTLE_ENDIAN
|
||||
#endif
|
||||
|
||||
// ------------------------------------------------------------
|
||||
#define ID_SCE MAKE_ID2('S', 'C')
|
||||
#define ID_LI MAKE_ID2('L', 'I')
|
||||
#define ID_OB MAKE_ID2('O', 'B')
|
||||
#define ID_ME MAKE_ID2('M', 'E')
|
||||
#define ID_CU MAKE_ID2('C', 'U')
|
||||
#define ID_MB MAKE_ID2('M', 'B')
|
||||
#define ID_MA MAKE_ID2('M', 'A')
|
||||
#define ID_TE MAKE_ID2('T', 'E')
|
||||
#define ID_IM MAKE_ID2('I', 'M')
|
||||
#define ID_IK MAKE_ID2('I', 'K')
|
||||
#define ID_WV MAKE_ID2('W', 'V')
|
||||
#define ID_LT MAKE_ID2('L', 'T')
|
||||
#define ID_SE MAKE_ID2('S', 'E')
|
||||
#define ID_LF MAKE_ID2('L', 'F')
|
||||
#define ID_LA MAKE_ID2('L', 'A')
|
||||
#define ID_CA MAKE_ID2('C', 'A')
|
||||
#define ID_IP MAKE_ID2('I', 'P')
|
||||
#define ID_KE MAKE_ID2('K', 'E')
|
||||
#define ID_WO MAKE_ID2('W', 'O')
|
||||
#define ID_SCR MAKE_ID2('S', 'R')
|
||||
#define ID_VF MAKE_ID2('V', 'F')
|
||||
#define ID_TXT MAKE_ID2('T', 'X')
|
||||
#define ID_SO MAKE_ID2('S', 'O')
|
||||
#define ID_SAMPLE MAKE_ID2('S', 'A')
|
||||
#define ID_GR MAKE_ID2('G', 'R')
|
||||
#define ID_ID MAKE_ID2('I', 'D')
|
||||
#define ID_AR MAKE_ID2('A', 'R')
|
||||
#define ID_AC MAKE_ID2('A', 'C')
|
||||
#define ID_SCRIPT MAKE_ID2('P', 'Y')
|
||||
#define ID_FLUIDSIM MAKE_ID2('F', 'S')
|
||||
#define ID_NT MAKE_ID2('N', 'T')
|
||||
#define ID_BR MAKE_ID2('B', 'R')
|
||||
|
||||
|
||||
#define ID_SEQ MAKE_ID2('S', 'Q')
|
||||
#define ID_CO MAKE_ID2('C', 'O')
|
||||
#define ID_PO MAKE_ID2('A', 'C')
|
||||
#define ID_NLA MAKE_ID2('N', 'L')
|
||||
|
||||
#define ID_VS MAKE_ID2('V', 'S')
|
||||
#define ID_VN MAKE_ID2('V', 'N')
|
||||
|
||||
|
||||
// ------------------------------------------------------------
|
||||
#define FORM MAKE_ID('F','O','R','M')
|
||||
#define DDG1 MAKE_ID('3','D','G','1')
|
||||
#define DDG2 MAKE_ID('3','D','G','2')
|
||||
#define DDG3 MAKE_ID('3','D','G','3')
|
||||
#define DDG4 MAKE_ID('3','D','G','4')
|
||||
#define GOUR MAKE_ID('G','O','U','R')
|
||||
#define BLEN MAKE_ID('B','L','E','N')
|
||||
#define DER_ MAKE_ID('D','E','R','_')
|
||||
#define V100 MAKE_ID('V','1','0','0')
|
||||
#define DATA MAKE_ID('D','A','T','A')
|
||||
#define GLOB MAKE_ID('G','L','O','B')
|
||||
#define IMAG MAKE_ID('I','M','A','G')
|
||||
#define TEST MAKE_ID('T','E','S','T')
|
||||
#define USER MAKE_ID('U','S','E','R')
|
||||
|
||||
|
||||
// ------------------------------------------------------------
|
||||
#define DNA1 MAKE_ID('D','N','A','1')
|
||||
#define REND MAKE_ID('R','E','N','D')
|
||||
#define ENDB MAKE_ID('E','N','D','B')
|
||||
#define NAME MAKE_ID('N','A','M','E')
|
||||
#define SDNA MAKE_ID('S','D','N','A')
|
||||
#define TYPE MAKE_ID('T','Y','P','E')
|
||||
#define TLEN MAKE_ID('T','L','E','N')
|
||||
#define STRC MAKE_ID('S','T','R','C')
|
||||
|
||||
|
||||
// ------------------------------------------------------------
|
||||
#define SWITCH_INT(a) { \
|
||||
char s_i, *p_i; \
|
||||
p_i= (char *)&(a); \
|
||||
s_i=p_i[0]; p_i[0]=p_i[3]; p_i[3]=s_i; \
|
||||
s_i=p_i[1]; p_i[1]=p_i[2]; p_i[2]=s_i; }
|
||||
|
||||
// ------------------------------------------------------------
|
||||
#define SWITCH_SHORT(a) { \
|
||||
char s_i, *p_i; \
|
||||
p_i= (char *)&(a); \
|
||||
s_i=p_i[0]; p_i[0]=p_i[1]; p_i[1]=s_i; }
|
||||
|
||||
// ------------------------------------------------------------
|
||||
#define SWITCH_LONGINT(a) { \
|
||||
char s_i, *p_i; \
|
||||
p_i= (char *)&(a); \
|
||||
s_i=p_i[0]; p_i[0]=p_i[7]; p_i[7]=s_i; \
|
||||
s_i=p_i[1]; p_i[1]=p_i[6]; p_i[6]=s_i; \
|
||||
s_i=p_i[2]; p_i[2]=p_i[5]; p_i[5]=s_i; \
|
||||
s_i=p_i[3]; p_i[3]=p_i[4]; p_i[4]=s_i; }
|
||||
|
||||
#endif//__B_DEFINES_H__
|
||||
1040
Extras/Serialize/BulletFileLoader/bFile.cpp
Normal file
1040
Extras/Serialize/BulletFileLoader/bFile.cpp
Normal file
File diff suppressed because it is too large
Load Diff
146
Extras/Serialize/BulletFileLoader/bFile.h
Normal file
146
Extras/Serialize/BulletFileLoader/bFile.h
Normal file
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
bParse
|
||||
Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef __BFILE_H__
|
||||
#define __BFILE_H__
|
||||
|
||||
#include "bCommon.h"
|
||||
#include "bChunk.h"
|
||||
#include <stdio.h>
|
||||
|
||||
namespace bParse {
|
||||
|
||||
// ----------------------------------------------------- //
|
||||
enum bFileFlags
|
||||
{
|
||||
FD_INVALID =0,
|
||||
FD_OK =1,
|
||||
FD_VOID_IS_8 =2,
|
||||
FD_ENDIAN_SWAP =4,
|
||||
FD_FILE_64 =8,
|
||||
FD_BITS_VARIES =16,
|
||||
FD_VERSION_VARIES = 32
|
||||
};
|
||||
|
||||
|
||||
// ----------------------------------------------------- //
|
||||
class bFile
|
||||
{
|
||||
protected:
|
||||
|
||||
char m_headerString[7];
|
||||
|
||||
bool mOwnsBuffer;
|
||||
char* mFileBuffer;
|
||||
int mFileLen;
|
||||
int mVersion;
|
||||
|
||||
|
||||
bPtrMap mLibPointers;
|
||||
|
||||
int mDataStart;
|
||||
bDNA* mFileDNA;
|
||||
bDNA* mMemoryDNA;
|
||||
|
||||
btAlignedObjectArray<char*> m_pointerFixupArray;
|
||||
btAlignedObjectArray<char*> m_pointerPtrFixupArray;
|
||||
|
||||
btAlignedObjectArray<bChunkInd> m_chunks;
|
||||
|
||||
//
|
||||
|
||||
bPtrMap mDataPointers;
|
||||
|
||||
|
||||
|
||||
int mFlags;
|
||||
|
||||
virtual void parseHeader();
|
||||
|
||||
virtual void parseData() = 0;
|
||||
|
||||
void resolvePointersMismatch();
|
||||
void resolvePointersChunk(const bChunkInd& dataChunk, bool verboseDumpAllBlocks);
|
||||
|
||||
void resolvePointersStructRecursive(char *strcPtr, int old_dna, bool verboseDumpAllBlocks, int recursion);
|
||||
void swapPtr(char *dst, char *src);
|
||||
|
||||
void parseStruct(char *strcPtr, char *dtPtr, int old_dna, int new_dna, bool fixupPointers);
|
||||
void getMatchingFileDNA(short* old, const char* lookupName, const char* lookupType, char *strcData, char *data, bool fixupPointers);
|
||||
char* getFileElement(short *firstStruct, char *lookupName, char *lookupType, char *data, short **foundPos);
|
||||
|
||||
|
||||
void swap(char *head, class bChunkInd& ch);
|
||||
|
||||
void swapData(char *data, short type, int arraySize);
|
||||
void swapStruct(int dna_nr, char *data);
|
||||
|
||||
|
||||
|
||||
|
||||
char* readStruct(char *head, class bChunkInd& chunk);
|
||||
char *getAsString(int code);
|
||||
|
||||
void parseInternal(bool verboseDumpAllTypes, char* memDna,int memDnaLength);
|
||||
|
||||
public:
|
||||
bFile(const char *filename, const char headerString[7]);
|
||||
|
||||
//todo: make memoryBuffer const char
|
||||
//bFile( const char *memoryBuffer, int len);
|
||||
bFile( char *memoryBuffer, int len, const char headerString[7]);
|
||||
~bFile();
|
||||
|
||||
bDNA* getFileDNA()
|
||||
{
|
||||
return mFileDNA;
|
||||
}
|
||||
|
||||
virtual void addDataBlock(char* dataBlock) = 0;
|
||||
|
||||
int getFlags() const
|
||||
{
|
||||
return mFlags;
|
||||
}
|
||||
|
||||
bPtrMap& getLibPointers()
|
||||
{
|
||||
return mLibPointers;
|
||||
}
|
||||
|
||||
void* findLibPointer(void *ptr);
|
||||
|
||||
bool ok();
|
||||
|
||||
virtual void parse(bool verboseDumpAllTypes) = 0;
|
||||
|
||||
virtual int write(const char* fileName, bool fixupPointers=false) = 0;
|
||||
|
||||
virtual void writeChunks(FILE* fp, bool fixupPointers );
|
||||
|
||||
virtual void writeDNA(FILE* fp) = 0;
|
||||
|
||||
void updateOldPointers();
|
||||
void resolvePointers(bool verboseDumpAllBlocks);
|
||||
|
||||
void dumpChunks(bDNA* dna);
|
||||
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif//__BFILE_H__
|
||||
252
Extras/Serialize/BulletFileLoader/btBulletFile.cpp
Normal file
252
Extras/Serialize/BulletFileLoader/btBulletFile.cpp
Normal file
@@ -0,0 +1,252 @@
|
||||
/*
|
||||
bParse
|
||||
Copyright (c) 2006-2010 Erwin Coumans http://gamekit.googlecode.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "btBulletFile.h"
|
||||
#include "bDefines.h"
|
||||
#include "bDNA.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
// 32 && 64 bit versions
|
||||
extern unsigned char sBulletDNAstr[];
|
||||
extern int sBulletDNAlen;
|
||||
|
||||
//not yetto. extern unsigned char DNAstr64[];
|
||||
//not yetto. extern int DNAlen64;
|
||||
|
||||
|
||||
using namespace bParse;
|
||||
|
||||
btBulletFile::btBulletFile()
|
||||
:bFile("", "BULLET ")
|
||||
{
|
||||
mMemoryDNA = new bDNA();
|
||||
mMemoryDNA->init((char*)sBulletDNAstr,sBulletDNAlen);
|
||||
}
|
||||
|
||||
|
||||
btBulletFile::btBulletFile(const char* fileName)
|
||||
:bFile(fileName, "BULLET ")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
btBulletFile::btBulletFile(char *memoryBuffer, int len)
|
||||
:bFile(memoryBuffer,len, "BULLET ")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
btBulletFile::~btBulletFile()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------------------- //
|
||||
void btBulletFile::parseData()
|
||||
{
|
||||
printf ("Building datablocks");
|
||||
printf ("Chunk size = %d",CHUNK_HEADER_LEN);
|
||||
printf ("File chunk size = %d",ChunkUtils::getOffset(mFlags));
|
||||
|
||||
const bool swap = (mFlags&FD_ENDIAN_SWAP)!=0;
|
||||
|
||||
|
||||
mDataStart = 12;
|
||||
|
||||
char *dataPtr = mFileBuffer+mDataStart;
|
||||
|
||||
bChunkInd dataChunk;
|
||||
dataChunk.code = 0;
|
||||
|
||||
|
||||
//dataPtr += ChunkUtils::getNextBlock(&dataChunk, dataPtr, mFlags);
|
||||
int seek = ChunkUtils::getNextBlock(&dataChunk, dataPtr, mFlags);
|
||||
//dataPtr += ChunkUtils::getOffset(mFlags);
|
||||
char *dataPtrHead = 0;
|
||||
|
||||
while (dataChunk.code != DNA1)
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
// one behind
|
||||
if (dataChunk.code == SDNA) break;
|
||||
//if (dataChunk.code == DNA1) break;
|
||||
|
||||
// same as (BHEAD+DATA dependancy)
|
||||
dataPtrHead = dataPtr+ChunkUtils::getOffset(mFlags);
|
||||
char *id = readStruct(dataPtrHead, dataChunk);
|
||||
|
||||
// lookup maps
|
||||
if (id)
|
||||
{
|
||||
mLibPointers.insert(dataChunk.oldPtr, (bStructHandle*)id);
|
||||
|
||||
m_chunks.push_back(dataChunk);
|
||||
// block it
|
||||
//bListBasePtr *listID = mMain->getListBasePtr(dataChunk.code);
|
||||
//if (listID)
|
||||
// listID->push_back((bStructHandle*)id);
|
||||
}
|
||||
|
||||
if (dataChunk.code == BT_RIGIDBODY_CODE)
|
||||
{
|
||||
m_rigidBodies.push_back((bStructHandle*) id);
|
||||
}
|
||||
|
||||
if (dataChunk.code == BT_COLLISIONOBJECT_CODE)
|
||||
{
|
||||
m_collisionObjects.push_back((bStructHandle*) id);
|
||||
}
|
||||
|
||||
if (dataChunk.code == BT_SHAPE_CODE)
|
||||
{
|
||||
m_collisionShapes.push_back((bStructHandle*) id);
|
||||
}
|
||||
|
||||
// if (dataChunk.code == GLOB)
|
||||
// {
|
||||
// m_glob = (bStructHandle*) id;
|
||||
// }
|
||||
|
||||
// next please!
|
||||
dataPtr += seek;
|
||||
|
||||
seek = ChunkUtils::getNextBlock(&dataChunk, dataPtr, mFlags);
|
||||
if (seek < 0)
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void btBulletFile::addDataBlock(char* dataBlock)
|
||||
{
|
||||
//mMain->addDatablock(dataBlock);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void btBulletFile::writeDNA(FILE* fp)
|
||||
{
|
||||
|
||||
bChunkInd dataChunk;
|
||||
dataChunk.code = DNA1;
|
||||
dataChunk.dna_nr = 0;
|
||||
dataChunk.nr = 1;
|
||||
|
||||
if (VOID_IS_8)
|
||||
{
|
||||
//dataChunk.len = DNAlen64;
|
||||
//dataChunk.oldPtr = DNAstr64;
|
||||
//fwrite(&dataChunk,sizeof(bChunkInd),1,fp);
|
||||
//fwrite(DNAstr64, DNAlen64,1,fp);
|
||||
}
|
||||
else
|
||||
{
|
||||
dataChunk.len = sBulletDNAlen;
|
||||
dataChunk.oldPtr = sBulletDNAstr;
|
||||
fwrite(&dataChunk,sizeof(bChunkInd),1,fp);
|
||||
fwrite(sBulletDNAstr, sBulletDNAlen,1,fp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void btBulletFile::parse(bool verboseDumpAllTypes)
|
||||
{
|
||||
if (VOID_IS_8)
|
||||
{
|
||||
exit(0);
|
||||
//parseInternal(verboseDumpAllTypes,(char*)DNAstr64,DNAlen64);
|
||||
}
|
||||
else
|
||||
{
|
||||
parseInternal(verboseDumpAllTypes,(char*)sBulletDNAstr,sBulletDNAlen);
|
||||
}
|
||||
}
|
||||
|
||||
// experimental
|
||||
int btBulletFile::write(const char* fileName, bool fixupPointers)
|
||||
{
|
||||
FILE *fp = fopen(fileName, "wb");
|
||||
if (fp)
|
||||
{
|
||||
char header[SIZEOFBLENDERHEADER] ;
|
||||
memcpy(header, m_headerString, 7);
|
||||
int endian= 1;
|
||||
endian= ((char*)&endian)[0];
|
||||
|
||||
if (endian)
|
||||
{
|
||||
header[7] = '_';
|
||||
} else
|
||||
{
|
||||
header[7] = '-';
|
||||
}
|
||||
if (VOID_IS_8)
|
||||
{
|
||||
header[8]='V';
|
||||
} else
|
||||
{
|
||||
header[8]='v';
|
||||
}
|
||||
|
||||
header[9] = '2';
|
||||
header[10] = '7';
|
||||
header[11] = '5';
|
||||
|
||||
fwrite(header,SIZEOFBLENDERHEADER,1,fp);
|
||||
|
||||
writeChunks(fp, fixupPointers);
|
||||
|
||||
writeDNA(fp);
|
||||
|
||||
fclose(fp);
|
||||
|
||||
} else
|
||||
{
|
||||
printf("Error: cannot open file %s for writing\n",fileName);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void btBulletFile::addStruct(const char* structType,void* data, int len, void* oldPtr, int code)
|
||||
{
|
||||
|
||||
bParse::bChunkInd dataChunk;
|
||||
dataChunk.code = code;
|
||||
dataChunk.nr = 1;
|
||||
dataChunk.len = len;
|
||||
dataChunk.dna_nr = mMemoryDNA->getReverseType(structType);
|
||||
dataChunk.oldPtr = oldPtr;
|
||||
|
||||
///Perform structure size validation
|
||||
short* structInfo= mMemoryDNA->getStruct(dataChunk.dna_nr);
|
||||
int elemBytes = mMemoryDNA->getLength(structInfo[0]);
|
||||
// int elemBytes = mMemoryDNA->getElementSize(structInfo[0],structInfo[1]);
|
||||
assert(len==elemBytes);
|
||||
|
||||
mLibPointers.insert(dataChunk.oldPtr, (bStructHandle*)data);
|
||||
m_chunks.push_back(dataChunk);
|
||||
}
|
||||
72
Extras/Serialize/BulletFileLoader/btBulletFile.h
Normal file
72
Extras/Serialize/BulletFileLoader/btBulletFile.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
bParse
|
||||
Copyright (c) 2006-2010 Charlie C & Erwin Coumans http://gamekit.googlecode.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef BT_BULLET_FILE_H
|
||||
#define BT_BULLET_FILE_H
|
||||
|
||||
|
||||
#include "bFile.h"
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
#include "bDefines.h"
|
||||
|
||||
#define BT_COLLISIONOBJECT_CODE MAKE_ID('C','O','B','J')
|
||||
#define BT_RIGIDBODY_CODE MAKE_ID('R','B','D','Y')
|
||||
#define BT_BOXSHAPE_CODE MAKE_ID('B','O','X','S')
|
||||
#define BT_SHAPE_CODE MAKE_ID('S','H','A','P')
|
||||
|
||||
|
||||
namespace bParse {
|
||||
|
||||
// ----------------------------------------------------- //
|
||||
class btBulletFile : public bFile
|
||||
{
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
public:
|
||||
|
||||
btAlignedObjectArray<bStructHandle*> m_rigidBodies;
|
||||
|
||||
btAlignedObjectArray<bStructHandle*> m_collisionObjects;
|
||||
|
||||
btAlignedObjectArray<bStructHandle*> m_collisionShapes;
|
||||
|
||||
btBulletFile();
|
||||
|
||||
btBulletFile(const char* fileName);
|
||||
|
||||
btBulletFile(char *memoryBuffer, int len);
|
||||
|
||||
virtual ~btBulletFile();
|
||||
|
||||
virtual void addDataBlock(char* dataBlock);
|
||||
|
||||
|
||||
// experimental
|
||||
virtual int write(const char* fileName, bool fixupPointers=false);
|
||||
|
||||
virtual void parse(bool verboseDumpAllTypes);
|
||||
|
||||
virtual void parseData();
|
||||
|
||||
virtual void writeDNA(FILE* fp);
|
||||
|
||||
void addStruct(const char* structType,void* data, int len, void* oldPtr, int code);
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif //BT_BULLET_FILE_H
|
||||
Reference in New Issue
Block a user