#pragma once
#include "array.h"
#include "table.h"
#include "box2d/collision.h"
#include "box2d/types.h"
typedef struct b2Shape b2Shape;
typedef struct b2MovePair b2MovePair;
typedef struct b2MoveResult b2MoveResult;
typedef struct b2StackAllocator b2StackAllocator;
typedef struct b2World b2World;
#define B2_PROXY_TYPE( KEY ) ( (b2BodyType)( ( KEY ) & 3 ) )
#define B2_PROXY_ID( KEY ) ( ( KEY ) >> 2 )
#define B2_PROXY_KEY( ID, TYPE ) ( ( ( ID ) << 2 ) | ( TYPE ) )
typedef struct b2BroadPhase
{
b2DynamicTree trees[b2_bodyTypeCount];
int proxyCount;
b2HashSet moveSet;
b2IntArray moveArray;
b2MoveResult* moveResults;
b2MovePair* movePairs;
int movePairCapacity;
_Atomic int movePairIndex;
b2HashSet pairSet;
} b2BroadPhase;
void b2CreateBroadPhase( b2BroadPhase* bp );
void b2DestroyBroadPhase( b2BroadPhase* bp );
int b2BroadPhase_CreateProxy( b2BroadPhase* bp, b2BodyType proxyType, b2AABB aabb, uint64_t categoryBits, int shapeIndex,
bool forcePairCreation );
void b2BroadPhase_DestroyProxy( b2BroadPhase* bp, int proxyKey );
void b2BroadPhase_MoveProxy( b2BroadPhase* bp, int proxyKey, b2AABB aabb );
void b2BroadPhase_EnlargeProxy( b2BroadPhase* bp, int proxyKey, b2AABB aabb );
void b2BroadPhase_RebuildTrees( b2BroadPhase* bp );
int b2BroadPhase_GetShapeIndex( b2BroadPhase* bp, int proxyKey );
void b2UpdateBroadPhasePairs( b2World* world );
bool b2BroadPhase_TestOverlap( const b2BroadPhase* bp, int proxyKeyA, int proxyKeyB );
void b2ValidateBroadphase( const b2BroadPhase* bp );
void b2ValidateNoEnlarged( const b2BroadPhase* bp );
static inline void b2BufferMove( b2BroadPhase* bp, int queryProxy )
{
bool alreadyAdded = b2AddKey( &bp->moveSet, queryProxy + 1 );
if ( alreadyAdded == false )
{
b2IntArray_Push( &bp->moveArray, queryProxy );
}
}