📄 gameunit.pas
字号:
{$ENDIF}
//===============================================================
//
// functions provided by the main engine
//
game_import_p = ^game_import_t;
pgame_import_t = game_import_p;
game_import_t = record
// special messages
bprintf: Procedure(printlevel: Integer; fmt: PChar {;...}); cdecl;
dprintf: Procedure(fmt: PChar {;...}); cdecl;
cprintf: Procedure(ent: edict_p; printlevel: Integer; fmt: PChar {;...}); cdecl;
centerprintf: Procedure(ent: edict_p; fmt: PChar {;...}); cdecl;
sound: Procedure(ent: edict_p; channel, soundindex: Integer; volume,attenuation,timeofs: Single); cdecl;
positioned_sound: Procedure(origin: vec3_p; ent: edict_p; channel, soundinedex: Integer; volume, attenuation, timeofs: Single); cdecl;
// config strings hold all the index strings, the lightstyles,
// and misc data like the sky definition and cdtrack.
// All of the current configstrings are sent to clients when
// they connect, and changes are sent to all connected clients.
configstring: Procedure(num: Integer; _string: PChar); cdecl;
error: Procedure(fmt: PChar {;...}); cdecl;
// the *index functions create configstrings and some internal server state
modelindex: Function(name: PChar): Integer; cdecl;
soundindex: Function(name: PChar): Integer; cdecl;
imageindex: Function(name: PChar): Integer; cdecl;
setmodel: Procedure(ent: edict_p; name: PChar); cdecl;
// collision detection
trace: Function(start, mins, maxs, _end: vec3_p; passent: edict_p; contentmask: Integer): trace_t; cdecl;
pointcontents: Function(point: vec3_t): Integer; cdecl;
inPVS: Function(p1, p2: vec3_t): qboolean; cdecl;
inPHS: Function(p1, p2: vec3_t): qboolean; cdecl;
SetAreaPortalState: Procedure(portalnum: Integer; open: qboolean); cdecl;
AreasConnected: Function(area1, area2: Integer): qboolean; cdecl;
// an entity will never be sent to a client or used for collision
// if it is not passed to linkentity. If the size, position, or
// solidity changes, it must be relinked.
linkentity: Procedure(ent: edict_p); cdecl;
unlinkentity: Procedure(ent: edict_p); cdecl; // call before removing an interactive edict
BoxEdicts: Function(mins, maxs: vec3_t; list: PParea_list; maxcount, areatype: Integer): Integer; cdecl;
Pmove: Procedure(pmove: pmove_p); cdecl; // player movement code common with client prediction
// network messaging
multicast: Procedure(origin: vec3_p; _to: multicast_t); cdecl;
unicast: Procedure(ent: edict_p; reliable: qboolean); cdecl;
WriteChar: Procedure(c: Integer); cdecl;
WriteByte: Procedure(c: Integer); cdecl;
WriteShort: Procedure(c: Integer); cdecl;
WriteLong: Procedure(c: Integer); cdecl;
WriteFloat: Procedure(f: Single); cdecl;
WriteString: Procedure(s: PChar); cdecl;
WritePosition: Procedure(pos: vec3_t); cdecl; // some fractional bits
WriteDir: Procedure(pos: vec3_t); cdecl; // single byte encoded, very coarse
WriteAngle: Procedure(f: Single); cdecl;
// managed memory allocation
TagMalloc: Function(size, tag: Integer): Pointer; cdecl;
TagFree: Procedure(block: pointer); cdecl;
FreeTags: Procedure(tag: Integer); cdecl;
// console variable interaction
cvar: function(var_name, value: PChar; flags: Integer): cvar_p; cdecl;
cvar_set: function(var_name, value: PChar): cvar_p; cdecl;
cvar_forceset: function(var_name, value: PChar): cvar_p; cdecl;
// ClientCommand and ServerCommand parameter access
argc: Function: Integer; cdecl;
argv: Function(n: Integer): PChar; cdecl;
args: Function: PChar; cdecl; // concatenation of all argv >= 1
// add commands to the server console as if they were typed in
// for map changing, etc
AddCommandString: Procedure(text: PChar); cdecl;
DebugGraph: Procedure(value: Single; color: Integer); cdecl;
end;
TGameImport = game_import_t;
PGameImport = game_import_p;
game_import_at = array [0..MaxInt div SizeOf(game_import_t)-1] of game_import_t;
game_import_a = ^game_import_at;
TGameImportArray = game_import_at;
PGameImportArray = game_import_a;
//
// functions exported by the game subsystem
//
game_export_p = ^game_export_t;
pgame_export_t = game_export_p;
game_export_t = record
apiversion: Integer;
// the init function will only be called when a game starts,
// not each time a level is loaded. Persistant data for clients
// and the server can be allocated in init
Init: procedure; cdecl;
Shutdown: Procedure; cdecl;
// each new level entered will cause a call to SpawnEntities
SpawnEntities: Procedure(mapname, entstring, spawnpoint: PChar); cdecl;
// Read/Write Game is for storing persistant cross level information
// about the world state and the clients.
// WriteGame is called every time a level is exited.
// ReadGame is called on a loadgame.
WriteGame: Procedure(filename: PChar; autosave: qboolean); cdecl;
ReadGame: Procedure(filename: PChar); cdecl;
// ReadLevel is called after the default map information has been
// loaded with SpawnEntities
WriteLevel: Procedure(filename: PChar); cdecl;
ReadLevel: Procedure(filename: PChar); cdecl;
ClientConnect: Function(ent: edict_p; userinfo: PChar): qboolean; cdecl;
ClientBegin: Procedure(ent: edict_p); cdecl;
ClientUserinfoChanged: Procedure(ent: edict_p; userinfo: PChar); cdecl;
ClientDisconnect: Procedure(ent: edict_p); cdecl;
ClientCommand: Procedure(ent: edict_p); cdecl;
ClientThink: Procedure(ent: edict_p; cmd: usercmd_p); cdecl;
RunFrame: Procedure; cdecl;
// ServerCommand will be called when an "sv <command>" command is issued on the
// server console.
// The game can issue gi.argc() / gi.argv() commands to get the rest
// of the parameters
ServerCommand: Procedure; cdecl;
//
// global variables shared between game and server
//
// The edict array is allocated in the game dll so it
// can vary in size from one game to another.
//
// The size will be fixed when ge->Init() is called
edicts: edict_p;
edict_size: Integer;
num_edicts: Integer; // current number, <= max_edicts
max_edicts: Integer;
end;
TGameExport = game_export_t;
PGameExport = game_export_p;
game_export_at = array [0..MaxInt div SizeOf(game_export_t)-1] of game_export_t;
game_export_a = ^game_export_at;
TGameExportArray = game_export_at;
PGameExportArray = game_export_a;
// CAK - TAKEN FROM g_local.h
Var
gi: game_import_t;
globals: game_export_t;
// CAK - Convenience functions by Carl Kenner.
// These allow you to use functions in gi properly
procedure gi_Error(Fmt: String; const Args: array of const);
procedure gi_bprintf(PrintLevel: Integer; Fmt: String; const Args: array of const);
procedure gi_dprintf(Fmt: String; const Args: array of const);
procedure gi_cprintf(Ent: edict_p; PrintLevel: Integer; Fmt: String; const Args: array of const);
procedure gi_centerprintf(ent: edict_p; fmt: String; const Args: array of const);
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
Implementation
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
Uses SysUtils;
procedure gi_Error(Fmt: String; const Args: array of const);
Var Buffer: Array[0..9999] of Char;
begin
Com_Sprintf(Buffer,sizeof(Buffer),PChar(Fmt),Args);
gi.error(Buffer);
end;
procedure gi_bprintf(PrintLevel: Integer; Fmt: String; const Args: array of const);
Var Buffer: Array[0..9999] of Char;
begin
Com_Sprintf(Buffer,sizeof(Buffer),PChar(Fmt),Args);
gi.bprintf(PrintLevel, Buffer);
end;
procedure gi_dprintf(Fmt: String; const Args: array of const);
Var Buffer: Array[0..9999] of Char;
begin
Com_Sprintf(Buffer,sizeof(Buffer),PChar(Fmt),Args);
gi.dprintf(Buffer);
end;
procedure gi_cprintf(Ent: edict_p; PrintLevel: Integer; Fmt: String; const Args: array of const);
Var Buffer: Array[0..9999] of Char;
begin
Com_Sprintf(Buffer,sizeof(Buffer),PChar(Fmt),Args);
gi.cprintf(Ent, PrintLevel, Buffer);
end;
procedure gi_centerprintf(ent: edict_p; fmt: String; const Args: array of const);
Var Buffer: Array[0..9999] of Char;
begin
Com_Sprintf(Buffer,sizeof(Buffer),PChar(Fmt),Args);
gi.centerprintf(Ent, Buffer);
end;
initialization
Assert(sizeof(solid_t)=4);
Assert(sizeof(link_t)=8);
Assert(sizeof(game_import_t)=176);
Assert(sizeof(game_export_t)=80);
{$IFNDEF GAME_INCLUDE}
Assert(sizeof(edict_t)=260);
Assert(sizeof(gclient_t)=188);
{$ENDIF}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -