Skip to content

Commit

Permalink
remove block array
Browse files Browse the repository at this point in the history
  • Loading branch information
erincatto committed Sep 18, 2024
1 parent 9044b4d commit 4bd25ae
Show file tree
Hide file tree
Showing 40 changed files with 552 additions and 929 deletions.
1 change: 0 additions & 1 deletion samples/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,6 @@ static void UpdateUI()
}
}

//
int main( int, char** )
{
#if defined( _WIN32 )
Expand Down
4 changes: 2 additions & 2 deletions samples/sample_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,8 +671,8 @@ class BenchmarkManyPyramids : public Sample
m_extent = 0.5f;
m_round = 0.0f;
m_baseCount = 10;
m_rowCount = g_sampleDebug ? 4 : 13;
m_columnCount = g_sampleDebug ? 4 : 14;
m_rowCount = g_sampleDebug ? 4 : 20;
m_columnCount = g_sampleDebug ? 4 : 20;
m_groundId = b2_nullBodyId;
m_bodyIds = nullptr;
m_bodyCount = 0;
Expand Down
4 changes: 0 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
set(BOX2D_SOURCE_FILES
aabb.c
aabb.h
allocate.c
allocate.h
array.c
array.h
bitset.c
bitset.h
block_array.c
block_array.h
body.c
body.h
broad_phase.c
Expand Down
129 changes: 0 additions & 129 deletions src/allocate.c

This file was deleted.

8 changes: 0 additions & 8 deletions src/allocate.h

This file was deleted.

1 change: 0 additions & 1 deletion src/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "array.h"

#include "allocate.h"
#include "core.h"

#include <string.h>
Expand Down
48 changes: 40 additions & 8 deletions src/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#pragma once

#include "assert.h"
#include "core.h"

// todo compare with https://github.com/skeeto/growable-buf
Expand Down Expand Up @@ -57,14 +56,26 @@ void b2Array_Resize( void** a, int elementSize, int count );
// Cons
// - macros suck, however all array functions are real, type-safe functions

// Array definition that doesn't need the type T to be defined
#define B2_ARRAY( T, PREFIX ) \
// Array declaration that doesn't need the type T to be defined
#define B2_DECLARE_ARRAY( T, PREFIX ) \
typedef struct \
{ \
struct T* data; \
int count; \
int capacity; \
} PREFIX##Array; \
PREFIX##Array PREFIX##Array_Create( int capacity ); \
void PREFIX##Array_Reserve( PREFIX##Array* a, int newCapacity ); \
void PREFIX##Array_Destroy( PREFIX##Array* a );

#define B2_DECLARE_ARRAY_NATIVE( T, PREFIX ) \
typedef struct \
{ \
T* data; \
int count; \
int capacity; \
} PREFIX##Array; \
/* Create array with initial capacity. Zero initialization is also supported */ \
PREFIX##Array PREFIX##Array_Create( int capacity ); \
void PREFIX##Array_Reserve( PREFIX##Array* a, int newCapacity ); \
void PREFIX##Array_Destroy( PREFIX##Array* a );
Expand All @@ -77,6 +88,17 @@ void b2Array_Resize( void** a, int elementSize, int count );
return a->data + index; \
} \
\
static inline T* PREFIX##Array_Add( PREFIX##Array* a ) \
{ \
if ( a->count == a->capacity ) \
{ \
int newCapacity = a->capacity < 2 ? 2 : a->capacity + ( a->capacity >> 1 ); \
PREFIX##Array_Reserve( a, newCapacity ); \
} \
a->count += 1; \
return a->data + ( a->count - 1 ); \
} \
\
static inline void PREFIX##Array_Push( PREFIX##Array* a, T value ) \
{ \
if ( a->count == a->capacity ) \
Expand All @@ -94,14 +116,17 @@ void b2Array_Resize( void** a, int elementSize, int count );
a->data[index] = value; \
} \
\
static inline void PREFIX##Array_RemoveSwap( PREFIX##Array* a, int index ) \
static inline int PREFIX##Array_RemoveSwap( PREFIX##Array* a, int index ) \
{ \
B2_ASSERT( 0 <= index && index < a->count ); \
int movedIndex = B2_NULL_INDEX; \
if ( index != a->count - 1 ) \
{ \
a->data[index] = a->data[a->count - 1]; \
movedIndex = a->count - 1; \
a->data[index] = a->data[movedIndex]; \
} \
a->count -= 1; \
return movedIndex; \
} \
\
static inline T PREFIX##Array_Pop( PREFIX##Array* a ) \
Expand Down Expand Up @@ -146,8 +171,15 @@ void b2Array_Resize( void** a, int elementSize, int count );
a->capacity = 0; \
}

B2_ARRAY( int, b2Int );
B2_DECLARE_ARRAY_NATIVE( int, b2Int );
B2_ARRAY_INLINE( int, b2Int );

typedef struct b2Body b2Body;
B2_ARRAY( b2Body, b2Body );
B2_DECLARE_ARRAY( b2Body, b2Body );
B2_DECLARE_ARRAY( b2BodySim, b2BodySim );
B2_DECLARE_ARRAY( b2BodyState, b2BodyState );
B2_DECLARE_ARRAY( b2Contact, b2Contact );
B2_DECLARE_ARRAY( b2ContactSim, b2ContactSim );
B2_DECLARE_ARRAY( b2Joint, b2Joint );
B2_DECLARE_ARRAY( b2JointSim, b2JointSim );
B2_DECLARE_ARRAY( b2Island, b2Island );
B2_DECLARE_ARRAY( b2IslandSim, b2IslandSim );
2 changes: 0 additions & 2 deletions src/bitset.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

#include "bitset.h"

#include "allocate.h"

#include <string.h>

b2BitSet b2CreateBitSet( uint32_t bitCapacity )
Expand Down
Loading

0 comments on commit 4bd25ae

Please sign in to comment.