PerthThe worklog
An open-world game, built in the open
Credits & data

Worklog › Code

Built

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:

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:

ProgramGameMonkey typedGDScript typed
fib(27)34.265.9
Float loop, 3 million13.148.7
Table fields, 2 million33.8340.4
Member variables, 2 million36.424.8
A* on a 40 x 40 grid78.6162.2
3,000 nodes moved, 100 frames47.260.7
48 workers waiting and answering42.7401.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.