Phil Steinmeyer's rumblings on the game biz, programming, and life...

Main Menu
Recent News
Recent Comments
Login
Username or e-mail:

Password:

remember me

Lost Password?

Register now!
Search
Who's Online
1 user(s) are online (1 user(s) are browsing News)

Members: 0
Guests: 1

more... eXTReMe Tracker
Game Biz : Porting to the Mac
Posted by Phil Steinmeyer on 2005/4/27 15:09:56

I did the Mac port of SnakeBite in a little under 2 days.  The actual port of the code turned out to be trivial – almost all the time was learning tools and such.

I had done a bit of Mac coding before – about 4 years ago I ported Railroad Tycoon 2 Gold (using an existing port of RT2 original as a base), then Tropico.  For those projects I used CodeWarrior, the most popular commercial C compiler for the Mac.  But CodeWarrior costs ~$500, and Macs include a free compiler/IDE called XCode, which seems to be the standard these days for Mac ports, so I went with XCode.

Like all new programming environments, it took a few hours to understand XCode, but overall I was pretty impressed with the environment.  Apparently it does Java and Objective C as well as C++, but I stuck the C++ side of the field.

My first snare was that of the cross-platform libraries I use (SDL, SDL_Mixer, and SDL_Image), only SDL came with properly compiled Mac binaries.  I struggled unsuccessfully to follow the instructions for command-line compilation of the latter two (using Mac’s Unix terminal), but failed.  Then I noticed that amongst the source code for these, there were CodeWarrior project files.  I opened these in XCode, which imported them perfectly, and 5 minutes later I had all my binaries and was good to go.

The game code compiled cleanly almost straight out of the gate – I only had 6 functions in an OS-dependent file that I needed to stub out.  With that done, it compiled clean and ran, but crashed right away.  XCode’s debugger made it easy to spot the problem (it stopped at the crash point with a nice stack trace).  The game couldn’t find the graphics files because they were referenced as “Graphics\Background.jpg” whereas OS-X uses a forward slash as a path separator (i.e. Graphics/Background.jpg).  Went through the code and quickly made the relevant changes (using #ifdef WIN32 to separate Windows functionality from Mac), and now I could run the game and see the graphics.

The last snare was that the colors were messed up, because Mac’s use a Big-Endian processor (PowerPC) versus PC’s Small-Endian Intel architecture.  I added some byte swapping code after images loaded, and finally, the game ran smoothly on the Mac.

I spent a few more hours playing with smaller issues (making Icons and URLs in Mac friendly format, compiling my App in release mode, etc), but overall, it was a remarkably simple process.  I still haven’t set up the files in a friendly-to-install way yet - I have a few questions pending here that I need to get cleared up before I do this last step.  Still, I remember that our Mac ports of games like Railroad Tycoon 2 took 6 months and cost $75K, so a 2 day port feels good.  To be fair, RT2 used Direct X code, which had to be ported to Mac’s native library, and also had more complicated file loading systems (where the Byte-Endian issue needed to be addressed).

So now I’ve got a codebase and framework that can be compiled natively for PC and Mac, and that can be taken to Java with more or less the push of a button.  Next step is to move into more serious content development, but I’ve got a few other issues (non-code related) to clear up before I proceed on that front.  It’s been fun playing with all these platforms, and hopefully it’ll result in some nice games and/or other apps at some point down the road.

Printer Friendly Page Send this Story to a Friend
The comments are owned by the poster. We aren't responsible for their content.
Poster Thread
Anonymous
Posted: 2005/4/28 1:47  Updated: 2005/4/28 1:47
 Re: Porting to the Mac
The Win32 API is perfectly happy with forward slash path separators, so no need to #ifdef - just change to /s everywhere.

And, by the way, what business do you have naming graphic resources by filename _within the code_?
Phil Steinmeyer
Posted: 2005/4/28 9:47  Updated: 2005/4/28 9:47
Webmaster
Joined: 2005/2/7
From: Fenton, Missouri
Posts: 33
 Re: Porting to the Mac
Yeah, I noticed that forward slash separators worked for Windows, but I wasn't sure if that was a Windows XP thing only - do forward slashes work when running a game on Win 98?
Anonymous
Posted: 2005/4/28 16:53  Updated: 2005/4/28 16:53
 Re: Porting to the Mac
Yep, we've shipped a couple of products using only ever forward slashes.
das-g
Posted: 2005/5/8 7:51  Updated: 2005/5/8 7:51
Just popping in
Joined: 2005/5/8
From:
Posts: 3
 Re: Porting to the Mac
Re: Embedding a framework:
look here on how to create a private embedded Framework if you haven't already found that article.

I believe manually copying the Framework to MyApplication.app/Contents/Frameworks/ is also a valid way, but I havent tested that since 10.2 (or whatever that was), so I'm not sure about it.

Also: SDL and compagnions tend to install in /Library. If you move them to ~Library you can just make another user to test your application with, so to this user it looks like a fresh system and you can spot any problems other users might have with your application.
Fast user switching (to be enabled in "System Preferences > Accounts > Login Options") is a godsend for this kind of work.
(you have to sacrifice easy upgradability (you have to manually move SDL.framework every time you update to your home library folder) and update the paths in your project but you gain some "easy" testing possibilities)

Oh yeah and to make a zip out of an application right click (or if you have a one button mouse hold down control while clicking) the application icon and choose "Create Archive of ..."