September 03, 2019

Programming languages are game engines too

Compilers are often described by it's inner structure. For example, they are containing of a parser and a lexer. What is missing in this description is what the purpose of a compiler is. The more elaborated way in thinking about programming languages is to imagine, how they utilized as a man machine interface. The programmer sends the sourcecode to the compiler and the compiler converts it into machine code.

An interpreter which can execute a programming language like Perl has much in common with a game engine. Similar to a game engine, the machine provides to the programmer an API interface. That's a list of actions who are allowed to enter. A sense making dialogue with a game engine would work in a way, that the programmers executes “move pacman to the left”. In response to this request, the game engine modifies the position of the character on the screen and adapts the graphics subroutines as well. The same is true for an interpreter who runs computer code. The users enters an action like “for (int i=0,i<5,i++)” and the interpreter is answering this request by executing a loop which contains of 5 single steps.

The interesting fact is, that for the normal user the inner working of a game engine or a compiler are not relevant. They only know which actions are allowed and use the machine in a pipeline. On the other hand, for the programmer of a game engine, it's not relevant who a game is played by the human. The only thing what a pacman game engine has to ensure is, that the program can handle certain situations and detect all the collisions with the map.

Fro reason of simplification it make sense to describe an engine as a rulebook in which certain actions are possible. The engine defines which commands can be entered by the outside and it defines how fast these actions are executed. The game engine is an intermediate which improves the communication. The engine itself is doing nothing, but it has to adapt to the needs of the environment.