15
15
// using the Windows DLL
16
16
#define BOX2D_EXPORT __declspec( dllimport )
17
17
#elif defined( box2d_EXPORTS )
18
- // building or using the Box2D shared library
18
+ // building or using the shared library
19
19
#define BOX2D_EXPORT __attribute__( ( visibility( "default" ) ) )
20
20
#else
21
21
// static library
44
44
*/
45
45
46
46
/// Prototype for user allocation function
47
- /// @param size the allocation size in bytes
48
- /// @param alignment the required alignment, guaranteed to be a power of 2
47
+ /// @param size the allocation size in bytes
48
+ /// @param alignment the required alignment, guaranteed to be a power of 2
49
49
typedef void * b2AllocFcn ( unsigned int size , int alignment );
50
50
51
51
/// Prototype for user free function
52
- /// @param mem the memory previously allocated through `b2AllocFcn`
52
+ /// @param mem the memory previously allocated through `b2AllocFcn`
53
53
typedef void b2FreeFcn ( void * mem );
54
54
55
55
/// Prototype for the user assert callback. Return 0 to skip the debugger break.
56
56
typedef int b2AssertFcn ( const char * condition , const char * fileName , int lineNumber );
57
57
58
58
/// This allows the user to override the allocation functions. These should be
59
- /// set during application startup.
59
+ /// set during application startup.
60
60
B2_API void b2SetAllocator ( b2AllocFcn * allocFcn , b2FreeFcn * freeFcn );
61
61
62
62
/// @return the total bytes allocated by Box2D
63
63
B2_API int b2GetByteCount ( void );
64
64
65
65
/// Override the default assert callback
66
- /// @param assertFcn a non-null assert callback
66
+ /// @param assertFcn a non-null assert callback
67
67
B2_API void b2SetAssertFcn ( b2AssertFcn * assertFcn );
68
68
69
69
/// Version numbering scheme.
@@ -86,27 +86,45 @@ B2_API b2Version b2GetVersion( void );
86
86
/**@}*/
87
87
88
88
//! @cond
89
- // Timer for profiling. This has platform specific code and may not work on every platform.
90
- typedef struct b2Timer
91
- {
92
- #if defined( _WIN32 )
93
- int64_t start ;
94
- #elif defined( __linux__ ) || defined( __APPLE__ )
95
- unsigned long long start_sec ;
96
- unsigned long long start_usec ;
89
+
90
+ // see https://github.com/scottt/debugbreak
91
+ #if defined( _MSC_VER )
92
+ #define B2_BREAKPOINT __debugbreak()
93
+ #elif defined( __GNUC__ ) || defined( __clang__ )
94
+ #define B2_BREAKPOINT __builtin_trap()
95
+ #else
96
+ // Unknown compiler
97
+ #include <assert.h>
98
+ #define B2_BREAKPOINT assert( 0 )
99
+ #endif
100
+
101
+ #if !defined( NDEBUG ) || defined( B2_ENABLE_ASSERT )
102
+ B2_API int b2InternalAssertFcn ( const char * condition , const char * fileName , int lineNumber );
103
+ #define B2_ASSERT ( condition ) \
104
+ do \
105
+ { \
106
+ if ( !( condition ) && b2InternalAssertFcn( #condition, __FILE__, (int)__LINE__ ) ) \
107
+ B2_BREAKPOINT; \
108
+ } \
109
+ while ( 0 )
97
110
#else
98
- int32_t dummy ;
111
+ #define B2_ASSERT ( ... ) ( (void)0 )
99
112
#endif
100
- } b2Timer ;
101
113
102
- B2_API b2Timer b2CreateTimer ( void );
103
- B2_API int64_t b2GetTicks ( b2Timer * timer );
104
- B2_API float b2GetMilliseconds ( const b2Timer * timer );
105
- B2_API float b2GetMillisecondsAndReset ( b2Timer * timer );
106
- B2_API void b2SleepMilliseconds ( int milliseconds );
114
+ /// Get the absolute number of system ticks. The value is platform specific.
115
+ B2_API uint64_t b2GetTicks ( void );
116
+
117
+ /// Get the milliseconds passed from an initial tick value.
118
+ B2_API float b2GetMilliseconds ( uint64_t ticks );
119
+
120
+ /// Get the milliseconds passed from an initial tick value. Resets the passed in
121
+ /// value to the current tick value.
122
+ B2_API float b2GetMillisecondsAndReset ( uint64_t * ticks );
123
+
124
+ /// Yield to be used in a busy loop.
107
125
B2_API void b2Yield ( void );
108
126
109
- // Simple djb2 hash function for determinism testing
127
+ /// Simple djb2 hash function for determinism testing
110
128
#define B2_HASH_INIT 5381
111
129
B2_API uint32_t b2Hash ( uint32_t hash , const uint8_t * data , int count );
112
130
0 commit comments