📄 q_shared.pas
字号:
//100%
{$ALIGN ON}{$MINENUMSIZE 4}
{----------------------------------------------------------------------------}
{ }
{ File(s): game\q_shared.c }
{ game\q_shared.h }
{ Content: stuff "included first by ALL program modules" }
{ }
{ Initial conversion by : savage }
{ Initial conversion on : 09-Jan-2002 }
{ }
{ This File contains part of convertion of Quake2 source to ObjectPascal. }
{ More information about this project can be found at: }
{ http://www.sulaco.co.za/quake2/ }
{ }
{ Copyright (C) 1997-2001 Id Software, Inc. }
{ }
{ This program is free software; you can redistribute it and/or }
{ modify it under the terms of the GNU General Public License }
{ as published by the Free Software Foundation; either version 2 }
{ of the License, or (at your option) any later version. }
{ }
{ This program is distributed in the hope that it will be useful, }
{ but WITHOUT ANY WARRANTY; without even the implied warranty of }
{ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. }
{ }
{ See the GNU General Public License for more details. }
{ }
{----------------------------------------------------------------------------}
{ 1) Updated on : 24-Feb-2002 }
{ Updated by : Carl A Kenner (carl_kenner@hotmail.com) }
{ }
{ 2) 26-Feb-2002 - Clootie (clootie@reactor.ru) }
{ *** edict_s and cplane_t *** set orecord (including pointers) to be }
{ [originally] defined only in one unit }
{ }
{ 1) Updated on : 3-Mar-2002 }
{ Updated by : Carl A Kenner (carl_kenner@hotmail.com) }
{
{ Updated on: 3-jun-2002
{ Updated by: Juha Hartikainen (juha@linearteam.org}
{ - Changed OUT function parameters to VAR.
{ - Added overloaded version of VectorCopy }
{ }
{----------------------------------------------------------------------------}
unit q_shared;
interface
uses
{$IFDEF WIN32}
Windows,
{$ENDIF}
q_shared_add,
Math;
const
// angle indexes
PITCH = 0; // up / down
YAW = 1; // left / right
ROLL = 2; // fall over
MAX_STRING_CHARS = 1024; // max length of a string passed to Cmd_TokenizeString
MAX_STRING_TOKENS = 80; // max tokens resulting from Cmd_TokenizeString
MAX_TOKEN_CHARS = 128; // max length of an individual token
MAX_QPATH = 64; // max length of a quake game pathname
MAX_OSPATH = 128; // max length of a filesystem pathname
//
// per-level limits
//
MAX_CLIENTS = 256; // absolute limit
MAX_EDICTS = 1024; // must change protocol to increase more
MAX_LIGHTSTYLES = 256;
MAX_MODELS = 256; // these are sent over the net as bytes
MAX_SOUNDS = 256; // so they cannot be blindly increased
MAX_IMAGES = 256;
MAX_ITEMS = 256;
MAX_GENERAL = (MAX_CLIENTS * 2); // general config strings
// game pr : integer flags
PRINT_LOW = 0; // pickup messages
PRINT_MEDIUM = 1; // death messages
PRINT_HIGH = 2; // critical messages
PRINT_CHAT = 3; // chat messages
ERR_FATAL = 0; // exit the entire game with a popup window
ERR_DROP = 1; // pr : integer to console and disconnect from game
ERR_DISCONNECT = 2; // don't kill server
PRINT_ALL = 0;
PRINT_DEVELOPER = 1; // only pr : integer when 'developer 1'
PRINT_ALERT = 2;
type
qboolean = q_shared_add.qboolean;
PQboolean = q_shared_add.Pqboolean;
// destination class for gi.multicast
multicast_t = q_shared_add.multicast_t;
multicast_p = q_shared_add.multicast_p;
tcdeclproc = procedure; cdecl;
(*
==============================================================
MATHLIB
==============================================================
*)
type
vec_t = q_shared_add.vec_t;
vec3_t = q_shared_add.vec3_t;
vec5_t = q_shared_add.vec5_t;
vec_p = q_shared_add.vec_p;
vec3_p = q_shared_add.vec3_p;
vec5_p = q_shared_add.vec5_p;
fixed4_t = integer;
fixed8_t = integer;
fixed16_t = integer;
fixed4_p = ^fixed4_t; // CAK
fixed8_p = ^fixed8_t; // CAK
fixed16_p = ^fixed16_t; // CAK
matrix33 = array[0..2, 0..2] of single; // CAK - Used for transform function below
matrix34 = array[0..2, 0..3] of single; // CAK - Used for transform function below
const
M_PI = 3.14159265358979323846; // matches value in gcc v2 math.h
var
vec3_origin: vec3_t = (0, 0, 0);
const
nanmask = 255 shl 23;
function IS_NAN(x: single): qboolean;
// microsoft's fabs seems to be ungodly slow...
// CAK - I don't know if borland's abs is ungodly slow
// CAK - if so, then maybe copy and paste to a new abs function
function Q_fabs(f: single): single;
function fabs(f: single): single; // SAME AS Q_fabs
function Q_ftol(f: single): LongInt;
// CAK - math functions, missing in Delphi 3
function floor(const x: Single): Integer;
function ceil(const x: Single): Integer;
// CAK - These were originally MACROS
function DotProduct(const v1, v2: vec3_t): vec_t;
procedure VectorSubtract(const veca, vecb: vec3_t; var out_: vec3_t); overload;
procedure VectorSubtract(const veca, vecb: array of smallint; var out_: array of integer); overload;
procedure VectorAdd(const veca, vecb: vec3_t; var out_: vec3_t);
procedure VectorCopy(const _in: vec3_t; var out_: vec3_t); overload;
procedure VectorCopy(const _in: vec3_t; var out_: array of smallint); overload;
procedure VectorCopy(const _in: array of smallint; var out_: array of smallint); overload;
procedure VectorCopy(const _in: array of smallint; var out_: vec3_t); overload;
procedure VectorClear(var a: vec3_t);
procedure VectorNegate(const a: vec3_t; var b: vec3_t);
procedure VectorSet(var v: vec3_t; x, y, z: vec_t);
procedure VectorMA(const veca: vec3_t; scale: single; const vecb: vec3_t; var vecc: vec3_t);
// just in you do't want to use the macros [sic - CAK]
function _DotProduct(const v1, v2: vec3_t): vec_t;
procedure _VectorSubtract(const veca, vecb: vec3_t; var out_: vec3_t);
procedure _VectorAdd(const veca, vecb: vec3_t; var out_: vec3_t);
procedure _VectorCopy(const _in: vec3_t; var out_: vec3_t);
procedure ClearBounds(var mins, maxs: vec3_t);
procedure AddPointToBounds(const v: vec3_t; var mins, maxs: vec3_t);
function VectorCompare(const v1, v2: vec3_t): integer;
function VectorLength(const v: vec3_t): vec_t;
procedure CrossProduct(const v1, v2: vec3_t; var cross: vec3_t);
function VectorNormalize(var v: vec3_t): vec_t; // result =s vector length
function VectorNormalize2(const v: vec3_t; var out_: vec3_t): vec_t;
procedure VectorInverse(var v: vec3_t);
procedure VectorScale(const _in: vec3_t; const scale: vec_t; var out_: vec3_t);
function Q_log2(val: Integer): Integer;
procedure R_ConcatRotations(const in1, in2: matrix33; var out_: matrix33);
procedure R_ConcatTransforms(const in1, in2: matrix34; var out_: matrix34);
// plane_t structure
// !!! if this is changed, it must be changed in asm code too !!!
type
cplane_p = q_shared_add.cplane_p;
cplane_t = q_shared_add.cplane_t;
cplane_arrp = q_shared_add.cplane_arrp;
procedure AngleVectors(const angles: vec3_t; forwards, right, up: vec3_p);
function BoxOnPlaneSide(var emins, emaxs: vec3_t; p: cplane_p): Integer;
function anglemod(a: single): single;
function LerpAngle(a2, a1, frac: single): single;
// CAK - This was originally a MACRO
function BOX_ON_PLANE_SIDE(var emins, emaxs: vec3_t; p: cplane_p): Integer;
procedure ProjectPointOnPlane(var dst: vec3_t; const p, normal: vec3_t);
procedure PerpendicularVector(var dst: vec3_t; const src: vec3_t);
procedure RotatePointAroundVector(var dst: vec3_t; const dir, point: vec3_t; degrees: single);
//=============================================
function COM_SkipPath(pathname: PChar): PChar;
procedure COM_StripExtension(in_, out_: PChar);
procedure COM_FileBase(in_, out_: PChar);
procedure COM_FilePath(in_, out_: PChar);
procedure COM_DefaultExtension(path, extension: PChar);
function COM_Parse(var data_p: PChar): PChar; // CAK - WARNING!!!! WAS ^PChar
// data is an in/out parm, returns a parsed out token
procedure Com_sprintf(dest: PChar; size: Integer; fmt: PChar; const Args: array of const);
procedure Com_PageInMemory(buffer: PByte; size: Integer);
//=============================================
// portable case insensitive compare
function Q_stricmp(s1, s2: PChar): Integer;
function Q_strcasecmp(s1, s2: PChar): Integer;
function Q_strncasecmp(s1, s2: PChar; n: Integer): Integer;
//=============================================
function BigShort(L: SmallInt): SmallInt;
function LittleShort(L: SmallInt): SmallInt;
function BigLong(L: LongInt): LongInt;
function LittleLong(L: LongInt): LongInt;
function BigFloat(L: Single): Single;
function LittleFloat(L: Single): Single;
procedure Swap_Init;
function va(format: PChar; const Args: array of const): PChar;
//=============================================
//
// key / value info strings
//
const
MAX_INFO_KEY = 64;
MAX_INFO_VALUE = 64;
MAX_INFO_STRING = 512;
function Info_ValueForKey(s, key: PChar): PChar;
procedure Info_RemoveKey(s, key: PChar);
procedure Info_SetValueForKey(s, key, value: PChar);
function Info_Validate(s: PChar): qboolean;
(*
==============================================================
SYSTEM SPECIFIC
==============================================================
*)
// directory searching
const
SFF_ARCH = $01;
SFF_HIDDEN = $02;
SFF_RDONLY = $04;
SFF_SUBDIR = $08;
SFF_SYSTEM = $10;
(*
==========================================================
CVARS (console variables)
==========================================================
*)
{$DEFINE CVAR}
const
CVAR_ARCHIVE = 1; // set to cause it to be saved to vars.rc
CVAR_USERINFO = 2; // added to userinfo when changed
CVAR_SERVERINFO = 4; // added to serverinfo when changed
CVAR_NOSET = 8; // don't allow change from console at all,
// but can be set from the command line
CVAR_LATCH = 16; // save changes until server restart
// nothing outside the Cvar_*() functions should modify these fields!
type
cvar_p = q_shared_add.cvar_p;
cvar_t = q_shared_add.cvar_t;
(*
==============================================================
COLLISION DETECTION
==============================================================
*)
// lower bits are stronger, and will eat weaker brushes completely
const
CONTENTS_SOLID = 1; // an eye is never valid in a solid
CONTENTS_WINDOW = 2; // translucent, but not watery
CONTENTS_AUX = 4;
CONTENTS_LAVA = 8;
CONTENTS_SLIME = 16;
CONTENTS_WATER = 32;
CONTENTS_MIST = 64;
LAST_VISIBLE_CONTENTS = 64;
// remaining contents are non-visible, and don't eat brushes
const
CONTENTS_AREAPORTAL = $8000;
CONTENTS_PLAYERCLIP = $10000;
CONTENTS_MONSTERCLIP = $20000;
// currents can be added to any other contents, and may be mixed
const
CONTENTS_CURRENT_0 = $40000;
CONTENTS_CURRENT_90 = $80000;
CONTENTS_CURRENT_180 = $100000;
CONTENTS_CURRENT_270 = $200000;
CONTENTS_CURRENT_UP = $400000;
CONTENTS_CURRENT_DOWN = $800000;
const
CONTENTS_ORIGIN = $1000000; // removed before bsping an entity
CONTENTS_MONSTER = $2000000; // should never be on a brush, only in game
CONTENTS_DEADMONSTER = $4000000;
CONTENTS_DETAIL = $8000000; // brushes to be added after vis leafs
CONTENTS_TRANSLUCENT = $10000000; // auto set if any surface has trans
CONTENTS_LADDER = $20000000;
const
SURF_LIGHT = $1; // value will hold the light strength
SURF_SLICK = $2; // effects game physics
SURF_SKY = $4; // don't draw, but add to skybox
SURF_WARP = $8; // turbulent water warp
SURF_TRANS33 = $10;
SURF_TRANS66 = $20;
SURF_FLOWING = $40; // scroll towards angle
SURF_NODRAW = $80; // don't bother referencing the texture
// content masks
const
MASK_ALL = (-1);
MASK_SOLID = (CONTENTS_SOLID or CONTENTS_WINDOW);
MASK_PLAYERSOLID = (CONTENTS_SOLID or CONTENTS_PLAYERCLIP or CONTENTS_WINDOW or
CONTENTS_MONSTER);
MASK_DEADSOLID = (CONTENTS_SOLID or CONTENTS_PLAYERCLIP or CONTENTS_WINDOW);
MASK_MONSTERSOLID = (CONTENTS_SOLID or CONTENTS_MONSTERCLIP or CONTENTS_WINDOW or
CONTENTS_MONSTER);
MASK_WATER = (CONTENTS_WATER or CONTENTS_LAVA or CONTENTS_SLIME);
MASK_OPAQUE = (CONTENTS_SOLID or CONTENTS_SLIME or CONTENTS_LAVA);
MASK_SHOT = (CONTENTS_SOLID or CONTENTS_MONSTER or CONTENTS_WINDOW or
CONTENTS_DEADMONSTER);
MASK_CURRENT = (CONTENTS_CURRENT_0 or CONTENTS_CURRENT_90 or CONTENTS_CURRENT_180
or CONTENTS_CURRENT_270 or CONTENTS_CURRENT_UP or CONTENTS_CURRENT_DOWN);
// gi.BoxEdicts can return a list of either solid or trigger entities
// FIXME: eliminate AREA_ distinction?
const
AREA_SOLID = 1;
AREA_TRIGGERS = 2;
// Cplane record was moved above prototypes so it would compile!
// type = recordure offset for asm code
const
CPLANE_NORMAL_X = 0;
CPLANE_NORMAL_Y = 4;
CPLANE_NORMAL_Z = 8;
CPLANE_DIST = 12;
CPLANE_TYPE = 16;
CPLANE_SIGNBITS = 17;
CPLANE_PAD0 = 18;
CPLANE_PAD1 = 19;
type
cmodel_p = ^cmodel_t;
cmodel_t = record
mins, maxs: vec3_t;
origin: vec3_t; // for sounds or lights
headnode: Integer;
end;
csurface_p = q_shared_add.csurface_p;
csurface_t = q_shared_add.csurface_t;
mapsurface_p = ^mapsurface_t;
mapsurface_t = record // used internally due to name len probs //ZOID
c: csurface_t;
rname: array[0..31] of Char;
end;
//==============================================
// entity_state_t->event values
// ertity events are for effects that take place reletive
// to an existing entities origin. Very network efficient.
// All muzzle flashes really should be converted to events...
entity_event_p = q_shared_add.entity_event_p;
entity_event_t = q_shared_add.entity_event_t;
// entity_state_t is the information conveyed from the server
// in an update message about entities that the client will
// need to render in some way
entity_state_p = q_shared_add.entity_state_p;
entity_state_t = q_shared_add.entity_state_t;
//==============================================
// pmove_state_t is the information necessary for client side movement
// prediction
pmtype_p = q_shared_add.pmtype_p;
pmtype_t = q_shared_add.pmtype_t;
// pmove.pm_flags
const
PMF_DUCKED = 1;
PMF_JUMP_HELD = 2;
PMF_ON_GROUND = 4;
PMF_TIME_WATERJUMP = 8; // pm_time is waterjump
PMF_TIME_LAND = 16; // pm_time is time before rejump
PMF_TIME_TELEPORT = 32; // pm_time is non-moving time
PMF_NO_PREDICTION = 64; // temporarily disables prediction (used for grappling hook)
type
{$IFNDEF GAMEDLL}
pmove_state_p = ^pmove_state_t;
pmove_state_t = record
pm_type: pmtype_t;
origin: array[0..2] of smallint; // 12.3
velocity: array[0..2] of smallint; // 12.3
pm_flags: byte; // ducked, jump_held, etc
pm_time: byte; // each unit = 8 ms
gravity: smallint;
delta_angles: array[0..2] of smallint; // add to command angles to get view direction
// changed by spawns, rotating objects, and teleporters
end;
{$ENDIF}
player_state_p = q_shared_add.player_state_p;
player_state_t = q_shared_add.player_state_t;
//
// button bits
//
const
BUTTON_ATTACK = 1;
BUTTON_USE = 2;
BUTTON_ANY = 128; // any key whatsoever
// usercmd_t is sent to the server each client frame
type
usercmd_p = q_shared_add.usercmd_p;
usercmd_t = q_shared_add.usercmd_t;
const
// entity_state_t.effects
// Effects are things handled on the client side (lights, particles, frame animations)
// that happen constantly on the given entity.
// An entity that has effects will be sent to the client
// even if it has a zero index model.
EF_ROTATE = $00000001; // rotate (bonus items)
EF_GIB = $00000002; // leave a trail
EF_BLASTER = $00000008; // redlight + trail
EF_ROCKET = $00000010; // redlight + trail
EF_GRENADE = $00000020;
EF_HYPERBLASTER = $00000040;
EF_BFG = $00000080;
EF_COLOR_SHELL = $00000100;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -