views:

757

answers:

10

Hello. I am going to start a game in about 3 weeks and I would really like the game to run at least on another platform (linux, MacOS) but my team thinks that's a lot of work. I am up for it but wanted to know what are the things I should watch out for that won't port to linux (apart from Windows specific APIs like DirectXsound)?

I've been reading online and Windows "_s" functions like sprintf_s appear to exist only on Windows; is this correct or are they implemented on linux also?

A: 

For the 'safe' functions: they are non-standard, and almost safe :)

xtofl
A: 

Endianess is something look out for.

Endianess is the order of the bits in a byte. Some platforms are big endian while some are little endian.

This can affect how cross-platform your program is. But the biggest impact this would have would be in network communications. You have to convert from one endian to another before sending or receiving a network message.

MrValdez
At this point that should be a trivial concern. As long as you define the byte order you are using for streamed data (disk, network, etc.) and stick to it you're fine. That's what "network" byte order is for.
MarkusQ
A: 

If you focus on gameplay, design a game, and them implement that porting should not be especially onerous. If you implement it simultaneous on several platforms it should be straight forward.

But if you focus on effects, design something that you feel is going to "blow the others out of the water," and try to paste a game idea onto them, you are doomed.

So really it is up to you.

MarkusQ
it's a 5 month school project we pitch 2 game ideas and they choose but i wanted to let know my team of potential hicups that could make my life miserable later when porting it. like making all their code with windows librarys when they can use the stl or boost.
Annerajb
A: 

Try to encapsulate any non-standard extentions like DirectX, OpenGL, SDL, etc. Then you only have to rewrite those parts based on platform.

I also would make it playable on one OS before even thinking of porting.

rlbond
that's what we are going for since our school everybody has windows operating systems on the game development program i cant convince my team of working on linux and windows so it's more of a side project for the experience.
Annerajb
A: 

Don't know much about windows-apis, but I set up a daily (or on-commit) fully automatic build-system on all platforms you want to support. If you develop something on your windows-box that doesn't work on the others, your build-system should notify you of "failed build on platform x, see logfile/attachment/whatnot for details". It'll catch a lot of cross-paltform issues. Unittests will help as well.

Whether or not to target multiple platforms from the start is a good idea is another question.

Personally I'd start developing on another platform and then see about porting it to windows at a later time ;-)

i am currently looking into this but since my school is forcing us to use alienbrain so we learn how to use it is a bit more tricky than a svn update and export.
Annerajb
+5  A: 

No, the _s functions are NOT implemented in the standard gcc library. (At least, grepping the include files for 'sprintf_s' turns up nothing at all.)

It might be worth looking at cross platform libraries like boost and apr to do some of the heavy lifting work.

A sample of specific things to look for:

  • Input/Output (DirectX / SDL / OpenGL)
  • Win32/windows.h functionality (CreateThread, etc)
  • Using windows controls on the UI
  • Synchronization primitives (critical sections, events)
  • Filepaths (directory separators, root names)
  • Wide char implementations (16 bit on windows, 32bit on linux)
  • No MFC support on linux (CString, etc)
Jim T
thank's this is exactly what i was looking for if anybody know anything Jim have forgotten post it here :D
Annerajb
+3  A: 

If I were you I would use some of the available Frameworks out there, that handle Platform independence.

I wrote a 3D-Game as a hobby project with a friend of mine, the server being in Java and the clients running on Windows and Linux. We ended up using Ogre as 3D-Engine and OpenAL as Sound-Engine, both platform independent and available under LGPL.

The only things I really had to write separately were the whole Socket-handling, reading the config from file system and the initialization of the System. Compared to the rest of the Program, that was almost nothing.

The most time consuming will be to set up the entire project to compile under Windows and Linux (or Mac), especially if you're concentrating on one and only occasionally check the other for problems. If you have one in your team who checks regularly for these problems while they're being produced you won't have that much overhead from that as well.

All in all compared to the programming of the game itself, adapting it to different platforms is almost no effort, if all frameworks used are well written, platform independent systems.

Mallox
A: 

Just remember that you are creating a model of game that does not depend on the details of any operating system. Your game depends on state management and algorithms which don't depend on the OS. The key is to write your game logic without dependencies to specific libraries which means a lot of encapsulation.

You shouldn't call sprintf_s directly you should write an routine, class, or MACRO that can be changed based on the platform, Don't use DWORD when you can use a class or typedef that can be tailored to different platforms.

For instance if you where making a football game, then algorithms for throwing the ball, running, tackling, positions of the players could be done completely in standard C++ without platform dependencies. If your encapsulation was good you could dump the state of you game to a file and display it separately with a rendering program.

BeWarned
yeah game will be encapsulated i was thinking more of thing similar to using dword's sprintf_s and windows specific stuff we already have the idea for the base engine architecture is more of small hiccups like oh i used _s in every function because of msvc warnings.
Annerajb
+2  A: 

If you truly want to do cross platform development easily I would suggest using one of the already built cross-platform engines like Unity or one of the Garage Games stuff like Torque Game Builder (2D).

I have virtually zero experience in either so can't tell you which is better but the Torque Game builder demo couldn't get through the first tutorial without having problems and they don't answer tech support questions in their forums like they claim to do so I can say avoid them if you are a novice in game design like myself. The big thing about Garage Games was supposed to be their great support, I saw zero support and in fact only saw a bunch of, "Hey, anybody here?" posts with no answers so I guess they are pretty much giving up on supporting their products.

http://unity3d.com/

http://www.garagegames.com/

Kludge
this is out of the question since it's for a school project and we are require to make our game from the ground up with only one third party api wich is prob going to be fmod.
Annerajb
A: 

I'm surprised nobody mentions libSDL and OpenGL because most cross platform games were written using those libraries.

If your game is 2D, you can use libSDL. A good example of game written using it is The Battle of Wesnoth. SDL uses DirectX on Windows, it's just a thin wrapper on it.

If your game is 3D, use OpenGL. For example, Quake 3 uses that library. You can find tons of examples and documentation on it. Of course, there are many libraries that wrap OpenGL, so you don't have to do low-level stuff. Look into OGRE, Crystal Space, etc.

As for the basic C/C++ libraries and functions compatibility, it's best you install some Linux and simply run man page for the function to see if it exists. Of you can look it up on the Internet.

Milan Babuškov
Well, the accepted answer mentions both SDL and OpenGL as far as I can see...
Subtwo
Looks like I missed that. Thanks for noting.
Milan Babuškov
and yeah we are already using opengl since our game is 3d and we have a good amount of experience the question is really aimed more to stuff like sprintf dword and all those kinda low level stuff. what i did is put vmware and install ubuntu and start compiling small classes that i am using.
Annerajb