<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://staging-wiki.unvanquished.net/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=The+White+Lion</id>
	<title>Unvanquished - User contributions [en-gb]</title>
	<link rel="self" type="application/atom+xml" href="https://staging-wiki.unvanquished.net/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=The+White+Lion"/>
	<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/wiki/Special:Contributions/The_White_Lion"/>
	<updated>2026-04-05T01:30:00Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.8</generator>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5108</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5108"/>
		<updated>2021-07-10T19:27:03Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Source Code Tree and File Descriptions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
This Wiki page is incomplete and a work-in-progress, nonetheless there is still helpful information on this web page.&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code Tree and File Descriptions==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt; - game assets&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; - data submodule&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; - engine submodule&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; - engine source code&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_api&amp;lt;/code&amp;gt; - contains definitions for the VM to engine function-procedures&lt;br /&gt;
**** &amp;lt;code&amp;gt;CommonProxies&amp;lt;/code&amp;gt; - proxy interface to the VM, has trap calls for sending messages to the VM&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;Cvar&amp;lt;/code&amp;gt; - the proxy interface for console variables&lt;br /&gt;
**** &amp;lt;code&amp;gt;Debugger&amp;lt;/code&amp;gt; - contains a routine to detect if a debugger is attached to the process&lt;br /&gt;
**** &amp;lt;code&amp;gt;FileSystem&amp;lt;/code&amp;gt; - interface to use the host filesystem through the VM&lt;br /&gt;
**** &amp;lt;code&amp;gt;KeyIdentification&amp;lt;/code&amp;gt; - contains an association table (unordered map) that links a keyboard key value with a string descriptor&lt;br /&gt;
**** &amp;lt;code&amp;gt;LineEditData&amp;lt;/code&amp;gt; - ?&lt;br /&gt;
**** &amp;lt;code&amp;gt;Log&amp;lt;/code&amp;gt; - filesystem logging&lt;br /&gt;
**** &amp;lt;code&amp;gt;IPC/&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;Common&amp;lt;/code&amp;gt; - common definitions for all IPC methods&lt;br /&gt;
***** &amp;lt;code&amp;gt;Command&amp;lt;/code&amp;gt; - the inter-process communication command buffer&lt;br /&gt;
***** &amp;lt;code&amp;gt;Channel&amp;lt;/code&amp;gt; - contains the inter-process communication namespace and engine-VM messaging functions&lt;br /&gt;
***** &amp;lt;code&amp;gt;Primitives&amp;lt;/code&amp;gt; - routines for the IPC VM-engine socket&lt;br /&gt;
**** &amp;lt;code&amp;gt;CM/&amp;lt;/code&amp;gt; - related to game collisions and map loading&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_local&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_patch&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_polylib&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_public&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;Color&amp;lt;/code&amp;gt; - related to colors&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; - common code: utility functions, typedefs, macros, and the like&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_shared.h&amp;lt;/code&amp;gt; - included first by ALL program modules. A user mod should never modify this file.&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_shared.cpp&amp;lt;/code&amp;gt; - stateless support routines that are included in each code module&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_math&amp;lt;/code&amp;gt; - stateless support routines that are included in each code module, related to math operations&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_Unicode&amp;lt;/code&amp;gt; - Unicode &amp;amp; UTF-8 handling&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; - renderer&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; - OpenGL shader code&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;sv_sgame&amp;lt;/code&amp;gt; - interface to the game module&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; - the sources for the game-logic modules, both Client and Server&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; - client-local game-logic code&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; - server-local game-logic code&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt; - directory containing sources for bot AI&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_api&amp;lt;/code&amp;gt; - forward function declarations related to the bot artificial intelligence code&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_convert&amp;lt;/code&amp;gt; - procedures for the conversation&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_local&amp;lt;/code&amp;gt; - server-local variable definitions, struct definitions, and forward declarations for the bot AI&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_navdraw&amp;lt;/code&amp;gt; - code for drawing bot AI navmesh for debug purposes&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_types&amp;lt;/code&amp;gt; - code that defines data types for bot AI code&lt;br /&gt;
**** &amp;lt;code&amp;gt;Components/&amp;lt;/code&amp;gt; - directory containing the sources for the CBSE entity components&lt;br /&gt;
***** &amp;lt;code&amp;gt;AcidTubeComponent&amp;lt;/code&amp;gt; - code for Acid Tube entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;AlienBuildableComponent&amp;lt;/code&amp;gt; - code for alien buildable entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;AlienClassComponent&amp;lt;/code&amp;gt; - code for alien class entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;ArmourComponent&amp;lt;/code&amp;gt; - the armour entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;ArmouryComponent&amp;lt;/code&amp;gt; - the armory entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;BarricadeComponent&amp;lt;/code&amp;gt; - the code for the barricade entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;BoosterComponent&amp;lt;/code&amp;gt; - the booster component entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;BuildableComponent&amp;lt;/code&amp;gt; - code for the buildable entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;DeferredFreeingComponent&amp;lt;/code&amp;gt; - code for the deferred freeing component&lt;br /&gt;
***** &amp;lt;code&amp;gt;DrillComponent&amp;lt;/code&amp;gt; - code for the drill entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;EggComponent&amp;lt;/code&amp;gt; - code for the egg entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;HealthComponent&amp;lt;/code&amp;gt; - the health component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;HiveComponent&amp;lt;/code&amp;gt; - the hive component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;HumanBuildableComponent&amp;lt;/code&amp;gt; - the human buildable component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;HumanClassComponent&amp;lt;/code&amp;gt; - the human class component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;IgnitableComponent&amp;lt;/code&amp;gt; - the ignitable component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;KnockbackComponent&amp;lt;/code&amp;gt; - the knockback component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;LeechComponent&amp;lt;/code&amp;gt; - the leech component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;MainBuildableComponent&amp;lt;/code&amp;gt; - the main buildable component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;MedipadComponent&amp;lt;/code&amp;gt; - the medi pad component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;MGTurretComponent&amp;lt;/code&amp;gt; - the MG turret component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;MiningComponent&amp;lt;/code&amp;gt; - the mining component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;OvermindComponent&amp;lt;/code&amp;gt; - the overmind component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;ReactorComponent&amp;lt;/code&amp;gt; - the reactor component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;RocketpodComponent&amp;lt;/code&amp;gt; - the rocket pod component for a CBSE entity&lt;br /&gt;
**** &amp;lt;code&amp;gt;CBSE&amp;lt;/code&amp;gt; - the files containing the core entity declarations and definitions&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSE.h&amp;lt;/code&amp;gt; - connects a source files to the CBSE backend and provides all needed types to CBSE&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSEBackend&amp;lt;/code&amp;gt; - has the declaration of the base entity, implementation of the base components, and helper routines to access entities and components&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSEComponents.h&amp;lt;/code&amp;gt; - files with all game entity component headers&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSEEntities.h&amp;lt;/code&amp;gt; - specific entity declarations&lt;br /&gt;
**** &amp;lt;code&amp;gt;Assert&amp;lt;/code&amp;gt; - daemon engine specific assert code&lt;br /&gt;
**** &amp;lt;code&amp;gt;Clustering&amp;lt;/code&amp;gt; - has code related to the (literal) clustering of base buildables&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_active&amp;lt;/code&amp;gt; - process server-local game events and server-local client effects&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_client&amp;lt;/code&amp;gt; - server-local functions for a client&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_entities&amp;lt;/code&amp;gt; - server functions for server-local game entities&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_main&amp;lt;/code&amp;gt; - core server game functions&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_utils&amp;lt;/code&amp;gt; - misc utility functions for game module&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_team&amp;lt;/code&amp;gt; - function-procedures related to game teams&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_local&amp;lt;/code&amp;gt; - header file with more header inclusions&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_svcmds&amp;lt;/code&amp;gt; - this file holds commands that can be executed by the server console, but not remote clients&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_spawn&amp;lt;/code&amp;gt; - contains the declarations of the spawn functions for various game map entities&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_session&amp;lt;/code&amp;gt; - code for client session data&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_physics&amp;lt;/code&amp;gt; - game physics code&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_admin&amp;lt;/code&amp;gt; - server admin management code&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_namelog&amp;lt;/code&amp;gt; - record client names that connect to the server&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_api&amp;lt;/code&amp;gt; - contains the interface for the server game-logic module to handle messages received from the VM&lt;br /&gt;
**** &amp;lt;code&amp;gt;Entities&amp;lt;/code&amp;gt; - contains helper routines for CBSE entity components&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_public&amp;lt;/code&amp;gt; - definitions shared by both the server game and client game modules&lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_local&amp;lt;/code&amp;gt; - local definitions for the bg (both games) files &lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_gameplay&amp;lt;/code&amp;gt; - gameplay related macro constants and external variable linkage&lt;br /&gt;
**** &amp;lt;code&amp;gt;parse&amp;lt;/code&amp;gt; - parsing game script files&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The game-logic modules are themselves programs and have a main entrance function of &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function. This main function is the first function called in the program and begins the initialization process. The virtual machine starts game-logic module execution by creating a sub-process via the operating system with a call to the function ''CreateProcessW()'' (see daemon/src/engine/framework/VirtualMachine.cpp at line 152 inside the function ''InternalLoadModule'').&lt;br /&gt;
&lt;br /&gt;
The server game is not started until a map is loaded.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
'''Game Objects or Entities:'''&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
There are a number of CBSE (and so Unvanquished) entity related helper functions located in the file Unvanquished/src/sgame/Entities.h, and their implementation inside the cpp file.&lt;br /&gt;
&lt;br /&gt;
Client-local game entities are drawn as computer graphics on the player's screen, any client input related interactions with these entities are transmitted to the server as commands and the server processes these commands and invokes the gameplay code for the entity or entities.&lt;br /&gt;
&lt;br /&gt;
There is an absolute maximum number of entities of 1024 (see ''MAX_GENTITIES'' macro definition of daemon/src/engine/qcommon/qshared.h), if this maximum is reached then the server will terminate. All active game entities are listed inside a global array (''g_entities'', see sg_main.cpp), when a new entity is created the server searches this list for the next available free entity slot and initializes this slot, the server may  force an entity slot to be reallocated to a new entity though this may lead to problems according to a comment in the file sg_entities.cpp:&lt;br /&gt;
&lt;br /&gt;
''Try to avoid reusing an entity that was recently freed, because it can cause the client to think the entity morphed into something else instead of being removed and recreated, which can cause interpolated angles and bad trails.''&lt;br /&gt;
&lt;br /&gt;
Clients are game entities too and from 0 to (''MAX_CLIENTS'' - 1)(see daemon/src/engine/qcommon/q_shared.h) of the server global game entity array is reserved for client entities.&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
'''Gameplay:'''&lt;br /&gt;
Gameplay code is all the code that makes the entities do things and defines game rules and defines game events and defines game behaviors. There is a lot of code in this category and only a little some of the code will be used as an example.&lt;br /&gt;
Gameplay is server-local, meaning gameplay effects happens on the server. For example, the combat mechanics and behaviors of the game Unvanquished are defined in the file src/sgame/sg_combat.cpp. When a player dies the function ''G_PlayerDie'' is called and this function handles game events related to the death of a player, such as adding credit to a client's score and broadcasting a notification to the clients saying a player has died. Another example of gameplay code is the player movement code, contained inside of the file src/shared/bg_pmove.cpp. When a player moves their player character with their keyboard that input is transmitted to the server as a client command and the server calls the functions inside bg_pmove.cpp to apply the movement change to the player character game entity in the game level simulated by the game server, a client is changing the position and orientation of their associated player character entity on the server.&lt;br /&gt;
&lt;br /&gt;
'''Client-Local Game Logic:'''&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==sg_main.cpp==&lt;br /&gt;
The file src/sgame/sg_main.cpp deserves its own section since there are a lot of core server game functions and important variables inside this file.&lt;br /&gt;
&lt;br /&gt;
A special structure with server game level information is inside this file, the &amp;lt;code&amp;gt;level_locals_t level&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
sg_main contains the proxy console variables, the game-logic modules cannot access the console variables directly so they are accessed via a proxy interface.&lt;br /&gt;
&lt;br /&gt;
'''Some Important Server Functions:'''&lt;br /&gt;
*&amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function initializes the server game&lt;br /&gt;
*&amp;lt;code&amp;gt;G_SpawnClients&amp;lt;/code&amp;gt; - spawns the clients into the server game&lt;br /&gt;
*&amp;lt;code&amp;gt;G_RunFrame&amp;lt;/code&amp;gt; - executes the server game frame&lt;br /&gt;
*&amp;lt;code&amp;gt;G_RunThink&amp;lt;/code&amp;gt; - executes the thinking code of the server game entities&lt;br /&gt;
*&amp;lt;code&amp;gt;ExitLevel&amp;lt;/code&amp;gt; - changes the server game level after the intermission&lt;br /&gt;
&lt;br /&gt;
'''The Game Frame:'''&lt;br /&gt;
The game frame is a single moment or instant of the game. For the client, the game frame is a single render frame of the game. Gameplay and game objects are processed on a frame basis, the game is updated to the current frame and then presented to the player as an immediate moment in the game. This is the purpose of the function G_RunFrame, as in Game_RunFrame. This function does all '''''game updates''''' for console variables, for game entities, and entity events, and etc. See the function definition for G_RunFrame of sg_main.cpp for implementation details.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5107</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5107"/>
		<updated>2021-07-10T18:15:14Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Program Ignition and Initialization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
This Wiki page is incomplete and a work-in-progress, nonetheless there is still helpful information on this web page.&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code Tree and File Descriptions==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt; - game assets&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; - data submodule&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; - engine submodule&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; - engine source code&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_api&amp;lt;/code&amp;gt; - contains definitions for the VM to engine function-procedures&lt;br /&gt;
**** &amp;lt;code&amp;gt;CommonProxies&amp;lt;/code&amp;gt; - proxy interface to the VM, has trap calls for sending messages to the VM&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;Cvar&amp;lt;/code&amp;gt; - the proxy interface for console variables&lt;br /&gt;
**** &amp;lt;code&amp;gt;Debugger&amp;lt;/code&amp;gt; - contains a routine to detect if a debugger is attached to the process&lt;br /&gt;
**** &amp;lt;code&amp;gt;FileSystem&amp;lt;/code&amp;gt; - interface to use the host filesystem through the VM&lt;br /&gt;
**** &amp;lt;code&amp;gt;KeyIdentification&amp;lt;/code&amp;gt; - contains an association table (unordered map) that links a keyboard key value with a string descriptor&lt;br /&gt;
**** &amp;lt;code&amp;gt;LineEditData&amp;lt;/code&amp;gt; - ?&lt;br /&gt;
**** &amp;lt;code&amp;gt;Log&amp;lt;/code&amp;gt; - filesystem logging&lt;br /&gt;
**** &amp;lt;code&amp;gt;IPC/&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;Common&amp;lt;/code&amp;gt; - common definitions for all IPC methods&lt;br /&gt;
***** &amp;lt;code&amp;gt;Command&amp;lt;/code&amp;gt; - the inter-process communication command buffer&lt;br /&gt;
***** &amp;lt;code&amp;gt;Channel&amp;lt;/code&amp;gt; - contains the inter-process communication namespace and engine-VM messaging functions&lt;br /&gt;
***** &amp;lt;code&amp;gt;Primitives&amp;lt;/code&amp;gt; - routines for the IPC VM-engine socket&lt;br /&gt;
**** &amp;lt;code&amp;gt;CM/&amp;lt;/code&amp;gt; - related to game collisions and map loading&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_local&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_patch&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_polylib&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_public&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;Color&amp;lt;/code&amp;gt; - related to colors&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; - common code: utility functions, typedefs, macros, and the like&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_shared.h&amp;lt;/code&amp;gt; - included first by ALL program modules. A user mod should never modify this file.&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_shared.cpp&amp;lt;/code&amp;gt; - stateless support routines that are included in each code module&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_math&amp;lt;/code&amp;gt; - stateless support routines that are included in each code module, related to math operations&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_Unicode&amp;lt;/code&amp;gt; - Unicode &amp;amp; UTF-8 handling&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; - renderer&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; - OpenGL shader code&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; - the sources for the game-logic modules, both Client and Server&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; - client-local game-logic code&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; - server-local game-logic code&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt; - directory containing sources for bot AI&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_api&amp;lt;/code&amp;gt; - forward function declarations related to the bot artificial intelligence code&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_convert&amp;lt;/code&amp;gt; - procedures for the conversation&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_local&amp;lt;/code&amp;gt; - server-local variable definitions, struct definitions, and forward declarations for the bot AI&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_navdraw&amp;lt;/code&amp;gt; - code for drawing bot AI navmesh for debug purposes&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_types&amp;lt;/code&amp;gt; - code that defines data types for bot AI code&lt;br /&gt;
**** &amp;lt;code&amp;gt;Components/&amp;lt;/code&amp;gt; - directory containing the sources for the CBSE entity components&lt;br /&gt;
***** &amp;lt;code&amp;gt;AcidTubeComponent&amp;lt;/code&amp;gt; - code for Acid Tube entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;AlienBuildableComponent&amp;lt;/code&amp;gt; - code for alien buildable entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;AlienClassComponent&amp;lt;/code&amp;gt; - code for alien class entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;ArmourComponent&amp;lt;/code&amp;gt; - the armour entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;ArmouryComponent&amp;lt;/code&amp;gt; - the armory entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;BarricadeComponent&amp;lt;/code&amp;gt; - the code for the barricade entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;BoosterComponent&amp;lt;/code&amp;gt; - the booster component entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;BuildableComponent&amp;lt;/code&amp;gt; - code for the buildable entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;DeferredFreeingComponent&amp;lt;/code&amp;gt; - code for the deferred freeing component&lt;br /&gt;
***** &amp;lt;code&amp;gt;DrillComponent&amp;lt;/code&amp;gt; - code for the drill entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;EggComponent&amp;lt;/code&amp;gt; - code for the egg entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;HealthComponent&amp;lt;/code&amp;gt; - the health component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;HiveComponent&amp;lt;/code&amp;gt; - the hive component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;HumanBuildableComponent&amp;lt;/code&amp;gt; - the human buildable component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;HumanClassComponent&amp;lt;/code&amp;gt; - the human class component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;IgnitableComponent&amp;lt;/code&amp;gt; - the ignitable component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;KnockbackComponent&amp;lt;/code&amp;gt; - the knockback component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;LeechComponent&amp;lt;/code&amp;gt; - the leech component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;MainBuildableComponent&amp;lt;/code&amp;gt; - the main buildable component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;MedipadComponent&amp;lt;/code&amp;gt; - the medi pad component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;MGTurretComponent&amp;lt;/code&amp;gt; - the MG turret component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;MiningComponent&amp;lt;/code&amp;gt; - the mining component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;OvermindComponent&amp;lt;/code&amp;gt; - the overmind component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;ReactorComponent&amp;lt;/code&amp;gt; - the reactor component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;RocketpodComponent&amp;lt;/code&amp;gt; - the rocket pod component for a CBSE entity&lt;br /&gt;
**** &amp;lt;code&amp;gt;CBSE&amp;lt;/code&amp;gt; - the files containing the core entity declarations and definitions&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSE.h&amp;lt;/code&amp;gt; - connects a source files to the CBSE backend and provides all needed types to CBSE&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSEBackend&amp;lt;/code&amp;gt; - has the declaration of the base entity, implementation of the base components, and helper routines to access entities and components&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSEComponents.h&amp;lt;/code&amp;gt; - files with all game entity component headers&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSEEntities.h&amp;lt;/code&amp;gt; - specific entity declarations&lt;br /&gt;
**** &amp;lt;code&amp;gt;Assert&amp;lt;/code&amp;gt; - daemon engine specific assert code&lt;br /&gt;
**** &amp;lt;code&amp;gt;Clustering&amp;lt;/code&amp;gt; - has code related to the (literal) clustering of base buildables&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_active&amp;lt;/code&amp;gt; - process server-local game events and server-local client effects&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_client&amp;lt;/code&amp;gt; - server-local functions for a client&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_entities&amp;lt;/code&amp;gt; - server functions for server-local game entities&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_main&amp;lt;/code&amp;gt; - core server game functions&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_utils&amp;lt;/code&amp;gt; - misc utility functions for game module&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_team&amp;lt;/code&amp;gt; - function-procedures related to game teams&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_local&amp;lt;/code&amp;gt; - header file with more header inclusions&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_svcmds&amp;lt;/code&amp;gt; - this file holds commands that can be executed by the server console, but not remote clients&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_spawn&amp;lt;/code&amp;gt; - contains the declarations of the spawn functions for various game map entities&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_session&amp;lt;/code&amp;gt; - code for client session data&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_physics&amp;lt;/code&amp;gt; - game physics code&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_admin&amp;lt;/code&amp;gt; - server admin management code&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_namelog&amp;lt;/code&amp;gt; - record client names that connect to the server&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_api&amp;lt;/code&amp;gt; - contains the interface for the server game-logic module to handle messages received from the VM&lt;br /&gt;
**** &amp;lt;code&amp;gt;Entities&amp;lt;/code&amp;gt; - contains helper routines for CBSE entity components&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_public&amp;lt;/code&amp;gt; - definitions shared by both the server game and client game modules&lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_local&amp;lt;/code&amp;gt; - local definitions for the bg (both games) files &lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_gameplay&amp;lt;/code&amp;gt; - gameplay related macro constants and external variable linkage&lt;br /&gt;
**** &amp;lt;code&amp;gt;parse&amp;lt;/code&amp;gt; - parsing game script files&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The game-logic modules are themselves programs and have a main entrance function of &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function. This main function is the first function called in the program and begins the initialization process. The virtual machine starts game-logic module execution by creating a sub-process via the operating system with a call to the function ''CreateProcessW()'' (see daemon/src/engine/framework/VirtualMachine.cpp at line 152 inside the function ''InternalLoadModule'').&lt;br /&gt;
&lt;br /&gt;
The server game is not started until a map is loaded.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
'''Game Objects or Entities:'''&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
There are a number of CBSE (and so Unvanquished) entity related helper functions located in the file Unvanquished/src/sgame/Entities.h, and their implementation inside the cpp file.&lt;br /&gt;
&lt;br /&gt;
Client-local game entities are drawn as computer graphics on the player's screen, any client input related interactions with these entities are transmitted to the server as commands and the server processes these commands and invokes the gameplay code for the entity or entities.&lt;br /&gt;
&lt;br /&gt;
There is an absolute maximum number of entities of 1024 (see ''MAX_GENTITIES'' macro definition of daemon/src/engine/qcommon/qshared.h), if this maximum is reached then the server will terminate. All active game entities are listed inside a global array (''g_entities'', see sg_main.cpp), when a new entity is created the server searches this list for the next available free entity slot and initializes this slot, the server may  force an entity slot to be reallocated to a new entity though this may lead to problems according to a comment in the file sg_entities.cpp:&lt;br /&gt;
&lt;br /&gt;
''Try to avoid reusing an entity that was recently freed, because it can cause the client to think the entity morphed into something else instead of being removed and recreated, which can cause interpolated angles and bad trails.''&lt;br /&gt;
&lt;br /&gt;
Clients are game entities too and from 0 to (''MAX_CLIENTS'' - 1)(see daemon/src/engine/qcommon/q_shared.h) of the server global game entity array is reserved for client entities.&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
'''Gameplay:'''&lt;br /&gt;
Gameplay code is all the code that makes the entities do things and defines game rules and defines game events and defines game behaviors. There is a lot of code in this category and only a little some of the code will be used as an example.&lt;br /&gt;
Gameplay is server-local, meaning gameplay effects happens on the server. For example, the combat mechanics and behaviors of the game Unvanquished are defined in the file src/sgame/sg_combat.cpp. When a player dies the function ''G_PlayerDie'' is called and this function handles game events related to the death of a player, such as adding credit to a client's score and broadcasting a notification to the clients saying a player has died. Another example of gameplay code is the player movement code, contained inside of the file src/shared/bg_pmove.cpp. When a player moves their player character with their keyboard that input is transmitted to the server as a client command and the server calls the functions inside bg_pmove.cpp to apply the movement change to the player character game entity in the game level simulated by the game server, a client is changing the position and orientation of their associated player character entity on the server.&lt;br /&gt;
&lt;br /&gt;
'''Client-Local Game Logic:'''&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==sg_main.cpp==&lt;br /&gt;
The file src/sgame/sg_main.cpp deserves its own section since there are a lot of core server game functions and important variables inside this file.&lt;br /&gt;
&lt;br /&gt;
A special structure with server game level information is inside this file, the &amp;lt;code&amp;gt;level_locals_t level&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
sg_main contains the proxy console variables, the game-logic modules cannot access the console variables directly so they are accessed via a proxy interface.&lt;br /&gt;
&lt;br /&gt;
'''Some Important Server Functions:'''&lt;br /&gt;
*&amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function initializes the server game&lt;br /&gt;
*&amp;lt;code&amp;gt;G_SpawnClients&amp;lt;/code&amp;gt; - spawns the clients into the server game&lt;br /&gt;
*&amp;lt;code&amp;gt;G_RunFrame&amp;lt;/code&amp;gt; - executes the server game frame&lt;br /&gt;
*&amp;lt;code&amp;gt;G_RunThink&amp;lt;/code&amp;gt; - executes the thinking code of the server game entities&lt;br /&gt;
*&amp;lt;code&amp;gt;ExitLevel&amp;lt;/code&amp;gt; - changes the server game level after the intermission&lt;br /&gt;
&lt;br /&gt;
'''The Game Frame:'''&lt;br /&gt;
The game frame is a single moment or instant of the game. For the client, the game frame is a single render frame of the game. Gameplay and game objects are processed on a frame basis, the game is updated to the current frame and then presented to the player as an immediate moment in the game. This is the purpose of the function G_RunFrame, as in Game_RunFrame. This function does all '''''game updates''''' for console variables, for game entities, and entity events, and etc. See the function definition for G_RunFrame of sg_main.cpp for implementation details.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5106</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5106"/>
		<updated>2021-07-10T16:55:38Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Program Ignition and Initialization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
