0

所以我和我的朋友发生了一个我们无法解决的争论。他正在编写一个通用的网络游戏库和一个地图编辑器。地图编辑器将地图保存为 XML,但地图编辑器也可以加载一个 Lua 脚本,将地图的详细信息导出到一个 Javascript 文件中,看起来像这样(他不想发布代码,所以这只是一个名称更改的片段):

// This probably isn't valid code, but this is the idea of the code generator
(function() {
Game.Level1 = function (state) {
    GameEngine.Group.call(this);
            var Object0 = new Game.Lo(new GameEngine.Point(654 , 975.13), 15, state);
            var slot123 = new GameEngine.TimeSlot(123);        //Start
            slot123.addEvent(new GameEngine.Event(Object0, "x", "current", 15, 200));
...

这个想法是游戏库将只运行此代码,而不必解析地图文件并动态生成对象。任何想要为不同库以不同语言输出代码的人都可以修改地图编辑器中生成代码的 Lua 脚本。(不限于脚本语言)。

我从未听说过这个想法,通常我希望地图数据采用 JSON 或 XML 等标准格式,并让游戏库解析它。

因此,鉴于他的库是用 javascript 编写的,并且他的地图可以生成 javascript 来加载文件,那么运行生成的代码与解析 JSON/XML 并从中生成对象之间的权衡是什么?

4

1 回答 1

0

In a generic sense loading the metadata from another script, can give added flexibility to the script generator about how the data is sent, displayed etc. For example, you can have complete math expressions, conditionals etc as the part of the loaded script, that will be parsed and loaded seamlessly by the script parser(interpreter). It might be harder to do the same thing by using XML or JSON ( imagine sending an expression to do Miller Cylindrical Projection via XML, on the fly).

I've seen many situations where the app creates its own scripting language (MAXscript, MEL for Maya) to provide flexibility to the user. These are probably not analogous to your friend's usage of Java script to load metadata. But IMHO, it is a continuous spectrum, starting from metadata text files, to XML,JSON, expression parsing, to full fledged script parsing.

On the other hand, sending complicated scripts, will mean exposing part your code base. Also everyone knows what XML does, and you can expect a non-programmer to use/modify XML files. They are comfortable doing it. They may not be comfortable even reading what they think of as 'programs' or 'scripts'. I've seen this first hand in my company, where the artists were uneasy modify a Lua file. They were comfortable modifying the same information, if it was a simple text file. There might some security issues as well, but I'm really not that familiar with it, so I can't comment.

于 2013-10-07T13:21:21.203 回答