GameMonkey Script for the game's scripts: a register VM, threads, update rates
The game's scripts are written in GameMonkey Script, a small language from 2002 by Matthew Riek and Greg Douglas (MIT), instead of GDScript. The language is taken, not the code: the parser, compiler and virtual machine are new, and every script value is the engine's own Variant, so nothing is converted when a script calls the engine or the engine calls a script.
Why this language: its threads. A mission is a thread that can sleep, block on a signal and be ended from outside, and the whole script state can be saved and restored as bytes.
What is built:
- A parser, a compiler and a register VM.
- Threads:
thread,yield,sleep,block,signal,fork, states, and a scheduler with a budget for each frame. - The engine binding:
.gmscripts on nodes, calls into any engine class, engine signals queued to the tick. - Optional type annotations with a checker and typed instructions.
- Tools: breakpoints, stepping, a view of every thread, a profiler, hot reload, completion.
- A game layer: missions that own what they make, tickets with deadlines, snapshots, save and load.
Update rates
A polling thread can be given a period and a phase, both in ticks. Phases are handed out in turn, so 150 threads at period 15 are 10 a tick, not 150 on every fifteenth tick. Nothing looks at the clock, so a replay or a restored save runs the same way.
Measured against GDScript
Milliseconds, best of 35, GDScript written as a GDScript programmer writes it:
| Program | GameMonkey typed | GDScript typed |
|---|---|---|
fib(27) | 34.2 | 65.9 |
| Float loop, 3 million | 13.1 | 48.7 |
| Table fields, 2 million | 33.8 | 340.4 |
| Member variables, 2 million | 36.4 | 24.8 |
| A* on a 40 x 40 grid | 78.6 | 162.2 |
| 3,000 nodes moved, 100 frames | 47.2 | 60.7 |
| 48 workers waiting and answering | 42.7 | 401.1 |
An earlier claim, "faster than typed GDScript on all nine programs", was true only against GDScript written with while loops. Written with for i in n, GDScript gains a third to a half, and the table above is against that form.
GDScript is still faster at member variables (24.8 ms against 36.4). The benchmark machine was not idle. The editor tools were exercised without a display. No game system uses the mission layer yet.