Source code

From SRB2 Wiki
Jump to: navigation, search

Source code is text written in a computer programming language. This text, after being compiled into machine code, controls the behavior of a computer program. SRB2's source code is written in the C programming language. Since SRB2 is open-source, the source code is publicly available and may be edited by anyone. This article is designed to give an overview over the way SRB2's source code is organized.


SRB2's source code is hosted via GitHub and GitLab. The most important branches or revisions of note are linked below:

  • v2.1.19 Source code: GitHub GitLab - source code for the latest official release of SRB2
  • master branch: GitHub GitLab - source code for the latest public revision of SRB2 that does not break netgame compatibility with the latest official release
  • next branch: GitHub GitLab - source code for the latest public revision of SRB2. Unlike master, this branch may contain some features for the next version of SRB2, and is not netgame compatible with the latest official release

Refer to Using GitHub for more information on using Git and GitHub to publish and contribute code.

Source code compiling

Main article: Source code compiling


Files Description
am_map.c, am_map.h Automap code
asm_defs.incASM Macros for use with assembly
byteptr.h Macros used for reading/writing data to a UINT8 pointer, used for packet creation and such
b_bot.c, b_bot.h Basic bot handling
command.c, command.h Handles console commands and variables from console input, scripts, and remote server
comptime.c Compiles data and time. Code::Blocks, XCode and the Makefile touch this file to update the timestamp SRB2 CMake Configuration file. Also contains asset hashes for non-CMake builds
console.c, console.h Console drawing, input
d_clisrv.c, d_clisrv.h System-independent networking code (client, server)
d_event.h Input event types and variables, event_t structure
d_main.c, d_main.h SRB2 main program. Game startup, and main loop code, system specific interface stuff
d_net.c, d_net.h System-independent networking code (main)
d_netcmd.c, d_netcmd.h Host/client network commands
d_netfil.c, d_netfil.h File transferring code
d_player.h Definition of the player_t structure, which represents players. Also contains related enums for abilities, powers, shields, etc
d_think.h Definitions of thinker structures used for AI
d_ticcmd.h Definition of ticcmd_t and button flags enum, for player movement commands
dehacked.c, dehacked.h Handles reading of data from SOC lumps, freeslots, and constants. (Note: these files were originally for reading "patch" files made by DeHackEd, an editor for Doom)
doomdata.h Basic data structures used to represent levels on disk
doomdef.h Contains macros for EXE versioning, tic rate, players, skin colors, reserved linedef tags, development mode, code under testing, and so on. Also includes prototypes for commonly used functions (e.g.: CONS_Printf, CONS_Alert, I_Error, I_Assert)
doomstat.h All the global variables that store the internal state, includes mapheader_t definition
doomtype.h Common type definitions used throughout the source code, e.g. all basic integer types, boolean, compiler-specific macros
endian.h Macros for endianness detection
f_finale.c, f_finale.h Title screen, intro, game evaluation, and credits
fastcmp.h Contains the string comparison functions fasticmp, fastcmp and fastncmp
f_wipe.c Screen fade handling
filesrch.c, filesrch.h File-searching code
g_game.c, g_game.h High-level game stuff: transitions between game states, level exits, main game event responder, setting up new games, gamedata handling, demo recording
g_input.c, g_input.h Handles mouse/keyboard/joystick inputs, mapping of inputs to the player's controls
g_state.h Game states variables and enums
hu_stuff.c, hu_stuff.h Heads-up display: message display, Rankings/Scores HUD
i_addrinfo.c, i_addrinfo.h getaddr stubs, for lesser OSes
i_joy.h Header file for system-dependent joystick-handling code
i_net.h Header file for system-dependent network code
i_sound.h Header file for system-dependent sound, music, CD code
i_system.h Header file for miscellaneous system-dependent code
i_tcp.c, i_tcp.h TCP driver, sockets code
i_video.h Header file for system-dependent video code
info.c, info.h Object type and state definitions, sprite prefixes
keys.h Macros for non-alphanumeric key codes (ASCII, scancodes)
lua_baselib.c Lua: Basic library functions
lua_consolelib.c Lua: Console library - functions, command/consvar handling
lua_hook.h Lua: Hook library (header file)
lua_hooklib.c Lua: Hook library (source file) - initialisation, functions
lua_hud.h Lua: HUD library (header file)
lua_hudlib.c Lua: HUD library (source file) - custom HUD rendering functions, enable/disable flags, patch handling
lua_infolib.c Lua: Info-table library - handling of Object types, states, sounds, sprite prefixes, and custom actions
lua_libs.h Lua: Header file for Lua libraries, userdata macros
lua_maplib.c Lua: Map library - handling of map components (sectors, linedefs, vertexes, FOFs, etc) and level headers
lua_mathlib.c Lua: Math library - basic math functions, fixed-point and angle/trig math functions
lua_mobjlib.c Lua: Mobj library - handling of Objects and Things
lua_playerlib.c Lua: Player library - handling of players, button commands, powers
lua_script.c, lua_script.h Lua scripting basics
lua_skinlib.c Lua: Skin library - handling of skins
lua_thinkerlib.c Lua: Thinker library - the thinkers.iterate function
lzf.c, lzf.h LZF compression and decompression routines copied from lzf_d.c from liblzf 1.7
m_aatree.c, m_aatree.h Partial implementation of AA trees
m_anigif.c, m_anigif.h Animated GIF creation movie mode
m_argv.c, m_argv.h Command line arguments
m_bbox.c, m_bbox.h Bounding boxes
m_cheat.c, m_cheat.h Title screen cheat codes; console command cheats for Single Player (god, noclip and notarget), development mode and Pandora's Box; object placement mode
m_cond.c, m_cond.h Handling of unlockables, condition sets and emblems
m_dllist.h This is Lee Killough's smart double-linked list implementation with pointer-to-pointer prev links.
m_fixed.c, m_fixed.h Fixed point numbers - arithmetic functions, definition of FRACUNIT and FRACBITS macros
m_menu.c, m_menu.h Handling of selection menus, options, sliders and icons
m_misc.c, m_misc.h Miscellaneous functions: configuration file loading, writing screenshots, GIF and APNG movies, miscellaneous string functions, vector and matrix math, M_Memcpy setup
m_queue.c, m_queue.h Queue-handling functions
m_random.c, m_random.h Random number-generation functions, both RNG and PRNG
m_swap.h Macros used to swap endianness of 16-bit and 32-bit data
md5.c, md5.h MD5-handling functions (see RFC 1321, from April 1992)
mserv.c, mserv.h Handles communication with the Master Server
p5prof.h This file provides macros to profile your code
p_ceilng.c Ceiling movement thinkers
p_enemy.c Action pointer function definitions. Also contains functions for enemy thinking and AI
p_floor.c Floor movement thinkers, miscellaneous thinkers for map specials
p_inter.c Object interaction: item pickup functions, Object damage/death functions
p_lights.c Sector lighting effects (strobe, lightning, etc)
p_local.h Global header for gamelogic/behavior code (p_* functions)
p_map.c Object movement (collisions, teleportation, sector movement), sector node handling, some utility functions
p_maputl.c, p_maputl.h Utility functions for distance checking, movement and collision in maps. Includes functions for setting/removing sector and blockmap links for Objects and Object/linedef iteration using the blockmap
p_mobj.c, p_mobj.h Definition and handling of map Objects (or "mobj"s). Contains basic spawning/removal, movement, etc functions, and the P_MobjThinker thinker function for handling AI and physics
p_polyobj.c, p_polyobj.h Polyobjects (setup, movement, collision, thinkers, etc)
p_pspr.h Sprite frame flags, translucency tables
p_saveg.c, p_saveg.h Archiving/un-archiving of Single Player savegames and $$$.sav
p_setup.c, p_setup.h Loading of map data and setup, WAD file loading
p_sight.c Line of sight/visibility checks, uses REJECT lookup table.
p_slopes.c, p_slopes.h ZDoom + Eternity Engine Slopes, ported and enhanced by Kalaron
p_spec.c, p_spec.h Special effects: texture animations, linedef executors, sector specials, weather, utility functions for sector/line/tag searches, FOF-spawning, thinkers for scrollers, friction, pushers, etc
p_telept.c Teleportation
p_tick.c, p_tick.h Base thinker code
p_user.c General Player-related code (movement, thinkers), contains some general Object-related functions
r_bsp.c, r_bsp.h BSP tree traversal (Software-only)
r_data.c, r_data.h Initialisation of data (textures, colormaps, etc.) for use in the rendering code
r_defs.h Type definitions used in the rendering engine
r_draw8.c 8bpp span/column drawer functions, included as part of r_draw.c. Some of these functions have ASM equivalents in the tmap_* files, which may be used instead of r_draw8.c's functions if the game is compiled with ASM support.
r_draw16.c 16bpp span/column drawer functions, included as part of r_draw.c (Unused: 16bpp support is not compiled with SRB2 by default; SRB2's software renderer only supports 8bpp)
r_draw.c, r_draw.h Drawer functions shared by both 8bpp and 16bpp, handling of skin colors and other translations
r_local.h Global header file for rendering/drawing code (r_* functions)
r_main.c, r_main.h Main rendering code, skybox and portal rendering (all Software-only); utility functions (BSP, geometry, trigonometry)
r_plane.c, r_plane.h Rendering of planes (floor/ceiling) and the sky (both Software-only)
r_segs.c, r_segs.h Rendering of walls (Software-only)
r_sky.c, r_sky.h Functions and variables related to sky rendering (sky rendering code is actually in r_plane.c)
r_splats.c, r_splats.h Floor and wall splats (Unused: splats are not compiled with SRB2 by default)
r_state.h Definitions for global variables used by the rendering engine
r_things.c, r_things.h Rendering of sprites (Software-only), sprite definitions, skin switching, loading of S_SKIN
s_sound.c, s_sound.h System-independent sound/music code
screen.c, screen.h Screen-handling code
sounds.c, sounds.h Sound and music definitions, related sound routines
st_stuff.c, st_stuff.h Heads-up display: Game HUD, HUD item positions. (Note: these files were originally used for the status bar seen in Doom)
string.c String functions that we need but are missing on some operating systems
t_facon.c fineacon lookup table
t_fsin.c finesine lookup table
t_ftan.c finetangent lookup table
t_tan2a.c tantoangle lookup table
tables.c, tables.h Lookup tables for fast trig calculation (sin, cos, tan), angle conversion functions
tmap.nasNASM Assembler optimised rendering code for software mode. Draw wall columns
tmap.sASM Optimised drawing routines for span/column rendering (Software-only) (Unused?)
tmap_asm.sASM Assembler optimised rendering code for software mode (Non-MMX, Pentium, MMX for K6). Draw wall columns (Unused: file is not compiled with SRB2 in any version)
tmap_mmx.nasNASM Assembler optimised rendering code for software mode, using SIMD instructions (specifically MMX). Draw wall columns
tmap_vc.nasNASM Assembler optimised math code for Visual C++
v_video.c, v_video.h Functions for drawing patches and blitting blocks onto the screen, Gamma correction LUT, palette-handling (all Software-only)
vid_copy.sASM Assembler optimised code for updating the linear frame buffer screen
w_wad.c, w_wad.h WAD loading code
y_inter.c, y_inter.h Tally screens (level cleared, special stage end, multiplayer results, etc), handling of bonuses
z_zone.c, z_zone.h Zone memory allocation

ASM Written in assembly; supports C preprocessor directives and C-style comments
NASM Written in NASM-style assembly


These sub-folders contain files specific to certain ports or features of SRB2:

Folder name Description
android Android
blua Files for "BLUA", a modified version of Lua used in SRB2
djgppdos DOS (DJGPP)
dummy Dummy interface
hardware OpenGL rendering code
locale Language support
nds Nintendo DS
sdl SDL 2.0
sdl12 SDL 1.2 (Unused)
win32 Windows 32-bit (DirectDraw)
win32ce Windows CE 32-bit

See also

External links