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 of SRB2's source code and the way it is organized. For instructions on how to compile SRB2's source code, see Source code compiling.

Links

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

  • v2.1.20 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.

Index

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 from/to pointers of various data types
b_bot.c, b_bot.h Basic bot handling
command.c, command.h Handling of console commands and variables
comptime.c Contains timestamps for the compilation date and time, which are updated when the code is compiled
config.h.in SRB2's CMake configuration file. Also contains hash codes for SRB2's asset files, which are used for non-CMake builds
console.c, console.h Console drawing and input
d_clisrv.c, d_clisrv.h System-independent networking code (client, server)
d_event.h Data types and variables for input event handling, including the event_t structure
d_main.c, d_main.h SRB2 main program: Game startup, 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 player data structures, including the player_t structure and enums for abilities, powers, shields, etc.
d_think.h Definitions of thinker structures used for Objects
d_ticcmd.h Definition of the ticcmd_t structure and the button flags enum, for player movement commands
dehacked.c, dehacked.h SOC handling: Reading SOC data, assigning freeslots, parsing constants. (Note: These files were originally used for reading "patch" files made by DeHackEd, an editor for Doom)
doomdata.h Data structures used to represent maps in WAD files
doomdef.h Contains important global definitions and macros, for example for EXE versioning, tic rate, maximum number of players, skin colors, reserved tags, development mode, code under testing, etc. Also includes declarations of commonly used functions (e.g.: CONS_Printf, CONS_Alert, I_Error, I_Assert)
doomstat.h Contains global variables that store the internal game 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 functions: 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 state variables and enums
hu_stuff.c, hu_stuff.h Heads-up display: message display, Rankings/Scores HUD
i_addrinfo.c, i_addrinfo.h Code for handling IP addresses
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: Base library functions
lua_consolelib.c Lua: Console library – functions, console command/variable handling
lua_hook.h, lua_hooklib.c Lua: Hook library – initialization, functions
lua_hud.h, lua_hudlib.c Lua: HUD library – 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/trigonometry 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 from LibLZF 1.7
m_aatree.c, m_aatree.h Partial implementation of AA trees
m_anigif.c, m_anigif.h Animated GIF creation for movie mode
m_argv.c, m_argv.h Handling of command line parameters
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 Doubly linked list implementation
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
mserv.c, mserv.h Handles communication with the Master Server
p5prof.h Provides macros for code profiling
p_ceilng.c Ceiling movement thinkers
p_enemy.c Definitions for actions and other enemy thinking functions
p_floor.c Floor movement thinkers, thinkers for various special map effects
p_inter.c Object interaction: item pickup functions, Object damage/death functions
p_lights.c Sector lighting effects (pulsating, flickering, blinking, glowing, fading, etc.)
p_local.h Global header for game logic/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 functions for spawning, removal, movement, etc., 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 Reading and writing of Single Player savegames and multiplayer save files ($$$.sav)
p_setup.c, p_setup.h WAD file loading, map data loading and setup
p_sight.c Line of sight/visibility checks, uses REJECT lookup table
p_slopes.c, p_slopes.h Slope handling
p_spec.c, p_spec.h Special effects: texture animations, linedef executors, sector specials, weather, utility functions for sector/linedef 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 8-bit color 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 16-bit color span/column drawer functions, included as part of r_draw.c (Unused: 16-bit color support is not compiled with SRB2 by default; SRB2's Software renderer only supports 8-bit color)
r_draw.c, r_draw.h Drawer functions used for both 8-bit color and 16-bit color, 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 for BSP, geometry and 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 (the actual sky rendering code is 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 Functions for string concatenation and copying, for operating systems that do not include them natively
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 trigonometry calculation (sin, cos, tan), angle conversion functions
tmap.nasNASM Assembler-optimized rendering code for drawing wall columns in Software mode
tmap.sASM Assembler-optimized drawing routines for span/column rendering (Software-only) (Unused?)
tmap_asm.sASM Assembler-optimized rendering code for drawing wall columns in Software mode (Non-MMX, Pentium, MMX for K6) (Unused: File is not compiled with SRB2 in any version)
tmap_mmx.nasNASM Assembler-optimized rendering code for drawing wall columns in Software mode, using SIMD instructions (specifically MMX)
tmap_vc.nasNASM Assembler-optimized math code for Visual C++
v_video.c, v_video.h Functions for drawing patches and blitting blocks onto the screen, gamma correction lookup tables, palette handling (all Software-only)
vid_copy.sASM Assembler-optimized 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 score 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

Folders

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