Defold-box2d Box2D extension

Setting & getting the category and mask bitmasks. You have it in the limitations in the Readme:

5)No binding some b2Fixture functions.

not support filter in fixture def.
...
void SetFilterData(const b2Filter& filter);
const b2Filter& GetFilterData() const;

Also Box2D: Dynamics Module

2 Likes

Oh I was sure that I add it)) sorry):joy:
I will add it in next release

2 Likes

I think that you ask about that.

void SetContactFilter(b2ContactFilter* filter);
1 Like

Hmm, that’s the one one b2World? Hmm, I don’t actually know about that one, I don’t think I would need that if there is a default filter function set.

What I mean is:

  1. In the b2FixtureDef you should be able to set the filter - which should have ‘categoryBits’, ‘maskBits’, and ‘groupIndex’ fields.

  2. After you create it, the b2Fixture should have:
    void SetFilterData (const b2Filter &filter)
    constb2Filter& GetFilterData () const

1 Like

:drooling_face:

2 Likes

Thanks for your reply) @ross.grams

I’ve released a new version 0.9.1
1)Add binding for b2Filter.

1 Like

Try to make this extenstion more user friendly.

1)Split documentation to different pages. Thanks to @ross.grams
2)Update ui for example scene.
3)Enable high dpi for example project.
4)Add --verify-graphics-calls=false to engine arguments.Fixed performance on chrome.

9 Likes

I’ve released a new version 0.9.2
The main feature is b2Shape binding. In prev version use table to describe shape. Now you can create b2Shapes, or continue to use tables.

[CHANGELOG]

  1. Add full binding for b2Shape.(Now you can create and manipulate box2d shapes)

  2. body:GetTransform() return b2Transform table. Prev was position and angle.

  3. Fixed debug render not draw transform(center of mass)

  4. Add Box2dFixture functions.(Box2dFixture full binding done)

    • Box2dFixture:GetAABB()
    • Box2dFixture:GetShape()
    • Box2dFixture:RayCast()
4 Likes

Hi @Mathias_Westerdahl
I need some help with ne. Can you please help me with it:)

How can i get lua_State *L from anywhere?

1)I can save lua_State *L to global variable when any native function called from lua.

Maybe you know easy way?

I need it because:

box2d is use assert function.

#define b2Assert(A) assert(A)
b2Assert(m_vertices == nullptr && m_count == 0);
b2Assert(count >= 2);

So if b2assert happened it crashed the engine.
I want to change assert to lua_error(L);

But lua_error need lua_State *L

You get the Lua state in the extension init function (where you register the Lua module)

2 Likes

Thanks.
I can save that luaState? it will not be changed?

Correct, that Lua state is valid until the matching extension ext function is called.

1 Like

Continue working on extenstion :partying_face:
I’ve released a new version 0.9.3

[CHANGELOG]
1)Refactor(add base class for b2objects wrappers, fixed some memory leaks)
2)Replace lua_error with luaL_error(luaL_error show line number)
3)Add Box2dWorld:SetDestructionListener(listener)
4)replace b2assert with printf

4 Likes

About b2assert. I use prinf because it worked. With luaL_error or dmLogError i have problems

If someone with c++ experience look on it, and help it will be awesome, i have no ideas:) @Mathias_Westerdahl

1)I try to replace it to luaL_error but nothing happened.

#define b2Assert(expr) \
  ( (expr)? (void)0 : (void) luaL_error(box2dDefoldNE::GLOBAL_L,"[ERROR]b2Assert. Expr:%s\n",#expr) )

2)I try to replace it to dmLogError but get compilation error.

#define b2Assert(expr) \
    ( (expr)? (void)0 : (void)dmLogError("[ERROR]b2Assert. Expr:%s\n",#expr) )
/box2d/native/include/b2_island.h
	Line 58: In file included from upload/box2d/native/src/dynamics/b2_island.cpp:32:
unexpected ';' before ')'
                b2Assert(m_bodyCount < m_bodyCapacity);
                ^

I’m not sure why that error pops up unfortunately.
I think your new defines look ok.

However, I’d avoid using the log-version, since the assert is intended to stop the execution since the data isn’t ok. Continuing to run past the assert is probably not best.
So I think using the Lua error version is better, since it exits out of the current function.

2 Likes

lual_Error not stop exit, i do not understand why)

I have test, for b2assert but it not exit when lual_Error call, i have no idea why😮

Box2d worked correct if assert not stopped.
Box2D use if and check after assert:)

I’d say, it might have worked ok for you. I don’t think it’s a guarantuee that it will work correctly for others.

Box2D use if and check after assert:)

Well, that’s ok, because the assumption is that there shouldn’t have been an assert!
And if it were, it should have stopped, and the developer should fix their problem.

2 Likes

Fxed error for dmLogError.
There was a “;” in dmLogError define. :grinning:

#define dmLogError(format, ... ) dmLogInternal(DM_LOG_SEVERITY_ERROR, DLIB_LOG_DOMAIN, format, __VA_ARGS__ );
#define dmLogErrorFixed(format, ... ) dmLogInternal(DM_LOG_SEVERITY_ERROR, DLIB_LOG_DOMAIN, format, __VA_ARGS__ )
1 Like

I wouldn’t recommend redefining the dmLog, but instead use your own scope.

#define b2Assert(expr) \
{ \
    if (!(expr)) { \
        dmLogError("[ERROR]b2Assert. Expr:%s\n",#expr); \
    } \
}

Just remember what I said about removing the asserts, which is essentially what you do now. To put it more to the point, if you go down this route, you can simply remove the b2Assert’s altogether, as they no longer fulfil their use.

2 Likes