Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
erincatto committed Aug 12, 2023
1 parent 4f2301f commit 5136235
Show file tree
Hide file tree
Showing 13 changed files with 216 additions and 37 deletions.
3 changes: 3 additions & 0 deletions include/box2d/debug_draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ typedef struct b2DebugDraw
/// Draw a point.
void (*DrawPoint)(b2Vec2 p, float size, b2Color color, void* context);

/// Draw a string.
void (*DrawString)(b2Vec2 p, const char* s, void* context);

bool drawShapes;
bool drawJoints;
bool drawAABBs;
Expand Down
3 changes: 3 additions & 0 deletions samples/collection/benchmark_pyramid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ class BenchmarkPyramid : public Sample

for (int32_t j = i; j < m_baseCount; ++j)
{
//float x = (1.5f * i + 1.0f) * m_extent + 3.0f * (j - i) * m_extent + centerX - 0.5f;
float x = (i + 1.0f) * m_extent + 2.25f * (j - i) * m_extent + centerX - 0.5f;

bodyDef.position = {x, y};

assert(m_bodyIndex < m_bodyCount);
Expand Down Expand Up @@ -105,6 +107,7 @@ class BenchmarkPyramid : public Sample
for (int32_t i = 0; i < m_rowCount; ++i)
{
b2Segment segment = {{-0.5f * groundWidth, groundY}, {0.5f * groundWidth, groundY}};
//b2Segment segment = {{-0.5f * 2.0f * groundWidth, groundY}, {0.5f * 2.0f * groundWidth, groundY}};
b2Body_CreateSegment(m_groundId, &shapeDef, &segment);
groundY += groundDeltaY;
}
Expand Down
22 changes: 6 additions & 16 deletions samples/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,11 @@ void DrawPointFcn(b2Vec2 p, float size, b2Color color, void* context)
static_cast<Draw*>(context)->DrawPoint(p, size, color);
}

//
void DrawStringFcn(b2Vec2 p, const char* s, void* context)
{
static_cast<Draw*>(context)->DrawString(p, s);
}

Draw::Draw()
{
m_showUI = true;
Expand All @@ -871,15 +875,13 @@ Draw::Draw()
m_debugDraw = {};
}

//
Draw::~Draw()
{
assert(m_points == nullptr);
assert(m_lines == nullptr);
assert(m_triangles == nullptr);
}

//
void Draw::Create()
{
m_points = static_cast<GLRenderPoints*>(malloc(sizeof(GLRenderPoints)));
Expand All @@ -901,14 +903,14 @@ void Draw::Create()
DrawSegmentFcn,
DrawTransformFcn,
DrawPointFcn,
DrawStringFcn,
true,
true,
false,
false,
this};
}

//
void Draw::Destroy()
{
m_points->Destroy();
Expand All @@ -928,7 +930,6 @@ void Draw::Destroy()
m_roundedTriangles = nullptr;
}

//
void Draw::DrawPolygon(const b2Vec2* vertices, int32_t vertexCount, b2Color color)
{
b2Vec2 p1 = vertices[vertexCount - 1];
Expand All @@ -941,7 +942,6 @@ void Draw::DrawPolygon(const b2Vec2* vertices, int32_t vertexCount, b2Color colo
}
}

//
void Draw::DrawSolidPolygon(const b2Vec2* vertices, int32_t vertexCount, b2Color color)
{
b2Color fillColor = {0.5f * color.r, 0.5f * color.g, 0.5f * color.b, 0.5f};
Expand Down Expand Up @@ -1038,7 +1038,6 @@ void Draw::DrawRoundedPolygon(const b2Vec2* vertices, int32_t count, float radiu
}
}

//
void Draw::DrawCircle(b2Vec2 center, float radius, b2Color color)
{
const float k_segments = 32.0f;
Expand All @@ -1061,7 +1060,6 @@ void Draw::DrawCircle(b2Vec2 center, float radius, b2Color color)
}
}

//
void Draw::DrawSolidCircle(b2Vec2 center, float radius, b2Vec2 axis, b2Color color)
{
b2Color fillColor = {0.5f * color.r, 0.5f * color.g, 0.5f * color.b, 0.5f};
Expand Down Expand Up @@ -1166,7 +1164,6 @@ void Draw::DrawCapsule(b2Vec2 p1, b2Vec2 p2, float radius, b2Color color)
m_lines->Vertex(p2, color);
}

//
void Draw::DrawSolidCapsule(b2Vec2 p1, b2Vec2 p2, float radius, b2Color color)
{
float length;
Expand Down Expand Up @@ -1267,14 +1264,12 @@ void Draw::DrawSolidCapsule(b2Vec2 p1, b2Vec2 p2, float radius, b2Color color)
m_lines->Vertex(p2, color);
}