This Wiki page is incomplete and a work-in-progress, nonetheless there is still helpful information on this web page.&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code Tree and File Descriptions==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt; - game assets&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; - data submodule&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; - engine submodule&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; - engine source code&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_api&amp;lt;/code&amp;gt; - contains definitions for the VM to engine function-procedures&lt;br /&gt;
**** &amp;lt;code&amp;gt;CommonProxies&amp;lt;/code&amp;gt; - proxy interface to the VM, has trap calls for sending messages to the VM&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;Cvar&amp;lt;/code&amp;gt; - the proxy interface for console variables&lt;br /&gt;
**** &amp;lt;code&amp;gt;Debugger&amp;lt;/code&amp;gt; - contains a routine to detect if a debugger is attached to the process&lt;br /&gt;
**** &amp;lt;code&amp;gt;FileSystem&amp;lt;/code&amp;gt; - interface to use the host filesystem through the VM&lt;br /&gt;
**** &amp;lt;code&amp;gt;KeyIdentification&amp;lt;/code&amp;gt; - contains an association table (unordered map) that links a keyboard key value with a string descriptor&lt;br /&gt;
**** &amp;lt;code&amp;gt;LineEditData&amp;lt;/code&amp;gt; - ?&lt;br /&gt;
**** &amp;lt;code&amp;gt;Log&amp;lt;/code&amp;gt; - filesystem logging&lt;br /&gt;
**** &amp;lt;code&amp;gt;IPC/&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;Common&amp;lt;/code&amp;gt; - common definitions for all IPC methods&lt;br /&gt;
***** &amp;lt;code&amp;gt;Command&amp;lt;/code&amp;gt; - the inter-process communication command buffer&lt;br /&gt;
***** &amp;lt;code&amp;gt;Channel&amp;lt;/code&amp;gt; - contains the inter-process communication namespace and engine-VM messaging functions&lt;br /&gt;
***** &amp;lt;code&amp;gt;Primitives&amp;lt;/code&amp;gt; - routines for the IPC VM-engine socket&lt;br /&gt;
**** &amp;lt;code&amp;gt;CM/&amp;lt;/code&amp;gt; - related to game collisions and map loading&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_local&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_patch&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_polylib&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_public&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;Color&amp;lt;/code&amp;gt; - related to colors&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; - common code: utility functions, typedefs, macros, and the like&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_shared.h&amp;lt;/code&amp;gt; - included first by ALL program modules. A user mod should never modify this file.&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_shared.cpp&amp;lt;/code&amp;gt; - stateless support routines that are included in each code module&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_math&amp;lt;/code&amp;gt; - stateless support routines that are included in each code module, related to math operations&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_Unicode&amp;lt;/code&amp;gt; - Unicode &amp;amp; UTF-8 handling&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; - renderer&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; - OpenGL shader code&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; - the sources for the game-logic modules, both Client and Server&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; - client-local game-logic code&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; - server-local game-logic code&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt; - directory containing sources for bot AI&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_api&amp;lt;/code&amp;gt; - forward function declarations related to the bot artificial intelligence code&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_convert&amp;lt;/code&amp;gt; - procedures for the conversation&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_local&amp;lt;/code&amp;gt; - server-local variable definitions, struct definitions, and forward declarations for the bot AI&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_navdraw&amp;lt;/code&amp;gt; - code for drawing bot AI navmesh for debug purposes&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_types&amp;lt;/code&amp;gt; - code that defines data types for bot AI code&lt;br /&gt;
**** &amp;lt;code&amp;gt;Components/&amp;lt;/code&amp;gt; - directory containing the sources for the CBSE entity components&lt;br /&gt;
***** &amp;lt;code&amp;gt;AcidTubeComponent&amp;lt;/code&amp;gt; - code for Acid Tube entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;AlienBuildableComponent&amp;lt;/code&amp;gt; - code for alien buildable entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;AlienClassComponent&amp;lt;/code&amp;gt; - code for alien class entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;ArmourComponent&amp;lt;/code&amp;gt; - the armour entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;ArmouryComponent&amp;lt;/code&amp;gt; - the armory entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;BarricadeComponent&amp;lt;/code&amp;gt; - the code for the barricade entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;BoosterComponent&amp;lt;/code&amp;gt; - the booster component entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;BuildableComponent&amp;lt;/code&amp;gt; - code for the buildable entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;DeferredFreeingComponent&amp;lt;/code&amp;gt; - code for the deferred freeing component&lt;br /&gt;
***** &amp;lt;code&amp;gt;DrillComponent&amp;lt;/code&amp;gt; - code for the drill entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;EggComponent&amp;lt;/code&amp;gt; - code for the egg entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;HealthComponent&amp;lt;/code&amp;gt; - the health component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;HiveComponent&amp;lt;/code&amp;gt; - the hive component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;HumanBuildableComponent&amp;lt;/code&amp;gt; - the human buildable component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;HumanClassComponent&amp;lt;/code&amp;gt; - the human class component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;IgnitableComponent&amp;lt;/code&amp;gt; - the ignitable component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;KnockbackComponent&amp;lt;/code&amp;gt; - the knockback component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;LeechComponent&amp;lt;/code&amp;gt; - the leech component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;MainBuildableComponent&amp;lt;/code&amp;gt; - the main buildable component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;MedipadComponent&amp;lt;/code&amp;gt; - the medi pad component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;MGTurretComponent&amp;lt;/code&amp;gt; - the MG turret component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;MiningComponent&amp;lt;/code&amp;gt; - the mining component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;OvermindComponent&amp;lt;/code&amp;gt; - the overmind component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;ReactorComponent&amp;lt;/code&amp;gt; - the reactor component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;RocketpodComponent&amp;lt;/code&amp;gt; - the rocket pod component for a CBSE entity&lt;br /&gt;
**** &amp;lt;code&amp;gt;CBSE&amp;lt;/code&amp;gt; - the files containing the core entity declarations and definitions&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSE.h&amp;lt;/code&amp;gt; - connects a source files to the CBSE backend and provides all needed types to CBSE&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSEBackend&amp;lt;/code&amp;gt; - has the declaration of the base entity, implementation of the base components, and helper routines to access entities and components&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSEComponents.h&amp;lt;/code&amp;gt; - files with all game entity component headers&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSEEntities.h&amp;lt;/code&amp;gt; - specific entity declarations&lt;br /&gt;
**** &amp;lt;code&amp;gt;Assert&amp;lt;/code&amp;gt; - daemon engine specific assert code&lt;br /&gt;
**** &amp;lt;code&amp;gt;Clustering&amp;lt;/code&amp;gt; - has code related to the (literal) clustering of base buildables&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_active&amp;lt;/code&amp;gt; - process server-local game events and server-local client effects&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_client&amp;lt;/code&amp;gt; - server-local functions for a client&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_entities&amp;lt;/code&amp;gt; - server functions for server-local game entities&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_main&amp;lt;/code&amp;gt; - core server game functions&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_utils&amp;lt;/code&amp;gt; - misc utility functions for game module&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_team&amp;lt;/code&amp;gt; - function-procedures related to game teams&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_local&amp;lt;/code&amp;gt; - header file with more header inclusions&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_svcmds&amp;lt;/code&amp;gt; - this file holds commands that can be executed by the server console, but not remote clients&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_spawn&amp;lt;/code&amp;gt; - contains the declarations of the spawn functions for various game map entities&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_session&amp;lt;/code&amp;gt; - code for client session data&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_physics&amp;lt;/code&amp;gt; - game physics code&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_admin&amp;lt;/code&amp;gt; - server admin management code&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_namelog&amp;lt;/code&amp;gt; - record client names that connect to the server&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_api&amp;lt;/code&amp;gt; - contains the interface for the server game-logic module to handle messages received from the VM&lt;br /&gt;
**** &amp;lt;code&amp;gt;Entities&amp;lt;/code&amp;gt; - contains helper routines for CBSE entity components&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_public&amp;lt;/code&amp;gt; - definitions shared by both the server game and client game modules&lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_local&amp;lt;/code&amp;gt; - local definitions for the bg (both games) files &lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_gameplay&amp;lt;/code&amp;gt; - gameplay related macro constants and external variable linkage&lt;br /&gt;
**** &amp;lt;code&amp;gt;parse&amp;lt;/code&amp;gt; - parsing game script files&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The game-logic modules are themselves programs and have a main entrance function of &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function. This main function is the first function called in the program and begins the initialization process. The virtual machine starts game-logic module execution by creating a sub-process via the operating system with a call to the function ''CreateProcessW()'' (see daemon/src/engine/framework/VirtualMachine.cpp at line 152 inside the function ''InternalLoadModule'').&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
'''Game Objects or Entities:'''&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
There are a number of CBSE (and so Unvanquished) entity related helper functions located in the file Unvanquished/src/sgame/Entities.h, and their implementation inside the cpp file.&lt;br /&gt;
&lt;br /&gt;
Client-local game entities are drawn as computer graphics on the player's screen, any client input related interactions with these entities are transmitted to the server as commands and the server processes these commands and invokes the gameplay code for the entity or entities.&lt;br /&gt;
&lt;br /&gt;
There is an absolute maximum number of entities of 1024 (see ''MAX_GENTITIES'' macro definition of daemon/src/engine/qcommon/qshared.h), if this maximum is reached then the server will terminate. All active game entities are listed inside a global array (''g_entities'', see sg_main.cpp), when a new entity is created the server searches this list for the next available free entity slot and initializes this slot, the server may  force an entity slot to be reallocated to a new entity though this may lead to problems according to a comment in the file sg_entities.cpp:&lt;br /&gt;
&lt;br /&gt;
''Try to avoid reusing an entity that was recently freed, because it can cause the client to think the entity morphed into something else instead of being removed and recreated, which can cause interpolated angles and bad trails.''&lt;br /&gt;
&lt;br /&gt;
Clients are game entities too and from 0 to (''MAX_CLIENTS'' - 1)(see daemon/src/engine/qcommon/q_shared.h) of the server global game entity array is reserved for client entities.&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
'''Gameplay:'''&lt;br /&gt;
Gameplay code is all the code that makes the entities do things and defines game rules and defines game events and defines game behaviors. There is a lot of code in this category and only a little some of the code will be used as an example.&lt;br /&gt;
Gameplay is server-local, meaning gameplay effects happens on the server. For example, the combat mechanics and behaviors of the game Unvanquished are defined in the file src/sgame/sg_combat.cpp. When a player dies the function ''G_PlayerDie'' is called and this function handles game events related to the death of a player, such as adding credit to a client's score and broadcasting a notification to the clients saying a player has died. Another example of gameplay code is the player movement code, contained inside of the file src/shared/bg_pmove.cpp. When a player moves their player character with their keyboard that input is transmitted to the server as a client command and the server calls the functions inside bg_pmove.cpp to apply the movement change to the player character game entity in the game level simulated by the game server, a client is changing the position and orientation of their associated player character entity on the server.&lt;br /&gt;
&lt;br /&gt;
'''Client-Local Game Logic:'''&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==sg_main.cpp==&lt;br /&gt;
The file src/sgame/sg_main.cpp deserves its own section since there are a lot of core server game functions and important variables inside this file.&lt;br /&gt;
&lt;br /&gt;
A special structure with server game level information is inside this file, the &amp;lt;code&amp;gt;level_locals_t level&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
sg_main contains the proxy console variables, the game-logic modules cannot access the console variables directly so they are accessed via a proxy interface.&lt;br /&gt;
&lt;br /&gt;
'''Some Important Server Functions:'''&lt;br /&gt;
*&amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function initializes the server game&lt;br /&gt;
*&amp;lt;code&amp;gt;G_SpawnClients&amp;lt;/code&amp;gt; - spawns the clients into the server game&lt;br /&gt;
*&amp;lt;code&amp;gt;G_RunFrame&amp;lt;/code&amp;gt; - executes the server game frame&lt;br /&gt;
*&amp;lt;code&amp;gt;G_RunThink&amp;lt;/code&amp;gt; - executes the thinking code of the server game entities&lt;br /&gt;
*&amp;lt;code&amp;gt;ExitLevel&amp;lt;/code&amp;gt; - changes the server game level after the intermission&lt;br /&gt;
&lt;br /&gt;
'''The Game Frame:'''&lt;br /&gt;
The game frame is a single moment or instant of the game. For the client, the game frame is a single render frame of the game. Gameplay and game objects are processed on a frame basis, the game is updated to the current frame and then presented to the player as an immediate moment in the game. This is the purpose of the function G_RunFrame, as in Game_RunFrame. This function does all '''''game updates''''' for console variables, for game entities, and entity events, and etc. See the function definition for G_RunFrame of sg_main.cpp for implementation details.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5105</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5105"/>
		<updated>2021-07-09T05:22:17Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* sg_main.cpp */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
This Wiki page is incomplete and a work-in-progress, nonetheless there is still helpful information on this web page.&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code Tree and File Descriptions==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt; - game assets&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; - data submodule&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; - engine submodule&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; - engine source code&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_api&amp;lt;/code&amp;gt; - contains definitions for the VM to engine function-procedures&lt;br /&gt;
**** &amp;lt;code&amp;gt;CommonProxies&amp;lt;/code&amp;gt; - proxy interface to the VM, has trap calls for sending messages to the VM&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;Cvar&amp;lt;/code&amp;gt; - the proxy interface for console variables&lt;br /&gt;
**** &amp;lt;code&amp;gt;Debugger&amp;lt;/code&amp;gt; - contains a routine to detect if a debugger is attached to the process&lt;br /&gt;
**** &amp;lt;code&amp;gt;FileSystem&amp;lt;/code&amp;gt; - interface to use the host filesystem through the VM&lt;br /&gt;
**** &amp;lt;code&amp;gt;KeyIdentification&amp;lt;/code&amp;gt; - contains an association table (unordered map) that links a keyboard key value with a string descriptor&lt;br /&gt;
**** &amp;lt;code&amp;gt;LineEditData&amp;lt;/code&amp;gt; - ?&lt;br /&gt;
**** &amp;lt;code&amp;gt;Log&amp;lt;/code&amp;gt; - filesystem logging&lt;br /&gt;
**** &amp;lt;code&amp;gt;IPC/&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;Common&amp;lt;/code&amp;gt; - common definitions for all IPC methods&lt;br /&gt;
***** &amp;lt;code&amp;gt;Command&amp;lt;/code&amp;gt; - the inter-process communication command buffer&lt;br /&gt;
***** &amp;lt;code&amp;gt;Channel&amp;lt;/code&amp;gt; - contains the inter-process communication namespace and engine-VM messaging functions&lt;br /&gt;
***** &amp;lt;code&amp;gt;Primitives&amp;lt;/code&amp;gt; - routines for the IPC VM-engine socket&lt;br /&gt;
**** &amp;lt;code&amp;gt;CM/&amp;lt;/code&amp;gt; - related to game collisions and map loading&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_local&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_patch&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_polylib&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_public&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;Color&amp;lt;/code&amp;gt; - related to colors&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; - common code: utility functions, typedefs, macros, and the like&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_shared.h&amp;lt;/code&amp;gt; - included first by ALL program modules. A user mod should never modify this file.&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_shared.cpp&amp;lt;/code&amp;gt; - stateless support routines that are included in each code module&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_math&amp;lt;/code&amp;gt; - stateless support routines that are included in each code module, related to math operations&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_Unicode&amp;lt;/code&amp;gt; - Unicode &amp;amp; UTF-8 handling&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; - renderer&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; - OpenGL shader code&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; - the sources for the game-logic modules, both Client and Server&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; - client-local game-logic code&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; - server-local game-logic code&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt; - directory containing sources for bot AI&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_api&amp;lt;/code&amp;gt; - forward function declarations related to the bot artificial intelligence code&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_convert&amp;lt;/code&amp;gt; - procedures for the conversation&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_local&amp;lt;/code&amp;gt; - server-local variable definitions, struct definitions, and forward declarations for the bot AI&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_navdraw&amp;lt;/code&amp;gt; - code for drawing bot AI navmesh for debug purposes&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_types&amp;lt;/code&amp;gt; - code that defines data types for bot AI code&lt;br /&gt;
**** &amp;lt;code&amp;gt;Components/&amp;lt;/code&amp;gt; - directory containing the sources for the CBSE entity components&lt;br /&gt;
***** &amp;lt;code&amp;gt;AcidTubeComponent&amp;lt;/code&amp;gt; - code for Acid Tube entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;AlienBuildableComponent&amp;lt;/code&amp;gt; - code for alien buildable entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;AlienClassComponent&amp;lt;/code&amp;gt; - code for alien class entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;ArmourComponent&amp;lt;/code&amp;gt; - the armour entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;ArmouryComponent&amp;lt;/code&amp;gt; - the armory entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;BarricadeComponent&amp;lt;/code&amp;gt; - the code for the barricade entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;BoosterComponent&amp;lt;/code&amp;gt; - the booster component entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;BuildableComponent&amp;lt;/code&amp;gt; - code for the buildable entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;DeferredFreeingComponent&amp;lt;/code&amp;gt; - code for the deferred freeing component&lt;br /&gt;
***** &amp;lt;code&amp;gt;DrillComponent&amp;lt;/code&amp;gt; - code for the drill entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;EggComponent&amp;lt;/code&amp;gt; - code for the egg entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;HealthComponent&amp;lt;/code&amp;gt; - the health component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;HiveComponent&amp;lt;/code&amp;gt; - the hive component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;HumanBuildableComponent&amp;lt;/code&amp;gt; - the human buildable component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;HumanClassComponent&amp;lt;/code&amp;gt; - the human class component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;IgnitableComponent&amp;lt;/code&amp;gt; - the ignitable component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;KnockbackComponent&amp;lt;/code&amp;gt; - the knockback component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;LeechComponent&amp;lt;/code&amp;gt; - the leech component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;MainBuildableComponent&amp;lt;/code&amp;gt; - the main buildable component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;MedipadComponent&amp;lt;/code&amp;gt; - the medi pad component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;MGTurretComponent&amp;lt;/code&amp;gt; - the MG turret component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;MiningComponent&amp;lt;/code&amp;gt; - the mining component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;OvermindComponent&amp;lt;/code&amp;gt; - the overmind component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;ReactorComponent&amp;lt;/code&amp;gt; - the reactor component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;RocketpodComponent&amp;lt;/code&amp;gt; - the rocket pod component for a CBSE entity&lt;br /&gt;
**** &amp;lt;code&amp;gt;CBSE&amp;lt;/code&amp;gt; - the files containing the core entity declarations and definitions&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSE.h&amp;lt;/code&amp;gt; - connects a source files to the CBSE backend and provides all needed types to CBSE&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSEBackend&amp;lt;/code&amp;gt; - has the declaration of the base entity, implementation of the base components, and helper routines to access entities and components&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSEComponents.h&amp;lt;/code&amp;gt; - files with all game entity component headers&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSEEntities.h&amp;lt;/code&amp;gt; - specific entity declarations&lt;br /&gt;
**** &amp;lt;code&amp;gt;Assert&amp;lt;/code&amp;gt; - daemon engine specific assert code&lt;br /&gt;
**** &amp;lt;code&amp;gt;Clustering&amp;lt;/code&amp;gt; - has code related to the (literal) clustering of base buildables&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_active&amp;lt;/code&amp;gt; - process server-local game events and server-local client effects&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_client&amp;lt;/code&amp;gt; - server-local functions for a client&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_entities&amp;lt;/code&amp;gt; - server functions for server-local game entities&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_main&amp;lt;/code&amp;gt; - core server game functions&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_utils&amp;lt;/code&amp;gt; - misc utility functions for game module&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_team&amp;lt;/code&amp;gt; - function-procedures related to game teams&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_local&amp;lt;/code&amp;gt; - header file with more header inclusions&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_svcmds&amp;lt;/code&amp;gt; - this file holds commands that can be executed by the server console, but not remote clients&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_spawn&amp;lt;/code&amp;gt; - contains the declarations of the spawn functions for various game map entities&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_session&amp;lt;/code&amp;gt; - code for client session data&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_physics&amp;lt;/code&amp;gt; - game physics code&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_admin&amp;lt;/code&amp;gt; - server admin management code&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_namelog&amp;lt;/code&amp;gt; - record client names that connect to the server&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_api&amp;lt;/code&amp;gt; - contains the interface for the server game-logic module to handle messages received from the VM&lt;br /&gt;
**** &amp;lt;code&amp;gt;Entities&amp;lt;/code&amp;gt; - contains helper routines for CBSE entity components&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_public&amp;lt;/code&amp;gt; - definitions shared by both the server game and client game modules&lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_local&amp;lt;/code&amp;gt; - local definitions for the bg (both games) files &lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_gameplay&amp;lt;/code&amp;gt; - gameplay related macro constants and external variable linkage&lt;br /&gt;
**** &amp;lt;code&amp;gt;parse&amp;lt;/code&amp;gt; - parsing game script files&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
'''Game Objects or Entities:'''&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
There are a number of CBSE (and so Unvanquished) entity related helper functions located in the file Unvanquished/src/sgame/Entities.h, and their implementation inside the cpp file.&lt;br /&gt;
&lt;br /&gt;
Client-local game entities are drawn as computer graphics on the player's screen, any client input related interactions with these entities are transmitted to the server as commands and the server processes these commands and invokes the gameplay code for the entity or entities.&lt;br /&gt;
&lt;br /&gt;
There is an absolute maximum number of entities of 1024 (see ''MAX_GENTITIES'' macro definition of daemon/src/engine/qcommon/qshared.h), if this maximum is reached then the server will terminate. All active game entities are listed inside a global array (''g_entities'', see sg_main.cpp), when a new entity is created the server searches this list for the next available free entity slot and initializes this slot, the server may  force an entity slot to be reallocated to a new entity though this may lead to problems according to a comment in the file sg_entities.cpp:&lt;br /&gt;
&lt;br /&gt;
''Try to avoid reusing an entity that was recently freed, because it can cause the client to think the entity morphed into something else instead of being removed and recreated, which can cause interpolated angles and bad trails.''&lt;br /&gt;
&lt;br /&gt;
Clients are game entities too and from 0 to (''MAX_CLIENTS'' - 1)(see daemon/src/engine/qcommon/q_shared.h) of the server global game entity array is reserved for client entities.&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
'''Gameplay:'''&lt;br /&gt;
Gameplay code is all the code that makes the entities do things and defines game rules and defines game events and defines game behaviors. There is a lot of code in this category and only a little some of the code will be used as an example.&lt;br /&gt;
Gameplay is server-local, meaning gameplay effects happens on the server. For example, the combat mechanics and behaviors of the game Unvanquished are defined in the file src/sgame/sg_combat.cpp. When a player dies the function ''G_PlayerDie'' is called and this function handles game events related to the death of a player, such as adding credit to a client's score and broadcasting a notification to the clients saying a player has died. Another example of gameplay code is the player movement code, contained inside of the file src/shared/bg_pmove.cpp. When a player moves their player character with their keyboard that input is transmitted to the server as a client command and the server calls the functions inside bg_pmove.cpp to apply the movement change to the player character game entity in the game level simulated by the game server, a client is changing the position and orientation of their associated player character entity on the server.&lt;br /&gt;
&lt;br /&gt;
'''Client-Local Game Logic:'''&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==sg_main.cpp==&lt;br /&gt;
The file src/sgame/sg_main.cpp deserves its own section since there are a lot of core server game functions and important variables inside this file.&lt;br /&gt;
&lt;br /&gt;
A special structure with server game level information is inside this file, the &amp;lt;code&amp;gt;level_locals_t level&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
sg_main contains the proxy console variables, the game-logic modules cannot access the console variables directly so they are accessed via a proxy interface.&lt;br /&gt;
&lt;br /&gt;
'''Some Important Server Functions:'''&lt;br /&gt;
*&amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function initializes the server game&lt;br /&gt;
*&amp;lt;code&amp;gt;G_SpawnClients&amp;lt;/code&amp;gt; - spawns the clients into the server game&lt;br /&gt;
*&amp;lt;code&amp;gt;G_RunFrame&amp;lt;/code&amp;gt; - executes the server game frame&lt;br /&gt;
*&amp;lt;code&amp;gt;G_RunThink&amp;lt;/code&amp;gt; - executes the thinking code of the server game entities&lt;br /&gt;
*&amp;lt;code&amp;gt;ExitLevel&amp;lt;/code&amp;gt; - changes the server game level after the intermission&lt;br /&gt;
&lt;br /&gt;
'''The Game Frame:'''&lt;br /&gt;
The game frame is a single moment or instant of the game. For the client, the game frame is a single render frame of the game. Gameplay and game objects are processed on a frame basis, the game is updated to the current frame and then presented to the player as an immediate moment in the game. This is the purpose of the function G_RunFrame, as in Game_RunFrame. This function does all '''''game updates''''' for console variables, for game entities, and entity events, and etc. See the function definition for G_RunFrame of sg_main.cpp for implementation details.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5104</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5104"/>
		<updated>2021-07-09T05:09:58Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* sg_main.cpp */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
