Merge pull request #38 from dumganhar/jsb2.0-box2d
Hack box2d for jsb2.0
This commit is contained in:
commit
4ea54c180d
|
|
@ -65,4 +65,6 @@ For discussion please visit http://box2d.org/forum
|
|||
#include <Box2D/Dynamics/Joints/b2WeldJoint.h>
|
||||
#include <Box2D/Dynamics/Joints/b2WheelJoint.h>
|
||||
|
||||
#include <Box2D/b2ObjectDestroyNotifier.h>
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
#include <Box2D/Dynamics/b2Body.h>
|
||||
#include <Box2D/Dynamics/b2Fixture.h>
|
||||
#include <Box2D/Dynamics/b2World.h>
|
||||
#include <Box2D/b2ObjectDestroyNotifier.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
#include <Box2D/Dynamics/b2Body.h>
|
||||
#include <Box2D/Dynamics/b2World.h>
|
||||
#include <Box2D/Common/b2BlockAllocator.h>
|
||||
#include <Box2D/b2ObjectDestroyNotifier.h>
|
||||
|
||||
#include <new>
|
||||
|
||||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
#include <Box2D/Collision/b2BroadPhase.h>
|
||||
#include <Box2D/Collision/b2Collision.h>
|
||||
#include <Box2D/Common/b2BlockAllocator.h>
|
||||
#include <Box2D/b2ObjectDestroyNotifier.h>
|
||||
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
#include <Box2D/Collision/b2TimeOfImpact.h>
|
||||
#include <Box2D/Common/b2Draw.h>
|
||||
#include <Box2D/Common/b2Timer.h>
|
||||
#include <Box2D/b2ObjectDestroyNotifier.h>
|
||||
#include <new>
|
||||
|
||||
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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
Loading…
Reference in New Issue