//
void Draw::DrawSegment(b2Vec2 p1, b2Vec2 p2, b2Color color)
{
m_lines->Vertex(p1, color);
m_lines->Vertex(p2, color);
}

//
void Draw::DrawTransform(b2Transform xf)
{
const float k_axisScale = 0.4f;
Expand All @@ -1291,13 +1286,11 @@ void Draw::DrawTransform(b2Transform xf)
m_lines->Vertex(p2, green);
}

//
void Draw::DrawPoint(b2Vec2 p, float size, b2Color color)
{
m_points->Vertex(p, color, size);
}

//
void Draw::DrawString(int x, int y, const char* string, ...)
{
// if (m_showUI == false)
Expand All @@ -1316,7 +1309,6 @@ void Draw::DrawString(int x, int y, const char* string, ...)
va_end(arg);
}

//
void Draw::DrawString(b2Vec2 pw, const char* string, ...)
{
b2Vec2 ps = g_camera.ConvertWorldToScreen(pw);
Expand All @@ -1332,7 +1324,6 @@ void Draw::DrawString(b2Vec2 pw, const char* string, ...)
va_end(arg);
}

//
void Draw::DrawAABB(b2AABB aabb, b2Color c)
{
b2Vec2 p1 = aabb.lowerBound;
Expand All @@ -1353,7 +1344,6 @@ void Draw::DrawAABB(b2AABB aabb, b2Color c)
m_lines->Vertex(p1, c);
}

//
void Draw::Flush()
{
m_roundedTriangles->Flush();
Expand Down
6 changes: 3 additions & 3 deletions src/bitset.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static inline void b2SetBit(b2BitSet* bitSet, uint32_t bitIndex)
uint32_t wordIndex = bitIndex / 64;
// TODO_ERIN support growing
B2_ASSERT(wordIndex < bitSet->wordCount);
bitSet->bits[wordIndex] |= ((uint64_t)1) << (bitIndex % 64);
bitSet->bits[wordIndex] |= ((uint64_t)1 << bitIndex % 64);
}

static inline void b2ClearBit(b2BitSet* bitSet, uint32_t bitIndex)
Expand All @@ -36,7 +36,7 @@ static inline void b2ClearBit(b2BitSet* bitSet, uint32_t bitIndex)
{
return;
}
bitSet->bits[wordIndex] &= ~(((uint64_t)1) << (bitIndex % 64));
bitSet->bits[wordIndex] &= ~((uint64_t)1 << bitIndex % 64);
}

static inline bool b2GetBit(const b2BitSet* bitSet, uint32_t bitIndex)
Expand All @@ -46,7 +46,7 @@ static inline bool b2GetBit(const b2BitSet* bitSet, uint32_t bitIndex)
{
return false;
}
return (bitSet->bits[wordIndex] & ((uint64_t)1) << (bitIndex % 64)) != 0;
return (bitSet->bits[wordIndex] & ((uint64_t)1 << bitIndex % 64)) != 0;
}

#if defined(_MSC_VER) && !defined(__clang__)
Expand Down
6 changes: 4 additions & 2 deletions src/body.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,10 @@ void b2World_DestroyBody(b2BodyId bodyId)

b2Contact* contact = world->contacts + contactIndex;

// TODO_ERIN could pass bodies
b2RemoveContactFromGraph(world, &world->graph, contact);
if (contact->colorIndex != B2_NULL_INDEX)
{
b2RemoveContactFromGraph(world, contact);
}

b2ContactEdge* twin = contact->edges + twinIndex;

Expand Down
9 changes: 4 additions & 5 deletions src/contact.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,6 @@ void b2CreateContact(b2World* world, b2Shape* shapeA, b2Shape* shapeB)
// Add to pair set for fast lookup
uint64_t pairKey = B2_SHAPE_PAIR_KEY(contact->shapeIndexA, contact->shapeIndexB);
b2AddKey(&world->broadPhase.pairSet, pairKey);

// TODO_ERIN could pass bodies
b2AddContactToGraph(world, &world->graph, contact);
}

void b2DestroyContact(b2World* world, b2Contact* contact)
Expand All @@ -273,8 +270,10 @@ void b2DestroyContact(b2World* world, b2Contact* contact)
b2Body* bodyA = world->bodies + edgeA->bodyIndex;
b2Body* bodyB = world->bodies + edgeB->bodyIndex;

// TODO_ERIN pass bodies
b2RemoveContactFromGraph(world, &world->graph, contact);
if (contact->colorIndex != B2_NULL_INDEX)
{
b2RemoveContactFromGraph(world, contact);
}

// if (contactListener && contact->IsTouching())
//{
Expand Down
Loading

0 comments on commit 5136235

Please sign in to comment.