Skip to content

box2d physics library #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 13, 2025
Merged

box2d physics library #63

merged 10 commits into from
May 13, 2025

Conversation

HMart81
Copy link
Contributor

@HMart81 HMart81 commented Mar 28, 2025

Box2D is a popular 2D Physics engine for 2d games, docs and more on https://box2d.org/

add ID values for GuiIconName to make it easy to embed icons id's in strings
changed loadDirectoryFiles to raylib 55 to follow new function signture and unloadDirectoryFiles missed the necessary argument
Box2D is a 2D Physics engine, see more on https://box2d.org/
Tried to follow c3 vendor guide lines "conform to C3 stdlib layout (tabs, Allman braces)" didn't do this first because was unaware of them, don't known if the tabs stuff is fully correct, thou I changed the leading ones to real tab, hope is enough.
@lerno
Copy link
Contributor

lerno commented Mar 30, 2025

This looks like this is also making changes to the raylib bindings? Also, it's 0.7.0 and 0.6.8, not 7.0.0 and 6.8.0 :D

@HMart81
Copy link
Contributor Author

HMart81 commented Mar 30, 2025

Oh sorry about that! I'm still a noob at this github technical stuff (yeh shows I'm not a professional programmer, i'm just a self taught one), if possible ignore the raygui and raylib stuff.
And I most have been on drugs about the 6.8.0 and 7.0.0 versioning numbers, I don't know how the hell I thought that.

@HMart81
Copy link
Contributor Author

HMart81 commented Mar 30, 2025

Thou looking at the two raylib changes I did (I did them some time ago, so I forgot about it...) they do make sense, as those were wrong function definitions/bindings in the original, unless those functions were already corrected in the mean time, I recommend that you also merge my raylib changes.

@lerno
Copy link
Contributor

lerno commented Mar 31, 2025

I've removed the 0.6.8 versions and I'm doing 0.7.0 now exclusively. Could you update the bindings and changes for it?

@HMart81
Copy link
Contributor Author

HMart81 commented Mar 31, 2025

Yes I can. :)

@lerno
Copy link
Contributor

lerno commented Apr 1, 2025

Could you do these changes?

@HMart81
Copy link
Contributor Author

HMart81 commented Apr 2, 2025

I already did the updates to 0.7.0, if that is what you are asking?

@lerno
Copy link
Contributor

lerno commented Apr 2, 2025

No, there are some new changes requested, see in the boxes above!

@HMart81
Copy link
Contributor Author

HMart81 commented Apr 4, 2025

Sorry for my ignorance but what boxes above? Can you point me to what you are talking about. Or can you write what you want me to change in a comment here?
I'm used to tortoise svn for most of my programing, so I still don't know all ins and outs of this website.

HMart81 added 2 commits April 5, 2025 15:23
changed the code to follow more closely @lerno suggestions (still not tested at this point...)
now fully compiles
@HMart81 HMart81 requested a review from lerno April 6, 2025 15:26
@lerno
Copy link
Contributor

lerno commented Apr 6, 2025

I'm sorry I haven't checked this yet. I'll try to have time soon. 🙏

}

// Body id references a body instance. This should be treated as an opaque handle.
struct B2BodyId
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make these implement comparisons using operator overloading with macro methods.

Copy link
Contributor Author

@HMart81 HMart81 May 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may have bitten more than I can chew...
ok... any examples I can look at, so I can see what you mean?
Btw If I didn't said this before, I will say it now, I never used box2d before this, I know almost nothing about it, I just heard Unity3D used it and thought a 2D physics engine, would be cool to use with C3 for simple 2D games, so probably for me to really optimize its library for C3, I would need to first learn well its ins and outs, but I will see what I can do.

//=====================================================================================================
module vendor::box2d::b2::b2math;

alias B2Vec2 = float[2]; // NOTE(HM) to support C3 vector math using (float[<2>])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can make B2Vec2 a typedef and then implement the different vector ops on it, but it's probably easier to leave it as is, since a float[2] will implicitly convert to a float[<2>] and vice versa. See if you want to use operator overloading on structs such as B2Rot.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it can stay like that for now better, it can always be changed later by me or others... the reality, I don't have much time to dedicate to this now. Not if you don't want to wait one more month for this... :(
Don't know how many people are waiting for this bindings, but they are always free to comment here. (...and also help btw....)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this stay like this?

"macos-x64" : {
"link-args" : [],
"dependencies" : [],
"linked-libraries" : []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add "linked-libraries" to macos and windows too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is mostly done?

ICON_254,
ICON_255,
// val is the ID number for the "#iconID#sometext" ability
enum GuiIconName : int (int val) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is the same as the ordinal the int val part can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have the impression we already discussed this? Even if is useless, I think those should stay?
Thou I will probably make them into a comment, or better, thinking about it, make them into a inline string, so you can use the enum member directly and just concatenate them into other strings?

like so:

enum GuiIconName  :  (inline String str) 
{
    CURSOR_HAND = "#19#", 
}

if( rgui::button(rec, CURSOR_HAND.zstr_tcopy()) ) { 
   //
}

Anyway why I think they should stay, the main reason is, because it removes the need to count each enum by hand, to know its value visually.
Imagine you saw a online tutorial on box2d and it used "#128#" on it (many do use the id directly like that), looking at that first time, what icon is that id?
If those index numbers are not there, for you to immediately connect the dots, you will have to count each enum member to find who is the 128 one...

But like I said, probably making them into a simple // comment or inline string is enough... but I'm not sure, I may be forgetting something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this modifications

edited the manifest file and provided a compiled box2d library for windows-x64 I use, but imo the best is for others to compile box2d themselves for their own CPU architecture...
Unfortunately cannot provide macos and linux ones at this time.
Changed the raygui icon enum to be a inline ZString so you can pass them directly to raygui functions as zero terminated strings for the "#id#" feature.
@lerno
Copy link
Contributor

lerno commented May 12, 2025

Hmm.. it has some conflicts now.

@lerno
Copy link
Contributor

lerno commented May 13, 2025

Let's merge this and let improvements come later.

@lerno lerno merged commit 7d98837 into c3lang:main May 13, 2025
2 checks passed
@HMart81
Copy link
Contributor Author

HMart81 commented May 13, 2025

Let's merge this and let improvements come later.

Agree and thanks for the patience in dealing with a noob like me. And sorry for not doing more but other work got in the way.

@HMart81 HMart81 deleted the hm_vendor branch May 13, 2025 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants