资源预览内容
第1页 / 共14页
第2页 / 共14页
第3页 / 共14页
第4页 / 共14页
第5页 / 共14页
第6页 / 共14页
第7页 / 共14页
第8页 / 共14页
第9页 / 共14页
第10页 / 共14页
亲,该文档总共14页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
Game Scripting in PythonBruce DawsonHumongous Entertainmentbrucedhumongous.comhttp:/www.cygnus-software.com/papers/IntroductionScripting languages allow rapid development of game behaviour without the pitfalls that await the unwary C+ programmer. Using an existing scripting language saves the time and cost of developing a custom language, and typically gives you a far more powerful language than you could create on your own.Python is an excellent choice for a game scripting language because it is powerful, easily embedded, can seamlessly be extended with C/C+ code, has most of the advanced features that make scripting languages worthwhile, and can also be used for automating production. Additionally, the books, development tools and libraries available for Python provide great opportunities for benefiting from the work of others.This session describes our experiences at Humongous Entertainment with integrating Python into our new game engine. It explains why we chose Python, the benefits weve seen, the problems weve encountered, and how we solved them.Why use a scripting language?C+ is a powerful language and an enormous improvement over C. However it is not the best choice for all tasks. The emphasis in C+ is run-time performance Stroustrup94 and no feature will make it into the language if it makes programs run slower. Thus, C+ programmers are burdened with many restrictions and inconveniences.A few of the restrictions that C+ programmers are so used to they usually dont notice include: Manual memory management: a huge amount of C+ programmer time is spent making sure that delete gets called at the appropriate time. Link phase: C+ modules are linked together so that function addresses dont need to be resolved at run-time. This improves run-time performance, but slows down the edit/test cycle. Lack of introspection: C+ code has way of knowing what members are in a class. This makes writing code to load and save objects an enormous task that in some scripting languages is a single call to a built-in function.C+ is static, scripting languages are dynamic. Grossly oversimplified this means that C+ runs fast, but scripting languages let you code faster.Thus, C+ should only be used when you need to optimize for run-time performance. On todays fast computers there are huge blocks of code where performance is not an issue. If you develop these in C+ when a scripting language would do then you are optimizing for the wrong thing.Whats wrong with SCUMM?Humongous has used SCUMM (Script Creation Utility for Maniac Mansion) to create over 50 different games. SCUMM is a powerful adventure game creation language, but it has some limitations. SCUMM was written more than a decade ago and it is missing some of the features found in more modern languages.Despite continual patching and maintenance, SCUMM will never be as full featured and robust as the many other languages available.Why Python?We explored the idea of creating a new, more modern proprietary language, but wisely discarded the idea. We are in the business of making games, not languages.After spending millions of dollars over the years maintaining a suite of proprietary tools we, really wanted to go with an existing scripting language rather than creating one. Existing languages let us get started faster, have lower maintenance costs, are generally better than a language we would create, and tend to get better over the years, even if we dont work on them.Once we decided that we wanted to use an existing scripting language we had to choose one. We needed something clean that would support object oriented programming and could be embedded in our games, without technical or licensing problems.We considered Lua Lua01 and Python Python02, both of which had been used in several games.Lua is smaller and probably easier to embed in an application, and has some nice language constructs. However, at the time we were choosing a language the documentation was a bit sketchy. This is probably because Lua is a newer language than Python.Python has more extension modules than Lua, more books written about it, and stackless Python Tismer01, which was a promising way of creating micro-threads for object AI. We ended up not using the stackless version of Python, but we did start using Python for writing automated build scripts and this gave us momentum. We knew the syntax, we liked it, and so we chose Python.Both languages have been improved since we made our decision Lua has become stackless and Python has acquired generators, which allow some similar functionality. Either language is a safe choice.Who is using Python in gamesPython has been used in a number of games, including: ToonTown - http:/www.toontown.com/ EveOnline - http:/www.eve-online.com/ Blade of Darkness - http:/www.codemastersusa.com/blade/with numerous other sightings that are
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号