节点文献

游戏脚本引擎设计与实现

【作者】 谌勇

【导师】 许大丹;

【作者基本信息】 昆明理工大学 , 计算机应用技术, 2007, 硕士

【摘要】 游戏脚本是计算机游戏逻辑的载体,游戏脚本引擎则是游戏脚本的运行支撑环境。将游戏脚本引入到游戏编程之后,可以避免游戏逻辑的硬编码化,从而大大提高计算机游戏的开发效率。目前国外已有多款适合作为游戏脚本引擎的动态编程语言(例如Python、Ruby、Lua等)被开发出来,而国内的游戏开发公司也开始逐步将这些游戏脚本引擎应用到自己的游戏产品开发之中。本文介绍了一个简单的游戏脚本引擎系统(XtremeScript脚本系统)的设计与实现,其核心的设计思路为:将计算机游戏逻辑写入到脚本文件(而不是硬编码到计算机游戏主应用程序中),虚拟机软件负责执行这些脚本文件,并将执行的结果通过特定的函数调用接口返回给计算机游戏主应用程序。XtremeScript脚本系统主要由三部分组成:XtremeScript编译器、XVM虚拟机、XVM汇编器。XtremeScript编译器可以将XtremeScript语言(C语言的一种子集)编译成XVM汇编语言(一种类似INTEL汇编语言的低级语言);XVM汇编器可以将XVM汇编语言汇编成XVM虚拟机可以识别并执行的字节码;XVM虚拟机是一个模拟XVM汇编语言CPU行为并嵌入在宿主程序(如游戏主应用程序)中运行的软件,它能识别并执行由XVM汇编语言汇编而成的字节码,并向宿主程序返回相应的运行结果。本文分析研究了一个简单的游戏脚本引擎(XtremeScript脚本系统)的工作原理和实现机制,构建了一个初步可用的脚本引擎系统,给出了脚本系统设计与实现的一条可行之路。在消化吸收原有工作的基础上,对相关的算法和程序实现进行了分析和优化,以语法制导的规则重写了编译器和汇编器的核心程序,使得程序结构变得清晰可读;以基于栈原则的简单寄存器分配算法和基于硬编码的决策树法等高效算法去替代原有算法,使得脚本系统生成的代码更加简洁,较大地提高了它的运行速度。

【Abstract】 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.

【关键词】 脚本引擎虚拟机汇编器编译器
【Key words】 Scripting EngineVirtual MachineAssemblerCompiler
  • 【分类号】TP311.52
  • 【被引频次】1
  • 【下载频次】447
节点文献中: 

本文链接的文献网络图示:

本文的引文网络