Box2D 3.1.0
A 2D physics engine for games
Loading...
Searching...
No Matches
base.h
1// SPDX-FileCopyrightText: 2023 Erin Catto
2// SPDX-License-Identifier: MIT
3
4#pragma once
5
6#include <stdint.h>
7
8// clang-format off
9//
10// Shared library macros
11#if defined( _MSC_VER ) && defined( box2d_EXPORTS )
12 // build the Windows DLL
13 #define BOX2D_EXPORT __declspec( dllexport )
14#elif defined( _MSC_VER ) && defined( BOX2D_DLL )
15 // using the Windows DLL
16 #define BOX2D_EXPORT __declspec( dllimport )
17#elif defined( box2d_EXPORTS )
18 // building or using the Box2D shared library
19 #define BOX2D_EXPORT __attribute__( ( visibility( "default" ) ) )
20#else
21 // static library
22 #define BOX2D_EXPORT
23#endif
24
25// C++ macros
26#ifdef __cplusplus
27 #define B2_API extern "C" BOX2D_EXPORT
28 #define B2_INLINE inline
29 #define B2_LITERAL(T) T
30 #define B2_ZERO_INIT {}
31#else
32 #define B2_API BOX2D_EXPORT
33 #define B2_INLINE static inline
35 #define B2_LITERAL(T) (T)
36 #define B2_ZERO_INIT {0}
37#endif
38// clang-format on
39
49typedef void* b2AllocFcn( unsigned int size, int alignment );
50
53typedef void b2FreeFcn( void* mem );
54
56typedef int b2AssertFcn( const char* condition, const char* fileName, int lineNumber );
57
60B2_API void b2SetAllocator( b2AllocFcn* allocFcn, b2FreeFcn* freeFcn );
61
63B2_API int b2GetByteCount( void );
64
67B2_API void b2SetAssertFcn( b2AssertFcn* assertFcn );
68
71typedef struct b2Version
72{
74 int major;
75
77 int minor;
78
81} b2Version;
82
84B2_API b2Version b2GetVersion( void );
85
89// Timer for profiling. This has platform specific code and may not work on every platform.
90typedef 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;
97#else
98 int32_t dummy;
99#endif
100} b2Timer;
101
102B2_API b2Timer b2CreateTimer( void );
103B2_API int64_t b2GetTicks( b2Timer* timer );
104B2_API float b2GetMilliseconds( const b2Timer* timer );
105B2_API float b2GetMillisecondsAndReset( b2Timer* timer );
106B2_API void b2SleepMilliseconds( int milliseconds );
107B2_API void b2Yield( void );
108
109// Simple djb2 hash function for determinism testing
110#define B2_HASH_INIT 5381
111B2_API uint32_t b2Hash( uint32_t hash, const uint8_t* data, int count );
112
int minor
Incremental changes.
Definition base.h:77
int revision
Bug fixes.
Definition base.h:80
int major
Significant changes.
Definition base.h:74
void * b2AllocFcn(unsigned int size, int alignment)
Prototype for user allocation function.
Definition base.h:49
void b2SetAllocator(b2AllocFcn *allocFcn, b2FreeFcn *freeFcn)
This allows the user to override the allocation functions.
void b2FreeFcn(void *mem)
Prototype for user free function.
Definition base.h:53
void b2SetAssertFcn(b2AssertFcn *assertFcn)
Override the default assert callback.
int b2AssertFcn(const char *condition, const char *fileName, int lineNumber)
Prototype for the user assert callback. Return 0 to skip the debugger break.
Definition base.h:56
int b2GetByteCount(void)
b2Version b2GetVersion(void)
Get the current version of Box2D.
Version numbering scheme.
Definition base.h:72