0 .A.Dventure

The Force is strong with this one.

The Source of It All...! [Part 2]

| Comments

In the last post we documented an overview of the game and also some vital resources that are to be used during the game-dev So lets start descending into the source. In this post we’ll discuss how the game starts and runs.

Also, you can access the doxygen generated doc of the game’s source available here. This documentation will be regularly updated and will be referred to throughout the blog.

If you build the game on your own, using the source, you typically get a binary pyrogenesis in the binaries/system directory and the game will be using data or scripts present in binaries/data/mods/public; unless the game is compiled with some flags specifying the binary, data or lib directories while setting up the workspace (info can be found here).

So let’s begin! When the game is run, it starts off by performing some initializations.

  1. The thread on which the game started is marked as the main thread and its named “main”. [GameSetup.cpp:827]
  2. The current time is noted so that elapsed time can be counted from this point. [GameSetup.cpp:838]
  3. The profiler is initialized and started. The profiler is used for analysing framerate fluctuations or glitches and temporal relationships between threads. [GameSetup.cpp:842]
  4. The locales are set for the game execution depending on the OS. [GameSetup.cpp:844]

After this is done, the game is then ready to start running. Now,

  1. The command line arguments are interpreted (if any given). [main.cpp:446]
  2. A virtual file system is created and the game’s cache and data are loaded. [main.cpp:465]
  3. The game is now started and the graphics initialized. [main.cpp:504]
  4. The input handlers are initialized and set. [main.cpp:506]

By now the game is up and running and the profiler would be capturing every frame. When the game is quit, the shutdown sequence starts. You can see all this starting from source/main.cpp and related files. There’s just too much code to inline in the post!

While this certainly gives a fair idea of how the game begins, its worth noting some classes and features available in the source.

The Core Engine modules are placed in source/ps/ directory and they are used all over the source. A few of them are –

  1. ArchiveBuilder: Used to package mod files into distributable archives.
  2. Console: The in-game scripting console.
  3. ConfigDB: Manage configuration variables for the game.
  4. CStr: A string wrapper designed to provide better string handling.
  5. Filesystem: A class to provide filesystem-like functionality to the API which makes it easier to access files for the game.
  6. GameSetup/CmdLineArgs: A class to parse the command line arguments.
  7. GameSetup/Paths: Wrapper class for OS Paths used in the game.

… and many more! You can have a look at the directory to view all the files in it. Our work isn’t done yet! Our initial focus has been on the AI which we’ll be covering next.

To be continued …

Comments