Source code

From SRB2 Wiki
Jump to navigation Jump to 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:

  • Official releases: GitHub, GitLab – These tags contain the source code for each official release of SRB2. The latest released tag is referenced by SRB2's developers for debugging crashes in the official release.
  • master branch: GitHub, GitLab – The source code for the latest official release. May include additional fixes for environment or compiling issues found after release. These changes typically maintain netplay compatability.
  • next branch: GitHub, GitLab – The source code for the latest public revision of SRB2. This branch includes features and code that will be introduced in the next release, therefore making this branch a constant work in progress. Once the next version of the game is released, next will be merged into master, and the cycle will continue.

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
apng.c, apng.h Support code for writing APNGs.
asm_defs.incASM Macros for use with assembly
b_bot.c, b_bot.h Basic bot handling
byteptr.h Macros used for reading/writing data from/to pointers of various data types
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
deh_lua.c Lua SOC library (freeslot(), actions, parsing constants)
deh_soc.c SOC handling: Reading SOC blocks
deh_tables.c, deh_tables.h Defines lists of strings for SOC/Lua, for parsing constants, actions, etc. as strings.
dehacked.c, dehacked.h SOC handling: Reading a SOC lump. (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
f_wipe.c Screen fade handling
fastcmp.h Contains the string comparison functions fasticmp, fastcmp and fastncmp
filesrch.c, filesrch.h File-searching code
g_demo.c, g_demo.h Demo recording
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
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
http-mserv.c HTTP based master server
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_threads.h Multithreading abstraction
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_blockmaplib.c Lua: Blockmap search library – the searchBlockmap function
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_polyobjlib.c Lua: PolyObject library – handling of PolyObjects
lua_script.c, lua_script.h Lua scripting basics
lua_skinlib.c Lua: Skin library – handling of skins
lua_taglib.c Lua: Tag library – handling of tag lists
lua_thinkerlib.c Lua: Thinker library – the mobjs.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_perfstats.c, m_perfstats.h Performance measurement tools
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_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_draw8.c 8-bit color (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_draw8_npo2.c 8-bit color span drawer functions (for non-powers-of-two flat dimensions), included as part of r_draw.c.
r_draw16.c 16-bit color (16bpp) 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_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_patch.c, r_patch.h Patch generation
r_patchrotation.c, r_patchrotation.h Patch rotation
r_picformats.c, r_picformats.h Picture generation
r_plane.c, r_plane.h Rendering of planes (floor/ceiling) and the sky (both Software-only)
r_portal.c, r_portal.h Portal rendering (Software-only)
r_segs.c, r_segs.h Rendering of walls (Software-only)
r_skins.c, r_skins.h Skin switching, loading of S_SKIN and P_SKIN
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_textures.c, r_textures.h Texture generation
r_things.c, r_things.h Rendering of sprites and other "masked" level components (Software-only), sprite definitions
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)
strcasestr.c Defines thestrcasestr function, for case insensitive substring searching
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
taglist.c, taglist.h Ingame sector/line/mapthing tagging
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)
version.h Defines the macros SRB2VERSION, MODID and MODVERSION
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 (Unsupported)
blua Files for "BLUA", a modified version of Lua used in SRB2
dummy Dummy interface
hardware OpenGL rendering code
locale Language support
sdl SDL 2.0
win32 Windows 32-bit (DirectDraw) (Unsupported)

See also

External links