There are several applications like Blitz3D or other kinds of game construction tools that compile scripts or other game data to a single executable file. How do they do that?


Different tools approach that in different ways, but the way Blitz3D does it is to wrap the code and an interpreter into a bundle. Then when you run the exe, that launches the interpreter and passes in the bundled code. It's pretty much the same as how, say, Python works when using py2exe.

In many game development tools, the code that is bundled along with the executable is simply raw text that the interpreter parses. However some take a bytecode approach like Java, where the source-code is turned into an intermediate form that the virtual machine uses. I think Unity uses this latter approach but I'm not sure.

Off the top of my head all game development tools I can think of that package executables are either based on this approach of a core interpreter/virtual machine and then packaging it with the code, or are libraries that you compile in Visual Studio or whatever.

  • \$\begingroup\$ Is the second approach is faster than the first? \$\endgroup\$ – Quazi Irfan Oct 11 '11 at 6:46
  • \$\begingroup\$ There are pros and cons, but the main thing to bear in mind with regards to speed is that all the really speed critical code (eg. rendering routines) is in the interpreter and thus the speed of the interpreted code isn't as important. The interpreted code simply calls a function like loadMesh() and the interpreter does the rest. It's the exact same situation as using a scripting language embedded in a game engine; indeed, there are frequent debates on Blitz3D's forum about whether or not it is a "game engine". \$\endgroup\$ – jhocking Oct 11 '11 at 12:08

Program flow, variable handling and the like are compiled into pure machine code, whereas the high-level commands are implemented as C++ library functions which are called from the runtime library compiled into every Blitz-generated executable. Non of the Blitz Basic family is interpreted like Python.

  • \$\begingroup\$ I'm not sure what you mean by "implemented as C++ library functions which are called from the runtime library", but either that's just a fancy way of saying the user's code is interpreted by the core engine, or you are simply mistaken. Several years ago there was a short-lived product called CoolBasic that worked by replacing the user code in a Blitz3D exe (it was shut down of course because this was hacking of questionable legality); that wouldn't have worked if the user's code was compiled into the runtime. \$\endgroup\$ – jhocking Apr 17 '15 at 12:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.