Quake 2 Source Code (v3.19)

repository·master·Indexed 25 days ago

https://github.com/id-software/quake-2

Complete source code for Quake 2, version 3.19, licensed under the GPL. Documentation covers client-side state management via client_state_t and client_static_t, input and movement prediction, visual effects and particle systems, and server-side management including server_t, client_t, spatial queries (SV_Trace, SV_PointContents), and entity physics management.

Tokens
2.1K
Snippets
2
Records
16
Agent score
86%

What's inside Quake 2

  1. Understand the Quake 2 GPL License

    master

    The source code is licensed under the GNU Public License (GPL).

    Key terms:

    • You may use the code for any purpose, including commercial use.
    • If you distribute new binary versions, you are required to make the entire source code available to everyone for free.
    • If you wish to pursue commercial exploitation without releasing your source changes, you must negotiate a separate license agreement with ID Software.

    Note on Data Files: All original Q2 data files remain under their original copyrights. You cannot redistribute original game data. However, you may create a standalone game via a 'total conversion' using your own original assets based on this source code.

  2. Communicate with clients using SV_ClientPrintf and SV_BroadcastPrintf

    master

    Use these functions to send text messages to specific clients or to all connected players.

    • SV_ClientPrintf(client_t *cl, int level, char *fmt, ...): Sends a formatted message to a specific client cl. The level parameter determines the message type/filtering.
    • SV_BroadcastPrintf(int level, char *fmt, ...): Sends a formatted message to all clients on the server.
  3. Retrieve entities in an area with SV_AreaEdicts

    master

    SV_AreaEdicts fills a list of entity pointers whose bounding boxes intersect a specified 3D area.

    Parameters:

    • vec3_t mins: Minimum corner of the area.
    • vec3_t maxs: Maximum corner of the area.
    • edict_t **list: Array to be filled with entity pointers.
    • int maxcount: Maximum number of pointers to fill.
    • int areatype: The type of area to check.

    Returns: The number of pointers successfully filled in the list.

  4. Trigger visual effects and particles

    master

    The client provides several functions to trigger visual effects, trails, and particles. These are used to enhance gameplay feedback.

    General Particle Effects:

    • CL_ParticleEffect(vec3_t org, vec3_t dir, int color, int count): Standard particle emission.
    • CL_ParticleEffect2(...) and CL_ParticleEffect3(...): Variations of particle effects.
    • CL_GenericParticleEffect(vec3_t org, vec3_t dir, int color, int count, int numcolors, int dirspread, float alphavel): Advanced particle control.

    Weapon and Movement Trails:

    • CL_BlasterTrail(vec3_t start, vec3_t end)
    • CL_QuadTrail(vec3_t start, vec3_t end)
    • CL_RailTrail(vec3_t start, vec3_t end)
    • CL_BubbleTrail(vec3_t start, vec3_t end)
    • CL_FlagTrail(vec3_t start, vec3_t end, float color)
    • CL_IonripperTrail(vec3_t start, vec3_t end)

    Specialized Effects:

    • CL_FlameEffects(centity_t *ent, vec3_t origin)
    • CL_Heatbeam(vec3_t start, vec3_t end)
    • CL_SmokeTrail(vec3_t start, vec3_t end, int colorStart, int colorRun, int spacing)
  5. Manage client input and movement prediction

    master

    Input is handled via usercmd_t structures. The client predicts movement locally to hide latency.

    • CL_InitInput(): Initializes the input system.
    • CL_SendCmd(): Sends the current command to the server.
    • CL_SendMove(usercmd_t *cmd): Sends a specific movement command.
    • CL_PredictMovement(): Performs local client-side movement prediction.
    • CL_InitPrediction(): Sets up the prediction system.
    • CL_CheckPredictionError(): Validates predicted movement against server state.
  6. Manage entity physics with SV_LinkEdict and SV_UnlinkEdict

    master

    To ensure correct collision detection and visibility (PVS), you must manage an entity's presence in the world's spatial structures.

    • SV_LinkEdict(edict_t *ent): Call this whenever an entity changes its origin, mins, maxs, or solid status. It automatically unlinks the entity if necessary and updates its bounding volumes and leaf numbers for PVS.
    • SV_UnlinkEdict(edict_t *ent): Call this before removing an entity or before attempting to move an entity to prevent it from clipping against itself.
  7. Perform spatial queries with SV_Trace and SV_PointContents

    master

    These functions are used for physics and collision detection within the game world.

    • SV_PointContents(vec3_t p): Returns the CONTENTS_* value at a specific point p. In Quake 2, this includes checks against entities to support moving liquids.
    • SV_Trace(vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, edict_t *passedict, int contentmask): Performs a trace from start to end.
      • mins and maxs are relative to the trace path.
      • passedict is an entity explicitly excluded from clipping checks (use NULL for default).
      • If the entire move is within a solid volume, trace.allsolid and trace.startsolid are set, and trace.fraction is 0.
  8. Access Client State and Static Information

    master

    The Quake 2 client manages state through two primary global structures: cl (client_state_t) and cls (client_static_t).

    • cl (client_state_t): Contains transient data that is wiped during server map changes. It includes current frame data, player movement prediction, view angles, inventory, and locally derived information like precached models and sounds.
    • cls (client_static_t): Contains persistent data that remains across server connections. It includes connection status (connstate_t), real-time counters, network channel information, and demo recording state.
  9. Broadcast messages with SV_Multicast

    master

    SV_Multicast is used to send a message to a specific set of clients defined by a multicast_t structure. This is typically used for efficient data marshalling before the message is sent.

    void SV_Multicast (vec3_t origin, multicast_t to);
  10. Reference Client CVars

    master

    The client exposes several configuration variables (cvars) for tuning gameplay and rendering. Common cvars include:

    • cl_predict: Enables/disables client-side prediction.
    • cl_autoskins: Enables/disables automatic skin selection.
    • cl_noskins: Disables all player skins.
    • sensitivity: Controls mouse sensitivity.
    • cl_shownet: Shows network information.
    • cl_timedemo: Enables timedemo mode.
    • cl_vwep: Controls view weapon visibility.
    • cl_footsteps: Enables/disables footstep sounds.
  11. Connection States (connstate_t)

    master

    The connstate_t enum tracks the current connection status of the client:

    • ca_uninitialized: Initial state.
    • ca_disconnected: Not currently talking to a server.
    • ca_connecting: Sending request packets to the server.
    • ca_connected: netchan_t established, waiting for svc_serverdata.
    • ca_active: Game views are being displayed.