This Wiki page is incomplete and a work-in-progress, nonetheless there is still helpful information on this web page.&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code Tree and File Descriptions==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt; - game assets&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; - data submodule&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; - engine submodule&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; - engine source code&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_api&amp;lt;/code&amp;gt; - contains definitions for the VM to engine function-procedures&lt;br /&gt;
**** &amp;lt;code&amp;gt;CommonProxies&amp;lt;/code&amp;gt; - proxy interface to the VM, has trap calls for sending messages to the VM&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;Cvar&amp;lt;/code&amp;gt; - the proxy interface for console variables&lt;br /&gt;
**** &amp;lt;code&amp;gt;Debugger&amp;lt;/code&amp;gt; - contains a routine to detect if a debugger is attached to the process&lt;br /&gt;
**** &amp;lt;code&amp;gt;FileSystem&amp;lt;/code&amp;gt; - interface to use the host filesystem through the VM&lt;br /&gt;
**** &amp;lt;code&amp;gt;KeyIdentification&amp;lt;/code&amp;gt; - contains an association table (unordered map) that links a keyboard key value with a string descriptor&lt;br /&gt;
**** &amp;lt;code&amp;gt;LineEditData&amp;lt;/code&amp;gt; - ?&lt;br /&gt;
**** &amp;lt;code&amp;gt;Log&amp;lt;/code&amp;gt; - filesystem logging&lt;br /&gt;
**** &amp;lt;code&amp;gt;IPC/&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;Common&amp;lt;/code&amp;gt; - common definitions for all IPC methods&lt;br /&gt;
***** &amp;lt;code&amp;gt;Command&amp;lt;/code&amp;gt; - the inter-process communication command buffer&lt;br /&gt;
***** &amp;lt;code&amp;gt;Channel&amp;lt;/code&amp;gt; - contains the inter-process communication namespace and engine-VM messaging functions&lt;br /&gt;
***** &amp;lt;code&amp;gt;Primitives&amp;lt;/code&amp;gt; - routines for the IPC VM-engine socket&lt;br /&gt;
**** &amp;lt;code&amp;gt;CM/&amp;lt;/code&amp;gt; - related to game collisions and map loading&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_local&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_patch&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_polylib&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_public&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;Color&amp;lt;/code&amp;gt; - related to colors&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; - common code: utility functions, typedefs, macros, and the like&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_shared.h&amp;lt;/code&amp;gt; - included first by ALL program modules. A user mod should never modify this file.&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_shared.cpp&amp;lt;/code&amp;gt; - stateless support routines that are included in each code module&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_math&amp;lt;/code&amp;gt; - stateless support routines that are included in each code module, related to math operations&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_Unicode&amp;lt;/code&amp;gt; - Unicode &amp;amp; UTF-8 handling&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; - renderer&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; - OpenGL shader code&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; - the sources for the game-logic modules, both Client and Server&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; - client-local game-logic code&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; - server-local game-logic code&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt; - directory containing sources for bot AI&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_api&amp;lt;/code&amp;gt; - forward function declarations related to the bot artificial intelligence code&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_convert&amp;lt;/code&amp;gt; - procedures for the conversation&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_local&amp;lt;/code&amp;gt; - server-local variable definitions, struct definitions, and forward declarations for the bot AI&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_navdraw&amp;lt;/code&amp;gt; - code for drawing bot AI navmesh for debug purposes&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_types&amp;lt;/code&amp;gt; - code that defines data types for bot AI code&lt;br /&gt;
**** &amp;lt;code&amp;gt;Components/&amp;lt;/code&amp;gt; - directory containing the sources for the CBSE entity components&lt;br /&gt;
***** &amp;lt;code&amp;gt;AcidTubeComponent&amp;lt;/code&amp;gt; - code for Acid Tube entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;AlienBuildableComponent&amp;lt;/code&amp;gt; - code for alien buildable entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;AlienClassComponent&amp;lt;/code&amp;gt; - code for alien class entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;ArmourComponent&amp;lt;/code&amp;gt; - the armour entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;ArmouryComponent&amp;lt;/code&amp;gt; - the armory entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;BarricadeComponent&amp;lt;/code&amp;gt; - the code for the barricade entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;BoosterComponent&amp;lt;/code&amp;gt; - the booster component entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;BuildableComponent&amp;lt;/code&amp;gt; - code for the buildable entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;DeferredFreeingComponent&amp;lt;/code&amp;gt; - code for the deferred freeing component&lt;br /&gt;
***** &amp;lt;code&amp;gt;DrillComponent&amp;lt;/code&amp;gt; - code for the drill entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;EggComponent&amp;lt;/code&amp;gt; - code for the egg entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;HealthComponent&amp;lt;/code&amp;gt; - the health component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;HiveComponent&amp;lt;/code&amp;gt; - the hive component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;HumanBuildableComponent&amp;lt;/code&amp;gt; - the human buildable component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;HumanClassComponent&amp;lt;/code&amp;gt; - the human class component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;IgnitableComponent&amp;lt;/code&amp;gt; - the ignitable component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;KnockbackComponent&amp;lt;/code&amp;gt; - the knockback component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;LeechComponent&amp;lt;/code&amp;gt; - the leech component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;MainBuildableComponent&amp;lt;/code&amp;gt; - the main buildable component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;MedipadComponent&amp;lt;/code&amp;gt; - the medi pad component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;MGTurretComponent&amp;lt;/code&amp;gt; - the MG turret component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;MiningComponent&amp;lt;/code&amp;gt; - the mining component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;OvermindComponent&amp;lt;/code&amp;gt; - the overmind component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;ReactorComponent&amp;lt;/code&amp;gt; - the reactor component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;RocketpodComponent&amp;lt;/code&amp;gt; - the rocket pod component for a CBSE entity&lt;br /&gt;
**** &amp;lt;code&amp;gt;CBSE&amp;lt;/code&amp;gt; - the files containing the core entity declarations and definitions&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSE.h&amp;lt;/code&amp;gt; - connects a source files to the CBSE backend and provides all needed types to CBSE&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSEBackend&amp;lt;/code&amp;gt; - has the declaration of the base entity, implementation of the base components, and helper routines to access entities and components&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSEComponents.h&amp;lt;/code&amp;gt; - files with all game entity component headers&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSEEntities.h&amp;lt;/code&amp;gt; - specific entity declarations&lt;br /&gt;
**** &amp;lt;code&amp;gt;Assert&amp;lt;/code&amp;gt; - daemon engine specific assert code&lt;br /&gt;
**** &amp;lt;code&amp;gt;Clustering&amp;lt;/code&amp;gt; - has code related to the (literal) clustering of base buildables&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_active&amp;lt;/code&amp;gt; - process server-local game events and server-local client effects&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_client&amp;lt;/code&amp;gt; - server-local functions for a client&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_entities&amp;lt;/code&amp;gt; - server functions for server-local game entities&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_main&amp;lt;/code&amp;gt; - core server game functions&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_utils&amp;lt;/code&amp;gt; - misc utility functions for game module&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_team&amp;lt;/code&amp;gt; - function-procedures related to game teams&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_local&amp;lt;/code&amp;gt; - header file with more header inclusions&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_svcmds&amp;lt;/code&amp;gt; - this file holds commands that can be executed by the server console, but not remote clients&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_spawn&amp;lt;/code&amp;gt; - contains the declarations of the spawn functions for various game map entities&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_session&amp;lt;/code&amp;gt; - code for client session data&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_physics&amp;lt;/code&amp;gt; - game physics code&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_admin&amp;lt;/code&amp;gt; - server admin management code&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_namelog&amp;lt;/code&amp;gt; - record client names that connect to the server&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_api&amp;lt;/code&amp;gt; - contains the interface for the server game-logic module to handle messages received from the VM&lt;br /&gt;
**** &amp;lt;code&amp;gt;Entities&amp;lt;/code&amp;gt; - contains helper routines for CBSE entity components&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_public&amp;lt;/code&amp;gt; - definitions shared by both the server game and client game modules&lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_local&amp;lt;/code&amp;gt; - local definitions for the bg (both games) files &lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_gameplay&amp;lt;/code&amp;gt; - gameplay related macro constants and external variable linkage&lt;br /&gt;
**** &amp;lt;code&amp;gt;parse&amp;lt;/code&amp;gt; - parsing game script files&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
'''Game Objects or Entities:'''&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
There are a number of CBSE (and so Unvanquished) entity related helper functions located in the file Unvanquished/src/sgame/Entities.h, and their implementation inside the cpp file.&lt;br /&gt;
&lt;br /&gt;
Client-local game entities are drawn as computer graphics on the player's screen, any client input related interactions with these entities are transmitted to the server as commands and the server processes these commands and invokes the gameplay code for the entity or entities.&lt;br /&gt;
&lt;br /&gt;
There is an absolute maximum number of entities of 1024 (see ''MAX_GENTITIES'' macro definition of daemon/src/engine/qcommon/qshared.h), if this maximum is reached then the server will terminate. All active game entities are listed inside a global array (''g_entities'', see sg_main.cpp), when a new entity is created the server searches this list for the next available free entity slot and initializes this slot, the server may  force an entity slot to be reallocated to a new entity though this may lead to problems according to a comment in the file sg_entities.cpp:&lt;br /&gt;
&lt;br /&gt;
''Try to avoid reusing an entity that was recently freed, because it can cause the client to think the entity morphed into something else instead of being removed and recreated, which can cause interpolated angles and bad trails.''&lt;br /&gt;
&lt;br /&gt;
Clients are game entities too and from 0 to (''MAX_CLIENTS'' - 1)(see daemon/src/engine/qcommon/q_shared.h) of the server global game entity array is reserved for client entities.&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
'''Gameplay:'''&lt;br /&gt;
Gameplay code is all the code that makes the entities do things and defines game rules and defines game events and defines game behaviors. There is a lot of code in this category and only a little some of the code will be used as an example.&lt;br /&gt;
Gameplay is server-local, meaning gameplay effects happens on the server. For example, the combat mechanics and behaviors of the game Unvanquished are defined in the file src/sgame/sg_combat.cpp. When a player dies the function ''G_PlayerDie'' is called and this function handles game events related to the death of a player, such as adding credit to a client's score and broadcasting a notification to the clients saying a player has died. Another example of gameplay code is the player movement code, contained inside of the file src/shared/bg_pmove.cpp. When a player moves their player character with their keyboard that input is transmitted to the server as a client command and the server calls the functions inside bg_pmove.cpp to apply the movement change to the player character game entity in the game level simulated by the game server, a client is changing the position and orientation of their associated player character entity on the server.&lt;br /&gt;
&lt;br /&gt;
'''Client-Local Game Logic:'''&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==sg_main.cpp==&lt;br /&gt;
The file src/sgame/sg_main.cpp deserves its own section since there are a lot of core server game functions and important variables inside this file.&lt;br /&gt;
&lt;br /&gt;
A special structure with server game level information is inside this file, the &amp;lt;code&amp;gt;level_locals_t level&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
sg_main contains the proxy console variables, the game-logic modules cannot access the console variables directly so they are accessed via a proxy interface.&lt;br /&gt;
&lt;br /&gt;
'''Some Important Server Functions:'''&lt;br /&gt;
*&amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function initializes the server game&lt;br /&gt;
*&amp;lt;code&amp;gt;G_SpawnClients&amp;lt;/code&amp;gt; - spawns the clients into the server game&lt;br /&gt;
*&amp;lt;code&amp;gt;G_RunFrame&amp;lt;/code&amp;gt; - executes the server game frame&lt;br /&gt;
*&amp;lt;code&amp;gt;G_RunThink&amp;lt;/code&amp;gt; - executes the thinking code of the server game entities&lt;br /&gt;
*&amp;lt;code&amp;gt;ExitLevel&amp;lt;/code&amp;gt; - changes the server game level after the intermission&lt;br /&gt;
&lt;br /&gt;
'''The Game Frame:'''&lt;br /&gt;
The game frame is a single moment or instant of the game. For the client, the game frame is a single render frame of the game. Gameplay and game objects are processed on a frame basis, the game is updated to the current frame and then presented to the player as an immediate moment in the game. This is the purpose of the function G_RunFrame, as in Game_RunFrame. This function does all game updates for console variables, for game entities, and entity events, and etc. See the function definition for G_RunFrame of sg_main.cpp for implementation details.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5103</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5103"/>
		<updated>2021-07-08T17:12:50Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* sg_main.cpp */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
This Wiki page is incomplete and a work-in-progress, nonetheless there is still helpful information on this web page.&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code Tree and File Descriptions==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt; - game assets&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; - data submodule&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; - engine submodule&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; - engine source code&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_api&amp;lt;/code&amp;gt; - contains definitions for the VM to engine function-procedures&lt;br /&gt;
**** &amp;lt;code&amp;gt;CommonProxies&amp;lt;/code&amp;gt; - proxy interface to the VM, has trap calls for sending messages to the VM&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;Cvar&amp;lt;/code&amp;gt; - the proxy interface for console variables&lt;br /&gt;
**** &amp;lt;code&amp;gt;Debugger&amp;lt;/code&amp;gt; - contains a routine to detect if a debugger is attached to the process&lt;br /&gt;
**** &amp;lt;code&amp;gt;FileSystem&amp;lt;/code&amp;gt; - interface to use the host filesystem through the VM&lt;br /&gt;
**** &amp;lt;code&amp;gt;KeyIdentification&amp;lt;/code&amp;gt; - contains an association table (unordered map) that links a keyboard key value with a string descriptor&lt;br /&gt;
**** &amp;lt;code&amp;gt;LineEditData&amp;lt;/code&amp;gt; - ?&lt;br /&gt;
**** &amp;lt;code&amp;gt;Log&amp;lt;/code&amp;gt; - filesystem logging&lt;br /&gt;
**** &amp;lt;code&amp;gt;IPC/&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;Common&amp;lt;/code&amp;gt; - common definitions for all IPC methods&lt;br /&gt;
***** &amp;lt;code&amp;gt;Command&amp;lt;/code&amp;gt; - the inter-process communication command buffer&lt;br /&gt;
***** &amp;lt;code&amp;gt;Channel&amp;lt;/code&amp;gt; - contains the inter-process communication namespace and engine-VM messaging functions&lt;br /&gt;
***** &amp;lt;code&amp;gt;Primitives&amp;lt;/code&amp;gt; - routines for the IPC VM-engine socket&lt;br /&gt;
**** &amp;lt;code&amp;gt;CM/&amp;lt;/code&amp;gt; - related to game collisions and map loading&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_local&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_patch&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_polylib&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_public&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;Color&amp;lt;/code&amp;gt; - related to colors&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; - common code: utility functions, typedefs, macros, and the like&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_shared.h&amp;lt;/code&amp;gt; - included first by ALL program modules. A user mod should never modify this file.&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_shared.cpp&amp;lt;/code&amp;gt; - stateless support routines that are included in each code module&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_math&amp;lt;/code&amp;gt; - stateless support routines that are included in each code module, related to math operations&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_Unicode&amp;lt;/code&amp;gt; - Unicode &amp;amp; UTF-8 handling&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; - renderer&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; - OpenGL shader code&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; - the sources for the game-logic modules, both Client and Server&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; - client-local game-logic code&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; - server-local game-logic code&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt; - directory containing sources for bot AI&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_api&amp;lt;/code&amp;gt; - forward function declarations related to the bot artificial intelligence code&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_convert&amp;lt;/code&amp;gt; - procedures for the conversation&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_local&amp;lt;/code&amp;gt; - server-local variable definitions, struct definitions, and forward declarations for the bot AI&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_navdraw&amp;lt;/code&amp;gt; - code for drawing bot AI navmesh for debug purposes&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_types&amp;lt;/code&amp;gt; - code that defines data types for bot AI code&lt;br /&gt;
**** &amp;lt;code&amp;gt;Components/&amp;lt;/code&amp;gt; - directory containing the sources for the CBSE entity components&lt;br /&gt;
***** &amp;lt;code&amp;gt;AcidTubeComponent&amp;lt;/code&amp;gt; - code for Acid Tube entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;AlienBuildableComponent&amp;lt;/code&amp;gt; - code for alien buildable entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;AlienClassComponent&amp;lt;/code&amp;gt; - code for alien class entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;ArmourComponent&amp;lt;/code&amp;gt; - the armour entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;ArmouryComponent&amp;lt;/code&amp;gt; - the armory entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;BarricadeComponent&amp;lt;/code&amp;gt; - the code for the barricade entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;BoosterComponent&amp;lt;/code&amp;gt; - the booster component entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;BuildableComponent&amp;lt;/code&amp;gt; - code for the buildable entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;DeferredFreeingComponent&amp;lt;/code&amp;gt; - code for the deferred freeing component&lt;br /&gt;
***** &amp;lt;code&amp;gt;DrillComponent&amp;lt;/code&amp;gt; - code for the drill entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;EggComponent&amp;lt;/code&amp;gt; - code for the egg entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;HealthComponent&amp;lt;/code&amp;gt; - the health component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;HiveComponent&amp;lt;/code&amp;gt; - the hive component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;HumanBuildableComponent&amp;lt;/code&amp;gt; - the human buildable component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;HumanClassComponent&amp;lt;/code&amp;gt; - the human class component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;IgnitableComponent&amp;lt;/code&amp;gt; - the ignitable component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;KnockbackComponent&amp;lt;/code&amp;gt; - the knockback component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;LeechComponent&amp;lt;/code&amp;gt; - the leech component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;MainBuildableComponent&amp;lt;/code&amp;gt; - the main buildable component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;MedipadComponent&amp;lt;/code&amp;gt; - the medi pad component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;MGTurretComponent&amp;lt;/code&amp;gt; - the MG turret component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;MiningComponent&amp;lt;/code&amp;gt; - the mining component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;OvermindComponent&amp;lt;/code&amp;gt; - the overmind component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;ReactorComponent&amp;lt;/code&amp;gt; - the reactor component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;RocketpodComponent&amp;lt;/code&amp;gt; - the rocket pod component for a CBSE entity&lt;br /&gt;
**** &amp;lt;code&amp;gt;CBSE&amp;lt;/code&amp;gt; - the files containing the core entity declarations and definitions&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSE.h&amp;lt;/code&amp;gt; - connects a source files to the CBSE backend and provides all needed types to CBSE&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSEBackend&amp;lt;/code&amp;gt; - has the declaration of the base entity, implementation of the base components, and helper routines to access entities and components&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSEComponents.h&amp;lt;/code&amp;gt; - files with all game entity component headers&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSEEntities.h&amp;lt;/code&amp;gt; - specific entity declarations&lt;br /&gt;
**** &amp;lt;code&amp;gt;Assert&amp;lt;/code&amp;gt; - daemon engine specific assert code&lt;br /&gt;
**** &amp;lt;code&amp;gt;Clustering&amp;lt;/code&amp;gt; - has code related to the (literal) clustering of base buildables&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_active&amp;lt;/code&amp;gt; - process server-local game events and server-local client effects&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_client&amp;lt;/code&amp;gt; - server-local functions for a client&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_entities&amp;lt;/code&amp;gt; - server functions for server-local game entities&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_main&amp;lt;/code&amp;gt; - core server game functions&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_utils&amp;lt;/code&amp;gt; - misc utility functions for game module&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_team&amp;lt;/code&amp;gt; - function-procedures related to game teams&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_local&amp;lt;/code&amp;gt; - header file with more header inclusions&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_svcmds&amp;lt;/code&amp;gt; - this file holds commands that can be executed by the server console, but not remote clients&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_spawn&amp;lt;/code&amp;gt; - contains the declarations of the spawn functions for various game map entities&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_session&amp;lt;/code&amp;gt; - code for client session data&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_physics&amp;lt;/code&amp;gt; - game physics code&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_admin&amp;lt;/code&amp;gt; - server admin management code&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_namelog&amp;lt;/code&amp;gt; - record client names that connect to the server&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_api&amp;lt;/code&amp;gt; - contains the interface for the server game-logic module to handle messages received from the VM&lt;br /&gt;
**** &amp;lt;code&amp;gt;Entities&amp;lt;/code&amp;gt; - contains helper routines for CBSE entity components&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_public&amp;lt;/code&amp;gt; - definitions shared by both the server game and client game modules&lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_local&amp;lt;/code&amp;gt; - local definitions for the bg (both games) files &lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_gameplay&amp;lt;/code&amp;gt; - gameplay related macro constants and external variable linkage&lt;br /&gt;
**** &amp;lt;code&amp;gt;parse&amp;lt;/code&amp;gt; - parsing game script files&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
'''Game Objects or Entities:'''&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
There are a number of CBSE (and so Unvanquished) entity related helper functions located in the file Unvanquished/src/sgame/Entities.h, and their implementation inside the cpp file.&lt;br /&gt;
&lt;br /&gt;
Client-local game entities are drawn as computer graphics on the player's screen, any client input related interactions with these entities are transmitted to the server as commands and the server processes these commands and invokes the gameplay code for the entity or entities.&lt;br /&gt;
&lt;br /&gt;
There is an absolute maximum number of entities of 1024 (see ''MAX_GENTITIES'' macro definition of daemon/src/engine/qcommon/qshared.h), if this maximum is reached then the server will terminate. All active game entities are listed inside a global array (''g_entities'', see sg_main.cpp), when a new entity is created the server searches this list for the next available free entity slot and initializes this slot, the server may  force an entity slot to be reallocated to a new entity though this may lead to problems according to a comment in the file sg_entities.cpp:&lt;br /&gt;
&lt;br /&gt;
''Try to avoid reusing an entity that was recently freed, because it can cause the client to think the entity morphed into something else instead of being removed and recreated, which can cause interpolated angles and bad trails.''&lt;br /&gt;
&lt;br /&gt;
Clients are game entities too and from 0 to (''MAX_CLIENTS'' - 1)(see daemon/src/engine/qcommon/q_shared.h) of the server global game entity array is reserved for client entities.&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
'''Gameplay:'''&lt;br /&gt;
Gameplay code is all the code that makes the entities do things and defines game rules and defines game events and defines game behaviors. There is a lot of code in this category and only a little some of the code will be used as an example.&lt;br /&gt;
Gameplay is server-local, meaning gameplay effects happens on the server. For example, the combat mechanics and behaviors of the game Unvanquished are defined in the file src/sgame/sg_combat.cpp. When a player dies the function ''G_PlayerDie'' is called and this function handles game events related to the death of a player, such as adding credit to a client's score and broadcasting a notification to the clients saying a player has died. Another example of gameplay code is the player movement code, contained inside of the file src/shared/bg_pmove.cpp. When a player moves their player character with their keyboard that input is transmitted to the server as a client command and the server calls the functions inside bg_pmove.cpp to apply the movement change to the player character game entity in the game level simulated by the game server, a client is changing the position and orientation of their associated player character entity on the server.&lt;br /&gt;
&lt;br /&gt;
'''Client-Local Game Logic:'''&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==sg_main.cpp==&lt;br /&gt;
The file src/sgame/sg_main.cpp deserves its own section since there are a lot of core server game functions and important variables inside this file.&lt;br /&gt;
&lt;br /&gt;
A special structure with server game level information is inside this file, the &amp;lt;code&amp;gt;level_locals_t level&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
sg_main contains the proxy console variables, the game-logic modules cannot access the console variables directly so they are accessed via a proxy interface.&lt;br /&gt;
&lt;br /&gt;
'''Some Important Server Functions:'''&lt;br /&gt;
*&amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function initializes the server game&lt;br /&gt;
*&amp;lt;code&amp;gt;G_SpawnClients&amp;lt;/code&amp;gt; - spawns the clients into the server game&lt;br /&gt;
*&amp;lt;code&amp;gt;G_RunFrame&amp;lt;/code&amp;gt; - executes the server game frame&lt;br /&gt;
*&amp;lt;code&amp;gt;G_RunThink&amp;lt;/code&amp;gt; - executes the thinking code of the server game entities&lt;br /&gt;
*&amp;lt;code&amp;gt;ExitLevel&amp;lt;/code&amp;gt; - changes the server game level after the intermission&lt;br /&gt;
&lt;br /&gt;
'''The Game Frame:'''&lt;br /&gt;
The game frame is a moment or instant in the server game simulation, the current game state for all non-player entities, everything that happens is processed by the program frame by frame, the server updates the game state of all non-player entities in order. The function G_RunFrame advances all non-player objects in the game.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5102</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5102"/>
		<updated>2021-07-08T17:04:45Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Source Code Tree and File Descriptions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
