游戏脚本引擎设计与实现
详细信息    本馆镜像全文|  推荐本文 |  |   获取CNKI官网全文
摘要
游戏脚本是计算机游戏逻辑的载体,游戏脚本引擎则是游戏脚本的运行支撑环境。将游戏脚本引入到游戏编程之后,可以避免游戏逻辑的硬编码化,从而大大提高计算机游戏的开发效率。目前国外已有多款适合作为游戏脚本引擎的动态编程语言(例如Python、Ruby、Lua等)被开发出来,而国内的游戏开发公司也开始逐步将这些游戏脚本引擎应用到自己的游戏产品开发之中。
     本文介绍了一个简单的游戏脚本引擎系统(XtremeScript脚本系统)的设计与实现,其核心的设计思路为:将计算机游戏逻辑写入到脚本文件(而不是硬编码到计算机游戏主应用程序中),虚拟机软件负责执行这些脚本文件,并将执行的结果通过特定的函数调用接口返回给计算机游戏主应用程序。
     XtremeScript脚本系统主要由三部分组成:XtremeScript编译器、XVM虚拟机、XVM汇编器。XtremeScript编译器可以将XtremeScript语言(C语言的一种子集)编译成XVM汇编语言(一种类似INTEL汇编语言的低级语言);XVM汇编器可以将XVM汇编语言汇编成XVM虚拟机可以识别并执行的字节码;XVM虚拟机是一个模拟XVM汇编语言CPU行为并嵌入在宿主程序(如游戏主应用程序)中运行的软件,它能识别并执行由XVM汇编语言汇编而成的字节码,并向宿主程序返回相应的运行结果。
     本文分析研究了一个简单的游戏脚本引擎(XtremeScript脚本系统)的工作原理和实现机制,构建了一个初步可用的脚本引擎系统,给出了脚本系统设计与实现的一条可行之路。
     在消化吸收原有工作的基础上,对相关的算法和程序实现进行了分析和优化,以语法制导的规则重写了编译器和汇编器的核心程序,使得程序结构变得清晰可读;以基于栈原则的简单寄存器分配算法和基于硬编码的决策树法等高效算法去替代原有算法,使得脚本系统生成的代码更加简洁,较大地提高了它的运行速度。
Game script is the carder of computer game logic,it runs within the computer game scripting engine.The introduction of game script can avoid the "hard-coded" of computer game logic,so it will greatly improve the efficiency of the development of computer games.Several dynamic programming languages which are suit to act as the computer game scripting engine have been forwarded now in foreign countries,such as Python,Ruby,Lua etc.,and domestic computer game development companies are starting to apply these game scripting engines in developing their own computer games.
     This paper introduce the design and implementation of a simple game scripting engine XtremeScript scripting system,the core of designation can be summaried as:Write the computer game logic into script files,rather than hard coding into computer game application,then the virtual machine will execute these script files and return the results to the computer game application through specific function invoking interfaces.
     XtremeScript scripting system includes three parts:XtremeScrpit compiler, XVM virtual machine,XVM assembler.XtremeScript compiler can compile XtremeScript language into XVM assemble language,XtremeScript language is a subset of C language and XVM assemble language is a language which analog to INTEL assemble language;XVM assembler can assemble XVM language into byteword which can be executed by XVM virtual machine;XVM virtual machine is a software which mocking the acts of XVM assemble language CPU and run within the host programs,such as computer game programs,it identifies and executes the bytewords which are assembled into by XVM assembler,and returns the corresponding results to the host programs.
     This paper analyzes and researchs the principles and mechanisms of a simple game scripting engine—XtremeScript scripting system,builds a game scripting system which can be put to use,and provides a feasible way to design and implement a scripting system.
     After absorbing the essence of original work,this paper analyzes and optimizes the related algorithms and programming structures—rewrite the compiler and assembler based on the syntax-directed rule to clarify the programming structure, replace the original algorithms with more effective algorithms(such as simple register allocation algorithm based on stack principle and decision tree algorithm based on hard-coded.),simplify the codes generated by scripting system,improve the speed of execution greatly.
引文
属性不符 现代编译原理—C语言描述,人民邮电出版社 2006年4月
    [17]端木春 Python史话 程序员:CSDN开发高手 2004年8期
    [18]孟岩,汤韬,罗景文 动静之变——裘宗燕教授访谈 程序员-2004年5期
    [19]汤韬 动态语言,隔岸观“火” 程序员-2004年5期
    [20]黄甫 动态语言:Ruby雄起 程序员-2005年12期
    [21]刘睿 动态语言面面观 软件世界-2007年5期
    [22]刘睿 动态语言难堪重任 软件世界-2007年5期
    [23]罗霄,任勇,山秀明 基于Python的混合语言编程及其实现计算机应用与软件 2004年12期
    [24]孟岩 未来属于动态语言——2006动态语言发展评述 程序员-2007年1期
    [25]邓际锋 一颗璀璨的月光宝石——Lua 程序员-2006年6期
    [26]陈革 易学易读且功能强大的Python语言 程序员-2001年1期
    [27]孟岩 中国不谈Python 程序员-2004年5期
    [28]林甲威.嵌入式数据库系统的研究和开发:[硕士学位论文].上海:复旦大学 2004
    [29]陆新年.DLX虚拟机及其C语言编译器:[硕士学位论文].北京:北京科技大学 2005
    [30]李巍.虚拟机机制研究:[硕士学位论文]四川:电子科技大学 2004
    [31]胡巍.嵌入式系统可重定向编译器的设计与实现:[硕士学位论文]安徽:中国科学技术大学 2004
    [32]崔慧敏,戴桂兰,王生原,张素琴 动态编译技术研究计算机科学 2004 Vol-31-7
    [33][美]Brian W.Kernighan Dennis M.Ritchie著,徐宝文,李志译C程序设计语言,机械工业出版社 2004年1月
    [34][美]Mark Allen Weiss著,冯舜玺 译 数据结构与算法分析—C语言描述,机械工业出版社 2004年1月
    [35]严蔚敏,陈文博 著,数据结构 机械工业出版社 1990年
    [36][美]Cormen Leiserson著,算法导论,高等教育出版社 2002年5月
    [37][美]J.L.Hennessy,D.A.Patterson著,Computer Architecture.A Quantitative Approach,机械工业出版社 1999年1月
    [38][美]J.L.Hennessy,D.A.Patterson著,郑纬民,汤志忠 译 计算机系统结构:一种定量的方法,清华大学出版社 2002年8月
    [39][捷克]Brainsoft 著,Z80 Assembler Construction,http://artax.karlin.mff.cuni.cz/~brain/
    [40][美]Thomas H.Cormen,Charles E.Leiserson,Ronald L.Rivest,Clifford Stein著,算法导论 INTRODUCTION TO ALGORITHMS(Second Edition),高等教育出版社 2002年5月
    [41][美]Kay A.Robbins,Steven Robbins 著,刘宗田,孙志勇,秦宗贵 译实用UNIX编程,机械工业出版社 1999年10月
    [42]钱焕延 著,编译技术 东南大学出版社 1995年3月
    [43]陈火旺 著,程序设计语言编译原理 国防工业出版社 1984年
    [44]LUA官方网站 http://www.lua.org
    [45]PYTHON官方网站 http://www.python.org
    [46]PYTHON官方网站 http://www.ruby-lang.org

© 2004-2018 中国地质图书馆版权所有 京ICP备05064691号 京公网安备11010802017129号

地址:北京市海淀区学院路29号 邮编:100083

电话:办公室:(+86 10)66554848;文献借阅、咨询服务、科技查新:66554700