I know there are arguably better tools out there for the job but I want to write a game in Xojo because I enjoy the language.
Rather than reinvent the wheel, I want to integrate the Box2D physics engine (C++ but ported to several languages) into the game. I know that Tom from bigdaddysurf.com tried to port Box2D to Realbasic a couple of years ago but couldn’t get it to work. My C++ knowledge is also not good enough to port a physics engine so I was wondering if there is anyway to wrap the C++ library and call it from Xojo. Perhaps as a declare? Is this at all possible?
Thanks,
[quote=135044:@Garry Pettet]I know there are arguably better tools out there for the job but I want to write a game in Xojo because I enjoy the language.
Rather than reinvent the wheel, I want to integrate the Box2D physics engine (C++ but ported to several languages) into the game. I know that Tom from bigdaddysurf.com tried to port Box2D to Realbasic a couple of years ago but couldn’t get it to work. My C++ knowledge is also not good enough to port a physics engine so I was wondering if there is anyway to wrap the C++ library and call it from Xojo. Perhaps as a declare? Is this at all possible?[/quote]
A plugin is probably the way, as it closely integrates into the language. I suppose the plugin SDK will help you. I never have done it, but am sure other members have. Certainly Christian the plugin wizard 
Another way, though less integrated, is a DLL : http://www.xojo.com/blog/en/2014/01/accessing-net-code-from-xojo.php
I have used it for simple tasks, but I doubt it will suffice for a game.
[quote=135044:@Garry Pettet]I know there are arguably better tools out there for the job but I want to write a game in Xojo because I enjoy the language.
Rather than reinvent the wheel, I want to integrate the Box2D physics engine (C++ but ported to several languages) into the game. I know that Tom from bigdaddysurf.com tried to port Box2D to Realbasic a couple of years ago but couldn’t get it to work. My C++ knowledge is also not good enough to port a physics engine so I was wondering if there is anyway to wrap the C++ library and call it from Xojo. Perhaps as a declare? Is this at all possible?
Thanks,[/quote]
Have you tried this: http://alwaysbusycorner.com/2014/03/06/xojorealbasic-abpe-the-physics-engine/
Wow. No I hadn’t.
This looks brilliant! I may now be able to close Xcode and put away my C++ books 
May have spoken to soon. Runs at about 5-10 FPS under Cocoa on a new Retina MacBook Pro 15" and 2-3 FPS if you enable the Retina flags after the build…
That bad? On my old Mac Pro (but no Retina of course) it runs really nicely.
I got that bad frame rates when I profile the project.
Having said that, I guess there’s two points where it could be enhanced: On one hand, the frequent calls to MacOSLib’s CGFunctions creates a lot of overhead in converting, creating and destroying objects.
And on the other hand, it was probably really a bit early to put away your C books. Did you have a look into the Accelerate framework? I wouldn’t be amazed if some of the optimized vector routines could help.
Stumbled across another blog post by @Alain Bailleul which utilises OpenGL. Pleased to say that it’s great.
Well, a plugin would be best probably, but I still wonder what you need from Box2d?
you could of course write also a shared library exposing the functions as C functions and wrap that with declares.
Alain Bailleul and Alwyn Bester are the guys to speak to.
They are both fantastic regarding this subject!
Also, both are really nice people and helpful.
I’m flattered by your vote of confidence Richard
However, until now I’ve only done pure Xojo programming when it comes to graphics, and never attempted to mix C/C++ code with Xojo (reason why I am also following this discussion).
I have discovered though, that with some patience and a decent amount of effort, it is definitely possible to push the running speed of pure Xojo code to very respectable levels that is suitable for most projects. There are a few experts on these forums that are also usually very willing to advise on how code can be optimized when you post your snippets.