diff --git a/sources/Box2D/Box2D.h b/sources/Box2D/Box2D.h index f98f87a5..b43aa6aa 100755 --- a/sources/Box2D/Box2D.h +++ b/sources/Box2D/Box2D.h @@ -65,4 +65,6 @@ For discussion please visit http://box2d.org/forum #include #include +#include + #endif diff --git a/sources/Box2D/Dynamics/Contacts/b2Contact.cpp b/sources/Box2D/Dynamics/Contacts/b2Contact.cpp index 8d0104e8..93ed4d5b 100755 --- a/sources/Box2D/Dynamics/Contacts/b2Contact.cpp +++ b/sources/Box2D/Dynamics/Contacts/b2Contact.cpp @@ -33,6 +33,7 @@ #include #include #include +#include b2ContactRegister b2Contact::s_registers[b2Shape::e_typeCount][b2Shape::e_typeCount]; bool b2Contact::s_initialized = false; @@ -119,6 +120,7 @@ void b2Contact::Destroy(b2Contact* contact, b2BlockAllocator* allocator) b2Assert(0 <= typeA && typeB < b2Shape::e_typeCount); b2Assert(0 <= typeA && typeB < b2Shape::e_typeCount); + b2NotifyObjectDestroyed(contact, b2ObjectType::CONTACT, typeid(*contact).name()); b2ContactDestroyFcn* destroyFcn = s_registers[typeA][typeB].destroyFcn; destroyFcn(contact, allocator); } diff --git a/sources/Box2D/Dynamics/Joints/b2Joint.cpp b/sources/Box2D/Dynamics/Joints/b2Joint.cpp index 50919495..7a6cf7a4 100755 --- a/sources/Box2D/Dynamics/Joints/b2Joint.cpp +++ b/sources/Box2D/Dynamics/Joints/b2Joint.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -127,6 +128,7 @@ b2Joint* b2Joint::Create(const b2JointDef* def, b2BlockAllocator* allocator) void b2Joint::Destroy(b2Joint* joint, b2BlockAllocator* allocator) { + b2NotifyObjectDestroyed(joint, b2ObjectType::JOIN, typeid(*joint).name()); joint->~b2Joint(); switch (joint->m_type) { diff --git a/sources/Box2D/Dynamics/b2Fixture.cpp b/sources/Box2D/Dynamics/b2Fixture.cpp index d97aa448..cacc5f9a 100755 --- a/sources/Box2D/Dynamics/b2Fixture.cpp +++ b/sources/Box2D/Dynamics/b2Fixture.cpp @@ -26,6 +26,7 @@ #include #include #include +#include b2Fixture::b2Fixture() { @@ -82,6 +83,7 @@ void b2Fixture::Destroy(b2BlockAllocator* allocator) case b2Shape::e_circle: { b2CircleShape* s = (b2CircleShape*)m_shape; + b2NotifyObjectDestroyed(s, b2ObjectType::CIRCLE_SHAPE, "b2CircleShape"); s->~b2CircleShape(); allocator->Free(s, sizeof(b2CircleShape)); } @@ -90,6 +92,7 @@ void b2Fixture::Destroy(b2BlockAllocator* allocator) case b2Shape::e_edge: { b2EdgeShape* s = (b2EdgeShape*)m_shape; + b2NotifyObjectDestroyed(s, b2ObjectType::EDGE_SHAPE, "b2EdgeShape"); s->~b2EdgeShape(); allocator->Free(s, sizeof(b2EdgeShape)); } @@ -98,6 +101,7 @@ void b2Fixture::Destroy(b2BlockAllocator* allocator) case b2Shape::e_polygon: { b2PolygonShape* s = (b2PolygonShape*)m_shape; + b2NotifyObjectDestroyed(s, b2ObjectType::POLYGON_SHAPE, "b2PolygonShape"); s->~b2PolygonShape(); allocator->Free(s, sizeof(b2PolygonShape)); } @@ -106,6 +110,7 @@ void b2Fixture::Destroy(b2BlockAllocator* allocator) case b2Shape::e_chain: { b2ChainShape* s = (b2ChainShape*)m_shape; + b2NotifyObjectDestroyed(s, b2ObjectType::CHAIN_SHAPE, "b2ChainShape"); s->~b2ChainShape(); allocator->Free(s, sizeof(b2ChainShape)); } @@ -117,6 +122,8 @@ void b2Fixture::Destroy(b2BlockAllocator* allocator) } m_shape = NULL; + + b2NotifyObjectDestroyed(this, b2ObjectType::FIXTURE, "b2Fixture"); } void b2Fixture::CreateProxies(b2BroadPhase* broadPhase, const b2Transform& xf) diff --git a/sources/Box2D/Dynamics/b2World.cpp b/sources/Box2D/Dynamics/b2World.cpp index 53bc14a2..2b75d9d2 100755 --- a/sources/Box2D/Dynamics/b2World.cpp +++ b/sources/Box2D/Dynamics/b2World.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include b2World::b2World(const b2Vec2& gravity) @@ -205,6 +206,7 @@ void b2World::DestroyBody(b2Body* b) } --m_bodyCount; + b2NotifyObjectDestroyed(b, b2ObjectType::BODY, "b2Body"); b->~b2Body(); m_blockAllocator.Free(b, sizeof(b2Body)); } diff --git a/sources/Box2D/b2ObjectDestroyNotifier.cpp b/sources/Box2D/b2ObjectDestroyNotifier.cpp new file mode 100644 index 00000000..2255c27a --- /dev/null +++ b/sources/Box2D/b2ObjectDestroyNotifier.cpp @@ -0,0 +1,16 @@ +#include "b2ObjectDestroyNotifier.h" + +static b2ObjectDestroyNotifer __objectDestroyNotifier = nullptr; + +void b2SetObjectDestroyNotifier(b2ObjectDestroyNotifer notifier) +{ + __objectDestroyNotifier = notifier; +} + +void b2NotifyObjectDestroyed(void* obj, b2ObjectType type, const char* typeName) +{ + if (__objectDestroyNotifier != nullptr) + { + __objectDestroyNotifier(obj, type, typeName); + } +} diff --git a/sources/Box2D/b2ObjectDestroyNotifier.h b/sources/Box2D/b2ObjectDestroyNotifier.h new file mode 100644 index 00000000..481d368c --- /dev/null +++ b/sources/Box2D/b2ObjectDestroyNotifier.h @@ -0,0 +1,18 @@ +#pragma once + +enum class b2ObjectType +{ + CONTACT, + CIRCLE_SHAPE, + EDGE_SHAPE, + POLYGON_SHAPE, + CHAIN_SHAPE, + FIXTURE, + JOIN, + BODY +}; + +typedef void (*b2ObjectDestroyNotifer)(void*, b2ObjectType, const char*); + +void b2SetObjectDestroyNotifier(b2ObjectDestroyNotifer notifier); +void b2NotifyObjectDestroyed(void* obj, b2ObjectType type, const char* typeName);