Technical Documentation

From Unvanquished
Revision as of 13:31, 15 April 2013 by Velociostrich (Talk | contribs) (GL3 Renderer: Update renderer info)

Jump to: navigation, search

Currently, this page isn't of much help, but you can change that by editing it!

Branches

The following branches are under active development and may be of interest:

  • librocket — Work to integrate libRocket is being done on this branch. libRocket is a library that will allow us to create user interfaces using dialects of HTML and CSS.
  • bots2 — New bot code, using behavior trees.

Language Oddities

  • You must use the INLINE macro instead of inline.
  • You must cast integers that are being used as enum values to an enum type. For example:
    BG_Class ( ( class_t ) self->client->ps.stats[ STAT_CLASS ] )
    

Source code & data structure

  • main/ Data associated with the game.
    • def/ Entity definitions for Radiant.
    • fonts/
    • gfx/
    • glsl/ OpenGL shader code.
    • lights/
    • models/
    • scripts/
    • sound/
    • translation/
    • ui/
  • src/
    • engine/ Engine source code.
      • asm/
      • client/
      • null/
      • qcommon/
      • renderer/ Vanilla (fixed-function pipeline) renderer
      • rendererGL/ Modern XReal-based renderer
      • server/
      • sys/
    • gamelogic/ Code that falls outside the scope of the core engine. These are all run in separate virtual machines.
      • cgame/ Client-side game code.
      • game/ Server-side game code.
      • ui/ User interface code.

Program entry point

The main function may be found at around line 591 of src/engine/sys/sys_main.c. Note that some magic happens on the Mac in src/engine/sys/SDLMain.m.

Lag compensation

Daemon uses Neil "haste" Toronto's Unlagged mod.

Data Files

Daemon uses a variety of file formats. Many of these formats are custom.

Game logic

Buildable information is encapsulated in the cg_buildables array (declared in src/gamelogic/cgame/cg_main.c)

Constants used to define gamelogic variables are in src/gamelogic/game/tremulous.h.

Types:

  • buildableInfo_t — Encapsulates data associated with buildables (sounds, animations, etc.).
  • buildable_t — An enumeration of all buildable types.
  • buildableAttributes_t — Encapsulates gameplay information associated with buildables. There is an array of these called bg_buildableList.

Server-side

Server game state initialization occurs in G_InitGame() in src/gamelogic/game/g_main.c.

Particle & trail system

For now, please see the Tremulous documentation.

GL3 Renderer

Source code for the modern OpenGL renderer is located in src/engine/rendererGL. This renderer is often referred to as the "GL3" renderer, whereas the legacy renderer (found in src/engine/renderer) is often referred to as the "vanilla" renderer.

Notes

  • There is some (highly experimental and untested) Direct X code mixed in the modern OpenGL renderer code.

Shaders are implemented as subclasses of the GLShader class. All are defined in src/engine/rendererGL/gl_shader.h.

  • Compiled GLSL shader files (located in the hard-coded location "glsl/" with the .bin filename extension) are read by GLShader::LoadShaderBinary().
  • All possible parameters (what OpenGL calls "uniform variables") that may be passed to a shader are enumerated in the shaderProgram_t structure in src/engine/rendererGL/tr_local.h.
  • Shaders with duplicate functionality is achieved with multiple inheritance. E.g., gl_genericShader is of type GLShader_generic* which derives from the following classes:
    • GLShader
    • u_ColorMap
    • u_ColorTextureMatrix
    • u_ViewOrigin
    • u_AlphaTest
    • u_ModelMatrix
    • u_ModelViewProjectionMatrix
    • u_ColorModulate
    • u_Color
    • u_BoneMatrix
    • u_VertexInterpolation
    • u_PortalPlane
    • GLDeformStage
    • GLCompileMacro_USE_PORTAL_CLIPPING
    • GLCompileMacro_USE_ALPHA_TESTING
    • GLCompileMacro_USE_VERTEX_SKINNING
    • GLCompileMacro_USE_VERTEX_ANIMATION
    • GLCompileMacro_USE_DEFORM_VERTEXES
    • GLCompileMacro_USE_TCGEN_ENVIRONMENT
    • GLCompileMacro_USE_TCGEN_LIGHTMAP
  • GLSL shaders may be found in main/glsl/. Please see the full article for a complete listing.

Helper classes

As mentioned above, shader classes make use of multiple inheritance to give them the relevant methods for controlling their behavior.

Uniform variables

Uniform variables are enumerated in the shaderProgram_t structure in src/engine/rendererGL/tr_local.h, and are controlled by classes beginning with the u_ prefix:

  • u_BoneMatrix — Provides the convenience method SetUniform_BoneMatrix.

Compile macros

  • GLCompileMacro_USE_ALPHA_TESTING
  • GLCompileMacro_USE_PORTAL_CLIPPING
  • GLCompileMacro_USE_FRUSTUM_CLIPPING
  • GLCompileMacro_USE_VERTEX_SKINNING
  • GLCompileMacro_USE_VERTEX_ANIMATION
  • GLCompileMacro_USE_DEFORM_VERTEXES
  • GLCompileMacro_USE_TCGEN_ENVIRONMENT
  • GLCompileMacro_USE_TCGEN_LIGHTMAP
  • GLCompileMacro_USE_NORMAL_MAPPING
  • GLCompileMacro_USE_PARALLAX_MAPPING
  • GLCompileMacro_USE_REFLECTIVE_SPECULAR
  • GLCompileMacro_TWOSIDED
  • GLCompileMacro_EYE_OUTSIDE
  • GLCompileMacro_BRIGHTPASS_FILTER
  • GLCompileMacro_LIGHT_DIRECTIONAL
  • GLCompileMacro_USE_SHADOWING
  • GLCompileMacro_USE_GBUFFER

Resources

Mac OS X users with XCode installed can access OpenGL man pages via the terminal.

Alternatively, OpenGL API reference documentation is available online:

Valgrind and fglrx

fglrx drivers cause Valgrind to spew out a lot of false errors. You can suppress these by using the --suppressions=/path/to/file.supp flag. You must pass the full path (no use of the tilde symbol). The following file can be used as a template for your suppression file. Keep in mind that the location of the fglrx library may need to be changed.

Resources

Publications

General Game Development

OpenGL

Quake