Python游戏脚本语言精讲.docx
- 文档编号:3026013
- 上传时间:2022-11-17
- 格式:DOCX
- 页数:15
- 大小:27.28KB
Python游戏脚本语言精讲.docx
《Python游戏脚本语言精讲.docx》由会员分享,可在线阅读,更多相关《Python游戏脚本语言精讲.docx(15页珍藏版)》请在冰豆网上搜索。
Python游戏脚本语言精讲
GameScriptinginPython
BruceDawson
HumongousEntertainment
bruced@
http:
//www.cygnus-
Introduction
ScriptinglanguagesallowrapiddevelopmentofgamebehaviourwithoutthepitfallsthatawaittheunwaryC++programmer.Usinganexistingscriptinglanguagesavesthetimeandcostofdevelopingacustomlanguage,andtypicallygivesyouafarmorepowerfullanguagethanyoucouldcreateonyourown.
Pythonisanexcellentchoiceforagamescriptinglanguagebecauseitispowerful,easilyembedded,canseamlesslybeextendedwithC/C++code,hasmostoftheadvancedfeaturesthatmakescriptinglanguagesworthwhile,andcanalsobeusedforautomatingproduction.Additionally,thebooks,developmenttoolsandlibrariesavailableforPythonprovidegreatopportunitiesforbenefitingfromtheworkofothers.
ThissessiondescribesourexperiencesatHumongousEntertainmentwithintegratingPythonintoournewgameengine.ItexplainswhywechosePython,thebenefitswe'veseen,theproblemswe'veencountered,andhowwesolvedthem.
Whyuseascriptinglanguage?
C++isapowerfullanguageandanenormousimprovementoverC.Howeveritisnotthebestchoiceforalltasks.TheemphasisinC++isrun-timeperformance[Stroustrup94]andnofeaturewillmakeitintothelanguageifitmakesprogramsrunslower.Thus,C++programmersareburdenedwithmanyrestrictionsandinconveniences.
Afewoftherestrictions–thatC++programmersaresousedtotheyusuallydon’tnotice–include:
∙Manualmemorymanagement:
ahugeamountofC++programmertimeisspentmakingsurethatdeletegetscalledattheappropriatetime.
∙Linkphase:
C++modulesarelinkedtogethersothatfunctionaddressesdon’tneedtoberesolvedatrun-time.Thisimprovesrun-timeperformance,butslowsdowntheedit/testcycle.
∙Lackofintrospection:
C++codehaswayofknowingwhatmembersareinaclass.Thismakeswritingcodetoloadandsaveobjectsanenormoustaskthatinsomescriptinglanguagesisasinglecalltoabuilt-infunction.
C++isstatic,scriptinglanguagesaredynamic.GrosslyoversimplifiedthismeansthatC++runsfast,butscriptinglanguagesletyoucodefaster.
Thus,C++shouldonlybeusedwhenyouneedtooptimizeforrun-timeperformance.Ontoday’sfastcomputerstherearehugeblocksofcodewhereperformanceisnotanissue.IfyoudeveloptheseinC++whenascriptinglanguagewoulddothenyouareoptimizingforthewrongthing.
What’swrongwithSCUMM?
HumongoushasusedSCUMM(ScriptCreationUtilityforManiacMansion)tocreateover50differentgames.SCUMMisapowerfuladventuregamecreationlanguage,butithassomelimitations.SCUMMwaswrittenmorethanadecadeagoanditismissingsomeofthefeaturesfoundinmoremodernlanguages.
Despitecontinualpatchingandmaintenance,SCUMMwillneverbeasfullfeaturedandrobustasthemanyotherlanguagesavailable.
WhyPython?
Weexploredtheideaofcreatinganew,moremodernproprietarylanguage,butwiselydiscardedtheidea.Weareinthebusinessofmakinggames,notlanguages.
Afterspendingmillionsofdollarsovertheyearsmaintainingasuiteofproprietarytoolswe,reallywantedtogowithanexistingscriptinglanguageratherthancreatingone.Existinglanguagesletusgetstartedfaster,havelowermaintenancecosts,aregenerallybetterthanalanguagewewouldcreate,andtendtogetbetterovertheyears,evenifwedon’tworkonthem.
Oncewedecidedthatwewantedtouseanexistingscriptinglanguagewehadtochooseone.Weneededsomethingcleanthatwouldsupportobjectorientedprogrammingandcouldbeembeddedinourgames,withouttechnicalorlicensingproblems.
WeconsideredLua[Lua01]andPython[Python02],bothofwhichhadbeenusedinseveralgames.
Luaissmallerandprobablyeasiertoembedinanapplication,andhassomenicelanguageconstructs.However,atthetimewewerechoosingalanguagethedocumentationwasabitsketchy.ThisisprobablybecauseLuaisanewerlanguagethanPython.
PythonhasmoreextensionmodulesthanLua,morebookswrittenaboutit,andstacklessPython[Tismer01],whichwasapromisingwayofcreatingmicro-threadsforobjectAI.WeendedupnotusingthestacklessversionofPython,butwedidstartusingPythonforwritingautomatedbuildscriptsandthisgaveusmomentum.Weknewthesyntax,welikedit,andsowechosePython.
Bothlanguageshavebeenimprovedsincewemadeourdecision–LuahasbecomestacklessandPythonhasacquiredgenerators,whichallowsomesimilarfunctionality.Eitherlanguageisasafechoice.
WhoisusingPythoningames
Pythonhasbeenusedinanumberofgames,including:
∙ToonTown-
∙EveOnline-http:
//www.eve-
∙BladeofDarkness-
withnumerousothersightingsthataredifficultto
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Python 游戏 脚本语言
![提示](https://static.bdocx.com/images/bang_tan.gif)