Defold-box2d Box2D extension

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

Thanks. I will use your code. It better😁
I am not good at c++ :))

I will later look on lual_error. Replacing assert with lual_error will be the best solution:)

1 Like

Hey, I think your contribution is great! :clap:

4 Likes

Ohh. luaL_error very strange :slight_smile:
It stop execution as excepted.
But on windows it does not contains error on stack. pcall return table from function args, not error string
On html that error is not catched by pcall, and game is crashed:)

#define b2Assert(expr) \
{ \
    if (!(expr)) { \
        dmLogError("[ERROR]b2Assert. Expr:%s",#expr); \
        luaL_error(box2dDefoldNE::GLOBAL_L,"[ERROR]b2Assert. Expr:%s",#expr); \
        dmLogError("After luaL_error"); \
    } \
}
test("b2Assert", function()
            local shape = box2d.NewPolygonShape()
            local status, value = pcall(shape.Set,shape,{ vmath.vector3(0, 0, 0), vmath.vector3(1, 0, 0) })
            assert_false(status)
            UTILS.test_error(value,"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
        end)

I’ve released a new version 1.0.0
Hooray :partying_face: :partying_face: :partying_face:

I am believe this extension is ready for using in games.

It 99% binding of box2d. Some functions and classes are not binded, but it have all you need to make a game with physic.

Now it have 241 tests. First version have 195.

Fixed some bugs, and add new functions.

[CHANGELOG]

1.Replace b2assert with dmLogError
2.Refactor wrapper for b2Contact
3.Fixed wrappers for box2dObjects was not delete.
4.Add old_manifold and impulse to contact listener
5.Add Box2dContact:GetNext()
6.Add Box2dWorld:GetContactList()
7.Add Box2dBody:GetJointList()
8.Add Box2dBody:GetContactList()

11 Likes

Make a simple game with box2d extension.

18 Likes

Thank you @d954mas for this extension! :heart:

As a kind reminder Dmitry beside of this created for us i.a. emmylua integrations for intellij and vscode, many open sourced game examples or 2.5D shooter example. So, I guess it’s reasonable I can shameleslly plug he also has Patreon/Coffee pages :wink:

3 Likes

Update to 1.0.1. Thanks to @AGulev
1)Add M1 architecture
2) Make installation easier. (not need to use app.manifest)

7 Likes

hii i’m using defold 1.6.3 i downloaded the box 2d project from Github (Demo Project) which runs fine in on build but when i build HTML5 it loads in browser but after showing Defold logo it shows black screen …do it support this version of Defold? or something else is wrong?

1 Like

Look at console, and fix some errors in lua.
It not worked in 1.6.3

You need to replace some ; with ,

I will fixed it in weekends.

1 Like

i hope soon it will be ready to use :upside_down_face: , btw i’m interested in creating "Real time Slice the Object " ( like fruit ninja but not predecided slices) … is it possible using this extension?

1 Like

Yes. You can create a polygon shape in runtime to make sliced parts.

In fruit ninja I think you can slice object only once?

2 Likes

not sure if it allows only one cut but i think they just spawn two prefabs of piece objects ( rather than cutting real collision shape of fruit into two) when the cut goes through fruit …

Yes, Fruit Ninja cuts fruits to two pre-defined parts most probably (instantiating two parts in place of the one that was “sliced”).

Metal Gear Rising has cuts that comes to my mind immediately, when you described them :smiley: I think we need also runtime resources creation features like dynamic mesh creation, dynamic texturing etc and afaik all the blocks are in Defold already, right?

2 Likes