This Wiki page is incomplete and a work-in-progress, nonetheless there is still helpful information on this web page.&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code Tree and File Descriptions==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt; - game assets&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; - data submodule&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; - engine submodule&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; - engine source code&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_api&amp;lt;/code&amp;gt; - contains definitions for the VM to engine function-procedures&lt;br /&gt;
**** &amp;lt;code&amp;gt;CommonProxies&amp;lt;/code&amp;gt; - proxy interface to the VM, has trap calls for sending messages to the VM&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;Cvar&amp;lt;/code&amp;gt; - the proxy interface for console variables&lt;br /&gt;
**** &amp;lt;code&amp;gt;Debugger&amp;lt;/code&amp;gt; - contains a routine to detect if a debugger is attached to the process&lt;br /&gt;
**** &amp;lt;code&amp;gt;FileSystem&amp;lt;/code&amp;gt; - interface to use the host filesystem through the VM&lt;br /&gt;
**** &amp;lt;code&amp;gt;KeyIdentification&amp;lt;/code&amp;gt; - contains an association table (unordered map) that links a keyboard key value with a string descriptor&lt;br /&gt;
**** &amp;lt;code&amp;gt;LineEditData&amp;lt;/code&amp;gt; - ?&lt;br /&gt;
**** &amp;lt;code&amp;gt;Log&amp;lt;/code&amp;gt; - filesystem logging&lt;br /&gt;
**** &amp;lt;code&amp;gt;IPC/&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;Common&amp;lt;/code&amp;gt; - common definitions for all IPC methods&lt;br /&gt;
***** &amp;lt;code&amp;gt;Command&amp;lt;/code&amp;gt; - the inter-process communication command buffer&lt;br /&gt;
***** &amp;lt;code&amp;gt;Channel&amp;lt;/code&amp;gt; - contains the inter-process communication namespace and engine-VM messaging functions&lt;br /&gt;
***** &amp;lt;code&amp;gt;Primitives&amp;lt;/code&amp;gt; - routines for the IPC VM-engine socket&lt;br /&gt;
**** &amp;lt;code&amp;gt;CM/&amp;lt;/code&amp;gt; - related to game collisions and map loading&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_local&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_patch&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_polylib&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_public&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;Color&amp;lt;/code&amp;gt; - related to colors&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; - common code: utility functions, typedefs, macros, and the like&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_shared.h&amp;lt;/code&amp;gt; - included first by ALL program modules. A user mod should never modify this file.&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_shared.cpp&amp;lt;/code&amp;gt; - stateless support routines that are included in each code module&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_math&amp;lt;/code&amp;gt; - stateless support routines that are included in each code module, related to math operations&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_Unicode&amp;lt;/code&amp;gt; - Unicode &amp;amp; UTF-8 handling&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; - renderer&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; - OpenGL shader code&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; - the sources for the game-logic modules, both Client and Server&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; - client-local game-logic code&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; - server-local game-logic code&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt; - directory containing sources for bot AI&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_api&amp;lt;/code&amp;gt; - forward function declarations related to the bot artificial intelligence code&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_convert&amp;lt;/code&amp;gt; - procedures for the conversation&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_local&amp;lt;/code&amp;gt; - server-local variable definitions, struct definitions, and forward declarations for the bot AI&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_navdraw&amp;lt;/code&amp;gt; - code for drawing bot AI navmesh for debug purposes&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_types&amp;lt;/code&amp;gt; - code that defines data types for bot AI code&lt;br /&gt;
**** &amp;lt;code&amp;gt;Components/&amp;lt;/code&amp;gt; - directory containing the sources for the CBSE entity components&lt;br /&gt;
***** &amp;lt;code&amp;gt;AcidTubeComponent&amp;lt;/code&amp;gt; - code for Acid Tube entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;AlienBuildableComponent&amp;lt;/code&amp;gt; - code for alien buildable entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;AlienClassComponent&amp;lt;/code&amp;gt; - code for alien class entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;ArmourComponent&amp;lt;/code&amp;gt; - the armour entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;ArmouryComponent&amp;lt;/code&amp;gt; - the armory entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;BarricadeComponent&amp;lt;/code&amp;gt; - the code for the barricade entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;BoosterComponent&amp;lt;/code&amp;gt; - the booster component entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;BuildableComponent&amp;lt;/code&amp;gt; - code for the buildable entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;DeferredFreeingComponent&amp;lt;/code&amp;gt; - code for the deferred freeing component&lt;br /&gt;
***** &amp;lt;code&amp;gt;DrillComponent&amp;lt;/code&amp;gt; - code for the drill entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;EggComponent&amp;lt;/code&amp;gt; - code for the egg entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;HealthComponent&amp;lt;/code&amp;gt; - the health component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;HiveComponent&amp;lt;/code&amp;gt; - the hive component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;HumanBuildableComponent&amp;lt;/code&amp;gt; - the human buildable component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;HumanClassComponent&amp;lt;/code&amp;gt; - the human class component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;IgnitableComponent&amp;lt;/code&amp;gt; - the ignitable component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;KnockbackComponent&amp;lt;/code&amp;gt; - the knockback component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;LeechComponent&amp;lt;/code&amp;gt; - the leech component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;MainBuildableComponent&amp;lt;/code&amp;gt; - the main buildable component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;MedipadComponent&amp;lt;/code&amp;gt; - the medi pad component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;MGTurretComponent&amp;lt;/code&amp;gt; - the MG turret component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;MiningComponent&amp;lt;/code&amp;gt; - the mining component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;OvermindComponent&amp;lt;/code&amp;gt; - the overmind component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;ReactorComponent&amp;lt;/code&amp;gt; - the reactor component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;RocketpodComponent&amp;lt;/code&amp;gt; - the rocket pod component for a CBSE entity&lt;br /&gt;
**** &amp;lt;code&amp;gt;CBSE&amp;lt;/code&amp;gt; - the files containing the core entity declarations and definitions&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSE.h&amp;lt;/code&amp;gt; - connects a source files to the CBSE backend and provides all needed types to CBSE&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSEBackend&amp;lt;/code&amp;gt; - has the declaration of the base entity, implementation of the base components, and helper routines to access entities and components&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSEComponents.h&amp;lt;/code&amp;gt; - files with all game entity component headers&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSEEntities.h&amp;lt;/code&amp;gt; - specific entity declarations&lt;br /&gt;
**** &amp;lt;code&amp;gt;Assert&amp;lt;/code&amp;gt; - daemon engine specific assert code&lt;br /&gt;
**** &amp;lt;code&amp;gt;Clustering&amp;lt;/code&amp;gt; - has code related to the (literal) clustering of base buildables&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_active&amp;lt;/code&amp;gt; - process server-local game events and server-local client effects&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_client&amp;lt;/code&amp;gt; - server-local functions for a client&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_entities&amp;lt;/code&amp;gt; - server functions for server-local game entities&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_main&amp;lt;/code&amp;gt; - core server game functions&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_utils&amp;lt;/code&amp;gt; - misc utility functions for game module&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_team&amp;lt;/code&amp;gt; - function-procedures related to game teams&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_local&amp;lt;/code&amp;gt; - header file with more header inclusions&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_svcmds&amp;lt;/code&amp;gt; - this file holds commands that can be executed by the server console, but not remote clients&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_spawn&amp;lt;/code&amp;gt; - contains the declarations of the spawn functions for various game map entities&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_session&amp;lt;/code&amp;gt; - code for client session data&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_physics&amp;lt;/code&amp;gt; - game physics code&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_admin&amp;lt;/code&amp;gt; - server admin management code&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_namelog&amp;lt;/code&amp;gt; - record client names that connect to the server&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_api&amp;lt;/code&amp;gt; - contains the interface for the server game-logic module to handle messages received from the VM&lt;br /&gt;
**** &amp;lt;code&amp;gt;Entities&amp;lt;/code&amp;gt; - contains helper routines for CBSE entity components&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_public&amp;lt;/code&amp;gt; - definitions shared by both the server game and client game modules&lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_local&amp;lt;/code&amp;gt; - local definitions for the bg (both games) files &lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_gameplay&amp;lt;/code&amp;gt; - gameplay related macro constants and external variable linkage&lt;br /&gt;
**** &amp;lt;code&amp;gt;parse&amp;lt;/code&amp;gt; - parsing game script files&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
'''Game Objects or Entities:'''&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
There are a number of CBSE (and so Unvanquished) entity related helper functions located in the file Unvanquished/src/sgame/Entities.h, and their implementation inside the cpp file.&lt;br /&gt;
&lt;br /&gt;
Client-local game entities are drawn as computer graphics on the player's screen, any client input related interactions with these entities are transmitted to the server as commands and the server processes these commands and invokes the gameplay code for the entity or entities.&lt;br /&gt;
&lt;br /&gt;
There is an absolute maximum number of entities of 1024 (see ''MAX_GENTITIES'' macro definition of daemon/src/engine/qcommon/qshared.h), if this maximum is reached then the server will terminate. All active game entities are listed inside a global array (''g_entities'', see sg_main.cpp), when a new entity is created the server searches this list for the next available free entity slot and initializes this slot, the server may  force an entity slot to be reallocated to a new entity though this may lead to problems according to a comment in the file sg_entities.cpp:&lt;br /&gt;
&lt;br /&gt;
''Try to avoid reusing an entity that was recently freed, because it can cause the client to think the entity morphed into something else instead of being removed and recreated, which can cause interpolated angles and bad trails.''&lt;br /&gt;
&lt;br /&gt;
Clients are game entities too and from 0 to (''MAX_CLIENTS'' - 1)(see daemon/src/engine/qcommon/q_shared.h) of the server global game entity array is reserved for client entities.&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
'''Gameplay:'''&lt;br /&gt;
Gameplay code is all the code that makes the entities do things and defines game rules and defines game events and defines game behaviors. There is a lot of code in this category and only a little some of the code will be used as an example.&lt;br /&gt;
Gameplay is server-local, meaning gameplay effects happens on the server. For example, the combat mechanics and behaviors of the game Unvanquished are defined in the file src/sgame/sg_combat.cpp. When a player dies the function ''G_PlayerDie'' is called and this function handles game events related to the death of a player, such as adding credit to a client's score and broadcasting a notification to the clients saying a player has died. Another example of gameplay code is the player movement code, contained inside of the file src/shared/bg_pmove.cpp. When a player moves their player character with their keyboard that input is transmitted to the server as a client command and the server calls the functions inside bg_pmove.cpp to apply the movement change to the player character game entity in the game level simulated by the game server, a client is changing the position and orientation of their associated player character entity on the server.&lt;br /&gt;
&lt;br /&gt;
'''Client-Local Game Logic:'''&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==sg_main.cpp==&lt;br /&gt;
The file src/sgame/sg_main.cpp deserves its own section since there are a lot of core server game functions and important variables inside this file.&lt;br /&gt;
&lt;br /&gt;
A special structure with server game level information is inside this file, the &amp;lt;code&amp;gt;level_locals_t level&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
sg_main contains the proxy console variables, the game-logic modules cannot access the console variables directly so they are accessed via a proxy interface.&lt;br /&gt;
&lt;br /&gt;
'''Some Important Server Functions:'''&lt;br /&gt;
*&amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function initializes the server game&lt;br /&gt;
*&amp;lt;code&amp;gt;G_SpawnClients&amp;lt;/code&amp;gt; - spawns the clients into the server game&lt;br /&gt;
*&amp;lt;code&amp;gt;G_RunFrame&amp;lt;/code&amp;gt; - executes the server game frame&lt;br /&gt;
*&amp;lt;code&amp;gt;G_RunThink&amp;lt;/code&amp;gt; - executes the thinking code of the server game entities&lt;br /&gt;
*&amp;lt;code&amp;gt;ExitLevel&amp;lt;/code&amp;gt; - changes the server game level after the intermission&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5101</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5101"/>
		<updated>2021-07-08T16:56:23Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Source Code Tree and File Descriptions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
This Wiki page is incomplete and a work-in-progress, nonetheless there is still helpful information on this web page.&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code Tree and File Descriptions==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt; - game assets&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; - data submodule&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; - engine submodule&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; - engine source code&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;CommonProxies&amp;lt;/code&amp;gt; - proxy interface to the VM, has trap calls for sending messages to the VM&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;Cvar&amp;lt;/code&amp;gt; - the proxy interface for console variables&lt;br /&gt;
**** &amp;lt;code&amp;gt;Debugger&amp;lt;/code&amp;gt; - contains a routine to detect if a debugger is attached to the process&lt;br /&gt;
**** &amp;lt;code&amp;gt;FileSystem&amp;lt;/code&amp;gt; - interface to use the host filesystem through the VM&lt;br /&gt;
**** &amp;lt;code&amp;gt;KeyIdentification&amp;lt;/code&amp;gt; - contains an association table (unordered map) that links a keyboard key value with a string descriptor&lt;br /&gt;
**** &amp;lt;code&amp;gt;LineEditData&amp;lt;/code&amp;gt; - ?&lt;br /&gt;
**** &amp;lt;code&amp;gt;Log&amp;lt;/code&amp;gt; - filesystem logging&lt;br /&gt;
**** &amp;lt;code&amp;gt;IPC/&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;Common&amp;lt;/code&amp;gt; - common definitions for all IPC methods&lt;br /&gt;
***** &amp;lt;code&amp;gt;Command&amp;lt;/code&amp;gt; - the inter-process communication command buffer&lt;br /&gt;
***** &amp;lt;code&amp;gt;Channel&amp;lt;/code&amp;gt; - contains the inter-process communication namespace and engine-VM messaging functions&lt;br /&gt;
***** &amp;lt;code&amp;gt;Primitives&amp;lt;/code&amp;gt; - routines for the IPC VM-engine socket&lt;br /&gt;
**** &amp;lt;code&amp;gt;CM&amp;lt;/code&amp;gt; - related to game collisions and map loading&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_local&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_patch&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_polylib&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_public&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;Color&amp;lt;/code&amp;gt; - related to colors&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; - common code: utility functions, typedefs, macros, and the like&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_shared.h&amp;lt;/code&amp;gt; - included first by ALL program modules. A user mod should never modify this file.&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_shared.cpp&amp;lt;/code&amp;gt; - stateless support routines that are included in each code module&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_math&amp;lt;/code&amp;gt; - stateless support routines that are included in each code module, related to math operations&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_Unicode&amp;lt;/code&amp;gt; - Unicode &amp;amp; UTF-8 handling&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; - renderer&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; - OpenGL shader code&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; - the sources for the game-logic modules, both Client and Server&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; - client-local game-logic code&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; - server-local game-logic code&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt; - directory containing sources for bot AI&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_api&amp;lt;/code&amp;gt; - forward function declarations related to the bot artificial intelligence code&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_convert&amp;lt;/code&amp;gt; - procedures for the conversation&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_local&amp;lt;/code&amp;gt; - server-local variable definitions, struct definitions, and forward declarations for the bot AI&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_navdraw&amp;lt;/code&amp;gt; - code for drawing bot AI navmesh for debug purposes&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_types&amp;lt;/code&amp;gt; - code that defines data types for bot AI code&lt;br /&gt;
**** &amp;lt;code&amp;gt;Components/&amp;lt;/code&amp;gt; - directory containing the sources for the CBSE entity components&lt;br /&gt;
***** &amp;lt;code&amp;gt;AcidTubeComponent&amp;lt;/code&amp;gt; - code for Acid Tube entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;AlienBuildableComponent&amp;lt;/code&amp;gt; - code for alien buildable entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;AlienClassComponent&amp;lt;/code&amp;gt; - code for alien class entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;ArmourComponent&amp;lt;/code&amp;gt; - the armour entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;ArmouryComponent&amp;lt;/code&amp;gt; - the armory entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;BarricadeComponent&amp;lt;/code&amp;gt; - the code for the barricade entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;BoosterComponent&amp;lt;/code&amp;gt; - the booster component entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;BuildableComponent&amp;lt;/code&amp;gt; - code for the buildable entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;DeferredFreeingComponent&amp;lt;/code&amp;gt; - code for the deferred freeing component&lt;br /&gt;
***** &amp;lt;code&amp;gt;DrillComponent&amp;lt;/code&amp;gt; - code for the drill entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;EggComponent&amp;lt;/code&amp;gt; - code for the egg entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;HealthComponent&amp;lt;/code&amp;gt; - the health component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;HiveComponent&amp;lt;/code&amp;gt; - the hive component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;HumanBuildableComponent&amp;lt;/code&amp;gt; - the human buildable component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;HumanClassComponent&amp;lt;/code&amp;gt; - the human class component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;IgnitableComponent&amp;lt;/code&amp;gt; - the ignitable component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;KnockbackComponent&amp;lt;/code&amp;gt; - the knockback component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;LeechComponent&amp;lt;/code&amp;gt; - the leech component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;MainBuildableComponent&amp;lt;/code&amp;gt; - the main buildable component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;MedipadComponent&amp;lt;/code&amp;gt; - the medi pad component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;MGTurretComponent&amp;lt;/code&amp;gt; - the MG turret component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;MiningComponent&amp;lt;/code&amp;gt; - the mining component for a CBSE entity&lt;br /&gt;
***** &amp;lt;code&amp;gt;OvermindComponent&amp;lt;/code&amp;gt; - the overmind component for a CBSE entity&lt;br /&gt;
**** &amp;lt;code&amp;gt;CBSE&amp;lt;/code&amp;gt; - the files containing the core entity declarations and definitions&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSE.h&amp;lt;/code&amp;gt; - connects a source files to the CBSE backend and provides all needed types to CBSE&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSEBackend&amp;lt;/code&amp;gt; - has the declaration of the base entity, implementation of the base components, and helper routines to access entities and components&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSEComponents.h&amp;lt;/code&amp;gt; - files with all game entity component headers&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSEEntities.h&amp;lt;/code&amp;gt; - specific entity declarations&lt;br /&gt;
**** &amp;lt;code&amp;gt;Assert&amp;lt;/code&amp;gt; - daemon engine specific assert code&lt;br /&gt;
**** &amp;lt;code&amp;gt;Clustering&amp;lt;/code&amp;gt; - has code related to the (literal) clustering of base buildables&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_active&amp;lt;/code&amp;gt; - process server-local game events and server-local client effects&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_client&amp;lt;/code&amp;gt; - server-local functions for a client&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_entities&amp;lt;/code&amp;gt; - server functions for server-local game entities&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_main&amp;lt;/code&amp;gt; - core server game functions&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_utils&amp;lt;/code&amp;gt; - misc utility functions for game module&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_team&amp;lt;/code&amp;gt; - function-procedures related to game teams&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_local&amp;lt;/code&amp;gt; - header file with more header inclusions&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_svcmds&amp;lt;/code&amp;gt; - this file holds commands that can be executed by the server console, but not remote clients&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_spawn&amp;lt;/code&amp;gt; - contains the declarations of the spawn functions for various game map entities&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_session&amp;lt;/code&amp;gt; - code for client session data&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_physics&amp;lt;/code&amp;gt; - game physics code&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_admin&amp;lt;/code&amp;gt; - server admin management code&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_namelog&amp;lt;/code&amp;gt; - record client names that connect to the server&lt;br /&gt;
**** &amp;lt;code&amp;gt;Entities&amp;lt;/code&amp;gt; - contains helper routines for CBSE entity components&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_public&amp;lt;/code&amp;gt; - definitions shared by both the server game and client game modules&lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_local&amp;lt;/code&amp;gt; - local definitions for the bg (both games) files &lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_gameplay&amp;lt;/code&amp;gt; - gameplay related macro constants and external variable linkage&lt;br /&gt;
**** &amp;lt;code&amp;gt;parse&amp;lt;/code&amp;gt; - parsing game script files&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
'''Game Objects or Entities:'''&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
There are a number of CBSE (and so Unvanquished) entity related helper functions located in the file Unvanquished/src/sgame/Entities.h, and their implementation inside the cpp file.&lt;br /&gt;
&lt;br /&gt;
Client-local game entities are drawn as computer graphics on the player's screen, any client input related interactions with these entities are transmitted to the server as commands and the server processes these commands and invokes the gameplay code for the entity or entities.&lt;br /&gt;
&lt;br /&gt;
There is an absolute maximum number of entities of 1024 (see ''MAX_GENTITIES'' macro definition of daemon/src/engine/qcommon/qshared.h), if this maximum is reached then the server will terminate. All active game entities are listed inside a global array (''g_entities'', see sg_main.cpp), when a new entity is created the server searches this list for the next available free entity slot and initializes this slot, the server may  force an entity slot to be reallocated to a new entity though this may lead to problems according to a comment in the file sg_entities.cpp:&lt;br /&gt;
&lt;br /&gt;
''Try to avoid reusing an entity that was recently freed, because it can cause the client to think the entity morphed into something else instead of being removed and recreated, which can cause interpolated angles and bad trails.''&lt;br /&gt;
&lt;br /&gt;
Clients are game entities too and from 0 to (''MAX_CLIENTS'' - 1)(see daemon/src/engine/qcommon/q_shared.h) of the server global game entity array is reserved for client entities.&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
'''Gameplay:'''&lt;br /&gt;
Gameplay code is all the code that makes the entities do things and defines game rules and defines game events and defines game behaviors. There is a lot of code in this category and only a little some of the code will be used as an example.&lt;br /&gt;
Gameplay is server-local, meaning gameplay effects happens on the server. For example, the combat mechanics and behaviors of the game Unvanquished are defined in the file src/sgame/sg_combat.cpp. When a player dies the function ''G_PlayerDie'' is called and this function handles game events related to the death of a player, such as adding credit to a client's score and broadcasting a notification to the clients saying a player has died. Another example of gameplay code is the player movement code, contained inside of the file src/shared/bg_pmove.cpp. When a player moves their player character with their keyboard that input is transmitted to the server as a client command and the server calls the functions inside bg_pmove.cpp to apply the movement change to the player character game entity in the game level simulated by the game server, a client is changing the position and orientation of their associated player character entity on the server.&lt;br /&gt;
&lt;br /&gt;
'''Client-Local Game Logic:'''&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==sg_main.cpp==&lt;br /&gt;
The file src/sgame/sg_main.cpp deserves its own section since there are a lot of core server game functions and important variables inside this file.&lt;br /&gt;
&lt;br /&gt;
A special structure with server game level information is inside this file, the &amp;lt;code&amp;gt;level_locals_t level&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
sg_main contains the proxy console variables, the game-logic modules cannot access the console variables directly so they are accessed via a proxy interface.&lt;br /&gt;
&lt;br /&gt;
'''Some Important Server Functions:'''&lt;br /&gt;
*&amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function initializes the server game&lt;br /&gt;
*&amp;lt;code&amp;gt;G_SpawnClients&amp;lt;/code&amp;gt; - spawns the clients into the server game&lt;br /&gt;
*&amp;lt;code&amp;gt;G_RunFrame&amp;lt;/code&amp;gt; - executes the server game frame&lt;br /&gt;
*&amp;lt;code&amp;gt;G_RunThink&amp;lt;/code&amp;gt; - executes the thinking code of the server game entities&lt;br /&gt;
*&amp;lt;code&amp;gt;ExitLevel&amp;lt;/code&amp;gt; - changes the server game level after the intermission&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5100</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5100"/>
		<updated>2021-07-08T05:49:21Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Source Code Tree and File Descriptions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
This Wiki page is incomplete and a work-in-progress, nonetheless there is still helpful information on this web page.&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code Tree and File Descriptions==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt; - game assets&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; - data submodule&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; - engine submodule&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; - engine source code&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;IPC/&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;Common&amp;lt;/code&amp;gt; - common definitions for all IPC methods&lt;br /&gt;
***** &amp;lt;code&amp;gt;Command&amp;lt;/code&amp;gt; - the inter-process communication command buffer&lt;br /&gt;
***** &amp;lt;code&amp;gt;Channel&amp;lt;/code&amp;gt; - contains the inter-process communication namespace and engine-VM messaging functions&lt;br /&gt;
**** &amp;lt;code&amp;gt;CM&amp;lt;/code&amp;gt; - related to game collisions and map loading&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_local&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_patch&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_polylib&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;cm_public&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;Color&amp;lt;/code&amp;gt; - related to colors&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; - common code: utility functions, typedefs, macros, and the like&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_shared.h&amp;lt;/code&amp;gt; - included first by ALL program modules. A user mod should never modify this file.&lt;br /&gt;
*****&amp;lt;code&amp;gt;q_shared.cpp&amp;lt;/code&amp;gt; - stateless support routines that are included in each code module&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; - renderer&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; - OpenGL shader code&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; - code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; - client-local game-logic code&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; - server-local game-logic code&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_api&amp;lt;/code&amp;gt; - forward function declarations related to the bot artificial intelligence code&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_convert&amp;lt;/code&amp;gt; - procedures for the conversation&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_local&amp;lt;/code&amp;gt; - server-local variable definitions, struct definitions, and forward declarations for the bot AI&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_navdraw&amp;lt;/code&amp;gt; - code for drawing bot AI navmesh for debug purposes&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_types&amp;lt;/code&amp;gt; - code that defines data types for bot AI code&lt;br /&gt;
**** &amp;lt;code&amp;gt;Components/&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;AcidTubeComponent&amp;lt;/code&amp;gt; - code for Acid Tube entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;AlienBuildableComponent&amp;lt;/code&amp;gt; - code for alien buildable entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;AlienClassComponent&amp;lt;/code&amp;gt; - code for alien class entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;ArmourComponent&amp;lt;/code&amp;gt; - the armour entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;ArmouryComponent&amp;lt;/code&amp;gt; - the armory entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;BarricadeComponent&amp;lt;/code&amp;gt; - the code for the barricade entity component&lt;br /&gt;
***** &amp;lt;code&amp;gt;BoosterComponent&amp;lt;/code&amp;gt; - the booster component entity component class&lt;br /&gt;
***** &amp;lt;code&amp;gt;BuildableComponent&amp;lt;/code&amp;gt; - code for the buildable entity component class&lt;br /&gt;
**** &amp;lt;code&amp;gt;CBSE&amp;lt;/code&amp;gt; - the files containing the basic entity code for Unvanquished and&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSE.h&amp;lt;/code&amp;gt; - connects a source files to the CBSE backend and provides all needed types to CBSE&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSEBackend&amp;lt;/code&amp;gt; - has the declaration of the base entity, implementation of the base components, and helper routines to access entities and components&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSEComponents.h&amp;lt;/code&amp;gt; - files with all game entity component headers&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSEEntities.h&amp;lt;/code&amp;gt; - specific entity declarations&lt;br /&gt;
**** &amp;lt;code&amp;gt;Assert&amp;lt;/code&amp;gt; - daemon engine specific assert code&lt;br /&gt;
**** &amp;lt;code&amp;gt;Clustering&amp;lt;/code&amp;gt; - has code related to the (literal) clustering of base buildables&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_active&amp;lt;/code&amp;gt; - process server-local game events and server-local client effects&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_client&amp;lt;/code&amp;gt; - server-local functions for a client&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_entities&amp;lt;/code&amp;gt; - server functions for server-local game entities&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_main&amp;lt;/code&amp;gt; - core server game functions&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_utils&amp;lt;/code&amp;gt; - misc utility functions for game module&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_team&amp;lt;/code&amp;gt; - function-procedures related to game teams&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_local&amp;lt;/code&amp;gt; - header file with more header inclusions&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_svcmds&amp;lt;/code&amp;gt; - this file holds commands that can be executed by the server console, but not remote clients&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_spawn&amp;lt;/code&amp;gt; - contains the declarations of the spawn functions for various game map entities&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_session&amp;lt;/code&amp;gt; - code for client session data&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_physics&amp;lt;/code&amp;gt; - game physics code&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_admin&amp;lt;/code&amp;gt; - server admin management code&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_namelog&amp;lt;/code&amp;gt; - record client names that connect to the server&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_public&amp;lt;/code&amp;gt; - definitions shared by both the server game and client game modules&lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_local&amp;lt;/code&amp;gt; - local definitions for the bg (both games) files &lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_gameplay&amp;lt;/code&amp;gt; - gameplay related macro constants and external variable linkage &lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
'''Game Objects or Entities:'''&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
There are a number of CBSE (and so Unvanquished) entity related helper functions located in the file Unvanquished/src/sgame/Entities.h, and their implementation inside the cpp file.&lt;br /&gt;
&lt;br /&gt;
Client-local game entities are drawn as computer graphics on the player's screen, any client input related interactions with these entities are transmitted to the server as commands and the server processes these commands and invokes the gameplay code for the entity or entities.&lt;br /&gt;
&lt;br /&gt;
There is an absolute maximum number of entities of 1024 (see ''MAX_GENTITIES'' macro definition of daemon/src/engine/qcommon/qshared.h), if this maximum is reached then the server will terminate. All active game entities are listed inside a global array (''g_entities'', see sg_main.cpp), when a new entity is created the server searches this list for the next available free entity slot and initializes this slot, the server may  force an entity slot to be reallocated to a new entity though this may lead to problems according to a comment in the file sg_entities.cpp:&lt;br /&gt;
&lt;br /&gt;
''Try to avoid reusing an entity that was recently freed, because it can cause the client to think the entity morphed into something else instead of being removed and recreated, which can cause interpolated angles and bad trails.''&lt;br /&gt;
&lt;br /&gt;
Clients are game entities too and from 0 to (''MAX_CLIENTS'' - 1)(see daemon/src/engine/qcommon/q_shared.h) of the server global game entity array is reserved for client entities.&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
'''Gameplay:'''&lt;br /&gt;
Gameplay code is all the code that makes the entities do things and defines game rules and defines game events and defines game behaviors. There is a lot of code in this category and only a little some of the code will be used as an example.&lt;br /&gt;
Gameplay is server-local, meaning gameplay effects happens on the server. For example, the combat mechanics and behaviors of the game Unvanquished are defined in the file src/sgame/sg_combat.cpp. When a player dies the function ''G_PlayerDie'' is called and this function handles game events related to the death of a player, such as adding credit to a client's score and broadcasting a notification to the clients saying a player has died. Another example of gameplay code is the player movement code, contained inside of the file src/shared/bg_pmove.cpp. When a player moves their player character with their keyboard that input is transmitted to the server as a client command and the server calls the functions inside bg_pmove.cpp to apply the movement change to the player character game entity in the game level simulated by the game server, a client is changing the position and orientation of their associated player character entity on the server.&lt;br /&gt;
&lt;br /&gt;
'''Client-Local Game Logic:'''&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==sg_main.cpp==&lt;br /&gt;
The file src/sgame/sg_main.cpp deserves its own section since there are a lot of core server game functions and important variables inside this file.&lt;br /&gt;
&lt;br /&gt;
A special structure with server game level information is inside this file, the &amp;lt;code&amp;gt;level_locals_t level&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
sg_main contains the proxy console variables, the game-logic modules cannot access the console variables directly so they are accessed via a proxy interface.&lt;br /&gt;
&lt;br /&gt;
'''Some Important Server Functions:'''&lt;br /&gt;
*&amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function initializes the server game&lt;br /&gt;
*&amp;lt;code&amp;gt;G_SpawnClients&amp;lt;/code&amp;gt; - spawns the clients into the server game&lt;br /&gt;
*&amp;lt;code&amp;gt;G_RunFrame&amp;lt;/code&amp;gt; - executes the server game frame&lt;br /&gt;
*&amp;lt;code&amp;gt;G_RunThink&amp;lt;/code&amp;gt; - executes the thinking code of the server game entities&lt;br /&gt;
*&amp;lt;code&amp;gt;ExitLevel&amp;lt;/code&amp;gt; - changes the server game level after the intermission&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5099</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5099"/>
		<updated>2021-07-08T05:06:25Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Source Code Tree and File Descriptions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
