Tuesday, September 1, 2009

Full Circle

Just about a year ago, I started to adapt the Cube 2 (Sauerbraten) engine into the Intensity Engine, a generic gaming/virtual worlds platform - something that can run all sorts of 3D environments, and not just games like insta ctf (which, for any non-gamers reading this, means "instagib capture-the-flag", or "one shot you're dead, capture the other team's flag and bring it back to your base"), etc. This involved a lot of work, among other things removing game-specific code and creating an API that lets scripts take the place of that code. In other words, where Sauerbraten has C++ code for insta ctf, the Intensity Engine has only an API, that lets JavaScript code implement all sorts of 3D 'activities', just one of which might be insta ctf (and others of which might not even be games).

Syntensity, however, is focused on games (at least for the near future), and it will launch with insta ctf as its main gameplay mode. So, over the last 4 days I wrote an insta ctf 'activity' for the Intensity Engine entirely from scratch. This ended up taking about 650 lines of code, split up into several components:
  • GameManager: Keeps score, assigns players to teams, and in general manages the game. Plugins for the GameManager let you control things like what determines when the game is over (a high enough score, for example).
  • Health: A plugin for the player class that adds a 'health' attribute ('state variable' in Intensity Engine terminology) to players, and manages player death and respawning.
  • Firing: Handles guns and their behavior (including delays after firing, etc.). A SniperRifle example gun gives the 'insta' gameplay element - one shot and you're dead.
  • CTF: A plugin for the GameManager that handles the flags and their behavior.
By using a component model, the code ends up being very extensible: The 'insta' element is entirely contained in the SniperRifle class, and the 'ctf' element in the CTF plugin. These could easily be swapped out with other plugins to get new gameplay modes.

(All the code is already in the repo, if anyone wants to take a look.)

So, after eliminating all the hardcoded insta ctf stuff in Sauerbraten, we have come full circle to implementing an insta ctf game mode, but this time written in JavaScript, and it's just one example of an activity which the Intensity Engine can run. Amusingly, insta ctf in Sauerbraten and in the Intensity Engine look quite similar from the outside (well, they would if we used the same models), but the internals are entirely different.


  1. Interesting idea you've done here, though, wouldn't Javascript be too slow to be adequate in this situation?

  2. @Alex:

    JavaScript is only used for the high-level game logic. It wouldn't be fast enough for rendering or physics, but for what we use it it should be sufficient. And we use Google V8, which is quite fast for a dynamic language engine (and also getting faster all the time).

    However, yes, this does mean the frame rate is lower than Sauerbraten would get on the same map.