📄 q_shared.pas
字号:
//100%
{$ALIGN 8}{$MINENUMSIZE 4}
{----------------------------------------------------------------------------}
{ }
{ File(s): game\q_shared.c }
{ game\q_shared.h }
{ ctf\q_shared.c }
{ ctf\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. }
{ }
{----------------------------------------------------------------------------}
{ Updated on : 23-Feb-2002 }
{ Updated by : Carl A Kenner (carl_kenner@hotmail.com) }
{ }
{----------------------------------------------------------------------------}
{ * Still dependent (to compile correctly) on: }
{ Nothing!!!! (download the latest g_local) }
{ Functions print error messages with Com_printf which calls ShowMessage() }
{ This is because I didn't know where to find the real Com_printf }
{----------------------------------------------------------------------------}
{ * TODO: }
{ Check for errors }
{ Link to genuine Com_printf }
{----------------------------------------------------------------------------}
unit q_shared;
interface
Uses Windows, g_local;
const
{$IFDEF WIN32}
{$DEFINE id386}
{$ELSE}
id386 = 0;
{$ENDIF}
{$IFDEF _M_ALPHA}
idaxp = 1;
{$ELSE}
idaxp = 0;
{$ENDIF}
// 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 = g_local.MAX_QPATH; // 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 = g_local.MAX_ITEMS; // CAK - MOVED to g_local
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 = g_local.qboolean; // CAK - MOVED to g_local
pqboolean = g_local.pqboolean; // CAK - MOVED to g_local
TQBooleanArray = g_local.TQBooleanArray;
PQBooleanArray = g_local.PQBooleanArray;
// destination class for gi.multicast
multicast_t = (
MULTICAST_ALL,
MULTICAST_PHS,
MULTICAST_PVS,
MULTICAST_ALL_R,
MULTICAST_PHS_R,
MULTICAST_PVS_R
);
multicast_p = ^multicast_t;
pmulticast_t = multicast_p;
TMulticast = multicast_t;
PMulticast = multicast_p;
(*
==============================================================
MATHLIB
==============================================================
*)
type
vec_t = g_local.vec_t; // CAK - MOVED to g_local
vec3_t = g_local.vec3_t;
vec5_t = g_local.vec5_t;
vec_p = g_local.vec_p; // CAK
vec3_p = g_local.vec3_p; // CAK
vec5_p = g_local.vec5_p; // CAK
TVec = g_local.TVec;
TVec3 = g_local.TVec3;
TVec5 = g_local.TVec5;
PVec = g_local.PVec;
PVec3 = g_local.PVec3;
PVec5 = g_local.PVec5;
vec_at = g_local.vec_at;
vec3_at = g_local.vec3_at;
vec5_at = g_local.vec5_at;
vec_a = g_local.vec_a;
vec3_a = g_local.vec3_a;
vec5_a = g_local.vec5_a;
TVecArray = g_local.TVecArray;
TVec3Array = g_local.TVecArray;
TVec5Array = g_local.TVecArray;
PVecArray = g_local.PVecArray;
PVec3Array = g_local.PVec3Array;
PVec5Array = g_local.PVec5Array;
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
{$IFNDEF M_PI}
{$DEFINE M_PI} // CAK - Consts need to be DEFINED also if used in IFDEF
const
M_PI = 3.14159265358979323846; // matches value in gcc v2 math.h
{$ENDIF}
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 - These were originally MACROS
function DotProduct(const v1,v2: vec3_t): vec_t;
procedure VectorSubtract (const veca,vecb: vec3_t; out _out: vec3_t);
procedure VectorAdd (const veca,vecb: vec3_t; out _out: vec3_t);
procedure VectorCopy (const _in: vec3_t; out _out: vec3_t);
procedure VectorClear(out a: vec3_t);
procedure VectorNegate(const a: vec3_t; out b: vec3_t);
procedure VectorSet(out v: vec3_t; x,y,z: vec_t);
procedure VectorMA (const veca: vec3_t; scale: single; const vecb: vec3_t; out 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; out _out: vec3_t);
procedure _VectorAdd (const veca,vecb: vec3_t; out _out: vec3_t);
procedure _VectorCopy (const _in: vec3_t; out _out: vec3_t);
procedure ClearBounds(out 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; out cross: vec3_t);
function VectorNormalize(var v: vec3_t): vec_t; // result =s vector length
function VectorNormalize2 (const v: vec3_t; out _out: vec3_t): vec_t;
procedure VectorInverse(var v: vec3_t);
procedure VectorScale(const _in: vec3_t; const scale: vec_t; out _out: vec3_t);
function Q_log2(val: Integer): Integer;
procedure R_ConcatRotations (const in1, in2: matrix33; out _out: matrix33);
procedure R_ConcatTransforms(const in1, in2: matrix34; out _out: matrix34);
// plane_t structure
// !!! if this is changed, it must be changed in asm code too !!!
type
cplane_p = ^cplane_t;
cplane_s = record
normal: vec3_t;
dist: single;
_type: byte; // for fast side tests
signbits: byte; // signx + (signyshl1) + (signzshl1)
pad: array[0..1] of byte;
end;
cplane_t = cplane_s;
pcplane_t = cplane_p;
pcplane_s = cplane_p;
procedure AngleVectors(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);
//=============================================
// CAK - added by Carl
function strncpy(dest, source: PChar; count: Integer): PChar;
function strncmp(s1, s2: PChar; count: Integer): 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;
const MAX_INFO_VALUE = 64;
const MAX_INFO_STRING = g_local.MAX_INFO_STRING; // MOVED TO g_local
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
==============================================================
*)
var
curtime: integer; // time returned by last Sys_Milliseconds
//function Sys_Milliseconds: integer;
//procedure Sys_Mkdir(path: PChar);
// large block stack allocation routines
//function Hunk_Begin(maxsize: Integer): Pointer;
//function Hunk_Alloc(size: Integer): Pointer;
//procedure Hunk_Free(buf: Pointer);
//function Hunk_End: Integer;
// directory searching
const
SFF_ARCH = $01;
SFF_HIDDEN = $02;
SFF_RDONLY = $04;
SFF_SUBDIR = $08;
SFF_SYSTEM = $10;
(*
** pass in an attribute mask of things you wish to REJECT
*)
//function Sys_FindFirst(path: PChar; musthave,canthave: Cardinal): PChar;
//function Sys_FindNext(musthave,canthave: Cardinal): PChar;
//procedure Sys_FindClose;
// this is only here so the functions in q_shared.c and q_shwin.c can link
//void Sys_Error (char *error, ...);
//void Com_Printf (char *msg, ...);
// CAK - MOVED TO g_local
(*
==========================================================
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 = g_local.cvar_p;
cvar_s = g_local.cvar_s;
cvar_t = g_local.cvar_t;
pcvar_t = g_local.pcvar_t;
pcvar_s = g_local.pcvar_s;
TCVar = g_local.TCVar;
PCVar = g_local.PCVar;
(*
==============================================================
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_s = record
mins, maxs: vec3_t;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -