What's the most cross-platform friendly coding

2019-03-29 11:02发布

问题:

Let's say I want to create FPS game, let's say clone Crysis so everybody understand what type of graphics & performance I'm after. What's the best code to write this game with so it's as easy as possible to port it to all the common platforms? Of course I want the application to feel and be native to the platform. This also means that it should be easy to take advantage of Snow Leopard's new features like OpenCL and Windows 7's new features. I realize that GUI has the written separately for different platforms and that's not a problem.

So my question is that what's the best language for the job. I'm not looking for one-for-all solution but more like language for the core. I guess one way to put it is to say that what's the best language if you need to port the same program to Windows, OS X & Linux? Java is out of the question.

回答1:

C (and now for some padding to reach 15 chars)



回答2:

Have you ever seen the Blues Brothers? In the movie, Jake and Elwood go into a hick bar to do a gig and ask what sort of music they like, to which the woman behind the bar answers:

We have both kinds: country AND western.

What has this got to do with this question? Well, you want to create high performance 3D graphics and you're asking what language to use?

We have both kinds: C and C++.



回答3:

You probably want C for your lower level graphics performance, either the variant of C89 that Visual C++ supports, or use MinGW and gcc C99 ( VC++ 2008 doesn't support declarations in for loops in C99 code, which is very annoying, but then they didn't do that right in C++ for years ).

Admittedly, if you're taking GNU with you and running full-screen with your own GUI then it's not really cross platform any more.

You also probably want either Lua or Python or another scripting language which plays well with calling C to give a sensible higher level way of controlling the game.



回答4:

C++. You can avoid millions of "if #define"'s for platform dependent things and instead use inheritance (derived classes for each platform and client using/knowing the abstract base class). A few exceptions to this can be made for the performance critical parts.

There are also lots of libraries for cross-platform development.



回答5:

I really recommend using Lua for any scripting. It is an ANSI C library so that means that a: it can be compiled in (at least most) C++ compilers, and: if there's a C compiler for the platform then you can use lua. It allows for significant extension of flexibility of your game and if you want it will let your players customize it too!



回答6:

Java is probably one of the easiest to learn, personally. Java though doesn't have have that great of a graphical system, it needs more code to support the graphical display if you are coding "GAMES," if you're going to code a website though choose JavaScript, CSS, and HTML/5. Or use only one of these languages normally best to choose two that best fit your comforts... =) For an FPS, I would recommend for beginners to use Java, if you have a good sense in what you want to create and it is a more complex game then use C# or C++, just because it uses less hardware if you want to make more complex games to run on multi platform.



回答7:

Whatever you use you're going to have to write platform-specific code. Languages like Java or other interpreted languages (Python be my personal preference) are going to allow you to use a lot of commonalities. However, since it's not a quick and simple project, I'd suggest </intelligent-looking-padding> C or C++.

Edit: GUI doesn't necessarily have to be written from scratch for every platform. Check wxWidgets.



回答8:

Most cross platform games are written in C++, because it is very good - performance wise; and its more user friendly than C. Games need maximum speed & efficiency!

You can hide away platform specific stuff behind certain abstractions and API's that you write so that you can port it easily. You can also use a cross platform framework such as Qt or wxWidgets for the window & GUI elements. Adding a scripting language to non critical parts is also nice. :)



回答9:

As most have noted here, you are almost certainly going to need C/C++ for your graphics in the end particularly for your high performance (graphics) requirements.

However there might be an opportunity to develop the "core" as you call it, in a scripting language which in turn is easy to embed within a C/C++ application. In which case, the top 2 scripting languages to look into would be Lua and Tcl.

Lua in particular is used in WoW among others I'm sure. Tcl on the other hand has more "batteries included" (libraries).



回答10:

I'd recommend C++ for large cross-platform projects as well. But I think what's also important are the build-tools you use. For example SCons or CMake can create project files/makefiles for most compilers under Windows/Linux/MacOS.



回答11:

C is a good language, but generally you want an object oriented language for programming game. If your looking for speed, go with C++, but if you don't have much programming experience, go with python. look into the sfml and pygame libraries.