Update to box2d 2.4.1

This commit is contained in:
Garrett Brown
2020-10-17 22:15:18 -04:00
parent 7d24beab90
commit 77f238767f
58 changed files with 879 additions and 367 deletions
+94 -114
View File
@@ -23,143 +23,123 @@
#ifndef B2_SETTINGS_H
#define B2_SETTINGS_H
#include <stddef.h>
#include <assert.h>
#include <float.h>
void loveAssert(bool test, const char* teststr);
#if !defined(NDEBUG)
#define b2DEBUG
#endif
#define B2_NOT_USED(x) ((void)(x))
//#define b2Assert(A) assert(A)
#define b2Assert(A) loveAssert((A), #A)
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
#define b2_maxFloat FLT_MAX
#define b2_epsilon FLT_EPSILON
#define b2_pi 3.14159265359f
#include "b2_types.h"
#include "b2_api.h"
/// @file
/// Global tuning constants based on meters-kilograms-seconds (MKS) units.
/// Settings that can be overriden for your application
///
// Collision
/// Define this macro in your build if you want to override settings
#ifdef B2_USER_SETTINGS
/// The maximum number of contact points between two convex shapes. Do
/// not change this value.
#define b2_maxManifoldPoints 2
/// This is a user file that includes custom definitions of the macros, structs, and functions
/// defined below.
#include "b2_user_settings.h"
#else
#include <stdarg.h>
#include <stdint.h>
// Tunable Constants
/// You can use this to change the length scale used by your game.
/// For example for inches you could use 39.4.
#define b2_lengthUnitsPerMeter 1.0f
/// The maximum number of vertices on a convex polygon. You cannot increase
/// this too much because b2BlockAllocator has a maximum object size.
#define b2_maxPolygonVertices 8
/// This is used to fatten AABBs in the dynamic tree. This allows proxies
/// to move by a small amount without triggering a tree adjustment.
/// This is in meters.
#define b2_aabbExtension 0.1f
// User data
/// This is used to fatten AABBs in the dynamic tree. This is used to predict
/// the future position based on the current displacement.
/// This is a dimensionless multiplier.
#define b2_aabbMultiplier 4.0f
/// You can define this to inject whatever data you want in b2Body
struct B2_API b2BodyUserData
{
b2BodyUserData()
{
pointer = 0;
}
/// A small length used as a collision and constraint tolerance. Usually it is
/// chosen to be numerically significant, but visually insignificant.
#define b2_linearSlop 0.005f
/// For legacy compatibility
uintptr_t pointer;
};
/// A small angle used as a collision and constraint tolerance. Usually it is
/// chosen to be numerically significant, but visually insignificant.
#define b2_angularSlop (2.0f / 180.0f * b2_pi)
/// You can define this to inject whatever data you want in b2Fixture
struct B2_API b2FixtureUserData
{
b2FixtureUserData()
{
pointer = 0;
}
/// The radius of the polygon/edge shape skin. This should not be modified. Making
/// this smaller means polygons will have an insufficient buffer for continuous collision.
/// Making it larger may create artifacts for vertex collision.
#define b2_polygonRadius (2.0f * b2_linearSlop)
/// For legacy compatibility
uintptr_t pointer;
};
/// Maximum number of sub-steps per contact in continuous physics simulation.
#define b2_maxSubSteps 8
/// You can define this to inject whatever data you want in b2Joint
struct B2_API b2JointUserData
{
b2JointUserData()
{
pointer = 0;
}
// Dynamics
/// Maximum number of contacts to be handled to solve a TOI impact.
#define b2_maxTOIContacts 32
/// A velocity threshold for elastic collisions. Any collision with a relative linear
/// velocity below this threshold will be treated as inelastic.
#define b2_velocityThreshold 1.0f
/// The maximum linear position correction used when solving constraints. This helps to
/// prevent overshoot.
#define b2_maxLinearCorrection 0.2f
/// The maximum angular position correction used when solving constraints. This helps to
/// prevent overshoot.
#define b2_maxAngularCorrection (8.0f / 180.0f * b2_pi)
/// The maximum linear velocity of a body. This limit is very large and is used
/// to prevent numerical problems. You shouldn't need to adjust this.
#define b2_maxTranslation 2.0f
#define b2_maxTranslationSquared (b2_maxTranslation * b2_maxTranslation)
/// The maximum angular velocity of a body. This limit is very large and is used
/// to prevent numerical problems. You shouldn't need to adjust this.
#define b2_maxRotation (0.5f * b2_pi)
#define b2_maxRotationSquared (b2_maxRotation * b2_maxRotation)
/// This scale factor controls how fast overlap is resolved. Ideally this would be 1 so
/// that overlap is removed in one time step. However using values close to 1 often lead
/// to overshoot.
#define b2_baumgarte 0.2f
#define b2_toiBaumgarte 0.75f
// Sleep
/// The time that a body must be still before it will go to sleep.
#define b2_timeToSleep 0.5f
/// A body cannot sleep if its linear velocity is above this tolerance.
#define b2_linearSleepTolerance 0.01f
/// A body cannot sleep if its angular velocity is above this tolerance.
#define b2_angularSleepTolerance (2.0f / 180.0f * b2_pi)
/// For legacy compatibility
uintptr_t pointer;
};
// Memory Allocation
/// Default allocation functions
B2_API void* b2Alloc_Default(int32 size);
B2_API void b2Free_Default(void* mem);
/// Implement this function to use your own memory allocator.
void* b2Alloc(int32 size);
inline void* b2Alloc(int32 size)
{
return b2Alloc_Default(size);
}
/// If you implement b2Alloc, you should also implement this function.
void b2Free(void* mem);
/// Logging function.
void b2Log(const char* string, ...);
/// Dump to a file. Only one dump file allowed at a time.
void b2OpenDump(const char* fileName);
void b2Dump(const char* string, ...);
void b2CloseDump();
/// Version numbering scheme.
/// See http://en.wikipedia.org/wiki/Software_versioning
struct b2Version
inline void b2Free(void* mem)
{
int32 major; ///< significant changes
int32 minor; ///< incremental changes
int32 revision; ///< bug fixes
};
b2Free_Default(mem);
}
/// Current version.
extern b2Version b2_version;
/// Default logging function
B2_API void b2Log_Default(const char* string, va_list args);
/// Implement this to use your own logging.
inline void b2Log(const char* string, ...)
{
va_list args;
va_start(args, string);
b2Log_Default(string, args);
va_end(args);
}
#endif // B2_USER_SETTINGS
void loveAssert(bool test, const char* teststr);
#define b2Assert(A) loveAssert((A), #A)
namespace love {
namespace physics {
namespace box2d {
struct bodyudata;
struct fixtureudata;
struct jointudata;
}
}
}
#define b2BodyUserData love::physics::box2d::bodyudata*
#define b2FixtureUserData love::physics::box2d::fixtureudata*
#define b2JointUserData love::physics::box2d::jointudata*
#include "b2_common.h"
#endif