This Wiki page is incomplete and a work-in-progress, nonetheless there is still helpful information on this web page.&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code Tree and File Descriptions==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt; - game assets&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; - data submodule&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; - engine submodule&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; - engine source code&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; - common code: utility functions, typedefs, macros, and the like&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_shared.h&amp;lt;/code&amp;gt; - included first by ALL program modules. A user mod should never modify this file.&lt;br /&gt;
*****&amp;lt;code&amp;gt;q_shared.cpp&amp;lt;/code&amp;gt; - stateless support routines that are included in each code module&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; - renderer&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; - OpenGL shader code&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; - code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; - client-local game-logic code&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; - server-local game-logic code&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_api&amp;lt;/code&amp;gt; - forward function declarations related to the bot artificial intelligence code&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_convert&amp;lt;/code&amp;gt; - procedures for the conversation&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_local&amp;lt;/code&amp;gt; - server-local variable definitions, struct definitions, and forward declarations for the bot AI&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_navdraw&amp;lt;/code&amp;gt; - code for drawing bot AI navmesh for debug purposes&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_types&amp;lt;/code&amp;gt; - code that defines data types for bot AI code&lt;br /&gt;
**** &amp;lt;code&amp;gt;AcidTubeComponent&amp;lt;/code&amp;gt; - code for Acid Tube entity component&lt;br /&gt;
**** &amp;lt;code&amp;gt;AlienBuildableComponent&amp;lt;/code&amp;gt; - code for alien buildable entity component&lt;br /&gt;
**** &amp;lt;code&amp;gt;AlienClassComponent&amp;lt;/code&amp;gt; - code for alien class entity component&lt;br /&gt;
**** &amp;lt;code&amp;gt;ArmourComponent&amp;lt;/code&amp;gt; - the armour entity component class&lt;br /&gt;
**** &amp;lt;code&amp;gt;ArmouryComponent&amp;lt;/code&amp;gt; - the armory entity component class&lt;br /&gt;
**** &amp;lt;code&amp;gt;Assert&amp;lt;/code&amp;gt; - daemon engine specific assert code&lt;br /&gt;
**** &amp;lt;code&amp;gt;BarricadeComponent&amp;lt;/code&amp;gt; - the code for the barricade entity component&lt;br /&gt;
**** &amp;lt;code&amp;gt;BoosterComponent&amp;lt;/code&amp;gt; - the booster component entity component class&lt;br /&gt;
**** &amp;lt;code&amp;gt;BuildableComponent&amp;lt;/code&amp;gt; - code for the buildable entity component class&lt;br /&gt;
**** &amp;lt;code&amp;gt;CBSE&amp;lt;/code&amp;gt; - the files containing the basic entity code for Unvanquished and&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSE.h&amp;lt;/code&amp;gt; - connects a source files to the CBSE backend and provides all needed types to CBSE&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSEBackend&amp;lt;/code&amp;gt; - has the declaration of the base entity, implementation of the base components, and helper routines to access entities and components&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSEComponents.h&amp;lt;/code&amp;gt; - files with all game entity component headers&lt;br /&gt;
***** &amp;lt;code&amp;gt;CBSEEntities.h&amp;lt;/code&amp;gt; - specific entity declarations&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_active&amp;lt;/code&amp;gt; - process server-local game events and server-local client effects&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_client&amp;lt;/code&amp;gt; - server-local functions for a client&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_entities&amp;lt;/code&amp;gt; - server functions for server-local game entities&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_main&amp;lt;/code&amp;gt; - core server game functions&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_utils&amp;lt;/code&amp;gt; - misc utility functions for game module&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_team&amp;lt;/code&amp;gt; - function-procedures related to game teams&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_local&amp;lt;/code&amp;gt; - header file with more header inclusions&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_svcmds&amp;lt;/code&amp;gt; - this file holds commands that can be executed by the server console, but not remote clients&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_spawn&amp;lt;/code&amp;gt; - contains the declarations of the spawn functions for various game map entities&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_session&amp;lt;/code&amp;gt; - code for client session data&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_physics&amp;lt;/code&amp;gt; - game physics code&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_admin&amp;lt;/code&amp;gt; - server admin management code&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_namelog&amp;lt;/code&amp;gt; - record client names that connect to the server&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_public&amp;lt;/code&amp;gt; - definitions shared by both the server game and client game modules&lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_local&amp;lt;/code&amp;gt; - local definitions for the bg (both games) files &lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_gameplay&amp;lt;/code&amp;gt; - gameplay related macro constants and external variable linkage &lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
'''Game Objects or Entities:'''&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
There are a number of CBSE (and so Unvanquished) entity related helper functions located in the file Unvanquished/src/sgame/Entities.h, and their implementation inside the cpp file.&lt;br /&gt;
&lt;br /&gt;
Client-local game entities are drawn as computer graphics on the player's screen, any client input related interactions with these entities are transmitted to the server as commands and the server processes these commands and invokes the gameplay code for the entity or entities.&lt;br /&gt;
&lt;br /&gt;
There is an absolute maximum number of entities of 1024 (see ''MAX_GENTITIES'' macro definition of daemon/src/engine/qcommon/qshared.h), if this maximum is reached then the server will terminate. All active game entities are listed inside a global array (''g_entities'', see sg_main.cpp), when a new entity is created the server searches this list for the next available free entity slot and initializes this slot, the server may  force an entity slot to be reallocated to a new entity though this may lead to problems according to a comment in the file sg_entities.cpp:&lt;br /&gt;
&lt;br /&gt;
''Try to avoid reusing an entity that was recently freed, because it can cause the client to think the entity morphed into something else instead of being removed and recreated, which can cause interpolated angles and bad trails.''&lt;br /&gt;
&lt;br /&gt;
Clients are game entities too and from 0 to (''MAX_CLIENTS'' - 1)(see daemon/src/engine/qcommon/q_shared.h) of the server global game entity array is reserved for client entities.&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
'''Gameplay:'''&lt;br /&gt;
Gameplay code is all the code that makes the entities do things and defines game rules and defines game events and defines game behaviors. There is a lot of code in this category and only a little some of the code will be used as an example.&lt;br /&gt;
Gameplay is server-local, meaning gameplay effects happens on the server. For example, the combat mechanics and behaviors of the game Unvanquished are defined in the file src/sgame/sg_combat.cpp. When a player dies the function ''G_PlayerDie'' is called and this function handles game events related to the death of a player, such as adding credit to a client's score and broadcasting a notification to the clients saying a player has died. Another example of gameplay code is the player movement code, contained inside of the file src/shared/bg_pmove.cpp. When a player moves their player character with their keyboard that input is transmitted to the server as a client command and the server calls the functions inside bg_pmove.cpp to apply the movement change to the player character game entity in the game level simulated by the game server, a client is changing the position and orientation of their associated player character entity on the server.&lt;br /&gt;
&lt;br /&gt;
'''Client-Local Game Logic:'''&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==sg_main.cpp==&lt;br /&gt;
The file src/sgame/sg_main.cpp deserves its own section since there are a lot of core server game functions and important variables inside this file.&lt;br /&gt;
&lt;br /&gt;
A special structure with server game level information is inside this file, the &amp;lt;code&amp;gt;level_locals_t level&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
sg_main contains the proxy console variables, the game-logic modules cannot access the console variables directly so they are accessed via a proxy interface.&lt;br /&gt;
&lt;br /&gt;
'''Some Important Server Functions:'''&lt;br /&gt;
*&amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function initializes the server game&lt;br /&gt;
*&amp;lt;code&amp;gt;G_SpawnClients&amp;lt;/code&amp;gt; - spawns the clients into the server game&lt;br /&gt;
*&amp;lt;code&amp;gt;G_RunFrame&amp;lt;/code&amp;gt; - executes the server game frame&lt;br /&gt;
*&amp;lt;code&amp;gt;G_RunThink&amp;lt;/code&amp;gt; - executes the thinking code of the server game entities&lt;br /&gt;
*&amp;lt;code&amp;gt;ExitLevel&amp;lt;/code&amp;gt; - changes the server game level after the intermission&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5098</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5098"/>
		<updated>2021-07-08T04:56:31Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Source Code Filesystem Tree Structure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
This Wiki page is incomplete and a work-in-progress, nonetheless there is still helpful information on this web page.&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code Tree and File Descriptions==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt; - game assets&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; - data submodule&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; - engine submodule&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; - engine source code&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; - common code: utility functions, typedefs, macros, and the like&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_shared.h&amp;lt;/code&amp;gt; - included first by ALL program modules. A user mod should never modify this file.&lt;br /&gt;
*****&amp;lt;code&amp;gt;q_shared.cpp&amp;lt;/code&amp;gt; - stateless support routines that are included in each code module&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; - renderer&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; - OpenGL shader code&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; - code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; - client-local game-logic code&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; - server-local game-logic code&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib&amp;lt;/code&amp;gt;&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_api&amp;lt;/code&amp;gt; - forward function declarations related to the bot artificial intelligence code&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_convert&amp;lt;/code&amp;gt; - procedures for the conversation&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_local&amp;lt;/code&amp;gt; - server-local variable definitions, struct definitions, and forward declarations for the bot AI&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_navdraw&amp;lt;/code&amp;gt; - code for drawing bot AI navmesh for debug purposes&lt;br /&gt;
***** &amp;lt;code&amp;gt;bot_types&amp;lt;/code&amp;gt; - code that defines data types for bot AI code&lt;br /&gt;
**** &amp;lt;code&amp;gt;AcidTubeComponent&amp;lt;/code&amp;gt; - code for Acid Tube entity component&lt;br /&gt;
**** &amp;lt;code&amp;gt;AlienBuildableComponent&amp;lt;/code&amp;gt; - code for alien buildable entity component&lt;br /&gt;
**** &amp;lt;code&amp;gt;AlienClassComponent&amp;lt;/code&amp;gt; - code for alien class entity component&lt;br /&gt;
**** &amp;lt;code&amp;gt;ArmourComponent&amp;lt;/code&amp;gt; - the armour entity component class&lt;br /&gt;
**** &amp;lt;code&amp;gt;ArmouryComponent&amp;lt;/code&amp;gt; - the armory entity component class&lt;br /&gt;
**** &amp;lt;code&amp;gt;Assert&amp;lt;/code&amp;gt; - daemon engine specific assert code&lt;br /&gt;
**** &amp;lt;code&amp;gt;BarricadeComponent&amp;lt;/code&amp;gt; - the code for the barricade entity component&lt;br /&gt;
**** &amp;lt;code&amp;gt;BoosterComponent&amp;lt;/code&amp;gt; - the booster component entity component class &lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_active&amp;lt;/code&amp;gt; - process server-local game events and server-local client effects&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_client&amp;lt;/code&amp;gt; - server-local functions for a client&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_entities&amp;lt;/code&amp;gt; - server functions for server-local game entities&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_main&amp;lt;/code&amp;gt; - core server game functions&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_utils&amp;lt;/code&amp;gt; - misc utility functions for game module&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_team&amp;lt;/code&amp;gt; - function-procedures related to game teams&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_local&amp;lt;/code&amp;gt; - header file with more header inclusions&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_svcmds&amp;lt;/code&amp;gt; - this file holds commands that can be executed by the server console, but not remote clients&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_spawn&amp;lt;/code&amp;gt; - contains the declarations of the spawn functions for various game map entities&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_session&amp;lt;/code&amp;gt; - code for client session data&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_physics&amp;lt;/code&amp;gt; - game physics code&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_admin&amp;lt;/code&amp;gt; - server admin management code&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_namelog&amp;lt;/code&amp;gt; - record client names that connect to the server&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_public&amp;lt;/code&amp;gt; - definitions shared by both the server game and client game modules&lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_local&amp;lt;/code&amp;gt; - local definitions for the bg (both games) files &lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_gameplay&amp;lt;/code&amp;gt; - gameplay related macro constants and external variable linkage &lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
'''Game Objects or Entities:'''&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
There are a number of CBSE (and so Unvanquished) entity related helper functions located in the file Unvanquished/src/sgame/Entities.h, and their implementation inside the cpp file.&lt;br /&gt;
&lt;br /&gt;
Client-local game entities are drawn as computer graphics on the player's screen, any client input related interactions with these entities are transmitted to the server as commands and the server processes these commands and invokes the gameplay code for the entity or entities.&lt;br /&gt;
&lt;br /&gt;
There is an absolute maximum number of entities of 1024 (see ''MAX_GENTITIES'' macro definition of daemon/src/engine/qcommon/qshared.h), if this maximum is reached then the server will terminate. All active game entities are listed inside a global array (''g_entities'', see sg_main.cpp), when a new entity is created the server searches this list for the next available free entity slot and initializes this slot, the server may  force an entity slot to be reallocated to a new entity though this may lead to problems according to a comment in the file sg_entities.cpp:&lt;br /&gt;
&lt;br /&gt;
''Try to avoid reusing an entity that was recently freed, because it can cause the client to think the entity morphed into something else instead of being removed and recreated, which can cause interpolated angles and bad trails.''&lt;br /&gt;
&lt;br /&gt;
Clients are game entities too and from 0 to (''MAX_CLIENTS'' - 1)(see daemon/src/engine/qcommon/q_shared.h) of the server global game entity array is reserved for client entities.&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
'''Gameplay:'''&lt;br /&gt;
Gameplay code is all the code that makes the entities do things and defines game rules and defines game events and defines game behaviors. There is a lot of code in this category and only a little some of the code will be used as an example.&lt;br /&gt;
Gameplay is server-local, meaning gameplay effects happens on the server. For example, the combat mechanics and behaviors of the game Unvanquished are defined in the file src/sgame/sg_combat.cpp. When a player dies the function ''G_PlayerDie'' is called and this function handles game events related to the death of a player, such as adding credit to a client's score and broadcasting a notification to the clients saying a player has died. Another example of gameplay code is the player movement code, contained inside of the file src/shared/bg_pmove.cpp. When a player moves their player character with their keyboard that input is transmitted to the server as a client command and the server calls the functions inside bg_pmove.cpp to apply the movement change to the player character game entity in the game level simulated by the game server, a client is changing the position and orientation of their associated player character entity on the server.&lt;br /&gt;
&lt;br /&gt;
'''Client-Local Game Logic:'''&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==sg_main.cpp==&lt;br /&gt;
The file src/sgame/sg_main.cpp deserves its own section since there are a lot of core server game functions and important variables inside this file.&lt;br /&gt;
&lt;br /&gt;
A special structure with server game level information is inside this file, the &amp;lt;code&amp;gt;level_locals_t level&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
sg_main contains the proxy console variables, the game-logic modules cannot access the console variables directly so they are accessed via a proxy interface.&lt;br /&gt;
&lt;br /&gt;
'''Some Important Server Functions:'''&lt;br /&gt;
*&amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function initializes the server game&lt;br /&gt;
*&amp;lt;code&amp;gt;G_SpawnClients&amp;lt;/code&amp;gt; - spawns the clients into the server game&lt;br /&gt;
*&amp;lt;code&amp;gt;G_RunFrame&amp;lt;/code&amp;gt; - executes the server game frame&lt;br /&gt;
*&amp;lt;code&amp;gt;G_RunThink&amp;lt;/code&amp;gt; - executes the thinking code of the server game entities&lt;br /&gt;
*&amp;lt;code&amp;gt;ExitLevel&amp;lt;/code&amp;gt; - changes the server game level after the intermission&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5097</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5097"/>
		<updated>2021-07-08T04:30:55Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Source Code Filesystem Tree Structure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
This Wiki page is incomplete and a work-in-progress, nonetheless there is still helpful information on this web page.&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code Filesystem Tree Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt; - game assets&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; - data submodule&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; - engine submodule&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; - engine source code&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; - common code: utility functions, typedefs, macros, and the like&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_shared.h&amp;lt;/code&amp;gt; - included first by ALL program modules. A user mod should never modify this file.&lt;br /&gt;
*****&amp;lt;code&amp;gt;q_shared.cpp&amp;lt;/code&amp;gt; - stateless support routines that are included in each code module&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; - renderer&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; - OpenGL shader code&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; - code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; - client-local game-logic code&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; - server-local game-logic code&lt;br /&gt;
**** &amp;lt;code&amp;gt;AcidTubeComponent&amp;lt;/code&amp;gt; - code for Acid Tube entity component&lt;br /&gt;
**** &amp;lt;code&amp;gt;AlienBuildableComponent&amp;lt;/code&amp;gt; - code for alien buildable entity component&lt;br /&gt;
**** &amp;lt;code&amp;gt;AlienClassComponent&amp;lt;/code&amp;gt; - code for alien class entity component&lt;br /&gt;
**** &amp;lt;code&amp;gt;ArmourComponent&amp;lt;/code&amp;gt; - the armour entity component class&lt;br /&gt;
**** &amp;lt;code&amp;gt;ArmouryComponent&amp;lt;/code&amp;gt; - the armory entity component class&lt;br /&gt;
**** &amp;lt;code&amp;gt;Assert&amp;lt;/code&amp;gt; - daemon engine specific assert code&lt;br /&gt;
**** &amp;lt;code&amp;gt;BarricadeComponent&amp;lt;/code&amp;gt; - the code for the barricade entity component&lt;br /&gt;
**** &amp;lt;code&amp;gt;BoosterComponent&amp;lt;/code&amp;gt; - the booster component entity component class&lt;br /&gt;
**** &amp;lt;code&amp;gt;bot_api&amp;lt;/code&amp;gt; - forward function declarations related to the bot artificial intelligence code&lt;br /&gt;
**** &amp;lt;code&amp;gt;bot_convert&amp;lt;/code&amp;gt; - procedures for the conversation &lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_active&amp;lt;/code&amp;gt; - process server-local game events and server-local client effects&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_client&amp;lt;/code&amp;gt; - server-local functions for a client&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_entities&amp;lt;/code&amp;gt; - server functions for server-local game entities&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_main&amp;lt;/code&amp;gt; - core server game functions&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_utils&amp;lt;/code&amp;gt; - misc utility functions for game module&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_team&amp;lt;/code&amp;gt; - function-procedures related to game teams&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_local&amp;lt;/code&amp;gt; - header file with more header inclusions&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_svcmds&amp;lt;/code&amp;gt; - this file holds commands that can be executed by the server console, but not remote clients&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_spawn&amp;lt;/code&amp;gt; - contains the declarations of the spawn functions for various game map entities&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_session&amp;lt;/code&amp;gt; - code for client session data&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_physics&amp;lt;/code&amp;gt; - game physics code&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_admin&amp;lt;/code&amp;gt; - server admin management code&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_namelog&amp;lt;/code&amp;gt; - record client names that connect to the server&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_public&amp;lt;/code&amp;gt; - definitions shared by both the server game and client game modules&lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_local&amp;lt;/code&amp;gt; - local definitions for the bg (both games) files &lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_gameplay&amp;lt;/code&amp;gt; - gameplay related macro constants and external variable linkage &lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
'''Game Objects or Entities:'''&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
There are a number of CBSE (and so Unvanquished) entity related helper functions located in the file Unvanquished/src/sgame/Entities.h, and their implementation inside the cpp file.&lt;br /&gt;
&lt;br /&gt;
Client-local game entities are drawn as computer graphics on the player's screen, any client input related interactions with these entities are transmitted to the server as commands and the server processes these commands and invokes the gameplay code for the entity or entities.&lt;br /&gt;
&lt;br /&gt;
There is an absolute maximum number of entities of 1024 (see ''MAX_GENTITIES'' macro definition of daemon/src/engine/qcommon/qshared.h), if this maximum is reached then the server will terminate. All active game entities are listed inside a global array (''g_entities'', see sg_main.cpp), when a new entity is created the server searches this list for the next available free entity slot and initializes this slot, the server may  force an entity slot to be reallocated to a new entity though this may lead to problems according to a comment in the file sg_entities.cpp:&lt;br /&gt;
&lt;br /&gt;
''Try to avoid reusing an entity that was recently freed, because it can cause the client to think the entity morphed into something else instead of being removed and recreated, which can cause interpolated angles and bad trails.''&lt;br /&gt;
&lt;br /&gt;
Clients are game entities too and from 0 to (''MAX_CLIENTS'' - 1)(see daemon/src/engine/qcommon/q_shared.h) of the server global game entity array is reserved for client entities.&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
'''Gameplay:'''&lt;br /&gt;
Gameplay code is all the code that makes the entities do things and defines game rules and defines game events and defines game behaviors. There is a lot of code in this category and only a little some of the code will be used as an example.&lt;br /&gt;
Gameplay is server-local, meaning gameplay effects happens on the server. For example, the combat mechanics and behaviors of the game Unvanquished are defined in the file src/sgame/sg_combat.cpp. When a player dies the function ''G_PlayerDie'' is called and this function handles game events related to the death of a player, such as adding credit to a client's score and broadcasting a notification to the clients saying a player has died. Another example of gameplay code is the player movement code, contained inside of the file src/shared/bg_pmove.cpp. When a player moves their player character with their keyboard that input is transmitted to the server as a client command and the server calls the functions inside bg_pmove.cpp to apply the movement change to the player character game entity in the game level simulated by the game server, a client is changing the position and orientation of their associated player character entity on the server.&lt;br /&gt;
&lt;br /&gt;
'''Client-Local Game Logic:'''&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==sg_main.cpp==&lt;br /&gt;
The file src/sgame/sg_main.cpp deserves its own section since there are a lot of core server game functions and important variables inside this file.&lt;br /&gt;
&lt;br /&gt;
A special structure with server game level information is inside this file, the &amp;lt;code&amp;gt;level_locals_t level&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
sg_main contains the proxy console variables, the game-logic modules cannot access the console variables directly so they are accessed via a proxy interface.&lt;br /&gt;
&lt;br /&gt;
'''Some Important Server Functions:'''&lt;br /&gt;
*&amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function initializes the server game&lt;br /&gt;
*&amp;lt;code&amp;gt;G_SpawnClients&amp;lt;/code&amp;gt; - spawns the clients into the server game&lt;br /&gt;
*&amp;lt;code&amp;gt;G_RunFrame&amp;lt;/code&amp;gt; - executes the server game frame&lt;br /&gt;
*&amp;lt;code&amp;gt;G_RunThink&amp;lt;/code&amp;gt; - executes the thinking code of the server game entities&lt;br /&gt;
*&amp;lt;code&amp;gt;ExitLevel&amp;lt;/code&amp;gt; - changes the server game level after the intermission&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5096</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5096"/>
		<updated>2021-07-07T17:23:46Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Source Code Filesystem Tree Structure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
