how does Box2d works in the iPhone

Hi guys,
first things first: happy new year! (a 'tad late, but please bear with me).

I'm having a hard time trying to figure out how does box2d works in those iOS game engines. The major problem is: I don't have a Mac nor will I have a mac in next 6 months, but I need to code for it nevertheless and I need to understand more of it to base my next programming decisions.

I'm planning on buying DragonfireSDK to program my games to the iPhone, being box2d compatibility is high-priority. I have sent the Dragonfire guys an email, but I'm still awaiting a reply.

My question: I know that Box2d in Cocos2d is in its original C++ implementation, but I don't understand how they manage do link and compile native c++ for the iPhone. Will I be able to program my whole game in C++ and then compile and link it in the iPhone later? or at least program the physics and then, later, call it from objective-c?

if you guys could teach me how these cross linking/compiling for Box2D in the iOS works, i'd be able to make a more informed decision and not leave my beloved C++ & box2d 😀
You should be able to link once and just code. Obj-C and C++ code can be seamlessly mixed. I don't know anything about this DragonFireSDK but if it's not free I wouldn't use it. Much less headache would come from using Apple's free tools. Of course that'd require you to get a Mac.
As already said, you can compile and link .cpp files into an iPhone program effortlessly. I just dropped all the Box2D source code into my project and that was that.

If you are coming from a C++ background the important points to note are:
- .c and .cpp files compile and link fine
- you cannot use c++ code in objective-c .m files, but if you change the extension to .mm you can use both c++ and obj-c in the same file.
- all interaction specific to the iOS hardware (touch input, playing sounds, threading etc) will need to use obj-c.
- in most cases where you want to do iOS specific things in c++ it's pretty simple to create a c++ wrapper for the obj-c code so you only need to figure it out once.
- you can pass objects of either language through code of the other using say, void* if necessary
- headers with obj-c specific code cannot be included by a .cpp file, but this is usually easily avoided by having two header files if necessary

Other useful tips:
- move strings between c++ and obj-c using:

Code: Select all

string stlstr;
NSString *nsstr = [NSString stringWithUTF8String:stlstr.c_str()];
...
stlstr = string( [nsstr UTF8String] );
man, I'm really you fan! your answers are always concise and straight to the point.

I will try to buy a mac then (but keep on programming in C++), that way I won't need to drop the language I've invested so much time learning nor will I risk working in a environment not compatible with the iOS.

thanks!
oh yeah, I knew I forgot to mention something:

look into 'hackintosh' if you don't have a mac yet. Since Mac OSX runs on Intel you can actually set it up on a typical PC. There are a few things to be careful of though, I think the most important thing is the motherboard, some of them may not be compatible. Last year I was looking at getting a second-hand mac but they were not cheap - then I realized I could build a more powerful 'mac' of my own and still have a nice windows PC in the process (I just need to turn it off and switch to a different hard drive).

You will probably find some tutorials showing you how to install Snow Leopard onto a pc using the official DVD, but I would recommend trying a purpose-made 'hackintosh' install by the name of iDeneb first (you should be able to get it via torrent), I found this to work quite well and these days I only switch back to windows to play games occasionally.
cool thing!

so you're doing all your programming in a hackintosh? even iOS? for what you said, I suppose it works fine. What are your experience specifically with programming for the iOS? what about the testing in the actual device / applestore process?
I have no experience with the app store yet, but so far development for iOS is very enjoyable. XCode has nice auto complete features, and you can install and run your app very easily over the standard iPhone/iPod USB cable, while viewing debug output on your computer in realtime, breakpoint etc also fully interactive while running on the device.

A few years ago I worked making apps for cellphones where we had to put the app onto a server and download it onto the phone to run... very painful in comparison.

Probably the greatest thing about making software on the iOS is that you can get people to look at it very easily. You don't need to get them to download or install, or get them in front of a PC to try something. You can just say hey check this out, take it out of your pocket and there you go - whether on a bus, train, wherever. This means a lot more early feedback to help you make something that people will like.
Just get a Mac Mini. You can get one new from Apple's Apple Store on its website with 4 GB RAM for $799. Then hook up any USB keyboard, USB mouse, and LCD display, and you're good to go. It comes with 4 USB ports. Apple keyboards come with extra USB ports built in for the USB Mouse, so that would leave you with 3 USB ports on the Mac Mini for iOS devices.

Mac Minis are better than iMacs for iPhone/iPod touch development because they are built to run like mini servers that can be left running, charging up your iOS devices. Doing that on an iMac could wear out the screen. But on the Mac Mini, just turn off the connected LCD display and let it run in the background.

➡️ Also, unlike a hackintosh, a Mac can be put to sleep real easy, and awakened just as you left it in less than a second a couple days later. You will spend less money and time buying a Mac Mini than building a hackintosh which may not even be acceptable for the App store submission process. 😎
Good points. I was soooo close to getting a mac mini but I am glad that I now also have a nice windows/linux machine as well, for around $450 and I can play around with different video cards etc.
About app-store submissions, I have heard it is not an issue. If the operating system doesn't know what it's running on how can it tell the store...
There are also the financial and legal risks of violating Apple's SDK and OS agreements when developing iPhone apps on a hackintosh. the Mac OS X operating system has hooks in it that can determine what hardware it is running on. Just because Apple seems not to bother an iOS developer using a hackintosh right now does not mean they would not go after him later, especially if he were to make a fortune in the App store business. And to make a fortune in the App store business is the reason we are here, right?

➡️ In other words, an iPhone App developer who becomes successful using a hackintosh to develop iPhone apps could and eventually probably would lose all their earnings in lawsuits from Apple, and they would not be able to defend themselves in court, because their violations of the license agreements that they entered into could not be clearer.

That people use hackintoshes to make iPhone Apps are rumors. People don't publicly announce that this or that particular App was made on a hackintosh due to the legal problems of such an announcement, so you can never know for sure whether there really are any successful iPhone developers using hackintoshes. But if there are, and they are found out, their fortunes will be ruined. 🙁

I am just an indie developer, but I also prefer to stay legal, just so that if I do make it big, I will be able to keep it. This is just my best advice for any of you considering your options to not neglect the legal issues, because they can and do bite. 😉

Original thread: https://box2d.org/forum/viewtopic.php?t=6200