Game Development Reference
In-Depth Information
Tradeoffs
Scripting languages aren't a panacea; there are tradeoffs that must be considered
before using one. The first consideration is that the performance of script is simply
not going to match the performance of a compiled language such as C++. Even
when compared to a JIT- or VM-based language such as Java or C#, an interpreted
scripting language such as Lua or Python will not have competitive performance.
That's because an interpreted language reads in the text-based code on demand,
rather than compiling it in advance. Certain scripting languages do provide the op-
tion to compile into an intermediary; although this still won't be as fast as a nat-
ively compiled language, it usually will be faster than an interpreted language.
Because there is still a performance gap, code that must be high performance
typically should not be implemented in script. In the case of an AI system, the
pathfindingalgorithm(forexample,A*)shouldbehighperformanceandtherefore
should not be written in script. But the state machines that drive the AI behavior
can absolutely be written in script, because they typically will not require complex
computations. Some other examples of what might be in script versus in C++ for
a sample game are listed in Table 11.1 .
Table 11.1 Scripting Language Usage in Sample Game
One big advantage of a scripting language is that it can allow for more rapid it-
eration during development. Suppose that for a particular game, the AI state ma-
chines are written in C++. While playing the game, an AI programmer notices that
one enemy is acting incorrectly. If the state machines are written in C++, the pro-
grammer may have many tools to diagnose the problem, but typically cannot fix it
while the game is running. Although Visual Studio does have an “edit and contin-
ue” feature in C++, in practice this will only work in certain situations. This means
that usually the programmer must stop the game, modify the code, build the ex-
ecutable, restart the game, and finally see if the problem went away.
Search WWH ::




Custom Search