This Wiki page is incomplete and a work-in-progress, nonetheless there is still helpful information on this web page.&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code Filesystem Tree Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt; - game assets&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; - data submodule&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; - engine submodule&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; - engine source code&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; - common code: utility functions, typedefs, macros, and the like&lt;br /&gt;
***** &amp;lt;code&amp;gt;q_shared.h&amp;lt;/code&amp;gt; - included first by ALL program modules. A user mod should never modify this file.&lt;br /&gt;
*****&amp;lt;code&amp;gt;q_shared.cpp&amp;lt;/code&amp;gt; - stateless support routines that are included in each code module&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; - renderer&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; - OpenGL shader code&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; - code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; - client-local game-logic code&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; - server-local game-logic code&lt;br /&gt;
**** &amp;lt;code&amp;gt;AcidTubeComponent.h&amp;lt;/code&amp;gt; - class declaration for the Acid Tube component entity&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_active.cpp&amp;lt;/code&amp;gt; - process server-local game events and server-local client effects&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_client.cpp&amp;lt;/code&amp;gt; - server-local functions for a client&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_entities.cpp&amp;lt;/code&amp;gt; - server functions for server-local game entities&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_main.cpp&amp;lt;/code&amp;gt; - core server game functions&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_utils.cpp&amp;lt;/code&amp;gt; - misc utility functions for game module&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_team.cpp&amp;lt;/code&amp;gt; - function-procedures related to game teams&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_local.h&amp;lt;/code&amp;gt; - header file with more header inclusions&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_svcmds&amp;lt;/code&amp;gt; - this file holds commands that can be executed by the server console, but not remote clients&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_spawn.h&amp;lt;/code&amp;gt; - contains the declarations of the spawn functions for various game map entities&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;bg_public.h&amp;lt;/code&amp;gt; - definitions shared by both the server game and client game modules&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
'''Game Objects or Entities:'''&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
There are a number of CBSE (and so Unvanquished) entity related helper functions located in the file Unvanquished/src/sgame/Entities.h, and their implementation inside the cpp file.&lt;br /&gt;
&lt;br /&gt;
Client-local game entities are drawn as computer graphics on the player's screen, any client input related interactions with these entities are transmitted to the server as commands and the server processes these commands and invokes the gameplay code for the entity or entities.&lt;br /&gt;
&lt;br /&gt;
There is an absolute maximum number of entities of 1024 (see ''MAX_GENTITIES'' macro definition of daemon/src/engine/qcommon/qshared.h), if this maximum is reached then the server will terminate. All active game entities are listed inside a global array (''g_entities'', see sg_main.cpp), when a new entity is created the server searches this list for the next available free entity slot and initializes this slot, the server may  force an entity slot to be reallocated to a new entity though this may lead to problems according to a comment in the file sg_entities.cpp:&lt;br /&gt;
&lt;br /&gt;
''Try to avoid reusing an entity that was recently freed, because it can cause the client to think the entity morphed into something else instead of being removed and recreated, which can cause interpolated angles and bad trails.''&lt;br /&gt;
&lt;br /&gt;
Clients are game entities too and from 0 to (''MAX_CLIENTS'' - 1)(see daemon/src/engine/qcommon/q_shared.h) of the server global game entity array is reserved for client entities.&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
'''Gameplay:'''&lt;br /&gt;
Gameplay code is all the code that makes the entities do things and defines game rules and defines game events and defines game behaviors. There is a lot of code in this category and only a little some of the code will be used as an example.&lt;br /&gt;
Gameplay is server-local, meaning gameplay effects happens on the server. For example, the combat mechanics and behaviors of the game Unvanquished are defined in the file src/sgame/sg_combat.cpp. When a player dies the function ''G_PlayerDie'' is called and this function handles game events related to the death of a player, such as adding credit to a client's score and broadcasting a notification to the clients saying a player has died. Another example of gameplay code is the player movement code, contained inside of the file src/shared/bg_pmove.cpp. When a player moves their player character with their keyboard that input is transmitted to the server as a client command and the server calls the functions inside bg_pmove.cpp to apply the movement change to the player character game entity in the game level simulated by the game server, a client is changing the position and orientation of their associated player character entity on the server.&lt;br /&gt;
&lt;br /&gt;
'''Client-Local Game Logic:'''&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==sg_main.cpp==&lt;br /&gt;
The file src/sgame/sg_main.cpp deserves its own section since there are a lot of core server game functions and important variables inside this file.&lt;br /&gt;
&lt;br /&gt;
A special structure with server game level information is inside this file, the &amp;lt;code&amp;gt;level_locals_t level&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
sg_main contains the proxy console variables, the game-logic modules cannot access the console variables directly so they are accessed via a proxy interface.&lt;br /&gt;
&lt;br /&gt;
'''Some Important Server Functions:'''&lt;br /&gt;
*&amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function initializes the server game&lt;br /&gt;
*&amp;lt;code&amp;gt;G_SpawnClients&amp;lt;/code&amp;gt; - spawns the clients into the server game&lt;br /&gt;
*&amp;lt;code&amp;gt;G_RunFrame&amp;lt;/code&amp;gt; - executes the server game frame&lt;br /&gt;
*&amp;lt;code&amp;gt;G_RunThink&amp;lt;/code&amp;gt; - executes the thinking code of the server game entities&lt;br /&gt;
*&amp;lt;code&amp;gt;ExitLevel&amp;lt;/code&amp;gt; - changes the server game level after the intermission&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5095</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5095"/>
		<updated>2021-07-06T03:59:36Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* sg_main.cpp */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
This Wiki page is incomplete and a work-in-progress, nonetheless there is still helpful information on this web page.&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code Filesystem Tree Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt; - game assets&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; - client-local game-logic code&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; - server-local game-logic code&lt;br /&gt;
**** &amp;lt;code&amp;gt;AcidTubeComponent.h&amp;lt;/code&amp;gt; - class declaration for the Acid Tube component entity&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_active.cpp&amp;lt;/code&amp;gt; - process server-local game events and server-local client effects&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_client.cpp&amp;lt;/code&amp;gt; - server-local functions for a client&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_entities.cpp&amp;lt;/code&amp;gt; - server functions for server-local game entities&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_main.cpp&amp;lt;/code&amp;gt; - core server game functions&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
'''Game Objects or Entities:'''&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
There are a number of CBSE (and so Unvanquished) entity related helper functions located in the file Unvanquished/src/sgame/Entities.h, and their implementation inside the cpp file.&lt;br /&gt;
&lt;br /&gt;
Client-local game entities are drawn as computer graphics on the player's screen, any client input related interactions with these entities are transmitted to the server as commands and the server processes these commands and invokes the gameplay code for the entity or entities.&lt;br /&gt;
&lt;br /&gt;
There is an absolute maximum number of entities of 1024 (see ''MAX_GENTITIES'' macro definition of daemon/src/engine/qcommon/qshared.h), if this maximum is reached then the server will terminate. All active game entities are listed inside a global array (''g_entities'', see sg_main.cpp), when a new entity is created the server searches this list for the next available free entity slot and initializes this slot, the server may  force an entity slot to be reallocated to a new entity though this may lead to problems according to a comment in the file sg_entities.cpp:&lt;br /&gt;
&lt;br /&gt;
''Try to avoid reusing an entity that was recently freed, because it can cause the client to think the entity morphed into something else instead of being removed and recreated, which can cause interpolated angles and bad trails.''&lt;br /&gt;
&lt;br /&gt;
Clients are game entities too and from 0 to (''MAX_CLIENTS'' - 1)(see daemon/src/engine/qcommon/q_shared.h) of the server global game entity array is reserved for client entities.&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
'''Gameplay:'''&lt;br /&gt;
Gameplay code is all the code that makes the entities do things and defines game rules and defines game events and defines game behaviors. There is a lot of code in this category and only a little some of the code will be used as an example.&lt;br /&gt;
Gameplay is server-local, meaning gameplay effects happens on the server. For example, the combat mechanics and behaviors of the game Unvanquished are defined in the file src/sgame/sg_combat.cpp. When a player dies the function ''G_PlayerDie'' is called and this function handles game events related to the death of a player, such as adding credit to a client's score and broadcasting a notification to the clients saying a player has died. Another example of gameplay code is the player movement code, contained inside of the file src/shared/bg_pmove.cpp. When a player moves their player character with their keyboard that input is transmitted to the server as a client command and the server calls the functions inside bg_pmove.cpp to apply the movement change to the player character game entity in the game level simulated by the game server, a client is changing the position and orientation of their associated player character entity on the server.&lt;br /&gt;
&lt;br /&gt;
'''Client-Local Game Logic:'''&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==sg_main.cpp==&lt;br /&gt;
The file src/sgame/sg_main.cpp deserves its own section since there are a lot of core server game functions and important variables inside this file.&lt;br /&gt;
&lt;br /&gt;
A special structure with server game level information is inside this file, the &amp;lt;code&amp;gt;level_locals_t level&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
sg_main contains the proxy console variables, the game-logic modules cannot access the console variables directly so they are accessed via a proxy interface.&lt;br /&gt;
&lt;br /&gt;
'''Some Important Server Functions:'''&lt;br /&gt;
*&amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function initializes the server game&lt;br /&gt;
*&amp;lt;code&amp;gt;G_SpawnClients&amp;lt;/code&amp;gt; - spawns the clients into the server game&lt;br /&gt;
*&amp;lt;code&amp;gt;G_RunFrame&amp;lt;/code&amp;gt; - executes the server game frame&lt;br /&gt;
*&amp;lt;code&amp;gt;G_RunThink&amp;lt;/code&amp;gt; - executes the thinking code of the server game entities&lt;br /&gt;
*&amp;lt;code&amp;gt;ExitLevel&amp;lt;/code&amp;gt; - changes the server game level after the intermission&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5094</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5094"/>
		<updated>2021-07-06T03:52:41Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
This Wiki page is incomplete and a work-in-progress, nonetheless there is still helpful information on this web page.&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code Filesystem Tree Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt; - game assets&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; - client-local game-logic code&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; - server-local game-logic code&lt;br /&gt;
**** &amp;lt;code&amp;gt;AcidTubeComponent.h&amp;lt;/code&amp;gt; - class declaration for the Acid Tube component entity&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_active.cpp&amp;lt;/code&amp;gt; - process server-local game events and server-local client effects&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_client.cpp&amp;lt;/code&amp;gt; - server-local functions for a client&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_entities.cpp&amp;lt;/code&amp;gt; - server functions for server-local game entities&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_main.cpp&amp;lt;/code&amp;gt; - core server game functions&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
'''Game Objects or Entities:'''&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
There are a number of CBSE (and so Unvanquished) entity related helper functions located in the file Unvanquished/src/sgame/Entities.h, and their implementation inside the cpp file.&lt;br /&gt;
&lt;br /&gt;
Client-local game entities are drawn as computer graphics on the player's screen, any client input related interactions with these entities are transmitted to the server as commands and the server processes these commands and invokes the gameplay code for the entity or entities.&lt;br /&gt;
&lt;br /&gt;
There is an absolute maximum number of entities of 1024 (see ''MAX_GENTITIES'' macro definition of daemon/src/engine/qcommon/qshared.h), if this maximum is reached then the server will terminate. All active game entities are listed inside a global array (''g_entities'', see sg_main.cpp), when a new entity is created the server searches this list for the next available free entity slot and initializes this slot, the server may  force an entity slot to be reallocated to a new entity though this may lead to problems according to a comment in the file sg_entities.cpp:&lt;br /&gt;
&lt;br /&gt;
''Try to avoid reusing an entity that was recently freed, because it can cause the client to think the entity morphed into something else instead of being removed and recreated, which can cause interpolated angles and bad trails.''&lt;br /&gt;
&lt;br /&gt;
Clients are game entities too and from 0 to (''MAX_CLIENTS'' - 1)(see daemon/src/engine/qcommon/q_shared.h) of the server global game entity array is reserved for client entities.&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
'''Gameplay:'''&lt;br /&gt;
Gameplay code is all the code that makes the entities do things and defines game rules and defines game events and defines game behaviors. There is a lot of code in this category and only a little some of the code will be used as an example.&lt;br /&gt;
Gameplay is server-local, meaning gameplay effects happens on the server. For example, the combat mechanics and behaviors of the game Unvanquished are defined in the file src/sgame/sg_combat.cpp. When a player dies the function ''G_PlayerDie'' is called and this function handles game events related to the death of a player, such as adding credit to a client's score and broadcasting a notification to the clients saying a player has died. Another example of gameplay code is the player movement code, contained inside of the file src/shared/bg_pmove.cpp. When a player moves their player character with their keyboard that input is transmitted to the server as a client command and the server calls the functions inside bg_pmove.cpp to apply the movement change to the player character game entity in the game level simulated by the game server, a client is changing the position and orientation of their associated player character entity on the server.&lt;br /&gt;
&lt;br /&gt;
'''Client-Local Game Logic:'''&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==sg_main.cpp==&lt;br /&gt;
The file src/sgame/sg_main.cpp deserves its own section since there are a lot of core server game functions and important variables inside this file.&lt;br /&gt;
&lt;br /&gt;
sg_main contains the proxy console variables, the game-logic modules cannot access the console variables directly so they are accessed via a proxy interface.&lt;br /&gt;
&lt;br /&gt;
'''Important server functions:'''&lt;br /&gt;
*&amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5093</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5093"/>
		<updated>2021-07-06T02:40:10Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Source Code Filesystem Tree Structure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
This Wiki page is incomplete and a work-in-progress, nonetheless there is still helpful information on this web page.&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code Filesystem Tree Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt; - game assets&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; - client-local game-logic code&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; - server-local game-logic code&lt;br /&gt;
**** &amp;lt;code&amp;gt;AcidTubeComponent.h&amp;lt;/code&amp;gt; - class declaration for the Acid Tube component entity&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_active.cpp&amp;lt;/code&amp;gt; - process server-local game events and server-local client effects&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_client.cpp&amp;lt;/code&amp;gt; - server-local functions for a client&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_entities.cpp&amp;lt;/code&amp;gt; - server functions for server-local game entities&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_main.cpp&amp;lt;/code&amp;gt; - core server game functions&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
'''Game Objects or Entities:'''&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
There are a number of CBSE (and so Unvanquished) entity related helper functions located in the file Unvanquished/src/sgame/Entities.h, and their implementation inside the cpp file.&lt;br /&gt;
&lt;br /&gt;
Client-local game entities are drawn as computer graphics on the player's screen, any client input related interactions with these entities are transmitted to the server as commands and the server processes these commands and invokes the gameplay code for the entity or entities.&lt;br /&gt;
&lt;br /&gt;
There is an absolute maximum number of entities of 1024 (see ''MAX_GENTITIES'' macro definition of daemon/src/engine/qcommon/qshared.h), if this maximum is reached then the server will terminate. All active game entities are listed inside a global array (''g_entities'', see sg_main.cpp), when a new entity is created the server searches this list for the next available free entity slot and initializes this slot, the server may  force an entity slot to be reallocated to a new entity though this may lead to problems according to a comment in the file sg_entities.cpp:&lt;br /&gt;
&lt;br /&gt;
''Try to avoid reusing an entity that was recently freed, because it can cause the client to think the entity morphed into something else instead of being removed and recreated, which can cause interpolated angles and bad trails.''&lt;br /&gt;
&lt;br /&gt;
Clients are game entities too and from 0 to (''MAX_CLIENTS'' - 1)(see daemon/src/engine/qcommon/q_shared.h) of the server global game entity array is reserved for client entities.&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
'''Gameplay:'''&lt;br /&gt;
Gameplay code is all the code that makes the entities do things and defines game rules and defines game events and defines game behaviors. There is a lot of code in this category and only a little some of the code will be used as an example.&lt;br /&gt;
Gameplay is server-local, meaning gameplay effects happens on the server. For example, the combat mechanics and behaviors of the game Unvanquished are defined in the file src/sgame/sg_combat.cpp. When a player dies the function ''G_PlayerDie'' is called and this function handles game events related to the death of a player, such as adding credit to a client's score and broadcasting a notification to the clients saying a player has died. Another example of gameplay code is the player movement code, contained inside of the file src/shared/bg_pmove.cpp. When a player moves their player character with their keyboard that input is transmitted to the server as a client command and the server calls the functions inside bg_pmove.cpp to apply the movement change to the player character game entity in the game level simulated by the game server, a client is changing the position and orientation of their associated player character entity on the server.&lt;br /&gt;
&lt;br /&gt;
'''Client-Local Game Logic:'''&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5092</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5092"/>
		<updated>2021-07-06T02:29:25Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Game Logic */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
This Wiki page is incomplete and a work-in-progress, nonetheless there is still helpful information on this web page.&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code Filesystem Tree Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt; - game assets&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; - client-local game-logic code&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; - server-local game-logic code&lt;br /&gt;
**** &amp;lt;code&amp;gt;AcidTubeComponent.h&amp;lt;/code&amp;gt; - class declaration for the Acid Tube component entity&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_active.cpp&amp;lt;/code&amp;gt; - process server-local game events and server-local client effects&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_entities.cpp&amp;lt;/code&amp;gt; - server functions for server-local game entities&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
'''Game Objects or Entities:'''&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
There are a number of CBSE (and so Unvanquished) entity related helper functions located in the file Unvanquished/src/sgame/Entities.h, and their implementation inside the cpp file.&lt;br /&gt;
&lt;br /&gt;
Client-local game entities are drawn as computer graphics on the player's screen, any client input related interactions with these entities are transmitted to the server as commands and the server processes these commands and invokes the gameplay code for the entity or entities.&lt;br /&gt;
&lt;br /&gt;
There is an absolute maximum number of entities of 1024 (see ''MAX_GENTITIES'' macro definition of daemon/src/engine/qcommon/qshared.h), if this maximum is reached then the server will terminate. All active game entities are listed inside a global array (''g_entities'', see sg_main.cpp), when a new entity is created the server searches this list for the next available free entity slot and initializes this slot, the server may  force an entity slot to be reallocated to a new entity though this may lead to problems according to a comment in the file sg_entities.cpp:&lt;br /&gt;
&lt;br /&gt;
''Try to avoid reusing an entity that was recently freed, because it can cause the client to think the entity morphed into something else instead of being removed and recreated, which can cause interpolated angles and bad trails.''&lt;br /&gt;
&lt;br /&gt;
Clients are game entities too and from 0 to (''MAX_CLIENTS'' - 1)(see daemon/src/engine/qcommon/q_shared.h) of the server global game entity array is reserved for client entities.&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
'''Gameplay:'''&lt;br /&gt;
Gameplay code is all the code that makes the entities do things and defines game rules and defines game events and defines game behaviors. There is a lot of code in this category and only a little some of the code will be used as an example.&lt;br /&gt;
Gameplay is server-local, meaning gameplay effects happens on the server. For example, the combat mechanics and behaviors of the game Unvanquished are defined in the file src/sgame/sg_combat.cpp. When a player dies the function ''G_PlayerDie'' is called and this function handles game events related to the death of a player, such as adding credit to a client's score and broadcasting a notification to the clients saying a player has died. Another example of gameplay code is the player movement code, contained inside of the file src/shared/bg_pmove.cpp. When a player moves their player character with their keyboard that input is transmitted to the server as a client command and the server calls the functions inside bg_pmove.cpp to apply the movement change to the player character game entity in the game level simulated by the game server, a client is changing the position and orientation of their associated player character entity on the server.&lt;br /&gt;
&lt;br /&gt;
'''Client-Local Game Logic:'''&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5091</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5091"/>
		<updated>2021-07-06T02:28:45Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Game Logic */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
This Wiki page is incomplete and a work-in-progress, nonetheless there is still helpful information on this web page.&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code Filesystem Tree Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt; - game assets&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; - client-local game-logic code&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; - server-local game-logic code&lt;br /&gt;
**** &amp;lt;code&amp;gt;AcidTubeComponent.h&amp;lt;/code&amp;gt; - class declaration for the Acid Tube component entity&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_active.cpp&amp;lt;/code&amp;gt; - process server-local game events and server-local client effects&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_entities.cpp&amp;lt;/code&amp;gt; - server functions for server-local game entities&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
'''Game Objects or Entities:'''&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
There are a number of CBSE (and so Unvanquished) entity related helper functions located in the file Unvanquished/src/sgame/Entities.h, and their implementation inside the cpp file.&lt;br /&gt;
&lt;br /&gt;
Client-local game entities are drawn as computer graphics on the player's screen, any client input related interactions with these entities are transmitted to the server as commands and the server processes these commands and invokes the gameplay code for the entity or entities.&lt;br /&gt;
&lt;br /&gt;
There is an absolute maximum number of entities of 1024 (see ''MAX_GENTITIES'' macro definition of daemon/src/engine/qcommon/qshared.h), if this maximum is reached then the server will terminate. All active game entities are listed inside a global array (''g_entities'', see sg_main.cpp), when a new entity is created the server searches this list for the next available free entity slot and initializes this slot, the server may  force an entity slot to be reallocated to a new entity though this may lead to problems according to a comment in the file sg_entities.cpp:&lt;br /&gt;
&lt;br /&gt;
''Try to avoid reusing an entity that was recently freed, because it can cause the client to think the entity morphed into something else instead of being removed and recreated, which can cause interpolated angles and bad trails.''&lt;br /&gt;
&lt;br /&gt;
Clients are game entities too and from 0 to (''MAX_CLIENTS'' - 1)(see daemon/src/engine/qcommon/q_shared.h) of the server global game entity array is reserved for client entities.&lt;br /&gt;
&lt;br /&gt;
'''Gameplay:'''&lt;br /&gt;
Gameplay code is all the code that makes the entities do things and defines game rules and defines game events and defines game behaviors. There is a lot of code in this category and only a little some of the code will be used as an example.&lt;br /&gt;
Gameplay is server-local, meaning gameplay effects happens on the server. For example, the combat mechanics and behaviors of the game Unvanquished are defined in the file src/sgame/sg_combat.cpp. When a player dies the function ''G_PlayerDie'' is called and this function handles game events related to the death of a player, such as adding credit to a client's score and broadcasting a notification to the clients saying a player has died. Another example of gameplay code is the player movement code, contained inside of the file src/shared/bg_pmove.cpp. When a player moves their player character with their keyboard that input is transmitted to the server as a client command and the server calls the functions inside bg_pmove.cpp to apply the movement change to the player character game entity in the game level simulated by the game server, a client is changing the position and orientation of their associated player character entity on the server.&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
'''Client-Local Game Logic:'''&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5090</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5090"/>
		<updated>2021-07-06T02:10:36Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Game Logic */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
This Wiki page is incomplete and a work-in-progress, nonetheless there is still helpful information on this web page.&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code Filesystem Tree Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt; - game assets&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; - client-local game-logic code&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; - server-local game-logic code&lt;br /&gt;
**** &amp;lt;code&amp;gt;AcidTubeComponent.h&amp;lt;/code&amp;gt; - class declaration for the Acid Tube component entity&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_active.cpp&amp;lt;/code&amp;gt; - process server-local game events and server-local client effects&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_entities.cpp&amp;lt;/code&amp;gt; - server functions for server-local game entities&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
There are a number of CBSE (and so Unvanquished) entity related helper functions located in the file Unvanquished/src/sgame/Entities.h, and their implementation inside the cpp file.&lt;br /&gt;
&lt;br /&gt;
Client-local game entities are drawn as computer graphics on the player's screen, any client input related interactions with these entities are transmitted to the server as commands and the server processes these commands and invokes the gameplay code for the entity or entities.&lt;br /&gt;
&lt;br /&gt;
There is an absolute maximum number of entities of 1024 (see ''MAX_GENTITIES'' macro definition of daemon/src/engine/qcommon/qshared.h), if this maximum is reached then the server will terminate. All active game entities are listed inside a global array (''g_entities'', see sg_main.cpp), when a new entity is created the server searches this list for the next available free entity slot and initializes this slot, the server may  force an entity slot to be reallocated to a new entity though this may lead to problems according to a comment in the file sg_entities.cpp:&lt;br /&gt;
&lt;br /&gt;
''Try to avoid reusing an entity that was recently freed, because it can cause the client to think the entity morphed into something else instead of being removed and recreated, which can cause interpolated angles and bad trails.''&lt;br /&gt;
&lt;br /&gt;
Clients are game entities too and from 0 to (''MAX_CLIENTS'' - 1)(see daemon/src/engine/qcommon/q_shared.h) of the server global game entity array is reserved for client entities.&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
'''Client-Local Game Logic:'''&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5089</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5089"/>
		<updated>2021-07-06T01:50:01Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Game Logic */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
