使用何种语言编写游戏

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

我该使用何种语言这是每个游戏编程FAQ里都有的问题。这个问题每星期都会在游戏开发论坛上被问上好几次。这是个很好的问题,但是,没人能给出简单的答案。在某些应用程序中,总有一些计算机语言优于其他语言。下面是几种用于编写游戏的主要编程语言的介绍及其优缺点。希望这篇文章能帮助你做出决定。ThisisaquestionthatbelongsineverygameprogrammingFAQ.Itseemstobeaskedinagamedevelopmentforumseveraltimesaweek.It'sagoodquestion,though,andnotonewithaneasyanswer.Therearecomputerlanguagesthatworkbetterforsomeapplicationsthanothers.Hereisalistofthemajorprogramminglanguagesusedtowritegamesalongwithdescriptions,advantages,anddisadvantages.Hopefullythislistwillhelpyoumakeadecision.1、C语言如果说FORTRAN和COBOL是第一代高级编译语言,那么C语言就是它们的孙子辈。C语言是DennisRitchie在七十年代创建的,它功能更强大且与ALGOL保持更连续的继承性,而ALGOL则是COBOL和FORTRAN的结构化继承者。C语言被设计成一个比它的前辈更精巧、更简单的版本,它适于编写系统级的程序,比如操作系统。在此之前,操作系统是使用汇编语言编写的,而且不可移植。C语言是第一个使得系统级代码移植成为可能的编程语言。IfFORTRANandCOBOLwerethefirstcompiledhigh-levellanguages,thenCistheirgrandchild.Itwascreatedinthe70'sbyDennisRitchieasatighterandmorecoherentsuccessortoALGOL,whichwasastructuredsuccessortoCOBOLandFORTRAN.Itwasdesignedtobeasmallerandsimplerversionofitspredecessors,suitableforwritingsystem-levelprograms,likeoperatingsystems.Beforethen,operatingsystemswerehand-codedinassemblyandwerenotportable.Cwasthefirstprogramminglanguagethatmadeportabilityarealityforsystem-levelcode.C语言支持结构化编程,也就是说C的程序被编写成一些分离的函数呼叫(调用)的集合,这些呼叫是自上而下运行,而不像一个单独的集成块的代码使用GOTO语句控制流程。因此,C程序比起集成性的FORTRAN及COBOL的“空心粉式代码”代码要简单得多。事实上,C仍然具有GOTO语句,不过它的功能被限制了,仅当结构化方案非常复杂时才建议使用。Cisalanguagethatsupportsstructuredprogramming.ThatistosaythatCprogramsarewrittenascollectionsofdisconnectedfunctioncallsthatruntop-downratherthanasinglemonolithicblockofcodewithprogramcontrol-flowhappeningviaGOTOstatements.Hence,CprogramsaregenerallyeasiertofollowthanmonolithicFORTRANandCOBOLspaghetti-code.Actually,CstillhasaGOTOstatement,butitsfunctionalityislimitedanditisonlyrecommendedasalastresortifstructuredsolutionsaremuchmorecomplicated.正由于它的系统编程根源,将C和汇编语言进行结合是相当容易的。函数调用接口非常简单,而且汇编语言指令还能内嵌到C代码中,所以,不需要连接独立的汇编模块。Truetoitssystem-programmingroots,itisfairlyeasytointerfaceCwithassemblylanguages.Thefunction-callinginterfaceisverysimple,andassemblylanguageinstructionscanbeembeddedwithinCcode,solinkinginseparateassembly-languagemodulesisnotnecessary.优点:有益于编写小而快的程序。很容易与汇编语言结合。具有很高的标准化,因此其他平台上的各版本非常相似。Advantages:Goodforwritingsmallfastprograms.Easytointerfacewithassemblylanguage.Verystandardized,soversionsonotherplatformsaresimilar.缺点:不容易支持面向对象技术。语法有时会非常难以理解,并造成滥用。Disadvantages:Doesnoteasilysupportobject-orientedtechniques.Syntaxcanbedifficultandlendsitselftoabuse.移植性:C语言的核心以及ANSI函数调用都具有移植性,但仅限于流程控制、内存管理和简单的文件处理。其他的东西都跟平台有关。比如说,为Windows和Mac开发可移植的程序,用户界面部分就需要用到与系统相关的函数调用。这一般意味着你必须写两次用户界面代码,不过还好有一些库可以减轻工作量。Portability:WhilethecoreofthelanguageandtheANSIfunctioncallsareveryportable,theyarelimitedtocontrol-flow,memorymanagement,andsimplefile-handling.Everythingelseisplatform-specific.Makingaprogramthat'sportablebetweenWindowsandtheMac,forinstance,requiresthattheuser-interfaceportionsbeusingsystem-specificfunctioncalls.Thisgenerallymeansthatyouneedtowritetheuser-interfacecodetwice.Therearelibraries,though,thatmaketheprocessabiteasier.用C语言编写的游戏:非常非常多。GamesWritteninC:Lotsandlots.资料:C语言的经典著作是《TheCProgrammingLanguage》,它经过多次修改,已经扩展到最初的三倍大,但它仍然是介绍C的优秀书本。一本极好的教程是《TheWaiteGroup'sCPrimerPlus》。Resources:TheclassicbookaboutCis[TheCProgrammingLanguage].It'sgonethroughseveraliterationsandhasexpandedtoaboutthreetimesitsoriginalsize,butit'sstillagoodintroductiontothelanguage.Anexcellenttutorialis[TheWaiteGroup'sCPrimerPlus].2、C++C++语言是具有面向对象特性的C语言的继承者。面向对象编程,或称OOP是结构化编程的下一步。OO程序由对象组成,其中的对象是数据和函数离散集合。有许多可用的对象库存在,这使得编程简单得只需要将一些程序“建筑材料”堆在一起(至少理论上是这样)。比如说,有很多的GUI和数据库的库实现为对象的集合。C++istheobject-orientedsuccessortoC.Object-oriented,orOO,programsarethenextstepbeyondstructuredprogramming.OOprogramsarebuiltoutofobjects,whicharepackagesofdataandfunctionscollectedintodiscreteunits.Therearemanylibrariesofobjectsavailablethatmakewritingprogramsassimpleaspullingtogetheracollectionofprogrambuildingblocks(atleastintheory).Forexample,therearemanyGUIanddatabaselibrariesthatareimplementedascollectionsofobjects.C++总是辩论的主题,尤其是在游戏开发论坛里。有几项C++的功能,比如虚拟函数,为函数呼叫的决策制定增加了一个额外层次,批评家很快指出C++程序将变得比相同功能的C程序来得大和慢。C++的拥护者则认为,用C写出与虚拟函数等价的代码同样会增加开支。这将是一个还在进行,而且不可能很快得出结论的争论。C++isthesubjectofcontroversy,especiallyinthegamedevelopmentcommunity.TherearefeaturesofC++,likevirtualfunctions,thataddanextralayerofdecision-makingtofunctioncalls,andcriticsarequicktopointoutthatC++programscanbelargerandslowerthanCcounterparts.C++advocatespointout,however,thatcodingtheequivalentofavirtualfunctioninCrequiresthesameoverhead.It'sanon-goingdebatethat'snotlikelytobedecidedsoon.我认为,C++的额外开支只是使用更好的语言的小付出。同样的争论发生在六十年代高级程序语言如COBOL和FORTRAN开始取代汇编成为语言所选的时候。批评家正确的指出使用高级语言编写的程序天生就比手写的汇编语言来得慢,而且必然如此。而高级语言支持者认为这么点小小的性能损失是值得的,因为COBOL和FORTRAN程序更容易编写和维护。Inmyopinion,theoverheadofC++issimplythepriceyoupayforabetterlanguage.Thissamedebatewentoninthe60'swhenhigh-levelprogramminglanguageslikeCOBOLandFORTRANstartedtodisplacehand-codedassemblyasthelanguageofchoice.Criticscorrectlypointedoutthatprogramswritteninhigh-levellanguageswereinherentlyslowerthanhand

1 / 11
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功