目录:
1、
1、C语言
2、C++
3、C++与C的抉择
4、汇编语言
5、Pascal语言
6、Visual Basic
7、Java
8、创作工具
9、结论
这是每个游戏编程FAQ里都有的问题。这个问题每星期都会在游戏开发论坛上被问上好几次。这是个很好的问题,但是,没人能给出简单的答案。在某些应用程序中,总有一些计算机语言优于其他语言。下面是几种用于编写游戏的主要编程语言的介绍及其优缺点。希望这篇文章能帮助你做出决定。
This is a question that belongs in every game programming FAQ. It seems to be asked in a game development forum several times a week. It's a good question, though, and not one with an easy answer. There are computer languages that work better for some applications than others. Here is a list of the major programming languages used to write games along with descriptions, advantages, and disadvantages. Hopefully this list will help you make a decision.basic语言if语句
1、C语言
如果说FORTRAN和COBOL是第一代高级编译语言,那么C语言就是它们的孙子辈。C语言是Dennis Ritchie在七十年代创建的,它功能更强大且与ALGOL保持更连续的继承性,而ALGOL则是COBOL和FORTRAN的结构化继承者。C语言被设计成一个比它的前辈更精巧、更简单的版本,它适于编写系统级的程序,比如操作系统。在此之前,操作系统是使用汇编语言编写的,而且不可移植。C语言是第一个使得系统级代码移植成为可能的编程语言。
If FORTRAN and COBOL were the first compiled high-level languages, then C is their grandchild. It w
as created in the 70's by Dennis Ritchie as a tighter and more coherent successor to ALGOL, which was a structured successor to COBOL and FORTRAN. It was designed to be a smaller and simpler version of its predecessors, suitable for writing system-level programs, like operating systems. Before then, operating systems were hand-coded in assembly and were not portable. C was the first programming language that made portability a reality for system-level code.
C语言支持结构化编程,也就是说C的程序被编写成一些分离的函数呼叫(调用)的集合,这些呼叫是自上而下运行,而不像一个单独的集成块的代码使用GOTO语句控制流程。因此,C程序比起集成性的FORTRAN及COBOL的“空心粉式代码”代码要简单得多。事实上,C仍然具有GOTO语句,不过它的功能被限制了,仅当结构化方案非常复杂时才建议使用。
C is a language that supports structured programming. That is to say that C programs are written as collections of disconnected function calls that run top-down rather than a single monolithic block of code with program control-flow happening via GOTO statements. Hence, C programs are generally easier to follow than monolithic FORTRAN and COBOL spaghetti-code. Actually, C
still has a GOTO statement, but its functionality is limited and it is only recommended as a last resort if structured solutions are much more complicated.
正由于它的系统编程根源,将C和汇编语言进行结合是相当容易的。函数调用接口非常简单,而且汇编语言指令还能内嵌到C代码中,所以,不需要连接独立的汇编模块。
True to its system-programming roots, it is fairly easy to interface C with assembly languages. The function-calling interface is very simple, and assembly language instructions can be embedded within C code, so linking in separate assembly-language modules is not necessary.
优点:有益于编写小而快的程序。很容易与汇编语言结合。具有很高的标准化,因此其他平台上的各版本非常相似。
Advantages: Good for writing small fast programs. Easy to interface with assembly language. Very standardized, so versions on other platforms are similar.
缺点:不容易支持面向对象技术。语法有时会非常难以理解,并造成滥用。
Disadvantages: Does not easily support object-oriented techniques. Syntax can be difficult and lends itself to abuse.
移植性:C语言的核心以及ANSI函数调用都具有移植性,但仅限于流程控制、内存管理和简单的文件处理。其他的东西都跟平台有关。比如说,为Windows和Mac开发可移植的程序,用户界面部分就需要
用到与系统相关的函数调用。这一般意味着你必须写两次用户界面代码,不过还好有一些库可以减轻工作量。
Portability: While the core of the language and the ANSI function calls are very portable, they are limited to control-flow, memory management, and simple file-handling. Everything else is platform-specific. Making a program that's portable between Windows and the Mac, for instance, requires that the user-interface portions be using system-specific function calls. This generally means that you need to write the user-interface code twice. There are libraries, though, that make the process a bit easier.
用C语言编写的游戏:非常非常多。
Games Written in C: Lots and lots.
资料:C语言的经典著作是《The C Programming Language》,它经过多次修改,已经扩展到最初的三倍大,但它仍然是介绍C的优秀书本。一本极好的教程是《The Waite Group's C Primer Plus》。
Resources: The classic book about C is [The C Programming Language].It's gone through several iterations and has expanded to about three times its original size, but it's still a good introduction to the language. An excellent tutorial is [The Waite Group's C Primer Plus].
2、C++
C++语言是具有面向对象特性的C语言的继承者。面向对象编程,或称OOP是结构化编程的下一步。OO程序由对象组成,其中的对象是数据和函数离散集合。有许多可用的
对象库存在,这使得编程简单得只需要将一些程序“建筑材料”堆在一起(至少理论上是这样)。比如说,有很多的GUI和数据库的库实现为对象的集合。
C++ is the object-oriented successor to C. Object-oriented, or OO, programs are the next step beyond structured programming. OO programs are built out of objects, which are packages of data and functions collected into discrete units. There are many libraries of objects available that make writing programs as simple as pulling together a collection of program "building blocks" (at least in theory). For example, there are many GUI and database libraries that are implemented as collections of objects.
C++总是辩论的主题,尤其是在游戏开发论坛里。有几项C++的功能,比如虚拟函数,为函数呼叫的决策制定增加了一个额外层次,批评家很快指出C++程序将变得比相同功能的C程序来得大和慢。C++的拥护者则认为,用C写出与虚拟函数等价的代码同样会增加开支。这将是一个还在进行,而且不可能很快得出结论的争论。
C++ is the subject of controversy, especially in the game development community. There are features of C++, like virtual functions, that add an extra layer of decision-making to function calls, and critics are quick to point out that C++ programs can be larger and slower than C counterparts. C++ advocates point out, however, that coding the equivalent of a virtual function in C requires the same overhead. It's an on-going debate that's not likely to be decided soon.
我认为,C++的额外开支只是使用更好的语言的小付出。同样的争论发生在六十年代高级程序语言如COBOL和FORTRAN开始取代汇编成为语言所选的时候。批评家正确的指出使用高级语言编写的程序天生就比手写的汇编语言来得慢,而且必然如此。而高级语言支持者认为这么点小小的性能损失是值得的,因为COBOL和FORTRAN程序更容易编写和维护。
In my opinion, the overhead of C++ is simply the price you pay for a better language. This same debate went on in the 60's when high-level programming languages like COBOL and FORTRAN started to displace hand-coded assembly as the language of choice. Critics correctly pointed out that programs written in high-level languages were inherently slower than hand-tuned assembly and always would be. High-level language advocates pointed out, however, that the slight performance hit was worth it because COBOL and FORTRAN programs were much easier to write and maintain.
优点:组织大型程序时比C语言好得多。很好的支持面向对象机制。通用数据结构,如链表和可增长的阵列组成的库减轻了由于处理低层细节的负担。
Advantages: Much better than C for organizing large programs. Supports the object-oriented paradigm nicely. Libraries of common data structures, li
ke linked lists and grow-able arrays, can remove much of the burden of having to deal with low-level details.
缺点:非常大而复杂。与C语言一样存在语法滥用问题。比C慢。大多数编译器没有把整个语言正确的实现。
Disadvantages: Extremely large and complicated. Like C, the syntax lends itself to abuse. Can be slower than C. Not many compilers implement the entire language correctly.
移植性:比C语言好多了,但依然不是很乐观。因为它具有与C语言相同的缺点,大多数可移植性用户界面库都使用C++对象实现。
Portability: Better than C, but still not great. While it shares the same disadvantage as C, most of the portable user-interface libraries are implemented as collections of C++ objects.
使用C++编写的游戏:非常非常多。大多数的商业游戏是使用C或C++编写的。
Games Written in C++: Lots and lots. Almost all commercial games are written in C or C++.
资料:最新版的《The C++ Programming Language》非常好。作为教程,有两个阵营,一个假定你知道C,另外一个假定你不知道。到目前为止,最好的C++教程是《Who's Afraid of C++》,如果你已经熟知C,那么试一下《Teach Yourself C++》。
Resources: The latest edition of The C++ Programming Language is excellent. As for tutorials, there are two camps, ones that assume you know C, and ones you don't. By far the best ground-up C++ tutorials are Who's Afraid of C++ and Who's Afraid of More C++. If you already know C, try Teach Yourself C++.
3、我该学习C++或是该从C开始(Should I learn C++, or should I start with C )
我不喜欢这种说法,但它是继“我该使用哪门语言”之后最经常被问及的问题。很不幸,不存在标准答案。你可以自学C并使用它来写程序,从而节省一大堆的时间,不过使用这种方法有两个弊端:
I thought this bore mentioning, as it's the second most commonly asked question next to "which programming language should I use?"Unfortunately, the answer isn't black and white. You could save
a lot of time by just teaching yourself C and writing apps, but there are two disadvantages to this approach.
你将错过那些面向对象的知识,因为它可能在你的游戏中使得数据建模更有效率的东西。
You're missing out on what will likely be a much more effective way of modeling the data in your game. By not learning OO programming off the bat, you could be enforcing bad programming habits that you'll have to un-learn later. Trust me on this one.
最大的商业游戏,包括第一人称射击游戏很多并没有使用C++。但是,这些程序的作者即使使用老的C的格式,他们通常坚持使用面向对象编程技术。如果你只想学C,至少要自学OO(面向对象)编程技术。OO是仿真(游戏)的完美方法,如果你不学习OO,你
将不得不“辛苦”的工作。
Many of the biggest commercial games, including most first-person shooters, get by without C++. The authors of these programs, however, always insist that they're using object-oriented programming techniques even though they're using plain old C. If you want to just learn C, at least teach yourself OO programming techniques. OO is the perfect methodology for simulations (read: games), and you'll really be doing it "the hard way" if you push off learning OO.
4、汇编语言(Assembly)
显然,汇编是第一个计算机语言。汇编语言实际上是你计算机处理器实际运行的指令的命令形式表示法。这意味着你将与处理器的底层打交道,比如寄存器和堆栈。如果你要的是类英语且有相关的自我说明的语言,这不是你想要的。
By default, assembly was the first computer language. Assembly language is actually a command-based representation of the actual instructions that your computer's processor runs. That means you will be dealing with the low-level details of your processor, like registers and stacks. If you're looking for a language that's English-like and is relatively self-documenting, this isn't it!
确切的说,任何你能在其他语言里做到的事情,汇编都能做,只是不那么简单 — 这是当然,就像说你既可以开车到某个地方,也可以走路去,只是难易之分。话虽不错,但是新技术让东西变得更易于使用。
By definition, anything you can do in any other language, you can do in assembly, only not as easily --of course, that's like saying that anywhere you can go in a car, you can go on foot, only not as easily. While the statement might be true, the later technologies made things much easier to use.
总的来说,汇编语言不会在游戏中单独应用。游戏使用汇编主要是使用它那些能提高性能的零零碎碎的部分。比如说,毁灭战士整体使用C来编写,有几段绘图程序使用汇编。这些程序每秒钟要调用数千次,因此,尽可能的简洁将有助于提高游戏的性能。而从C里调用汇编写的函数是相当简单的,因此同时使用两种语言不成问题。
In general, assembly language is not used on its own for games. Games that use assembly language use it in bits and pieces where it can improve performance. For example, DOOM is written entirely in C with a couple of drawing routines hand-coded in assembly. They are the routines that are called a few thousand times a second, so making the routine as tight as possible really helped the performance of the game. It's fairly easy to write a function in assembly that is call-able from C, so using both languages wasn't a problem.
特别注意:语言的名字叫“汇编”。把汇编语言翻译成真实的机器码的工具叫“汇编程序”。把这门语言叫做“汇编程序”这种用词不当相
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论