This Wiki page is incomplete and a work-in-progress, nonetheless there is still helpful information on this web page.&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code Filesystem Tree Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt; - game assets&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; - client-local game-logic code&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; - server-local game-logic code&lt;br /&gt;
**** &amp;lt;code&amp;gt;AcidTubeComponent.h&amp;lt;/code&amp;gt; - class declaration for the Acid Tube component entity&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_active.cpp&amp;lt;/code&amp;gt; - process server-local game events and server-local client effects&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_entities.cpp&amp;lt;/code&amp;gt; - server functions for server-local game entities&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
There are a number of CBSE (and so Unvanquished) entity related helper functions located in the file Unvanquished/src/sgame/Entities.h, and their implementation inside the cpp file.&lt;br /&gt;
&lt;br /&gt;
Client-local game entities are drawn as computer graphics on the player's screen, any client input related interactions with these entities are transmitted to the server as commands and the server processes these commands and invokes the gameplay code for the entity or entities.&lt;br /&gt;
&lt;br /&gt;
There is an absolute maximum number of entities of 1024 (see ''MAX_GENTITIES'' macro definition of daemon/src/engine/qcommon/qshared.h)&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
'''Client-Local Game Logic:'''&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5088</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5088"/>
		<updated>2021-07-06T01:41:21Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Source Code Filesystem Tree Structure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
This Wiki page is incomplete and a work-in-progress, nonetheless there is still helpful information on this web page.&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code Filesystem Tree Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt; - game assets&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; - client-local game-logic code&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; - server-local game-logic code&lt;br /&gt;
**** &amp;lt;code&amp;gt;AcidTubeComponent.h&amp;lt;/code&amp;gt; - class declaration for the Acid Tube component entity&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_active.cpp&amp;lt;/code&amp;gt; - process server-local game events and server-local client effects&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_entities.cpp&amp;lt;/code&amp;gt; - server functions for server-local game entities&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
There are a number of CBSE (and so Unvanquished) entity related helper functions located in the file Unvanquished/src/sgame/Entities.h, and their implementation inside the cpp file.&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
'''Client-Local Game Logic:'''&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5087</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5087"/>
		<updated>2021-07-06T01:07:34Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Source Code Filesystem Tree Structure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
This Wiki page is incomplete and a work-in-progress, nonetheless there is still helpful information on this web page.&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code Filesystem Tree Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt; - game assets&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; - client-local game-logic code&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; - server-local game-logic code&lt;br /&gt;
**** &amp;lt;code&amp;gt;AcidTubeComponent.h&amp;lt;/code&amp;gt; - class declaration for the Acid Tube component entity&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_active.cpp&amp;lt;/code&amp;gt; - process server-local game events and server-local client effects&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_entities.cpp&amp;lt;/code&amp;gt; - server functions for game entities&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
There are a number of CBSE (and so Unvanquished) entity related helper functions located in the file Unvanquished/src/sgame/Entities.h, and their implementation inside the cpp file.&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
'''Client-Local Game Logic:'''&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5086</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5086"/>
		<updated>2021-07-05T23:44:30Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Source Code Filesystem Tree Structure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
This Wiki page is incomplete and a work-in-progress, nonetheless there is still helpful information on this web page.&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code Filesystem Tree Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt; - game assets&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; - client-local game-logic code&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; - server-local game-logic code&lt;br /&gt;
**** &amp;lt;code&amp;gt;AcidTubeComponent.h&amp;lt;/code&amp;gt; - class declaration for the Acid Tube component entity&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_active.cpp&amp;lt;/code&amp;gt; - process server-local game events and server-local client effects&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
There are a number of CBSE (and so Unvanquished) entity related helper functions located in the file Unvanquished/src/sgame/Entities.h, and their implementation inside the cpp file.&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
'''Client-Local Game Logic:'''&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5085</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5085"/>
		<updated>2021-07-05T23:07:17Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Source Code &amp;amp;amp; Data Structure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
This Wiki page is incomplete and a work-in-progress, nonetheless there is still helpful information on this web page.&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code Filesystem Tree Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt; - game assets&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; Client-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; Server-side game code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_active.cpp&amp;lt;/code&amp;gt; - process server-local game events and server-local clients&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
There are a number of CBSE (and so Unvanquished) entity related helper functions located in the file Unvanquished/src/sgame/Entities.h, and their implementation inside the cpp file.&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
'''Client-Local Game Logic:'''&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5084</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5084"/>
		<updated>2021-07-05T23:06:12Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Source Code &amp;amp;amp; Data Structure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
This Wiki page is incomplete and a work-in-progress, nonetheless there is still helpful information on this web page.&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code &amp;amp;amp; Data Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt; - game assets&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; Client-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; Server-side game code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;sg_active.cpp&amp;lt;/code&amp;gt; - process server-local game events and server-local clients&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
There are a number of CBSE (and so Unvanquished) entity related helper functions located in the file Unvanquished/src/sgame/Entities.h, and their implementation inside the cpp file.&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
'''Client-Local Game Logic:'''&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5083</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5083"/>
		<updated>2021-07-05T23:02:30Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
This Wiki page is incomplete and a work-in-progress, nonetheless there is still helpful information on this web page.&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code &amp;amp;amp; Data Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt; - game assets&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; Client-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; Server-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
There are a number of CBSE (and so Unvanquished) entity related helper functions located in the file Unvanquished/src/sgame/Entities.h, and their implementation inside the cpp file.&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
'''Client-Local Game Logic:'''&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5082</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5082"/>
		<updated>2021-07-05T22:44:41Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Game Logic */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code &amp;amp;amp; Data Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt; - game assets&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; Client-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; Server-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
There are a number of CBSE (and so Unvanquished) entity related helper functions located in the file Unvanquished/src/sgame/Entities.h, and their implementation inside the cpp file.&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
'''Client-Local Game Logic:'''&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5081</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5081"/>
		<updated>2021-07-05T20:25:23Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code &amp;amp;amp; Data Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt; - game assets&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; Client-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; Server-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
'''Client-Local Game Logic:'''&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5080</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5080"/>
		<updated>2021-07-05T20:23:49Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Source Code &amp;amp;amp; Data Structure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code &amp;amp;amp; Data Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt; - game assets&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; Client-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; Server-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
'''Client-Local Game Logic:'''&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5079</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5079"/>
		<updated>2021-07-05T20:21:30Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Game Logic */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code &amp;amp;amp; Data Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; Client-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; Server-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
'''Client-Local Game Logic:'''&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5078</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5078"/>
		<updated>2021-07-05T20:21:15Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Client-Side */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code &amp;amp;amp; Data Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; Client-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; Server-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
'''Client-Local Game Logic:'''&lt;br /&gt;
&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5077</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5077"/>
		<updated>2021-07-05T20:20:23Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code &amp;amp;amp; Data Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; Client-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; Server-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
==Client-Side==&lt;br /&gt;
&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5076</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5076"/>
		<updated>2021-07-05T20:19:07Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Game Logic */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code &amp;amp;amp; Data Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; Client-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; Server-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
==Client-Side==&lt;br /&gt;
&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Server-Side==&lt;br /&gt;
&lt;br /&gt;
Server game state initialization occurs in &amp;lt;code&amp;gt;G_InitGame()&amp;lt;/code&amp;gt; in {{SourceFile|src/sgame/sg_main.cpp}}.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5075</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5075"/>
		<updated>2021-07-05T20:18:50Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Game Logic */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code &amp;amp;amp; Data Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; Client-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; Server-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h. The base class for Unvanquished game entities is nested inside of the base class for game entities of the original Quake III source, see &amp;lt;code&amp;gt;struct gentity_s&amp;lt;/code&amp;gt; at line 111 of Unvanquished/src/sgame/sg_struct.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
==Client-Side==&lt;br /&gt;
&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Server-Side==&lt;br /&gt;
&lt;br /&gt;
Server game state initialization occurs in &amp;lt;code&amp;gt;G_InitGame()&amp;lt;/code&amp;gt; in {{SourceFile|src/sgame/sg_main.cpp}}.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5074</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5074"/>
		<updated>2021-07-05T20:14:54Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Game Logic */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code &amp;amp;amp; Data Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; Client-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; Server-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
'''Game Logic Categories:'''&lt;br /&gt;
The game code can be thought of as being separated into two distinct categories: game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
Game objects are the objects that exist in the game world, they have a graphical representation (the actual game asset, such as the armory mesh model), they have hit points, and can receive damage from a source and die if their hit points reaches 0, they can heal themselves (replenish hit points), and they are created when the map loads or while the game is running (for example when a player creates a drill entity to increase build points for their team), and they can be destroyed, and etc. Entities in Unvanquished are designed to have components, a component is a C++ class with gameplay functionality that is incorporated into the basic entity itself and the basic entity acquires the functionality of the component. A component is owned by a parent entity. The base class definition for Unvanquished game entities is contained inside of Unvanquished/src/sgame/backend/CBSEBackend.h.&lt;br /&gt;
&lt;br /&gt;
Here are some example component classes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ArmouryComponentBase&amp;lt;/code&amp;gt; - at line 1867 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class HealthComponentBase&amp;lt;/code&amp;gt; - at line 475 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;class ThinkingComponentBase&amp;lt;/code&amp;gt; - at line 359 of Unvanquished/src/sgame/backend/CBSEBackend.h&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''CBSE:''' Unvanquished uses the CBSE Toolchain to implement the game entity components. CBSE is a code generator based on Python and requires Python3 and Python3-yaml to generate the actual C++ code, and a C++ 11 compiler to compile the generated code. See https://github.com/DaemonEngine/CBSE-Toolchain for more information.&lt;br /&gt;
&lt;br /&gt;
==Client-Side==&lt;br /&gt;
&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Server-Side==&lt;br /&gt;
&lt;br /&gt;
Server game state initialization occurs in &amp;lt;code&amp;gt;G_InitGame()&amp;lt;/code&amp;gt; in {{SourceFile|src/sgame/sg_main.cpp}}.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5072</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5072"/>
		<updated>2021-07-05T05:33:07Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* System Architecture */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code &amp;amp;amp; Data Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; Client-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; Server-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user then updates its game-state per this input (for example, the player using their keyboard to move the character forward some distance) then transmit these input events to the Server, and to actually draw the computer graphics, and etc. The Server has the task of simulating the game itself but does not render any graphics for a user, for example game objects would exist on the Server, and the Server would tell the Client that game object exists and it should be drawn on the screen. These examples are not all functionalities the Client or Server performs. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands, for example the user moving their controlled character somewhere else in the level, these movements would be transmitted as commands to the Server to update its game state with the new player location. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the time the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are updates or changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
==Client-Side==&lt;br /&gt;
&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Server-Side==&lt;br /&gt;
&lt;br /&gt;
Server game state initialization occurs in &amp;lt;code&amp;gt;G_InitGame()&amp;lt;/code&amp;gt; in {{SourceFile|src/sgame/sg_main.cpp}}.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5071</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5071"/>
		<updated>2021-07-05T03:22:31Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Program Ignition and Initialization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code &amp;amp;amp; Data Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; Client-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; Server-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user and transmit these input events to the Server and to actually draw the computer graphics, while the Server has the task of simulating the game itself but does not render any graphics for a user. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The game-logic modules (client game and server game) are created as child processes by the virtual machine (see daemon/src/engine/framework/VirtualMachine.cpp) The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
==Client-Side==&lt;br /&gt;
&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Server-Side==&lt;br /&gt;
&lt;br /&gt;
Server game state initialization occurs in &amp;lt;code&amp;gt;G_InitGame()&amp;lt;/code&amp;gt; in {{SourceFile|src/sgame/sg_main.cpp}}.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5070</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5070"/>
		<updated>2021-07-05T01:36:54Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Program Ignition and Initialization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code &amp;amp;amp; Data Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; Client-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; Server-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user and transmit these input events to the Server and to actually draw the computer graphics, while the Server has the task of simulating the game itself but does not render any graphics for a user. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). All game-logic modules must have a main function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The main functions of the modules calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
==Client-Side==&lt;br /&gt;
&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Server-Side==&lt;br /&gt;
&lt;br /&gt;
Server game state initialization occurs in &amp;lt;code&amp;gt;G_InitGame()&amp;lt;/code&amp;gt; in {{SourceFile|src/sgame/sg_main.cpp}}.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5069</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5069"/>
		<updated>2021-07-05T01:33:03Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Program Ignition and Initialization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code &amp;amp;amp; Data Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; Client-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; Server-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user and transmit these input events to the Server and to actually draw the computer graphics, while the Server has the task of simulating the game itself but does not render any graphics for a user. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: '''CGameVM''' and '''GameVM'''. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). This main function is called by the Virtual Machine, all game-logic modules must implement this function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The main functions of the exes calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
==Client-Side==&lt;br /&gt;
&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Server-Side==&lt;br /&gt;
&lt;br /&gt;
Server game state initialization occurs in &amp;lt;code&amp;gt;G_InitGame()&amp;lt;/code&amp;gt; in {{SourceFile|src/sgame/sg_main.cpp}}.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5068</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5068"/>
		<updated>2021-07-05T01:00:25Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* System Architecture */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code &amp;amp;amp; Data Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; Client-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; Server-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user and transmit these input events to the Server and to actually draw the computer graphics, while the Server has the task of simulating the game itself but does not render any graphics for a user. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands. Quake III (and so Daemon) does this synchronization efficiently, the client receives a snapshot (a program object that contains data about the server's game state since the snapshot was sent to the client) and the client updates this snapshot with 'deltas' it receives from the server, these deltas are changes to the server game state and only these changes are transmitted.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: &amp;lt;code&amp;gt;CGameVM&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;GameVM&amp;lt;/code&amp;gt;. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). This main function is called by the Virtual Machine, all game-logic modules must implement this function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The main functions of the exes calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
==Client-Side==&lt;br /&gt;
&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Server-Side==&lt;br /&gt;
&lt;br /&gt;
Server game state initialization occurs in &amp;lt;code&amp;gt;G_InitGame()&amp;lt;/code&amp;gt; in {{SourceFile|src/sgame/sg_main.cpp}}.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5067</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5067"/>
		<updated>2021-07-05T00:56:41Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* System Architecture */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code &amp;amp;amp; Data Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; Client-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; Server-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user and transmit these input events to the Server and to actually draw the computer graphics, while the Server has the task of simulating the game itself but does not render any graphics for a user. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machines:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: &amp;lt;code&amp;gt;CGameVM&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;GameVM&amp;lt;/code&amp;gt;. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). This main function is called by the Virtual Machine, all game-logic modules must implement this function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The main functions of the exes calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
==Client-Side==&lt;br /&gt;
&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Server-Side==&lt;br /&gt;
&lt;br /&gt;
Server game state initialization occurs in &amp;lt;code&amp;gt;G_InitGame()&amp;lt;/code&amp;gt; in {{SourceFile|src/sgame/sg_main.cpp}}.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5066</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5066"/>
		<updated>2021-07-05T00:55:37Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* System Architecture */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code &amp;amp;amp; Data Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; Client-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; Server-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user and transmit these input events to the Server and to actually draw the computer graphics, while the Server has the task of simulating the game itself but does not render any graphics for a user. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machiness:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay. The Daemon engine and the virtual machines are in the system code category while the Unvanquished game code is in the game-logic code category.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: &amp;lt;code&amp;gt;CGameVM&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;GameVM&amp;lt;/code&amp;gt;. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). This main function is called by the Virtual Machine, all game-logic modules must implement this function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The main functions of the exes calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
==Client-Side==&lt;br /&gt;
&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Server-Side==&lt;br /&gt;
&lt;br /&gt;
Server game state initialization occurs in &amp;lt;code&amp;gt;G_InitGame()&amp;lt;/code&amp;gt; in {{SourceFile|src/sgame/sg_main.cpp}}.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5065</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5065"/>
		<updated>2021-07-05T00:49:21Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* System Architecture */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code &amp;amp;amp; Data Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; Client-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; Server-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
'''General:'''&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user and transmit these input events to the Server and to actually draw the computer graphics, while the Server has the task of simulating the game itself but does not render any graphics for a user. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands.&lt;br /&gt;
&lt;br /&gt;
'''The Virtual Machiness:'''&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
'''Code Categorization:'''&lt;br /&gt;
The code of Daemon and Unvanquished are 2 categories: the engine system code the game Unvanquished is based on and the actual game-logic code that defines playable game objects and gameplay.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: &amp;lt;code&amp;gt;CGameVM&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;GameVM&amp;lt;/code&amp;gt;. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). This main function is called by the Virtual Machine, all game-logic modules must implement this function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The main functions of the exes calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
==Client-Side==&lt;br /&gt;
&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Server-Side==&lt;br /&gt;
&lt;br /&gt;
Server game state initialization occurs in &amp;lt;code&amp;gt;G_InitGame()&amp;lt;/code&amp;gt; in {{SourceFile|src/sgame/sg_main.cpp}}.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5064</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5064"/>
		<updated>2021-07-05T00:47:07Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Program Ignition and Initialization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code &amp;amp;amp; Data Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; Client-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; Server-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user and transmit these input events to the Server and to actually draw the computer graphics, while the Server has the task of simulating the game itself but does not render any graphics for a user. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands.&lt;br /&gt;
&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: &amp;lt;code&amp;gt;CGameVM&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;GameVM&amp;lt;/code&amp;gt;. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server game-logic modules is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). This main function is called by the Virtual Machine, all game-logic modules must implement this function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The main functions of the exes calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
==Client-Side==&lt;br /&gt;
&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Server-Side==&lt;br /&gt;
&lt;br /&gt;
Server game state initialization occurs in &amp;lt;code&amp;gt;G_InitGame()&amp;lt;/code&amp;gt; in {{SourceFile|src/sgame/sg_main.cpp}}.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5063</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5063"/>
		<updated>2021-07-05T00:45:04Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code &amp;amp;amp; Data Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; Client-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; Server-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user and transmit these input events to the Server and to actually draw the computer graphics, while the Server has the task of simulating the game itself but does not render any graphics for a user. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands.&lt;br /&gt;
&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Virtual Machines:'''&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: &amp;lt;code&amp;gt;CGameVM&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;GameVM&amp;lt;/code&amp;gt;. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
'''Initialization for Game-Logic Modules:'''&lt;br /&gt;
The entrance into the program code for the client and server is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). This main function is called by the Virtual Machine, all game-logic modules must implement this function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the virtual machine for the game-logic module (for example: the client virtual machine invokes '''Main''' of VMMain.cpp for the client game-logic module) and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The main functions of the exes calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
==Client-Side==&lt;br /&gt;
&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Server-Side==&lt;br /&gt;
&lt;br /&gt;
Server game state initialization occurs in &amp;lt;code&amp;gt;G_InitGame()&amp;lt;/code&amp;gt; in {{SourceFile|src/sgame/sg_main.cpp}}.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5062</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5062"/>
		<updated>2021-07-05T00:40:34Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Program Ignition and Initialization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code &amp;amp;amp; Data Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; Client-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; Server-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user and transmit these input events to the Server and to actually draw the computer graphics, while the Server has the task of simulating the game itself but does not render any graphics for a user. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands.&lt;br /&gt;
