Sign in to follow this  
Darchitect

So, cross platform development: do I have the basic structure down?

Recommended Posts

Darchitect    100
So I've been lurking around for a bit, and love the incredibly helpful community here.
I'm a noob, so patience, please.

My short term goal is to do the tutorials on Lazyfoo.net, and then build them to be functional on both Windows and OS X. I figure this will be a great exercise to help with my longer term goals.

In order to do this, I need the following:

1. A language. I'm learning C++ with occasional forays into Python.

2. A cross-platform IDE. I'm leaning towards Code::Blocks. I'd love to learn Xcode (it's already installed) at some point, but I get the feeling trying to get it to spit out a functional Windows game would be a nightmare.

3. A cross-platform windowing solution or library. WxWidgets for that.

4. A multimedia library. Looks like SFML will do.

So! Have I got the basic tools in place? Please, punch holes in my plan. Thanks in advance!

Share this post


Link to post
Share on other sites
epreisz    167
Firstly, I wouldn't recommend shooting for building a cross-platform engine as your first attempt. For each platform you support, you exponentially increase your chances of creating bugs. It's very common for you to fix one bug on one platform and cause a new bug on another. It's sort of like cross-browser issues when making web pages.

...and as I would tell my students at Full Sail (when I taught there)...I hope that my advice not to do something pisses you off and drives you to do it an prove me wrong :)

At some point you are going to write code that ties all of the libraries you are using together. If you want it to be cross-platform, you need to make sure that you don't use any cross-platform code without first abstracting the system.

For Example:
Let's say you want to create a Window. If you make a call to the Win 32 call [color=#000000][font=Consolas, Courier, monospace][size=3]HWND WINAPI CreateWindow [/size][/font][/color]It won't compile on OSX. On OSX you would need to call..some other function that I don't have memorized... So how do you handle this situation?

Abstraction!

Create one function call named MyCreateWindow(). If you are compiling for OSX, You should implement that function with the OSX specific code....if you are compiling Windows you use the windows specific code. As long as you use MyCreateWindow() instead of the OS specific window, your game will continue to compile across all each platform.

You can "Implement" the functions in a couple of ways... The quick and dirty way is to use a pre-processor directive.

#ifdef OSX
OSX Specific call
#elseifdef WINDOWS
Windows specific call
#endif

[url="http://www.cplusplus.com/doc/tutorial/preprocessor/"]http://www.cplusplus.com/doc/tutorial/preprocessor/[/url]

Or...you can set it up in the IDE. Create one project that contains OSX/CreateWindow.cpp and one that contains the file WINDOWS/CreateWindow.cpp. The CreateWindow.h file IS cross platform since it doesn't contain any API specific calls.

So....in closing...making a cross platform game is not that hard, but it is tedious...and can be a little bit messy.

Share this post


Link to post
Share on other sites
mhagain    13430
Definitely agreed with the above. Going full cross-platform is not a good thing for a first project. In addition to API differences you're going to find things that are bugs on one platform but that aren't on another, and you're going to need a good understanding of how each platform works behind the scenes in order to pull it off successfully. A wrapper library can only go so far, but there are subtleties - like needing to initialize some things in certain order on different platforms - that you won't be aware of and that will bite you.

Better to focus on a single platform for a first project, and focus on getting your own code working right.

Share this post


Link to post
Share on other sites
Darchitect    100
Thanks for the replies. Very informative. I think I will probably start with Code::Blocks, write a few of the basic programs (tic tac toe, pong) for Mac and then try to port the code to Windows just to see what the work load is like and get a feel for the different requirements.

But I see how very, very tedious writing an abstracted function for every single API call could be. Ugh. No wonder people use Cider or Wine or other emulators to run games.

One would think that a company would have produced an open-source IDE that can handle this automatically. I guess that is what Code::Blocks is trying to do.

In my still very uneducated mind, I guess I was hoping to write all the code in one IDE, check the box that says "Compile for Windows and Mac," et voila! An .exe and an .app ready to be shared with the world! It seems like it should be possible with all the open source libraries.

I have a feeling I'll read this post in a year's time and giggle at the old me.

Share this post


Link to post
Share on other sites
swiftcoder    18432
[quote name='Darchitect' timestamp='1329521002' post='4914042']
In my still very uneducated mind, I guess I was hoping to write all the code in one IDE, check the box that says "Compile for Windows and Mac," et voila! An .exe and an .app ready to be shared with the world! It seems like it should be possible with all the open source libraries.[/quote]
High-level SDKs tend to do this. For example, either of the Unity or UDK game engines can deploy any of Mac/Windows/iOS binary at the touch of a button.

For more traditional development, you are going to have to have a Mac and a Windows box sitting in front of you, and compile separately on each one.

Share this post


Link to post
Share on other sites
epreisz    167
[quote]I have a feeling I'll read this post in a year's time and giggle at the old me.[/quote]

[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left]Heh, I have a post from 1998 that I still find every once in a while...still it's not a dumb question.[/left][/size][/font][/color]


[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left]Remember, hardware manufactures are always trying to set themselves apart and software developers are always trying to bring them together. It's as classic as the fight against good and evil. [/left][/size][/font][/color]

Share this post


Link to post
Share on other sites
Promit    13246
The only correct way to write a cross platform engine is to write a single platform engine for each platform you're targeting, and then use the knowledge gained in all that work to put together an engine that works across everything. After a while you get a feel for what kinds of things are needed to handle lots of platforms smoothly.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this