&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Initialization for Virtual Machines==&lt;br /&gt;
There are two virtual machines as parts of the Daemon and Unvanquished game systems: &amp;lt;code&amp;gt;CGameVM&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;GameVM&amp;lt;/code&amp;gt;. '''CGameVM''' is the virtual machine for the client and '''GameVM''' is the virtual machine for the server. See daemon/src/engine/client/client.h for the class declaration of the client VM and daemon/src/engine/server/server.h for the class declaration of the server VM.&lt;br /&gt;
&lt;br /&gt;
The client VM is created with a call to &amp;lt;code&amp;gt;CGameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void CL_StartHunkUsers()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;void CL_Disconnect( bool ''showMainMenu'' )&amp;lt;/code&amp;gt;. See daemon/src/engine/client/cl_cgame.cpp.&lt;br /&gt;
&lt;br /&gt;
The server VM is created with a call to &amp;lt;code&amp;gt;void GameVM::Start()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_InitGameProgs()&amp;lt;/code&amp;gt; and this is called from &amp;lt;code&amp;gt;void SV_SpawnServer(std::string ''pakname'', std::string ''mapname'')&amp;lt;/code&amp;gt;. The server VM is created when the server game starts running. See daemon/src/engine/server/sv_init.cpp.&lt;br /&gt;
&lt;br /&gt;
== Initialization for Game-Logic Modules==&lt;br /&gt;
&lt;br /&gt;
The entrance into the program code for the client and server is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). This main function is called by the Virtual Machine, all game-logic modules must implement this function. Each game-logic module has its own VM, the '''cgame''' (as in client game) and '''sgame''' (as in server game) has their own VMs. The '''cgame''' VM is the class '''CGameVM''', its class declaration is inside daemon/src/engine/client/client.h. The '''sgame''' VM is the class '''GameVM''', its class declaration is inside daemon/src/engine/server/server.h. Both VMs inherit from &amp;lt;code&amp;gt;VM::VMBase&amp;lt;/code&amp;gt;. Each VM has a function called &amp;lt;code&amp;gt;Start()&amp;lt;/code&amp;gt; and this is the function that actually creates a new VM (via a call to &amp;lt;code&amp;gt;Create()&amp;lt;/code&amp;gt; and initiates the game-logic module.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the engine's VM loader and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The main functions of the exes calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
==Client-Side==&lt;br /&gt;
&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Server-Side==&lt;br /&gt;
&lt;br /&gt;
Server game state initialization occurs in &amp;lt;code&amp;gt;G_InitGame()&amp;lt;/code&amp;gt; in {{SourceFile|src/sgame/sg_main.cpp}}.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5061</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5061"/>
		<updated>2021-07-05T00:15:53Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* System Architecture */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code &amp;amp;amp; Data Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; Client-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; Server-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user and transmit these input events to the Server and to actually draw the computer graphics, while the Server has the task of simulating the game itself but does not render any graphics for a user. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands.&lt;br /&gt;
&lt;br /&gt;
The Daemon and Unvanquished systems are ultimately descendants of the original Quake III Arena game engine known as Id 3. The Id 3 game engine has a virtual machine incorporated into the executable program and functions as an intermediary between the actual game logic code and the engine. The game logic system interfaces with the virtual machine to invoke engine functionalities, the game code does not invoke engine functions itself, the virtual machine does that action. Communication between the game code and the engine happens via Inter-Process Communication (IPC) through special pipe files, the engine sends messages to a virtual machine and the virtual machine invokes game code functions according to the type of message it receives from the engine. The game logic sends messages to the virtual machine to invoke engine functions. The client subsystem of Daemon has its own virtual machine and the server subsystem of Daemon has its own virtual machine.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
The entrance into the program code for the client and server is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). This main function is called by the Virtual Machine, all game-logic modules must implement this function. Each game-logic module has its own VM, the '''cgame''' (as in client game) and '''sgame''' (as in server game) has their own VMs. The '''cgame''' VM is the class '''CGameVM''', its class declaration is inside daemon/src/engine/client/client.h. The '''sgame''' VM is the class '''GameVM''', its class declaration is inside daemon/src/engine/server/server.h. Both VMs inherit from &amp;lt;code&amp;gt;VM::VMBase&amp;lt;/code&amp;gt;. Each VM has a function called &amp;lt;code&amp;gt;Start()&amp;lt;/code&amp;gt; and this is the function that actually creates a new VM (via a call to &amp;lt;code&amp;gt;Create()&amp;lt;/code&amp;gt; and initiates the game-logic module.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the engine's VM loader and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The main functions of the exes calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
==Client-Side==&lt;br /&gt;
&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Server-Side==&lt;br /&gt;
&lt;br /&gt;
Server game state initialization occurs in &amp;lt;code&amp;gt;G_InitGame()&amp;lt;/code&amp;gt; in {{SourceFile|src/sgame/sg_main.cpp}}.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5060</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5060"/>
		<updated>2021-07-04T23:57:57Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: /* Program Ignition and Initialization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code &amp;amp;amp; Data Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; Client-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; Server-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user and transmit these input events to the Server and to actually draw the computer graphics, while the Server has the task of simulating the game itself but does not render any graphics for a user. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
The entrance into the program code for the client and server is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). This main function is called by the Virtual Machine, all game-logic modules must implement this function. Each game-logic module has its own VM, the '''cgame''' (as in client game) and '''sgame''' (as in server game) has their own VMs. The '''cgame''' VM is the class '''CGameVM''', its class declaration is inside daemon/src/engine/client/client.h. The '''sgame''' VM is the class '''GameVM''', its class declaration is inside daemon/src/engine/server/server.h. Both VMs inherit from &amp;lt;code&amp;gt;VM::VMBase&amp;lt;/code&amp;gt;. Each VM has a function called &amp;lt;code&amp;gt;Start()&amp;lt;/code&amp;gt; and this is the function that actually creates a new VM (via a call to &amp;lt;code&amp;gt;Create()&amp;lt;/code&amp;gt; and initiates the game-logic module.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the engine's VM loader and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The main functions of the exes calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
==Client-Side==&lt;br /&gt;
&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Server-Side==&lt;br /&gt;
&lt;br /&gt;
Server game state initialization occurs in &amp;lt;code&amp;gt;G_InitGame()&amp;lt;/code&amp;gt; in {{SourceFile|src/sgame/sg_main.cpp}}.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5059</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5059"/>
		<updated>2021-07-04T23:17:37Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code &amp;amp;amp; Data Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; Client-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; Server-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user and transmit these input events to the Server and to actually draw the computer graphics, while the Server has the task of simulating the game itself but does not render any graphics for a user. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
The entrance into the program code for the client and server is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). This main function is called by the Virtual Machine, all game-logic modules must implement this function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the engine's VM loader and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The main functions of the exes calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
The function of the Client is to receive input events generated by the human user and transmit these events to the Server, and to draw computer generated graphics to the user's screen.&lt;br /&gt;
&lt;br /&gt;
Input is received through SDL input capture, see the function &amp;lt;code&amp;gt;void IN_Frame()&amp;lt;/code&amp;gt; of ''daemon/src/engine/sys/SDL_Input.cpp''.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
==Client-Side==&lt;br /&gt;
&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Server-Side==&lt;br /&gt;
&lt;br /&gt;
Server game state initialization occurs in &amp;lt;code&amp;gt;G_InitGame()&amp;lt;/code&amp;gt; in {{SourceFile|src/sgame/sg_main.cpp}}.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
	<entry>
		<id>https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5058</id>
		<title>Technical Documentation</title>
		<link rel="alternate" type="text/html" href="https://staging-wiki.unvanquished.net/index.php?title=Technical_Documentation&amp;diff=5058"/>
		<updated>2021-07-04T23:08:05Z</updated>

		<summary type="html">&lt;p&gt;The White Lion: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OutOfDate}}&lt;br /&gt;
&lt;br /&gt;
If you have a question that is not answered here, you can always hop on [[IRC]].&lt;br /&gt;
&lt;br /&gt;
==Getting Started==&lt;br /&gt;
&lt;br /&gt;
If you have not already, go [[Getting_the_source|get the code]], read up on your options for [[development environments]], and [[Compiling_the_source|compile it]]. Instructions are available for a variety of platforms. If your platform of choice is not listed, you are welcome to add instructions for it.&lt;br /&gt;
&lt;br /&gt;
From there, play the game! The [[Running the game]] page contains documentation on all the most commonly used and user-accessible commands and console variables. If you have trouble, see the [[troubleshooting]] page for possible solutions. &lt;br /&gt;
&lt;br /&gt;
There are also very detailed instructions on [[Testing|testing the game]], which includes information on using sophisticated profiling tools such as apitrace, GPUPerfStudio, gDEBugger, valgrind, and clang-analyzer.&lt;br /&gt;
&lt;br /&gt;
===Need something to work on?===&lt;br /&gt;
&lt;br /&gt;
There are all sorts of existing tasks listed on our [https://github.com/Unvanquished/Unvanquished/issues issues reported on the bug tracker] you are free to fix.  Please drop in on [[IRC]] and tell us what you're up to.&lt;br /&gt;
&lt;br /&gt;
===Giving Back===&lt;br /&gt;
&lt;br /&gt;
You are welcome to contribute in any way possible! We have [[Contributing/Code|guidelines for contributing code]] as well as documentation on [[Coding_convention|coding conventions]].&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
If you are attempting to generate the Microsoft Visual Studio solution file for the Unvanquished game system make sure you have installed all Python related dependencies for cmake to generate the solution file. If cmake fails to generate the solution file because of alleged missing Python dependencies but you know you have them for a fact then check the cmake variable &amp;lt;code&amp;gt;_Python_EXECUTABLE_&amp;lt;/code&amp;gt; that its value is set to the location of the Python executable of the Python installation having the dependencies, for example &amp;quot;C:\Program Files\Python39\python.exe&amp;quot; and not the Python executable obtained from the Windows App Store &amp;quot;C:\Program Files\WindowsApps\...&amp;quot;. Pip would install Python dependencies for the non-Windows App Store executable.&lt;br /&gt;
&lt;br /&gt;
==Language Oddities==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You must use the &amp;lt;code&amp;gt;INLINE&amp;lt;/code&amp;gt; macro instead of &amp;lt;code&amp;gt;inline&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;li&amp;gt;You must cast integers that are being used as enum values to an enum type. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BG_Class ( ( class_t ) self-&amp;gt;client-&amp;gt;ps.stats[ STAT_CLASS ] )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source Code &amp;amp;amp; Data Structure==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;pkg/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;unvanquished_src.dpkdir&amp;lt;/code&amp;gt; Data submodule.&lt;br /&gt;
*** &amp;lt;code&amp;gt;fonts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;gfx/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;lights/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;models/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;scripts/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;sound/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;translation/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;ui/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;daemon/&amp;lt;/code&amp;gt; Engine submodule.&lt;br /&gt;
** &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt; Engine source code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;common/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;engine/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;audio/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;botlib/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;crash_server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;framework/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;null/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;qcommon/&amp;lt;/code&amp;gt; Common code: utility functions, typedefs, macros, and the like.&lt;br /&gt;
**** &amp;lt;code&amp;gt;renderer/&amp;lt;/code&amp;gt; Renderer.&lt;br /&gt;
***** &amp;lt;code&amp;gt;glsl_source/&amp;lt;/code&amp;gt; OpenGL shader code.&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;sys/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;client/&amp;lt;/code&amp;gt;&lt;br /&gt;
**** &amp;lt;code&amp;gt;server/&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;src/&amp;lt;/code&amp;gt; Code that falls outside the scope of the core engine. Client and server game codes run in separate [[virtual machines]].&lt;br /&gt;
*** &amp;lt;code&amp;gt;cgame/&amp;lt;/code&amp;gt; Client-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;sgame/&amp;lt;/code&amp;gt; Server-side game code.&lt;br /&gt;
*** &amp;lt;code&amp;gt;shared/&amp;lt;/code&amp;gt;&lt;br /&gt;
*** &amp;lt;code&amp;gt;utils/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==System Architecture==&lt;br /&gt;
&lt;br /&gt;
The architecture of the Daemon game engine is fundamentally the Client and Server architecture. In essence the Client uses a service provided by the Server. In the case of Daemon and Unvanquished, the service is the game Unvanquished and the Client receives this game when the Client connects to the game Server. The Client and Server are two different programs executed on the computer, the Client is &amp;quot;daemon.exe&amp;quot; and the Server is &amp;quot;daemonded.exe&amp;quot;. This separation into two different programs makes it possible for the Server program to be executed on a machine a part of another computer network connected to the Internet so the Server and Client does not necessarily execute on the same computer machine but the same machine can execute both Client and Server (hence 'local' game, the Client connects to the server running on the host machine &amp;quot;127.0.0.1&amp;quot;).&lt;br /&gt;
The Client and Server do different things. The Client has the task of receiving input by the user and transmit these input events to the Server and to actually draw the computer graphics, while the Server has the task of simulating the game itself but does not render any graphics for a user. Each entity in this relationship keeps separate game states and these game states must be synchronized, whatever happens on the side of the Server game is transmitted to the Client as game updates and anything the Client needs to happen must be transmitted to the Server as client commands.&lt;br /&gt;
&lt;br /&gt;
==Program Ignition and Initialization==&lt;br /&gt;
The engine system is compiled into a static library (.lib file) and linked into (incorporated) the client executable (&amp;quot;daemon.exe&amp;quot;) (and the server executable &amp;quot;daemonded.exe&amp;quot;), this means that when the program (application) is started by double-clicking the file in the WindowsOS GUI the engine is loaded into memory.&lt;br /&gt;
&lt;br /&gt;
The entry point into the game system is the function &amp;lt;code&amp;gt;ALIGN_STACK_FOR_MINGW int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 666 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L666]). This function is called by SDL and is macro defined as SDL_main (see SDL_main.h, lines 120-121). &lt;br /&gt;
&lt;br /&gt;
Main (SDL_main) calls &amp;lt;code&amp;gt;static void Init(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; in the file System.cpp at line 525 (as of the latest Github commit for 28 June 2021 [https://github.com/DaemonEngine/Daemon/blob/b5e4eedca774adddb8f786851966def7e29680c7/src/engine/framework/System.cpp#L525]), this function initializes the engine and any error that happens here is fatal. As part of the initialization procedure, a special pipe file is created within the base game directory file tree structure, the game communicates with the engine through this pipe file, both the engine system and game system shares this pipe file to communicate data to each other.&lt;br /&gt;
&lt;br /&gt;
The entrance into the program code for the client and server is the function &amp;lt;code&amp;gt;int main(int ''argc'', char** ''argv'')&amp;lt;/code&amp;gt; of VMMain.cpp at line 120, this is true only if the client and server are built as executables, this code is not compiled if the client and server are compiled into dynamic link libraries (dlls). This main function is called by the Virtual Machine, all game-logic modules must implement this function.&lt;br /&gt;
&lt;br /&gt;
This entry point is called by the engine's VM loader and it is not designed to be invoked directly (activating the executable by double-clicking on the exe file in WindowsOS). The main functions of the exes calls &amp;lt;code&amp;gt;static void CommonInit(Sys::OSHandle ''rootsocket'')&amp;lt;/code&amp;gt; and from within this function the program enters its main (infinite) loop (&amp;lt;code&amp;gt;while(true)&amp;lt;/code&amp;gt;) and this function interfaces with the virtual machine with the function &amp;lt;code&amp;gt;void VM::VMHandleSyscall(uint32_t ''id'', Util::Reader ''reader'')&amp;lt;/code&amp;gt;, this function is contained within the sg_api.cpp (src/sgame/sg_api.cpp) and cg_api.cpp (src/cgame/cg_api.cpp) files.&lt;br /&gt;
&lt;br /&gt;
The sg_api.cpp file contains code that receives messages from its VM and executes function callbacks depending on the type of message received. The initialization related messages are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_STATIC_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1.&amp;lt;code&amp;gt;VM::InitializeProxies(''milliseconds'')&amp;lt;/code&amp;gt; - invokes 2 other initialization functions, &amp;lt;code&amp;gt;Cmd::InitializeProxy()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Cvar::InitializeProxy()&amp;lt;/code&amp;gt;, to register commands with the VM and to register global static client variables (cvars).&lt;br /&gt;
&lt;br /&gt;
2.&amp;lt;code&amp;gt;FS::Initialize()&amp;lt;/code&amp;gt; - sends a message to the VM and the VM interfaces with the engine to initialize the filesystem.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;code&amp;gt;VM::VMInit()&amp;lt;/code&amp;gt; - makes the VM allocate memory for clients and game entities and loads map collision data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;GAME_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. Sets &amp;lt;code&amp;gt;g_cheats.integer&amp;lt;/code&amp;gt; to the parameter value of &amp;lt;code&amp;gt;''cheats''&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; - this function is called from sg_main.cpp and performs many functions, such as setting the cvars inside the VM to default values, and defines global level variables, and sets up logging, and gets server info, and loads config files, and initializes entities for the game, and loads emoticons, and etc. see &amp;lt;code&amp;gt;G_InitGame&amp;lt;/code&amp;gt; of sg_main.cpp at about line 690 for more details.&lt;br /&gt;
&lt;br /&gt;
The init message codes are different for cg_api.cpp, &amp;lt;code&amp;gt;CG_STATIC_INIT&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt;, the purpose of them both are the same, although there are some minor differences. See cg_api.cpp for more information. The &amp;lt;code&amp;gt;CG_INIT&amp;lt;/code&amp;gt; message is generated by the engine and transmitted to the client game-logic module for processing, the message originates from src/engine/client/cl_cgame.cpp within the function &amp;lt;code&amp;gt;void CGameVM::CGameInit(int serverMessageNum, int clientNum)&amp;lt;/code&amp;gt;. There is one initialization message unique to cg_api.cpp and that is &amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;CG_ROCKET_VM_INIT&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;code&amp;gt;CG_Rocket_Init&amp;lt;/code&amp;gt; - essentially starts the user interface for the game, the user interface for the game is based on libRocket.&lt;br /&gt;
&lt;br /&gt;
Some information related to the VM and program ignition, from a comment in the file src/engine/framework/VirtualMachine.h:&lt;br /&gt;
&lt;br /&gt;
 * To better support mods the gamelogic is treated like any other asset and can&lt;br /&gt;
 * be downloaded from a server. However it is considered untrusted code so we&lt;br /&gt;
 * need to run it in a sandbox. We use NaCl to provide the sandboxing which&lt;br /&gt;
 * means that the gamelogic is in another process and that we have to use IPC and&lt;br /&gt;
 * shared memory to communicate with it.&lt;br /&gt;
 *&lt;br /&gt;
 * The gamelogic can be compiled to and ran from several executable formats that&lt;br /&gt;
 * will all start at the &amp;quot;main&amp;quot; function whose first job will be to retrieve the&lt;br /&gt;
 * root socket handle to communicate with the engine. The different executable&lt;br /&gt;
 * formats are:&lt;br /&gt;
 *  - A native shared library loaded at runtime and started in the engine process,&lt;br /&gt;
 * this shared lib exports a &amp;quot;main&amp;quot; function pointer which is called by the&lt;br /&gt;
 * engine, providing a handle to the root socket in argv[1]. Because the gamelogic&lt;br /&gt;
 * lives in the same process as the engine, any leaks in the gamelogic will be&lt;br /&gt;
 * engine leaks. However because it is in the same process, it is easier to debug&lt;br /&gt;
 * as the debugger doesn't automatically attach to child process.&lt;br /&gt;
 *  - An NaCl executable started in a new sandboxed process. The &amp;quot;main&amp;quot; function is&lt;br /&gt;
 * ran first and the root socket handle is given via an environment variable. This&lt;br /&gt;
 * is how the gamelogic is ran when we do not trust the code as it won't be able to&lt;br /&gt;
 * access anything apart from the file handles the engine gives it. When the NaCl&lt;br /&gt;
 * gamelogic exits the OS will clean up any leaks for us. It is also slightly slower&lt;br /&gt;
 * than native format (no SSE and code alignment constraints).&lt;br /&gt;
 *  - A native executable started in a new process, obviously the &amp;quot;main&amp;quot; function&lt;br /&gt;
 * is the first one ran. The root socket handle is given in argv[1]. It doesn't&lt;br /&gt;
 * provide sandboxing like the nacl executable but the OS will still clean up any&lt;br /&gt;
 * leak for us.&lt;br /&gt;
 *&lt;br /&gt;
 * When setting the cgame VM type to non-default values, make sure to use /devmap&lt;br /&gt;
 * (rather than /map) as it is a 'CHEAT' cvar.&lt;br /&gt;
 *&lt;br /&gt;
 * TL;DR&lt;br /&gt;
 * - Native DLL: no sandboxing, no cleaning up but debugger support. Use for dev.&lt;br /&gt;
 * - NaCl exe: sandboxing, no leaks, slightly slower, hard to debug. Use for regular players.&lt;br /&gt;
 * - Native exe: no sandboxing, no leaks, hard to debug. Might be used by server owners for perf.&lt;br /&gt;
&lt;br /&gt;
==Lag Compensation==&lt;br /&gt;
&lt;br /&gt;
Daemon uses Neil &amp;quot;haste&amp;quot; Toronto's [https://www.ra.is/unlagged/contents.html Unlagged mod].&lt;br /&gt;
&lt;br /&gt;
==Data Files==&lt;br /&gt;
&lt;br /&gt;
Daemon uses a variety of file formats. Many of these formats are custom. &amp;lt;!-- just try and provide a dump of all configuration files, then I'll reorganize them --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Bot behavior trees&lt;br /&gt;
* Player configuration files&lt;br /&gt;
** Crosshair configuration&lt;br /&gt;
** Pubkey&lt;br /&gt;
** GUID&lt;br /&gt;
* Server configuration files&lt;br /&gt;
** [[Map_layouts|Map layouts]]&lt;br /&gt;
** Map rotations&lt;br /&gt;
* Particle &amp;amp; trail system files&lt;br /&gt;
* Sound configurations&lt;br /&gt;
** [[Music_and_sounds#Buildables|Buildables]]&lt;br /&gt;
* Model data ([[Exporting_Models#What_is_MD5.3F|discussion of supported formats]])&lt;br /&gt;
** Skins&lt;br /&gt;
** [[Exporting_Models#MD3_3|MD3 animation configuration files]] &amp;amp;mdash; specify which frames are for which animations&lt;br /&gt;
** Configuration files&lt;br /&gt;
*** [[Exporting_Models#Buildables_2|Buildables]]&lt;br /&gt;
*** [[Exporting_Models#Weapons_2|Weapons]]&lt;br /&gt;
*** [[Exporting_Models#Player_models_2|Player models]]&lt;br /&gt;
* Map data&lt;br /&gt;
** Map geometry (BSPs)&lt;br /&gt;
** Color grading configurations&lt;br /&gt;
&lt;br /&gt;
==Game Logic==&lt;br /&gt;
&lt;br /&gt;
Game logic is split into twos areas: server-side, and client-side, user interface is part of client side. Each runs in its own [[Virtual_machines|virtual machine]].&lt;br /&gt;
&lt;br /&gt;
On Quake 3 derivatives like Tremulous, there was &amp;lt;code&amp;gt;cgame.qvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;game.qvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ui.qvm&amp;lt;/code&amp;gt; (client-side, server-side, user interface).&lt;br /&gt;
&lt;br /&gt;
With Dæmon Engine and Unvanquished there are &amp;lt;code&amp;gt;cgame.nexe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sgame.nexe&amp;lt;/code&amp;gt; (client-side and server-side).&lt;br /&gt;
&lt;br /&gt;
==Client-Side==&lt;br /&gt;
&lt;br /&gt;
Buildable information is encapsulated in the &amp;lt;code&amp;gt;cg_buildables&amp;lt;/code&amp;gt; array (declared in {{SourceFile|src/cgame/cg_main.cpp}})&lt;br /&gt;
&lt;br /&gt;
Constants used to define gamelogic variables are in {{SourceFile|src/shared/bg_gameplay.h}}.&lt;br /&gt;
&lt;br /&gt;
Types:&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableInfo_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates data associated with buildables (sounds, animations, etc.).&lt;br /&gt;
* &amp;lt;code&amp;gt;buildable_t&amp;lt;/code&amp;gt; &amp;amp;mdash; An enumeration of all buildable types.&lt;br /&gt;
* &amp;lt;code&amp;gt;buildableAttributes_t&amp;lt;/code&amp;gt; &amp;amp;mdash; Encapsulates gameplay information associated with buildables. There is an array of these called &amp;lt;code&amp;gt;bg_buildableList&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Server-Side==&lt;br /&gt;
&lt;br /&gt;
Server game state initialization occurs in &amp;lt;code&amp;gt;G_InitGame()&amp;lt;/code&amp;gt; in {{SourceFile|src/sgame/sg_main.cpp}}.&lt;br /&gt;
&lt;br /&gt;
==Particle &amp;amp;amp; Trail System==&lt;br /&gt;
&lt;br /&gt;
For now, please see the [https://dl.unvanquished.net/docs/20060317-000.tremulous-manual.pdf Tremulous documentation].&lt;br /&gt;
&lt;br /&gt;
==GL3 Renderer==&lt;br /&gt;
&lt;br /&gt;
Source code for the modern OpenGL renderer is located in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer}}. This renderer is sometime referred to as the &amp;quot;GL3&amp;quot; renderer in opposite to the now-removed  “legacy” renderer (also called “vanilla” in the past).&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
* Shaders are implemented as subclasses of the &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt; class. All are defined in {{SourceFile|repository=DaemonEngine/Daemon|src/engine/renderer/gl_shader.h}}.&lt;br /&gt;
* Each GLSL shader has their compilation and loading controlled by the single &amp;lt;code&amp;gt;GLShaderManager&amp;lt;/code&amp;gt; class&lt;br /&gt;
* Compiled shaders are cached to disk when possible to speed up load times&lt;br /&gt;
* Shader compilation may be done up front before the game loads, or delayed till the main menu depending on the value of &amp;lt;code&amp;gt;r_lazyShaders&amp;lt;/code&amp;gt;&lt;br /&gt;
* All possible parameters (what OpenGL calls [http://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml &amp;quot;uniform variables&amp;quot;]) that may be passed to a shader are enumerated through multiple inheritance.&amp;lt;br/&amp;gt;For Example, &amp;lt;code&amp;gt;gl_genericShader&amp;lt;/code&amp;gt; is of type &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; which derives from the following classes.&amp;lt;br/&amp;gt;That list may be obsolete, see &amp;lt;code&amp;gt;GLShader_generic&amp;lt;/code&amp;gt; class definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} for up to date information:&lt;br /&gt;
** &amp;lt;code&amp;gt;GLShader&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorTextureMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewOrigin&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ViewUp&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_AlphaThreshold&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ModelViewProjectionMatrix&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_ColorModulate&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Color&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_Bones&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_VertexInterpolation&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;u_DepthScale&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLDeformStage&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;u_*&amp;lt;/code&amp;gt; parent classes provide functions that allow external code to set shader uniforms. e.g &amp;lt;code&amp;gt;gl_genericShader-&amp;gt;SetUniform_ColorTextureMatrix()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GLSL shaders may be found in &amp;lt;code&amp;gt;src/engine/renderer/glsl_source&amp;lt;/code&amp;gt;. Please see the [[GLSL Shaders|full article]] for a complete listing.&lt;br /&gt;
&lt;br /&gt;
===Helper Classes===&lt;br /&gt;
&lt;br /&gt;
As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.&lt;br /&gt;
&lt;br /&gt;
====Compile Macros====&lt;br /&gt;
&lt;br /&gt;
Compile macros are used to reduce the number of uniforms needed, and speed up execution by eliminating useless &amp;lt;code&amp;gt;if ( )&amp;lt;/code&amp;gt; statements.&lt;br /&gt;
&lt;br /&gt;
They also allow for easy code reuse when turning off some features like e.g Normal Mapping.&lt;br /&gt;
&lt;br /&gt;
Compile macros are set when rendering before the call to &amp;lt;code&amp;gt;shader-&amp;gt;BindProgram()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
This list may be obsolete, an updated list can be found in the &amp;lt;code&amp;gt;EGLCompileMacro&amp;lt;/code&amp;gt; enum definition in {{SourceFile|repository=DaemonEngine/daemon|src/engine/renderer/gl_shader.h}} file:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_BSP_SURFACE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SKINNING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_ANIMATION&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_VERTEX_SPRITE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_ENVIRONMENT&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_TCGEN_LIGHTMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_LIGHT_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DELUXE_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_HEIGHTMAP_IN_NORMALMAP&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_RELIEF_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_REFLECTIVE_SPECULAR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_LIGHT_DIRECTIONAL&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_SHADOWING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_DEPTH_FADE&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_PHYSICAL_MAPPING&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;GLCompileMacro_USE_ALPHA_TESTING&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
Mac OS X users with XCode installed can access OpenGL man pages via the terminal. &amp;lt;!-- TODO: discuss how to get these on windows or linux? --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, OpenGL API reference documentation is available online:&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language (GLSL) Reference Pages]&lt;br /&gt;
* [http://www.khronos.org/files/opengl-quick-reference-card.pdf OpenGL 3.3 &amp;amp;amp; GLSL Quick Reference Card]&lt;br /&gt;
&lt;br /&gt;
==Valgrind and OpenGL drivers==&lt;br /&gt;
&lt;br /&gt;
Some OpenGL drivers may cause Valgrind to spew out a lot of false errors. You can suppress these by using the &amp;lt;code&amp;gt;--suppressions=/path/to/file.supp&amp;lt;/code&amp;gt; flag. You must pass the full path (no use of the tilde symbol). For example, the following [http://www.mediafire.com/?z6ehwrxpw2m469h file] can be used as a template for your suppression file when using the fglrx driver, keeping in mind that the location of the fglrx library may need to be changed. Note: the fglrx driver no longer exist, but the tip may apply to others drivers.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
===Publications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://halo.bungie.net/Inside/publications.aspx Bungie, Inc.] &amp;amp;mdash; creators of the Marathon, Myth, and Halo franchises.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://dice.se/publications/ DICE SE] &amp;amp;mdash; creators of the Battlefield franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.guerrilla-games.com/publications/ Guerilla Games] &amp;amp;mdash; creators of the Killzone franchise.&lt;br /&gt;
&amp;lt;p&amp;gt;Also of interest is the &amp;quot;Making of Killzone 2&amp;quot; video series, not listed on their site:&amp;lt;/p&amp;gt;&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-1?objectid=748475 Part 1]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-2?objectid=748475 Part 2]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-3?objectid=748475 Part 3]&lt;br /&gt;
* [http://www.ign.com/videos/2009/01/27/killzone-2-ps3-the-making-of-killzone-2-part-4?objectid=748475 Part 4]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[http://www.valvesoftware.com/company/publications.html Valve Software] &amp;amp;mdash; creators of the Half-Life franchise.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===General Game Development===&lt;br /&gt;
&lt;br /&gt;
* [http://devmaster.net/ Devmaster.net]&lt;br /&gt;
&lt;br /&gt;
===OpenGL===&lt;br /&gt;
&lt;br /&gt;
* [http://www.opengl.org/ Official OpenGL page]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/man3/ OpenGL 3.3 Reference Pages]&lt;br /&gt;
* [http://www.opengl.org/sdk/docs/manglsl/ OpenGL Shading Language Reference Pages]&lt;br /&gt;
* [http://arcsynthesis.org/gltut/ Learning Modern 3D Graphics Programming]&lt;br /&gt;
&lt;br /&gt;
===Quake===&lt;br /&gt;
&lt;br /&gt;
* [http://fd.fabiensanglard.net/doom3/pdfs/johnc-plan_1999.pdf John Carmack's notes from development]&lt;br /&gt;
* &amp;quot;Looking at the Quake 3 Source&amp;quot;&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-1.html Part 1]&lt;br /&gt;
** [http://element61.blogspot.com/2005/08/looking-at-quake-3-source-part-2.html Part 2]&lt;br /&gt;
** [http://element61.blogspot.com/2005/09/looking-at-quake-3-source-part-3.html Part 3]&lt;br /&gt;
* [http://www.quakewiki.net/archives/code3arena/ Code3Arena]&lt;br /&gt;
* [http://www.modwiki.net/wiki/MD5_(file_format) MD5 file format] (website down since 2013, use https://web.archive.org/web/20120930061040/http://www.modwiki.net/wiki/MD5_%28file_format%29 )&lt;br /&gt;
* [http://tfc.duke.free.fr/coding/md5-specs-en.html Another MD5 format article]&lt;br /&gt;
* [http://fabiensanglard.net/quake3/index.php Quake 3 Source Code Review]&lt;br /&gt;
* [http://www.quake3world.com/forum/index.php Quake3World Discussion Forums]&lt;br /&gt;
* [http://wiki.ioquake3.org/ ioquake3 project wiki] &amp;amp;mdash; Primarily oriented for users, developers and server administrators.&lt;/div&gt;</summary>
		<author><name>The White Lion</name></author>
	</entry>
</feed>