Merge branch 'cleanup'

Conflicts:
	src/common/header/common.h
	src/common/header/shared.h
	src/common/misc.c
	src/unix/main.c
	src/unix/system.c
This commit is contained in:
Yamagi Burmeister 2012-07-09 14:35:37 +02:00
commit 7ac71db523
44 changed files with 10379 additions and 9120 deletions

View file

@ -478,28 +478,21 @@ CLIENT_OBJS_ := \
src/client/sound/snd_mix.o \
src/client/sound/snd_vorbis.o \
src/client/sound/snd_wav.o \
src/common/argproc.o \
src/common/clientserver.o \
src/common/collision.o \
src/common/crc.o \
src/common/cmdparser.o \
src/common/cvar.o \
src/common/filesystem.o \
src/common/glob.o \
src/common/md4.o \
src/common/movemsg.o \
src/common/misc.o \
src/common/netchan.o \
src/common/pmove.o \
src/common/szone.o \
src/common/zone.o \
src/common/command/cmd_execution.o \
src/common/command/cmd_parser.o \
src/common/command/cmd_script.o \
src/common/common/com_arg.o \
src/common/common/com_clientserver.o \
src/common/message/msg_io.o \
src/common/message/msg_read.o \
src/common/model/cm_areaportals.o \
src/common/model/cm_box.o \
src/common/model/cm_boxtracing.o \
src/common/model/cm_bsp.o \
src/common/model/cm_vis.o \
src/common/shared/flash.o \
src/common/shared/rand.o \
src/common/shared/shared.o \
@ -540,28 +533,21 @@ endif
# Used by the server
SERVER_OBJS_ := \
src/common/argproc.o \
src/common/clientserver.o \
src/common/collision.o \
src/common/crc.o \
src/common/cmdparser.o \
src/common/cvar.o \
src/common/filesystem.o \
src/common/glob.o \
src/common/md4.o \
src/common/misc.o \
src/common/movemsg.o \
src/common/netchan.o \
src/common/pmove.o \
src/common/szone.o \
src/common/zone.o \
src/common/command/cmd_execution.o \
src/common/command/cmd_parser.o \
src/common/command/cmd_script.o \
src/common/common/com_arg.o \
src/common/common/com_clientserver.o \
src/common/message/msg_io.o \
src/common/message/msg_read.o \
src/common/model/cm_areaportals.o \
src/common/model/cm_box.o \
src/common/model/cm_boxtracing.o \
src/common/model/cm_bsp.o \
src/common/model/cm_vis.o \
src/common/shared/rand.o \
src/common/shared/shared.o \
src/common/unzip/ioapi.o \

View file

@ -24,7 +24,7 @@
* =======================================================================
*/
#include "../header/common.h"
#include "header/common.h"
#define MAX_NUM_ARGVS 50
@ -35,82 +35,108 @@ char *com_argv[MAX_NUM_ARGVS+1];
* Returns the position (1 to argc-1) in the program's argument list
* where the given parameter apears, or 0 if not present
*/
int COM_CheckParm (char *parm)
int
COM_CheckParm(char *parm)
{
int i;
for (i = 1; i < com_argc; i++)
{
if (!strcmp(parm, com_argv[i]))
{
return i;
}
}
return 0;
}
int COM_Argc (void)
int
COM_Argc(void)
{
return com_argc;
}
char *COM_Argv (int arg)
char *
COM_Argv(int arg)
{
if ((arg < 0) || (arg >= com_argc) || !com_argv[arg])
{
if (arg < 0 || arg >= com_argc || !com_argv[arg])
return "";
}
return com_argv[arg];
}
void COM_ClearArgv (int arg)
void
COM_ClearArgv(int arg)
{
if ((arg < 0) || (arg >= com_argc) || !com_argv[arg])
{
if (arg < 0 || arg >= com_argc || !com_argv[arg])
return;
}
com_argv[arg] = "";
}
void COM_InitArgv (int argc, char **argv)
void
COM_InitArgv(int argc, char **argv)
{
int i;
if (argc > MAX_NUM_ARGVS)
{
Com_Error(ERR_FATAL, "argc > MAX_NUM_ARGVS");
}
com_argc = argc;
for (i = 0; i < argc; i++)
{
if (!argv[i] || strlen(argv[i]) >= MAX_TOKEN_CHARS )
if (!argv[i] || (strlen(argv[i]) >= MAX_TOKEN_CHARS))
{
com_argv[i] = "";
}
else
{
com_argv[i] = argv[i];
}
}
}
/*
* Adds the given string at the end of the current argument list
*/
void COM_AddParm (char *parm)
void
COM_AddParm(char *parm)
{
if (com_argc == MAX_NUM_ARGVS)
{
Com_Error(ERR_FATAL, "COM_AddParm: MAX_NUM)ARGS");
}
com_argv[com_argc++] = parm;
}
int memsearch (byte *start, int count, int search)
int
memsearch(byte *start, int count, int search)
{
int i;
for (i = 0; i < count; i++)
{
if (start[i] == search)
{
return i;
}
}
return -1;
}
char *CopyString (char *in)
char *
CopyString(char *in)
{
char *out;
@ -119,7 +145,8 @@ char *CopyString (char *in)
return out;
}
void Info_Print (char *s)
void
Info_Print(char *s)
{
char key[512];
char value[512];
@ -127,14 +154,18 @@ void Info_Print (char *s)
int l;
if (*s == '\\')
{
s++;
}
while (*s)
{
o = key;
while (*s && *s != '\\')
{
*o++ = *s++;
}
l = o - key;
@ -145,7 +176,9 @@ void Info_Print (char *s)
}
else
{
*o = 0;
}
Com_Printf("%s", key);
@ -159,13 +192,18 @@ void Info_Print (char *s)
s++;
while (*s && *s != '\\')
{
*o++ = *s++;
}
*o = 0;
if (*s)
{
s++;
}
Com_Printf("%s\n", value);
}
}

View file

@ -24,7 +24,7 @@
* =======================================================================
*/
#include "../header/common.h"
#include "header/common.h"
#include <stdlib.h>
#include <setjmp.h>
@ -40,10 +40,13 @@ static char *rd_buffer;
static int rd_buffersize;
static void (*rd_flush)(int target, char *buffer);
void Com_BeginRedirect (int target, char *buffer, int buffersize, void (*flush))
void
Com_BeginRedirect(int target, char *buffer, int buffersize, void (*flush))
{
if (!target || !buffer || !buffersize || !flush)
{
return;
}
rd_target = target;
rd_buffer = buffer;
@ -53,7 +56,8 @@ void Com_BeginRedirect (int target, char *buffer, int buffersize, void (*flush))
*rd_buffer = 0;
}
void Com_EndRedirect (void)
void
Com_EndRedirect(void)
{
rd_flush(rd_target, rd_buffer);
@ -67,7 +71,8 @@ void Com_EndRedirect (void)
* Both client and server can use this, and it will output
* to the apropriate place.
*/
void Com_Printf (char *fmt, ...)
void
Com_Printf(char *fmt, ...)
{
va_list argptr;
char msg[MAXPRINTMSG];
@ -105,30 +110,41 @@ void Com_Printf (char *fmt, ...)
Com_sprintf(name, sizeof(name), "%s/qconsole.log", FS_Gamedir());
if (logfile_active->value > 2)
{
logfile = fopen(name, "a");
}
else
{
logfile = fopen(name, "w");
}
}
if (logfile)
{
fprintf(logfile, "%s", msg);
}
if (logfile_active->value > 1)
{
fflush(logfile); /* force it to save every time */
}
}
}
/*
* A Com_Printf that only shows up if the "developer" cvar is set
*/
void Com_DPrintf (char *fmt, ...)
void
Com_DPrintf(char *fmt, ...)
{
va_list argptr;
char msg[MAXPRINTMSG];
if (!developer || !developer->value)
{
return; /* don't confuse non-developers with techie stuff... */
}
va_start(argptr, fmt);
vsnprintf(msg, MAXPRINTMSG, fmt, argptr);
@ -141,13 +157,16 @@ void Com_DPrintf (char *fmt, ...)
* A Com_Printf that only shows up when either the "modder" or "developer"
* cvars is set
*/
void Com_MDPrintf (char *fmt, ...)
void
Com_MDPrintf(char *fmt, ...)
{
va_list argptr;
char msg[MAXPRINTMSG];
if ((!modder || !modder->value) && (!developer || !developer->value))
{
return;
}
va_start(argptr, fmt);
vsnprintf(msg, MAXPRINTMSG, fmt, argptr);
@ -160,14 +179,17 @@ void Com_MDPrintf (char *fmt, ...)
* Both client and server can use this, and it will
* do the apropriate things.
*/
void Com_Error (int code, char *fmt, ...)
void
Com_Error(int code, char *fmt, ...)
{
va_list argptr;
static char msg[MAXPRINTMSG];
static qboolean recursive;
if (recursive)
{
Sys_Error("recursive error after: %s", msg);
}
recursive = true;
@ -186,7 +208,8 @@ void Com_Error (int code, char *fmt, ...)
else if (code == ERR_DROP)
{
Com_Printf ("********************\nERROR: %s\n********************\n", msg);
Com_Printf("********************\nERROR: %s\n********************\n",
msg);
SV_Shutdown(va("Server crashed: %s\n", msg), false);
#ifndef DEDICATED_ONLY
CL_Drop();
@ -217,19 +240,23 @@ void Com_Error (int code, char *fmt, ...)
* Both client and server can use this, and it will
* do the apropriate things.
*/
void Com_Quit (void)
void
Com_Quit(void)
{
Com_Printf("\n----------- shutting down ----------\n");
SV_Shutdown("Server quit\n", false);
Sys_Quit();
}
int Com_ServerState (void)
int
Com_ServerState(void)
{
return server_state;
}
void Com_SetServerState (int state)
void
Com_SetServerState(int state)
{
server_state = state;
}

1004
src/common/cmdparser.c Normal file

File diff suppressed because it is too large Load diff

1876
src/common/collision.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,571 +0,0 @@
/*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* =======================================================================
*
* This file implements the command execution, e.g. directs the commands
* to the appropriate subsystems.
*
* =======================================================================
*/
#include "../header/common.h"
#include "../header/cmd.h"
typedef struct cmd_function_s
{
struct cmd_function_s *next;
char *name;
xcommand_t function;
} cmd_function_t;
static int cmd_argc;
static char *cmd_argv [ MAX_STRING_TOKENS ];
static char *cmd_null_string = "";
static char cmd_args [ MAX_STRING_CHARS ];
char retval [ 256 ];
static cmd_function_t *cmd_functions; /* possible commands to execute */
int
Cmd_Argc ( void )
{
return ( cmd_argc );
}
char *
Cmd_Argv ( int arg )
{
if ( (unsigned) arg >= cmd_argc )
{
return ( cmd_null_string );
}
return ( cmd_argv [ arg ] );
}
/*
* Returns a single string containing argv(1) to argv(argc()-1)
*/
char *
Cmd_Args ( void )
{
return ( cmd_args );
}
char *
Cmd_MacroExpandString ( char *text )
{
int i, j, count, len;
qboolean inquote;
char *scan;
static char expanded [ MAX_STRING_CHARS ];
char temporary [ MAX_STRING_CHARS ];
char *token, *start;
inquote = false;
scan = text;
len = strlen( scan );
if ( len >= MAX_STRING_CHARS )
{
Com_Printf( "Line exceeded %i chars, discarded.\n", MAX_STRING_CHARS );
return ( NULL );
}
count = 0;
for ( i = 0; i < len; i++ )
{
if ( scan [ i ] == '"' )
{
inquote ^= 1;
}
if ( inquote )
{
continue; /* don't expand inside quotes */
}
if ( scan [ i ] != '$' )
{
continue;
}
/* scan out the complete macro */
start = scan + i + 1;
token = COM_Parse( &start );
if ( !start )
{
continue;
}
token = (char *) Cvar_VariableString( token );
j = strlen( token );
len += j;
if ( len >= MAX_STRING_CHARS )
{
Com_Printf( "Expanded line exceeded %i chars, discarded.\n", MAX_STRING_CHARS );
return ( NULL );
}
strncpy( temporary, scan, i );
strcpy( temporary + i, token );
strcpy( temporary + i + j, start );
strcpy( expanded, temporary );
scan = expanded;
i--;
if ( ++count == 100 )
{
Com_Printf( "Macro expansion loop, discarded.\n" );
return ( NULL );
}
}
if ( inquote )
{
Com_Printf( "Line has unmatched quote, discarded.\n" );
return ( NULL );
}
return ( scan );
}
/*
* Parses the given string into command line tokens.
* $Cvars will be expanded unless they are in a quoted token
*/
void
Cmd_TokenizeString ( char *text, qboolean macroExpand )
{
int i;
const char *com_token;
/* clear the args from the last string */
for ( i = 0; i < cmd_argc; i++ )
{
Z_Free( cmd_argv [ i ] );
}
cmd_argc = 0;
cmd_args [ 0 ] = 0;
/* macro expand the text */
if ( macroExpand )
{
text = Cmd_MacroExpandString( text );
}
if ( !text )
{
return;
}
while ( 1 )
{
/* skip whitespace up to a /n */
while ( *text && *text <= ' ' && *text != '\n' )
{
text++;
}
if ( *text == '\n' )
{
/* a newline seperates commands in the buffer */
text++;
break;
}
if ( !*text )
{
return;
}
/* set cmd_args to everything after the first arg */
if ( cmd_argc == 1 )
{
int l;
strcpy( cmd_args, text );
/* strip off any trailing whitespace */
l = strlen( cmd_args ) - 1;
for ( ; l >= 0; l-- )
{
if ( cmd_args [ l ] <= ' ' )
{
cmd_args [ l ] = 0;
}
else
{
break;
}
}
}
com_token = COM_Parse( &text );
if ( !text )
{
return;
}
if ( cmd_argc < MAX_STRING_TOKENS )
{
cmd_argv [ cmd_argc ] = Z_Malloc( strlen( com_token ) + 1 );
strcpy( cmd_argv [ cmd_argc ], com_token );
cmd_argc++;
}
}
}
void
Cmd_AddCommand ( char *cmd_name, xcommand_t function )
{
cmd_function_t *cmd;
/* fail if the command is a variable name */
if ( Cvar_VariableString( cmd_name ) [ 0 ] )
{
Cmd_RemoveCommand( cmd_name );
}
/* fail if the command already exists */
for ( cmd = cmd_functions; cmd; cmd = cmd->next )
{
if ( !strcmp( cmd_name, cmd->name ) )
{
Com_Printf( "Cmd_AddCommand: %s already defined\n", cmd_name );
return;
}
}
cmd = Z_Malloc( sizeof ( cmd_function_t ) );
cmd->name = cmd_name;
cmd->function = function;
cmd->next = cmd_functions;
cmd_functions = cmd;
}
void
Cmd_RemoveCommand ( char *cmd_name )
{
cmd_function_t *cmd, **back;
back = &cmd_functions;
while ( 1 )
{
cmd = *back;
if ( !cmd )
{
Com_Printf( "Cmd_RemoveCommand: %s not added\n", cmd_name );
return;
}
if ( !strcmp( cmd_name, cmd->name ) )
{
*back = cmd->next;
Z_Free( cmd );
return;
}
back = &cmd->next;
}
}
qboolean
Cmd_Exists ( char *cmd_name )
{
cmd_function_t *cmd;
for ( cmd = cmd_functions; cmd; cmd = cmd->next )
{
if ( !strcmp( cmd_name, cmd->name ) )
{
return ( true );
}
}
return ( false );
}
int qsort_strcomp ( const void *s1, const void *s2 )
{
return (strcmp(*(char **)s1, *(char **)s2));
}
char *
Cmd_CompleteCommand ( char *partial )
{
cmd_function_t *cmd;
int len, i, o, p;
cmdalias_t *a;
cvar_t *cvar;
char *pmatch [ 1024 ];
qboolean diff = false;
len = strlen( partial );
if ( !len )
{
return ( NULL );
}
/* check for exact match */
for ( cmd = cmd_functions; cmd; cmd = cmd->next )
{
if ( !strcmp( partial, cmd->name ) )
{
return ( cmd->name );
}
}
for ( a = cmd_alias; a; a = a->next )
{
if ( !strcmp( partial, a->name ) )
{
return ( a->name );
}
}
for ( cvar = cvar_vars; cvar; cvar = cvar->next )
{
if ( !strcmp( partial, cvar->name ) )
{
return ( cvar->name );
}
}
for ( i = 0; i < 1024; i++ )
{
pmatch [ i ] = NULL;
}
i = 0;
/* check for partial match */
for ( cmd = cmd_functions; cmd; cmd = cmd->next )
{
if ( !strncmp( partial, cmd->name, len ) )
{
pmatch [ i ] = cmd->name;
i++;
}
}
for ( a = cmd_alias; a; a = a->next )
{
if ( !strncmp( partial, a->name, len ) )
{
pmatch [ i ] = a->name;
i++;
}
}
for ( cvar = cvar_vars; cvar; cvar = cvar->next )
{
if ( !strncmp( partial, cvar->name, len ) )
{
pmatch [ i ] = cvar->name;
i++;
}
}
if ( i )
{
if ( i == 1 )
{
return ( pmatch [ 0 ] );
}
/* Sort it */
qsort(pmatch, i, sizeof(pmatch[0]), qsort_strcomp);
Com_Printf( "\n\n", partial );
for ( o = 0; o < i; o++ )
{
Com_Printf( " %s\n", pmatch [ o ] );
}
strcpy( retval, "" );
p = 0;
while ( !diff && p < 256 )
{
retval [ p ] = pmatch [ 0 ] [ p ];
for ( o = 0; o < i; o++ )
{
if ( p > strlen( pmatch [ o ] ) )
{
continue;
}
if ( retval [ p ] != pmatch [ o ] [ p ] )
{
retval [ p ] = 0;
diff = true;
}
}
p++;
}
return ( retval );
}
return ( NULL );
}
qboolean
Cmd_IsComplete ( char *command )
{
cmd_function_t *cmd;
cmdalias_t *a;
cvar_t *cvar;
/* check for exact match */
for ( cmd = cmd_functions; cmd; cmd = cmd->next )
{
if ( !strcmp( command, cmd->name ) )
{
return ( true );
}
}
for ( a = cmd_alias; a; a = a->next )
{
if ( !strcmp( command, a->name ) )
{
return ( true );
}
}
for ( cvar = cvar_vars; cvar; cvar = cvar->next )
{
if ( !strcmp( command, cvar->name ) )
{
return ( true );
}
}
return ( false );
}
/*
* A complete command line has been parsed, so try to execute it
*/
void
Cmd_ExecuteString ( char *text )
{
cmd_function_t *cmd;
cmdalias_t *a;
Cmd_TokenizeString( text, true );
/* execute the command line */
if ( !Cmd_Argc() )
{
return; /* no tokens */
}
/* check functions */
for ( cmd = cmd_functions; cmd; cmd = cmd->next )
{
if ( !Q_strcasecmp( cmd_argv [ 0 ], cmd->name ) )
{
if ( !cmd->function )
{
/* forward to server command */
Cmd_ExecuteString( va( "cmd %s", text ) );
}
else
{
cmd->function();
}
return;
}
}
/* check alias */
for ( a = cmd_alias; a; a = a->next )
{
if ( !Q_strcasecmp( cmd_argv [ 0 ], a->name ) )
{
if ( ++alias_count == ALIAS_LOOP_COUNT )
{
Com_Printf( "ALIAS_LOOP_COUNT\n" );
return;
}
Cbuf_InsertText( a->value );
return;
}
}
/* check cvars */
if ( Cvar_Command() )
{
return;
}
#ifndef DEDICATED_ONLY
/* send it as a server command if we are connected */
Cmd_ForwardToServer();
#endif
}
void
Cmd_List_f ( void )
{
cmd_function_t *cmd;
int i;
i = 0;
for ( cmd = cmd_functions; cmd; cmd = cmd->next, i++ )
{
Com_Printf( "%s\n", cmd->name );
}
Com_Printf( "%i commands\n", i );
}
void
Cmd_Init ( void )
{
/* register our commands */
Cmd_AddCommand( "cmdlist", Cmd_List_f );
Cmd_AddCommand( "exec", Cmd_Exec_f );
Cmd_AddCommand( "echo", Cmd_Echo_f );
Cmd_AddCommand( "alias", Cmd_Alias_f );
Cmd_AddCommand( "wait", Cmd_Wait_f );
}

View file

@ -1,278 +0,0 @@
/*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*
* =======================================================================
*
* This file implements the main part of the command processor. Every
* command which is send vie the command line at startup, via the
* console and via rcon is processed here and send to the apropriate
* subsystem.
*
* =======================================================================
*/
#include "../header/common.h"
#include "../header/cmd.h"
/*
* Causes execution of the remainder of the command buffer to be delayed
* until next frame. This allows commands like: bind g "impulse 5 ;
* +attack ; wait ; -attack ; impulse 2"
*/
void Cmd_Wait_f (void) {
cmd_wait = true;
}
/* COMMAND BUFFER */
sizebuf_t cmd_text;
byte cmd_text_buf[8192];
char defer_text_buf[8192];
void Cbuf_Init (void) {
SZ_Init (&cmd_text, cmd_text_buf, sizeof(cmd_text_buf));
}
/*
* Adds command text at the end of the buffer
*/
void Cbuf_AddText (char *text) {
int l;
l = strlen (text);
if (cmd_text.cursize + l >= cmd_text.maxsize) {
Com_Printf ("Cbuf_AddText: overflow\n");
return;
}
SZ_Write (&cmd_text, text, strlen (text));
}
/*
* Adds command text immediately after the current command
* Adds a \n to the text
*/
void Cbuf_InsertText (char *text) {
char *temp;
int templen;
/* copy off any commands still remaining in the exec buffer */
templen = cmd_text.cursize;
if (templen) {
temp = Z_Malloc (templen);
memcpy (temp, cmd_text.data, templen);
SZ_Clear (&cmd_text);
} else
temp = NULL;
/* add the entire text of the file */
Cbuf_AddText (text);
/* add the copied off data */
if (templen) {
SZ_Write (&cmd_text, temp, templen);
Z_Free (temp);
}
}
void Cbuf_CopyToDefer (void) {
memcpy(defer_text_buf, cmd_text_buf, cmd_text.cursize);
defer_text_buf[cmd_text.cursize] = 0;
cmd_text.cursize = 0;
}
void Cbuf_InsertFromDefer (void) {
Cbuf_InsertText (defer_text_buf);
defer_text_buf[0] = 0;
}
void Cbuf_ExecuteText (int exec_when, char *text) {
switch (exec_when) {
case EXEC_NOW:
Cmd_ExecuteString (text);
break;
case EXEC_INSERT:
Cbuf_InsertText (text);
break;
case EXEC_APPEND:
Cbuf_AddText (text);
break;
default:
Com_Error (ERR_FATAL, "Cbuf_ExecuteText: bad exec_when");
}
}
void Cbuf_Execute (void) {
int i;
char *text;
char line[1024];
int quotes;
alias_count = 0; /* don't allow infinite alias loops */
while (cmd_text.cursize) {
/* find a \n or ; line break */
text = (char *)cmd_text.data;
quotes = 0;
for (i=0 ; i< cmd_text.cursize ; i++) {
if (text[i] == '"')
quotes++;
if ( !(quotes&1) && text[i] == ';')
break; /* don't break if inside a quoted string */
if (text[i] == '\n')
break;
}
if( i > sizeof( line ) - 1 ) {
i = sizeof( line ) - 1;
}
memcpy (line, text, i);
line[i] = 0;
/* delete the text from the command buffer and move remaining
commands down this is necessary because commands (exec,
alias) can insert data at the beginning of the text buffer */
if (i == cmd_text.cursize)
cmd_text.cursize = 0;
else {
i++;
cmd_text.cursize -= i;
memmove (text, text+i, cmd_text.cursize);
}
/* execute the command line */
Cmd_ExecuteString (line);
if (cmd_wait) {
/* skip out while text still remains in buffer,
leaving it for next frame */
cmd_wait = false;
break;
}
}
}
/*
* Adds command line parameters as script statements Commands lead with
* a +, and continue until another +
*
* Set commands are added early, so they are guaranteed to be set before
* the client and server initialize for the first time.
*
* Other commands are added late, after all initialization is complete.
*/
void Cbuf_AddEarlyCommands (qboolean clear) {
int i;
char *s;
for (i=0 ; i<COM_Argc() ; i++) {
s = COM_Argv(i);
if (strcmp (s, "+set"))
continue;
Cbuf_AddText (va("set %s %s\n", COM_Argv(i+1), COM_Argv(i+2)));
if (clear) {
COM_ClearArgv(i);
COM_ClearArgv(i+1);
COM_ClearArgv(i+2);
}
i+=2;
}
}
/*
* Adds command line parameters as script statements
* Commands lead with a + and continue until another + or -
* quake +vid_ref gl +map amlev1
*
* Returns true if any late commands were added, which
* will keep the demoloop from immediately starting
*/
qboolean Cbuf_AddLateCommands (void) {
int i, j;
int s;
char *text, *build, c;
int argc;
qboolean ret;
/* build the combined string to parse from */
s = 0;
argc = COM_Argc();
for (i=1 ; i<argc ; i++) {
s += strlen (COM_Argv(i)) + 1;
}
if (!s)
return false;
text = Z_Malloc (s+1);
text[0] = 0;
for (i=1 ; i<argc ; i++) {
strcat (text,COM_Argv(i));
if (i != argc-1)
strcat (text, " ");
}
/* pull out the commands */
build = Z_Malloc (s+1);
build[0] = 0;
for (i=0 ; i<s-1 ; i++) {
if (text[i] == '+') {
i++;
for (j=i ; (text[j] != '+') && (text[j] != '-') && (text[j] != 0) ; j++)
;
c = text[j];
text[j] = 0;
strcat (build, text+i);
strcat (build, "\n");
text[j] = c;
i = j-1;
}
}
ret = (build[0] != 0);
if (ret)
Cbuf_AddText (build);
Z_Free (text);
Z_Free (build);
return ret;
}

View file

@ -1,127 +0,0 @@
/*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* =======================================================================
*
* This file implements the command processor for command scripting.
*
* =======================================================================
*/
#include "../header/common.h"
#include "../header/cmd.h"
void Cmd_Exec_f (void) {
char *f, *f2;
int len;
if (Cmd_Argc () != 2) {
Com_Printf ("exec <filename> : execute a script file\n");
return;
}
len = FS_LoadFile (Cmd_Argv(1), (void **)&f);
if (!f) {
Com_Printf ("couldn't exec %s\n",Cmd_Argv(1));
return;
}
Com_Printf ("execing %s\n",Cmd_Argv(1));
/* the file doesn't have a trailing 0, so we need to copy it off */
f2 = Z_Malloc(len+1);
memcpy (f2, f, len);
f2[len] = 0;
Cbuf_InsertText (f2);
Z_Free (f2);
FS_FreeFile (f);
}
/*
* Just prints the rest of the line to the console
*/
void Cmd_Echo_f (void) {
int i;
for (i=1 ; i<Cmd_Argc() ; i++)
Com_Printf ("%s ",Cmd_Argv(i));
Com_Printf ("\n");
}
/*
* Creates a new command that executes
* a command string (possibly ; seperated)
*/
void Cmd_Alias_f (void) {
cmdalias_t *a;
char cmd[1024];
int i, c;
char *s;
if (Cmd_Argc() == 1) {
Com_Printf ("Current alias commands:\n");
for (a = cmd_alias ; a ; a=a->next)
Com_Printf ("%s : %s\n", a->name, a->value);
return;
}
s = Cmd_Argv(1);
if (strlen(s) >= MAX_ALIAS_NAME) {
Com_Printf ("Alias name is too long\n");
return;
}
/* if the alias already exists, reuse it */
for (a = cmd_alias ; a ; a=a->next) {
if (!strcmp(s, a->name)) {
Z_Free (a->value);
break;
}
}
if (!a) {
a = Z_Malloc (sizeof(cmdalias_t));
a->next = cmd_alias;
cmd_alias = a;
}
strcpy (a->name, s);
/* copy the rest of the command line */
cmd[0] = 0; /* start out with a null string */
c = Cmd_Argc();
for (i=2 ; i< c ; i++) {
strcat (cmd, Cmd_Argv(i));
if (i != (c - 1))
strcat (cmd, " ");
}
strcat (cmd, "\n");
a->value = CopyString (cmd);
}

View file

@ -31,8 +31,7 @@
#define CRC_INIT_VALUE 0xffff
#define CRC_XOR_VALUE 0x0000
static unsigned short crctable[256] =
{
static unsigned short crctable[256] = {
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
@ -67,29 +66,36 @@ static unsigned short crctable[256] =
0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
};
void CRC_Init(unsigned short *crcvalue)
void
CRC_Init(unsigned short *crcvalue)
{
*crcvalue = CRC_INIT_VALUE;
}
void CRC_ProcessByte(unsigned short *crcvalue, byte data)
void
CRC_ProcessByte(unsigned short *crcvalue, byte data)
{
*crcvalue = (*crcvalue << 8) ^ crctable[(*crcvalue >> 8) ^ data];
}
unsigned short CRC_Value(unsigned short crcvalue)
unsigned short
CRC_Value(unsigned short crcvalue)
{
return crcvalue ^ CRC_XOR_VALUE;
}
unsigned short CRC_Block (byte *start, int count)
unsigned short
CRC_Block(byte *start, int count)
{
unsigned short crc;
CRC_Init(&crc);
while (count--)
{
crc = (crc << 8) ^ crctable[(crc >> 8) ^ *start++];
}
return crc;
}

View file

@ -19,7 +19,7 @@
*
* =======================================================================
*
* The Quake II CVAR subsystem. Implements dynamic variable tracking.
* The Quake II CVAR subsystem. Implements dynamic variable handling.
*
* =======================================================================
*/
@ -28,56 +28,75 @@
cvar_t *cvar_vars;
static qboolean Cvar_InfoValidate (char *s)
static qboolean
Cvar_InfoValidate(char *s)
{
if (strstr(s, "\\"))
{
return false;
}
if (strstr(s, "\""))
{
return false;
}
if (strstr(s, ";"))
{
return false;
}
return true;
}
static cvar_t *Cvar_FindVar (const char *var_name)
static cvar_t *
Cvar_FindVar(const char *var_name)
{
cvar_t *var;
for (var = cvar_vars; var; var = var->next)
{
if (!strcmp(var_name, var->name))
{
return var;
}
}
return NULL;
}
float Cvar_VariableValue (char *var_name)
float
Cvar_VariableValue(char *var_name)
{
cvar_t *var;
var = Cvar_FindVar(var_name);
if (!var)
{
return 0;
}
return strtod(var->string, (char **)NULL);
}
const char *Cvar_VariableString (const char *var_name)
const char *
Cvar_VariableString(const char *var_name)
{
cvar_t *var;
var = Cvar_FindVar(var_name);
if (!var)
{
return "";
}
return var->string;
}
char *Cvar_CompleteVariable (char *partial)
char *
Cvar_CompleteVariable(char *partial)
{
cvar_t *cvar;
int len;
@ -85,17 +104,27 @@ char *Cvar_CompleteVariable (char *partial)
len = (int)strlen(partial);
if (!len)
{
return NULL;
}
/* check exact match */
for (cvar = cvar_vars; cvar; cvar = cvar->next)
{
if (!strcmp(partial, cvar->name))
{
return cvar->name;
}
}
/* check partial match */
for (cvar = cvar_vars; cvar; cvar = cvar->next)
{
if (!strncmp(partial, cvar->name, len))
{
return cvar->name;
}
}
return NULL;
}
@ -104,7 +133,8 @@ char *Cvar_CompleteVariable (char *partial)
* If the variable already exists, the value will not be set
* The flags will be or'ed in if the variable exists.
*/
cvar_t *Cvar_Get (char *var_name, char *var_value, int flags)
cvar_t *
Cvar_Get(char *var_name, char *var_value, int flags)
{
cvar_t *var;
@ -126,7 +156,9 @@ cvar_t *Cvar_Get (char *var_name, char *var_value, int flags)
}
if (!var_value)
{
return NULL;
}
if (flags & (CVAR_USERINFO | CVAR_SERVERINFO))
{
@ -152,7 +184,8 @@ cvar_t *Cvar_Get (char *var_name, char *var_value, int flags)
return var;
}
cvar_t *Cvar_Set2 (char *var_name, char *value, qboolean force)
cvar_t *
Cvar_Set2(char *var_name, char *value, qboolean force)
{
cvar_t *var;
@ -185,7 +218,9 @@ cvar_t *Cvar_Set2 (char *var_name, char *value, qboolean force)
if (var->latched_string)
{
if (strcmp(value, var->latched_string) == 0)
{
return var;
}
Z_Free(var->latched_string);
}
@ -193,8 +228,10 @@ cvar_t *Cvar_Set2 (char *var_name, char *value, qboolean force)
else
{
if (strcmp(value, var->string) == 0)
{
return var;
}
}
if (Com_ServerState())
{
@ -228,12 +265,16 @@ cvar_t *Cvar_Set2 (char *var_name, char *value, qboolean force)
}
if (!strcmp(value, var->string))
{
return var;
}
var->modified = true;
if (var->flags & CVAR_USERINFO)
{
userinfo_modified = true;
}
Z_Free(var->string);
@ -243,17 +284,20 @@ cvar_t *Cvar_Set2 (char *var_name, char *value, qboolean force)
return var;
}
cvar_t *Cvar_ForceSet (char *var_name, char *value)
cvar_t *
Cvar_ForceSet(char *var_name, char *value)
{
return Cvar_Set2(var_name, value, true);
}
cvar_t *Cvar_Set (char *var_name, char *value)
cvar_t *
Cvar_Set(char *var_name, char *value)
{
return Cvar_Set2(var_name, value, false);
}
cvar_t *Cvar_FullSet (char *var_name, char *value, int flags)
cvar_t *
Cvar_FullSet(char *var_name, char *value, int flags)
{
cvar_t *var;
@ -267,7 +311,9 @@ cvar_t *Cvar_FullSet (char *var_name, char *value, int flags)
var->modified = true;
if (var->flags & CVAR_USERINFO)
{
userinfo_modified = true;
}
Z_Free(var->string);
@ -279,15 +325,20 @@ cvar_t *Cvar_FullSet (char *var_name, char *value, int flags)
return var;
}
void Cvar_SetValue (char *var_name, float value)
void
Cvar_SetValue(char *var_name, float value)
{
char val[32];
if (value == (int)value)
{
Com_sprintf(val, sizeof(val), "%i", (int)value);
}
else
{
Com_sprintf(val, sizeof(val), "%f", value);
}
Cvar_Set(var_name, val);
}
@ -295,14 +346,17 @@ void Cvar_SetValue (char *var_name, float value)
/*
* Any variables with latched values will now be updated
*/
void Cvar_GetLatchedVars (void)
void
Cvar_GetLatchedVars(void)
{
cvar_t *var;
for (var = cvar_vars; var; var = var->next)
{
if (!var->latched_string)
{
continue;
}
Z_Free(var->string);
var->string = var->latched_string;
@ -320,7 +374,8 @@ void Cvar_GetLatchedVars (void)
/*
* Handles variable inspection and changing from the console
*/
qboolean Cvar_Command (void)
qboolean
Cvar_Command(void)
{
cvar_t *v;
@ -328,7 +383,9 @@ qboolean Cvar_Command (void)
v = Cvar_FindVar(Cmd_Argv(0));
if (!v)
{
return false;
}
/* perform a variable print or set */
if (Cmd_Argc() == 1)
@ -344,14 +401,15 @@ qboolean Cvar_Command (void)
/*
* Allows setting and defining of arbitrary cvars from console
*/
void Cvar_Set_f (void)
void
Cvar_Set_f(void)
{
int c;
int flags;
c = Cmd_Argc();
if (c != 3 && c != 4)
if ((c != 3) && (c != 4))
{
Com_Printf("usage: set <variable> <value> [u / s]\n");
return;
@ -360,10 +418,14 @@ void Cvar_Set_f (void)
if (c == 4)
{
if (!strcmp(Cmd_Argv(3), "u"))
{
flags = CVAR_USERINFO;
}
else if (!strcmp(Cmd_Argv(3), "s"))
{
flags = CVAR_SERVERINFO;
}
else
{
@ -375,14 +437,17 @@ void Cvar_Set_f (void)
}
else
{
Cvar_Set(Cmd_Argv(1), Cmd_Argv(2));
}
}
/*
* Appends lines containing "set variable value" for all variables
* with the archive flag set to true.
*/
void Cvar_WriteVariables (char *path)
void
Cvar_WriteVariables(char *path)
{
cvar_t *var;
char buffer[1024];
@ -394,7 +459,8 @@ void Cvar_WriteVariables (char *path)
{
if (var->flags & CVAR_ARCHIVE)
{
Com_sprintf (buffer, sizeof(buffer), "set %s \"%s\"\n", var->name, var->string);
Com_sprintf(buffer, sizeof(buffer), "set %s \"%s\"\n",
var->name, var->string);
fprintf(f, "%s", buffer);
}
}
@ -402,7 +468,8 @@ void Cvar_WriteVariables (char *path)
fclose(f);
}
void Cvar_List_f (void)
void
Cvar_List_f(void)
{
cvar_t *var;
int i;
@ -412,31 +479,49 @@ void Cvar_List_f (void)
for (var = cvar_vars; var; var = var->next, i++)
{
if (var->flags & CVAR_ARCHIVE)
{
Com_Printf("*");
}
else
{
Com_Printf(" ");
}
if (var->flags & CVAR_USERINFO)
{
Com_Printf("U");
}
else
{
Com_Printf(" ");
}
if (var->flags & CVAR_SERVERINFO)
{
Com_Printf("S");
}
else
{
Com_Printf(" ");
}
if (var->flags & CVAR_NOSET)
{
Com_Printf("-");
}
else if (var->flags & CVAR_LATCH)
{
Com_Printf("L");
}
else
{
Com_Printf(" ");
}
Com_Printf(" %s \"%s\"\n", var->name, var->string);
}
@ -446,7 +531,8 @@ void Cvar_List_f (void)
qboolean userinfo_modified;
char *Cvar_BitInfo (int bit)
char *
Cvar_BitInfo(int bit)
{
static char info[MAX_INFO_STRING];
cvar_t *var;
@ -456,8 +542,10 @@ char *Cvar_BitInfo (int bit)
for (var = cvar_vars; var; var = var->next)
{
if (var->flags & bit)
{
Info_SetValueForKey(info, var->name, var->string);
}
}
return info;
}
@ -466,7 +554,8 @@ char *Cvar_BitInfo (int bit)
* returns an info string containing
* all the CVAR_USERINFO cvars
*/
char *Cvar_Userinfo (void)
char *
Cvar_Userinfo(void)
{
return Cvar_BitInfo(CVAR_USERINFO);
}
@ -475,7 +564,8 @@ char *Cvar_Userinfo (void)
* returns an info string containing
* all the CVAR_SERVERINFO cvars
*/
char *Cvar_Serverinfo (void)
char *
Cvar_Serverinfo(void)
{
return Cvar_BitInfo(CVAR_SERVERINFO);
}
@ -483,9 +573,10 @@ char *Cvar_Serverinfo (void)
/*
* Reads in all archived cvars
*/
void Cvar_Init (void)
void
Cvar_Init(void)
{
Cmd_AddCommand("set", Cvar_Set_f);
Cmd_AddCommand("cvarlist", Cvar_List_f);
}

File diff suppressed because it is too large Load diff

View file

@ -40,13 +40,13 @@ glob_match_after_star ( char *pattern, char *text )
{
if ((c == '?') && (*t++ == '\0'))
{
return ( 0 );
return 0;
}
}
if (c == '\0')
{
return ( 1 );
return 1;
}
if (c == '\\')
@ -62,12 +62,12 @@ glob_match_after_star ( char *pattern, char *text )
{
if (((c == '[') || (*t == c1)) && glob_match(p - 1, t))
{
return ( 1 );
return 1;
}
if (*t++ == '\0')
{
return ( 0 );
return 0;
}
}
}
@ -103,7 +103,7 @@ glob_match ( char *pattern, char *text )
if (*t == '\0')
{
return ( 0 );
return 0;
}
else
{
@ -116,13 +116,13 @@ glob_match ( char *pattern, char *text )
if (*p++ != *t++)
{
return ( 0 );
return 0;
}
break;
case '*':
return ( glob_match_after_star( p, t ) );
return glob_match_after_star(p, t);
case '[':
{
@ -131,7 +131,7 @@ glob_match ( char *pattern, char *text )
if (!c1)
{
return ( 0 );
return 0;
}
invert = ((*p == '!') || (*p == '^'));
@ -155,7 +155,7 @@ glob_match ( char *pattern, char *text )
if (c == '\0')
{
return ( 0 );
return 0;
}
c = *p++;
@ -171,7 +171,7 @@ glob_match ( char *pattern, char *text )
if (cend == '\0')
{
return ( 0 );
return 0;
}
c = *p++;
@ -190,7 +190,7 @@ glob_match ( char *pattern, char *text )
if (!invert)
{
return ( 0 );
return 0;
}
break;
@ -202,14 +202,14 @@ glob_match ( char *pattern, char *text )
{
if (c == '\0')
{
return ( 0 );
return 0;
}
c = *p++;
if (c == '\0')
{
return ( 0 );
return 0;
}
else if (c == '\\')
{
@ -219,7 +219,7 @@ glob_match ( char *pattern, char *text )
if (invert)
{
return ( 0 );
return 0;
}
break;
@ -229,10 +229,11 @@ glob_match ( char *pattern, char *text )
if (c != *t++)
{
return ( 0 );
return 0;
}
}
}
return ( *t == '\0' );
return *t == '\0';
}

View file

@ -1,49 +0,0 @@
/*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* =======================================================================
*
* The header for the command processor system
*
* =======================================================================
*/
#ifndef CO_CMD_H
#define CO_CMD_H
#define MAX_ALIAS_NAME 32
#define ALIAS_LOOP_COUNT 16
typedef struct cmdalias_s {
struct cmdalias_s *next;
char name[MAX_ALIAS_NAME];
char *value;
} cmdalias_t;
cmdalias_t *cmd_alias;
qboolean cmd_wait;
int alias_count; /* for detecting runaway loops */
void Cmd_Exec_f (void);
void Cmd_Echo_f (void);
void Cmd_Alias_f (void);
void Cmd_Wait_f (void);
#endif

View file

@ -1,124 +0,0 @@
/*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* =======================================================================
*
* The header file for the common model stuff.
*
* =======================================================================
*/
#ifndef CO_CMODEL_H
#define CO_CMODEL_H
typedef struct
{
cplane_t *plane;
int children[2]; /* negative numbers are leafs */
} cnode_t;
typedef struct
{
cplane_t *plane;
mapsurface_t *surface;
} cbrushside_t;
typedef struct
{
int contents;
int cluster;
int area;
unsigned short firstleafbrush;
unsigned short numleafbrushes;
} cleaf_t;
typedef struct
{
int contents;
int numsides;
int firstbrushside;
int checkcount; /* to avoid repeated testings */
} cbrush_t;
typedef struct
{
int numareaportals;
int firstareaportal;
int floodnum; /* if two areas have equal floodnums, they are connected */
int floodvalid;
} carea_t;
int checkcount;
char map_name[MAX_QPATH];
int numbrushsides;
cbrushside_t map_brushsides[MAX_MAP_BRUSHSIDES];
int numtexinfo;
mapsurface_t map_surfaces[MAX_MAP_TEXINFO];
int numplanes;
cplane_t map_planes[MAX_MAP_PLANES+6]; /* extra for box hull */
int numnodes;
cnode_t map_nodes[MAX_MAP_NODES+6]; /* extra for box hull */
cleaf_t map_leafs[MAX_MAP_LEAFS];
int emptyleaf, solidleaf;
int numleafbrushes;
unsigned short map_leafbrushes[MAX_MAP_LEAFBRUSHES];
int numcmodels;
cmodel_t map_cmodels[MAX_MAP_MODELS];
int numbrushes;
cbrush_t map_brushes[MAX_MAP_BRUSHES];
int numvisibility;
byte map_visibility[MAX_MAP_VISIBILITY];
int numentitychars;
char map_entitystring[MAX_MAP_ENTSTRING];
carea_t map_areas[MAX_MAP_AREAS];
int numareaportals;
dareaportal_t map_areaportals[MAX_MAP_AREAPORTALS];
mapsurface_t nullsurface;
int floodvalid;
qboolean portalopen[MAX_MAP_AREAPORTALS];
cvar_t *map_noareas;
void CM_InitBoxHull (void);
void FloodAreaConnections (void);
#ifndef DEDICATED_ONLY
int c_pointcontents;
int c_traces, c_brush_traces;
#endif
int CM_BoxLeafnums_headnode (vec3_t mins, vec3_t maxs, int *list, int listsize, int headnode, int *topnode);
#endif

View file

@ -94,11 +94,13 @@ void MSG_WriteCoord (sizebuf_t *sb, float f);
void MSG_WritePos(sizebuf_t *sb, vec3_t pos);
void MSG_WriteAngle(sizebuf_t *sb, float f);
void MSG_WriteAngle16(sizebuf_t *sb, float f);
void MSG_WriteDeltaUsercmd (sizebuf_t *sb, struct usercmd_s *from, struct usercmd_s *cmd);
void MSG_WriteDeltaEntity (struct entity_state_s *from, struct entity_state_s *to, sizebuf_t *msg, qboolean force, qboolean newentity);
void MSG_WriteDeltaUsercmd(sizebuf_t *sb, struct usercmd_s *from,
struct usercmd_s *cmd);
void MSG_WriteDeltaEntity(struct entity_state_s *from,
struct entity_state_s *to, sizebuf_t *msg,
qboolean force, qboolean newentity);
void MSG_WriteDir(sizebuf_t *sb, vec3_t vector);
void MSG_BeginReading(sizebuf_t *sb);
int MSG_ReadChar(sizebuf_t *sb);
@ -113,7 +115,9 @@ float MSG_ReadCoord (sizebuf_t *sb);
void MSG_ReadPos(sizebuf_t *sb, vec3_t pos);
float MSG_ReadAngle(sizebuf_t *sb);
float MSG_ReadAngle16(sizebuf_t *sb);
void MSG_ReadDeltaUsercmd (sizebuf_t *sb, struct usercmd_s *from, struct usercmd_s *cmd);
void MSG_ReadDeltaUsercmd(sizebuf_t *sb,
struct usercmd_s *from,
struct usercmd_s *cmd);
void MSG_ReadDir(sizebuf_t *sb, vec3_t vector);
@ -132,7 +136,6 @@ extern float LittleFloat (float l);
/* ================================================================== */
int COM_Argc(void);
char *COM_Argv(int arg); /* range and null checked */
void COM_ClearArgv(int arg);
@ -148,7 +151,6 @@ char *CopyString (char *in);
void Info_Print(char *s);
/* PROTOCOL */
#define PROTOCOL_VERSION 34
@ -164,8 +166,6 @@ void Info_Print (char *s);
#define UPDATE_BACKUP 16 /* copies of entity_state_t to keep buffered */
#define UPDATE_MASK (UPDATE_BACKUP - 1)
/* server to client */
enum svc_ops_e
{
@ -293,19 +293,18 @@ enum clc_ops_e
#define U_SOUND (1 << 26)
#define U_SOLID (1 << 27)
/* CMD - Command text buffering and command execution */
/*
Any number of commands can be added in a frame, from several different
sources. Most commands come from either keybindings or console line
input, but remote servers can also send across commands and entire text
files can be execed.
The + command line options are also added to the command buffer.
The game starts with a Cbuf_AddText ("exec quake.rc\n"); Cbuf_Execute
();
* Any number of commands can be added in a frame, from several different
* sources. Most commands come from either keybindings or console line
* input, but remote servers can also send across commands and entire text
* files can be execed.
*
* The + command line options are also added to the command buffer.
*
* The game starts with a Cbuf_AddText ("exec quake.rc\n"); Cbuf_Execute
* ();
*/
#define EXEC_NOW 0 /* don't return until completed */
@ -313,29 +312,36 @@ The game starts with a Cbuf_AddText ("exec quake.rc\n"); Cbuf_Execute
#define EXEC_APPEND 2 /* add to end of the command buffer */
void Cbuf_Init(void);
/* allocates an initial text buffer that will grow as needed */
void Cbuf_AddText(char *text);
/* as new commands are generated from the console or keybindings, */
/* the text is added to the end of the command buffer. */
void Cbuf_InsertText(char *text);
/* when a command wants to issue other commands immediately, the text is */
/* inserted at the beginning of the buffer, before any remaining unexecuted */
/* commands. */
void Cbuf_ExecuteText(int exec_when, char *text);
/* this can be used in place of either Cbuf_AddText or Cbuf_InsertText */
void Cbuf_AddEarlyCommands(qboolean clear);
/* adds all the +set commands from the command line */
qboolean Cbuf_AddLateCommands(void);
/* adds all the remaining + commands from the command line */
/* Returns true if any late commands were added, which */
/* will keep the demoloop from immediately starting */
void Cbuf_Execute(void);
/* Pulls off \n terminated lines of text from the command buffer and sends */
/* them through Cmd_ExecuteString. Stops when the buffer is empty. */
/* Normally called once per frame, but may be explicitly invoked. */
@ -343,14 +349,15 @@ void Cbuf_Execute (void);
void Cbuf_CopyToDefer(void);
void Cbuf_InsertFromDefer(void);
/* These two functions are used to defer any pending commands while a map */
/* is being loaded */
/*=================================================================== */
/*
Command execution takes a null terminated string, breaks it into tokens,
then searches for a command or variable that matches the first token.
* Command execution takes a null terminated string, breaks it into tokens,
* then searches for a command or variable that matches the first token.
*/
typedef void (*xcommand_t)(void);
@ -358,6 +365,7 @@ typedef void (*xcommand_t) (void);
void Cmd_Init(void);
void Cmd_AddCommand(char *cmd_name, xcommand_t function);
/* called by the init functions of other parts of the program to */
/* register commands and functions to call for them. */
/* The cmd_name is referenced later, so it should not be in temp memory */
@ -366,94 +374,111 @@ void Cmd_AddCommand (char *cmd_name, xcommand_t function);
void Cmd_RemoveCommand(char *cmd_name);
qboolean Cmd_Exists(char *cmd_name);
/* used by the cvar code to check for cvar / command name overlap */
char *Cmd_CompleteCommand(char *partial);
/* attempts to match a partial command for automatic command line completion */
/* returns NULL if nothing fits */
int Cmd_Argc(void);
char *Cmd_Argv(int arg);
char *Cmd_Args(void);
/* The functions that execute commands get their parameters with these */
/* functions. Cmd_Argv () will return an empty string, not a NULL */
/* if arg > argc, so string operations are always safe. */
void Cmd_TokenizeString(char *text, qboolean macroExpand);
/* Takes a null terminated string. Does not need to be /n terminated. */
/* breaks the string up into arg tokens. */
void Cmd_ExecuteString(char *text);
/* Parses a single line of text into arguments and tries to execute it */
/* as if it was typed at the console */
void Cmd_ForwardToServer(void);
/* adds the current command line as a clc_stringcmd to the client message. */
/* things like godmode, noclip, etc, are commands directed to the server, */
/* so when they are typed in at the console, they will need to be forwarded. */
/* CVAR */
/*
cvar_t variables are used to hold scalar or string variables that can be
changed or displayed at the console or prog code as well as accessed
directly in C code.
The user can access cvars from the console in three ways:
r_draworder prints the current value
r_draworder 0 sets the current value to 0
set r_draworder 0 as above, but creates the cvar if not present
Cvars are restricted from having the same names as commands to keep this
interface from being ambiguous.
* cvar_t variables are used to hold scalar or string variables that can be
* changed or displayed at the console or prog code as well as accessed
* directly in C code.
*
* The user can access cvars from the console in three ways:
* r_draworder prints the current value
* r_draworder 0 sets the current value to 0
* set r_draworder 0 as above, but creates the cvar if not present
* Cvars are restricted from having the same names as commands to keep this
* interface from being ambiguous.
*/
extern cvar_t *cvar_vars;
cvar_t *Cvar_Get(char *var_name, char *value, int flags);
/* creates the variable if it doesn't exist, or returns the existing one */
/* if it exists, the value will not be changed, but flags will be ORed in */
/* that allows variables to be unarchived without needing bitflags */
cvar_t *Cvar_Set(char *var_name, char *value);
/* will create the variable if it doesn't exist */
cvar_t *Cvar_ForceSet(char *var_name, char *value);
/* will set the variable even if NOSET or LATCH */
cvar_t *Cvar_FullSet(char *var_name, char *value, int flags);
void Cvar_SetValue(char *var_name, float value);
/* expands value to a string and calls Cvar_Set */
float Cvar_VariableValue(char *var_name);
/* returns 0 if not defined or non numeric */
const char *Cvar_VariableString(const char *var_name);
/* returns an empty string if not defined */
char *Cvar_CompleteVariable(char *partial);
/* attempts to match a partial variable name for command line completion */
/* returns NULL if nothing fits */
void Cvar_GetLatchedVars(void);
/* any CVAR_LATCHED variables that have been set will now take effect */
qboolean Cvar_Command(void);
/* called by Cmd_ExecuteString when Cmd_Argv(0) doesn't match a known */
/* command. Returns true if the command was a variable reference that */
/* was handled. (print or change) */
void Cvar_WriteVariables(char *path);
/* appends lines containing "set variable value" for all variables */
/* with the archive flag set to true. */
void Cvar_Init(void);
char *Cvar_Userinfo(void);
/* returns an info string containing all the CVAR_USERINFO cvars */
char *Cvar_Serverinfo(void);
/* returns an info string containing all the CVAR_SERVERINFO cvars */
extern qboolean userinfo_modified;
@ -494,7 +519,8 @@ void NET_Shutdown (void);
void NET_Config(qboolean multiplayer);
qboolean NET_GetPacket (netsrc_t sock, netadr_t *net_from, sizebuf_t *net_message);
qboolean NET_GetPacket(netsrc_t sock, netadr_t *net_from,
sizebuf_t *net_message);
void NET_SendPacket(netsrc_t sock, int length, void *data, netadr_t to);
qboolean NET_CompareAdr(netadr_t a, netadr_t b);
@ -574,16 +600,15 @@ int CM_HeadnodeForBox (vec3_t mins, vec3_t maxs);
/* returns an ORed contents mask */
int CM_PointContents(vec3_t p, int headnode);
int CM_TransformedPointContents (vec3_t p, int headnode, vec3_t origin, vec3_t angles);
trace_t CM_BoxTrace (vec3_t start, vec3_t end,
vec3_t mins, vec3_t maxs,
int headnode, int brushmask);
trace_t CM_TransformedBoxTrace (vec3_t start, vec3_t end,
vec3_t mins, vec3_t maxs,
int headnode, int brushmask,
int CM_TransformedPointContents(vec3_t p, int headnode,
vec3_t origin, vec3_t angles);
trace_t CM_BoxTrace(vec3_t start, vec3_t end, vec3_t mins,
vec3_t maxs, int headnode, int brushmask);
trace_t CM_TransformedBoxTrace(vec3_t start, vec3_t end,
vec3_t mins, vec3_t maxs, int headnode,
int brushmask, vec3_t origin, vec3_t angles);
byte *CM_ClusterPVS(int cluster);
byte *CM_ClusterPHS(int cluster);
@ -657,10 +682,13 @@ qboolean FS_FileExists(char *path);
void FS_CopyFile(const char *srcPath, const char *dstPath);
void FS_RenameFile(const char *oldPath, const char *newPath);
void FS_DeleteFile(const char *path);
int FS_GetFileList(const char *path, const char *extension, char *buffer, int size, fsSearchType_t searchType);
char **FS_ListPak(char *find, int *num); /* Knighmare- pak list function */
char **FS_ListFiles(char *findname, int *numfiles, unsigned musthave, unsigned canthave);
char **FS_ListFiles2(char *findname, int *numfiles, unsigned musthave, unsigned canthave);
int FS_GetFileList(const char *path, const char *extension,
char *buffer, int size, fsSearchType_t searchType);
char **FS_ListPak(char *find, int *num);
char **FS_ListFiles(char *findname, int *numfiles,
unsigned musthave, unsigned canthave);
char **FS_ListFiles2(char *findname, int *numfiles,
unsigned musthave, unsigned canthave);
void FS_FreeList(char **list, int nfiles);
void FS_InitFilesystem(void);
@ -676,12 +704,10 @@ int FS_LoadFile(char *path, void **buffer);
/* properly handles partial reads */
void FS_FreeFile(void *buffer);
void FS_CreatePath(char *path);
/* MISC */
#define ERR_FATAL 0 /* exit the entire game with a popup window */
#define ERR_DROP 1 /* print to console and disconnect from game */
#define ERR_QUIT 2 /* not an error, just a normal exit */

View file

@ -46,7 +46,6 @@ typedef struct
#define MAX_FILES_IN_PACK 4096
/* PCX files are used for as many images as possible */
typedef struct
@ -66,7 +65,6 @@ typedef struct
unsigned char data; /* unbounded */
} pcx_t;
/* .MD2 triangle model file format */
#define IDALIASHEADER (('2' << 24) + ('P' << 16) + ('D' << 8) + 'I')
@ -111,12 +109,12 @@ typedef struct
} daliasframe_t;
/* the glcmd format:
- a positive integer starts a tristrip command, followed by that many
vertex structures.
- a negative integer starts a trifan command, followed by -x vertexes
a zero indicates the end of the command list.
- a vertex consists of a floating point s, a floating point t,
and an integer vertex index. */
* - a positive integer starts a tristrip command, followed by that many
* vertex structures.
* - a negative integer starts a trifan command, followed by -x vertexes
* a zero indicates the end of the command list.
* - a vertex consists of a floating point s, a floating point t,
* and an integer vertex index. */
typedef struct
{
@ -140,7 +138,6 @@ typedef struct
int ofs_frames; /* offset for first frame */
int ofs_glcmds;
int ofs_end; /* end of file */
} dmdl_t;
/* .SP2 sprite file format */
@ -182,9 +179,8 @@ typedef struct miptex_s
#define IDBSPHEADER (('P' << 24) + ('S' << 16) + ('B' << 8) + 'I') /* little-endian "IBSP" */
#define BSPVERSION 38
/* upper design bounds */
/* leaffaces, leafbrushes, planes, and verts are still bounded by */
/* 16 bit short limits */
/* upper design bounds: leaffaces, leafbrushes, planes, and
* verts are still bounded by 16 bit short limits */
#define MAX_MAP_MODELS 1024
#define MAX_MAP_BRUSHES 8192
#define MAX_MAP_ENTITIES 2048
@ -252,17 +248,15 @@ typedef struct
float mins[3], maxs[3];
float origin[3]; /* for sounds or lights */
int headnode;
int firstface, numfaces; /* submodels just draw faces */
/* without walking the bsp tree */
int firstface, numfaces; /* submodels just draw faces without
walking the bsp tree */
} dmodel_t;
typedef struct
{
float point[3];
} dvertex_t;
/* 0-2 are axial planes */
#define PLANE_X 0
#define PLANE_Y 1
@ -282,10 +276,9 @@ typedef struct
int type; /* PLANE_X - PLANE_ANYZ */
} dplane_t;
/* contents flags are seperate bits
- given brush can contribute multiple content bits
- multiple brushes can be in a single leaf */
* - given brush can contribute multiple content bits
* - multiple brushes can be in a single leaf */
/* lower bits are stronger, and will eat weaker brushes completely */
#define CONTENTS_SOLID 1 /* an eye is never valid in a solid */
@ -343,14 +336,15 @@ typedef struct
typedef struct texinfo_s
{
float vecs[2][4]; /* [s/t][xyz offset] */
int flags; /* miptex flags + overrides */
int value; /* light emission, etc */
int flags; /* miptex flags + overrides light emission, etc */
int value;
char texture[32]; /* texture name (textures*.wal) */
int nexttexinfo; /* for animations, -1 = end of chain */
} texinfo_t;
/* note that edge 0 is never used, because negative edge nums are used for */
/* counterclockwise use of the edge in a face */
/* note that edge 0 is never used, because negative edge
nums are used for counterclockwise use of the edge in
a face */
typedef struct
{
unsigned short v[2]; /* vertex numbers */
@ -404,9 +398,9 @@ typedef struct
#define ANGLE_UP -1
#define ANGLE_DOWN -2
/* the visibility lump consists of a header with a count, then */
/* byte offsets for the PVS and PHS of each cluster, then the raw */
/* compressed bit vectors */
/* the visibility lump consists of a header with a count, then
* byte offsets for the PVS and PHS of each cluster, then the raw
* compressed bit vectors */
#define DVIS_PVS 0
#define DVIS_PHS 1
typedef struct
@ -415,9 +409,9 @@ typedef struct
int bitofs[8][2]; /* bitofs[numclusters][2] */
} dvis_t;
/* each area has a list of portals that lead into other areas */
/* when portals are closed, other areas may not be visible or */
/* hearable even if the vis info says that it should be */
/* each area has a list of portals that lead into other areas
* when portals are closed, other areas may not be visible or
* hearable even if the vis info says that it should be */
typedef struct
{
int portalnum;
@ -431,3 +425,4 @@ typedef struct
} darea_t;
#endif

View file

@ -60,9 +60,7 @@ typedef enum {false, true} qboolean;
#define MAX_OSPATH 128 /* max length of a filesystem pathname */
#endif
/* */
/* per-level limits */
/* */
#define MAX_CLIENTS 256 /* absolute limit */
#define MAX_EDICTS 1024 /* must change protocol to increase more */
#define MAX_LIGHTSTYLES 256
@ -128,9 +126,11 @@ extern vec3_t vec3_origin;
#define Q_ftol(f) (long)(f)
#define DotProduct(x, y) (x[0] * y[0] + x[1] * y[1] + x[2] * y[2])
#define VectorSubtract(a, b, c) (c[0] = a[0] - b[0], c[1] = a[1] - b[1], c[2] = \
#define VectorSubtract(a, b, c) \
(c[0] = a[0] - b[0], c[1] = a[1] - b[1], c[2] = \
a[2] - b[2])
#define VectorAdd(a, b, c) (c[0] = a[0] + b[0], c[1] = a[1] + b[1], c[2] = \
#define VectorAdd(a, b, c) \
(c[0] = a[0] + b[0], c[1] = a[1] + b[1], c[2] = \
a[2] + b[2])
#define VectorCopy(a, b) (b[0] = a[0], b[1] = a[1], b[2] = a[2])
#define VectorClear(a) (a[0] = a[1] = a[2] = 0)
@ -183,8 +183,10 @@ float LerpAngle(float a1, float a2, float frac);
void ProjectPointOnPlane(vec3_t dst, const vec3_t p, const vec3_t normal);
void PerpendicularVector(vec3_t dst, const vec3_t src);
void RotatePointAroundVector(vec3_t dst, const vec3_t dir,
const vec3_t point, float degrees);
void RotatePointAroundVector(vec3_t dst,
const vec3_t dir,
const vec3_t point,
float degrees);
/* ============================================= */
@ -364,16 +366,20 @@ typedef struct cvar_s
/* content masks */
#define MASK_ALL (-1)
#define MASK_SOLID (CONTENTS_SOLID | CONTENTS_WINDOW)
#define MASK_PLAYERSOLID (CONTENTS_SOLID | CONTENTS_PLAYERCLIP | \
#define MASK_PLAYERSOLID \
(CONTENTS_SOLID | CONTENTS_PLAYERCLIP | \
CONTENTS_WINDOW | CONTENTS_MONSTER)
#define MASK_DEADSOLID (CONTENTS_SOLID | CONTENTS_PLAYERCLIP | CONTENTS_WINDOW)
#define MASK_MONSTERSOLID (CONTENTS_SOLID | CONTENTS_MONSTERCLIP | \
#define MASK_MONSTERSOLID \
(CONTENTS_SOLID | CONTENTS_MONSTERCLIP | \
CONTENTS_WINDOW | CONTENTS_MONSTER)
#define MASK_WATER (CONTENTS_WATER | CONTENTS_LAVA | CONTENTS_SLIME)
#define MASK_OPAQUE (CONTENTS_SOLID | CONTENTS_SLIME | CONTENTS_LAVA)
#define MASK_SHOT (CONTENTS_SOLID | CONTENTS_MONSTER | CONTENTS_WINDOW | \
#define MASK_SHOT \
(CONTENTS_SOLID | CONTENTS_MONSTER | CONTENTS_WINDOW | \
CONTENTS_DEADMONSTER)
#define MASK_CURRENT (CONTENTS_CURRENT_0 | CONTENTS_CURRENT_90 | \
#define MASK_CURRENT \
(CONTENTS_CURRENT_0 | CONTENTS_CURRENT_90 | \
CONTENTS_CURRENT_180 | CONTENTS_CURRENT_270 | \
CONTENTS_CURRENT_UP | \
CONTENTS_CURRENT_DOWN)
@ -458,10 +464,10 @@ typedef enum
#define PMF_NO_PREDICTION 64 /* temporarily disables prediction (used for grappling hook) */
/* this structure needs to be communicated bit-accurate/
from the server to the client to guarantee that
prediction stays in sync, so no floats are used.
if any part of the game code modifies this struct, it
will result in a prediction error of some degree. */
* from the server to the client to guarantee that
* prediction stays in sync, so no floats are used.
* if any part of the game code modifies this struct, it
* will result in a prediction error of some degree. */
typedef struct
{
pmtype_t pm_type;
@ -472,7 +478,7 @@ typedef struct
byte pm_time; /* each unit = 8 ms */
short gravity;
short delta_angles[3]; /* add to command angles to get view direction
changed by spawns, rotating objects, and teleporters */
* changed by spawns, rotating objects, and teleporters */
} pmove_state_t;
/* button bits */
@ -520,10 +526,10 @@ typedef struct
} pmove_t;
/* 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. */
* 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. */
#define EF_ROTATE 0x00000001 /* rotate (bonus items) */
#define EF_GIB 0x00000002 /* leave a trail */
#define EF_BLASTER 0x00000008 /* redlight + trail */
@ -844,9 +850,9 @@ typedef struct
extern vec3_t monster_flash_offset[];
/* Temp entity events are for things that happen
at a location seperate from any existing entity.
Temporary entity messages are explicitly constructed
and broadcast. */
* at a location seperate from any existing entity.
* Temporary entity messages are explicitly constructed
* and broadcast. */
typedef enum
{
TE_GUNSHOT,
@ -916,9 +922,9 @@ typedef enum
#define SPLASH_BLOOD 6
/* sound channels:
channel 0 never willingly overrides
other channels (1-7) allways override
a playing sound on that channel */
* channel 0 never willingly overrides
* other channels (1-7) allways override
* a playing sound on that channel */
#define CHAN_AUTO 0
#define CHAN_WEAPON 1
#define CHAN_VOICE 2
@ -993,8 +999,8 @@ typedef enum
#define SHORT2ANGLE(x) ((x) * (360.0 / 65536))
/* config strings are a general means of communication from
the server to all connected clients. Each config string
can be at most MAX_QPATH characters. */
* the server to all connected clients. Each config string
* can be at most MAX_QPATH characters. */
#define CS_NAME 0
#define CS_CDTRACK 1
#define CS_SKY 2
@ -1018,9 +1024,9 @@ typedef enum
/* ============================================== */
/* entity_state_t->event values
entity 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 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... */
typedef enum
{
EV_NONE,
@ -1034,8 +1040,8 @@ typedef enum
} 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 */
* in an update message about entities that the client will
* need to render in some way */
typedef struct entity_state_s
{
int number; /* edict index */
@ -1061,9 +1067,9 @@ typedef struct entity_state_s
/* ============================================== */
/* player_state_t is the information needed in addition to pmove_state_t
to rendered a view. There will only be 10 player_state_t sent each second,
but the number of pmove_state_t changes will be reletive to client
frame rates */
* to rendered a view. There will only be 10 player_state_t sent each second,
* but the number of pmove_state_t changes will be reletive to client
* frame rates */
typedef struct
{
pmove_state_t pmove; /* for prediction */

View file

@ -14,15 +14,18 @@
#define G(X, Y, Z) (((X)&(Y)) | ((X)&(Z)) | ((Y)&(Z)))
#define H(X, Y, Z) ((X) ^ (Y) ^ (Z))
#define S(a, b, c, d, k, s) { \
#define S(a, b, c, d, k, s) \
{ \
a += (F((b), (c), (d)) + X[(k)]); \
a = ROTATELEFT32(a, s); \
}
#define T(a, b, c, d, k, s) { \
#define T(a, b, c, d, k, s) \
{ \
a += (G((b), (c), (d)) + X[(k)] + 0x5A827999); \
a = ROTATELEFT32(a, s); \
}
#define U(a, b, c, d, k, s) { \
#define U(a, b, c, d, k, s) \
{ \
a += (H((b), (c), (d)) + X[(k)] + 0x6ED9EBA1); \
a = ROTATELEFT32(a, s); \
}
@ -33,7 +36,8 @@ static uint32_t B, BB;
static uint32_t C, CC;
static uint32_t D, DD;
static void DoMD4()
static void
DoMD4()
{
AA = A;
BB = B;
@ -97,7 +101,8 @@ static void DoMD4()
D += DD;
}
static void PerformMD4(const unsigned char *buf, int length, unsigned char *digest)
static void
PerformMD4(const unsigned char *buf, int length, unsigned char *digest)
{
int len = length / 64; /* number of full blocks */
int rem = length % 64; /* number of left over bytes */
@ -146,7 +151,9 @@ static void PerformMD4(const unsigned char *buf, int length, unsigned char *dige
X[j] = ((ptr[0] << 0) | (ptr[1] << 8) | ((0x80U) << 16));
break;
case 3:
X[j] = ((ptr[0]<< 0)|(ptr[1]<< 8)|(ptr[2]<<16)|((0x80U)<<24));
X[j] =
((ptr[0] <<
0) | (ptr[1] << 8) | (ptr[2] << 16) | ((0x80U) << 24));
break;
}
@ -155,7 +162,9 @@ static void PerformMD4(const unsigned char *buf, int length, unsigned char *dige
if (j > 14)
{
for ( ; j < 16; j++)
{
X[j] = 0;
}
DoMD4();
@ -163,7 +172,9 @@ static void PerformMD4(const unsigned char *buf, int length, unsigned char *dige
}
for ( ; j < 14; j++)
{
X[j] = 0;
}
X[14] = (length & 0x1FFFFFFF) << 3;
X[15] = (length & ~0x1FFFFFFF) >> 29;
@ -193,10 +204,13 @@ static void PerformMD4(const unsigned char *buf, int length, unsigned char *dige
D = DD = 0;
for (j = 0; j < 16; j++)
{
X[j] = 0;
}
}
unsigned Com_BlockChecksum (void *buffer, int length)
unsigned
Com_BlockChecksum(void *buffer, int length)
{
uint32_t digest[4];
unsigned val;
@ -207,3 +221,4 @@ unsigned Com_BlockChecksum (void *buffer, int length)
return val;
}

View file

@ -1,243 +0,0 @@
/*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* =======================================================================
*
* Message reading and preprocessing
*
* =======================================================================
*/
#include "../header/common.h"
void MSG_BeginReading (sizebuf_t *msg)
{
msg->readcount = 0;
}
int MSG_ReadChar (sizebuf_t *msg_read)
{
int c;
if (msg_read->readcount+1 > msg_read->cursize)
c = -1;
else
c = (signed char)msg_read->data[msg_read->readcount];
msg_read->readcount++;
return c;
}
int MSG_ReadByte (sizebuf_t *msg_read)
{
int c;
if (msg_read->readcount+1 > msg_read->cursize)
c = -1;
else
c = (unsigned char)msg_read->data[msg_read->readcount];
msg_read->readcount++;
return c;
}
int MSG_ReadShort (sizebuf_t *msg_read)
{
int c;
if (msg_read->readcount+2 > msg_read->cursize)
c = -1;
else
c = (short)(msg_read->data[msg_read->readcount]
+ (msg_read->data[msg_read->readcount+1]<<8));
msg_read->readcount += 2;
return c;
}
int MSG_ReadLong (sizebuf_t *msg_read)
{
int c;
if (msg_read->readcount+4 > msg_read->cursize)
c = -1;
else
c = msg_read->data[msg_read->readcount]
+ (msg_read->data[msg_read->readcount+1]<<8)
+ (msg_read->data[msg_read->readcount+2]<<16)
+ (msg_read->data[msg_read->readcount+3]<<24);
msg_read->readcount += 4;
return c;
}
float MSG_ReadFloat (sizebuf_t *msg_read)
{
union
{
byte b[4];
float f;
int l;
} dat;
if (msg_read->readcount+4 > msg_read->cursize)
dat.f = -1;
else
{
dat.b[0] = msg_read->data[msg_read->readcount];
dat.b[1] = msg_read->data[msg_read->readcount+1];
dat.b[2] = msg_read->data[msg_read->readcount+2];
dat.b[3] = msg_read->data[msg_read->readcount+3];
}
msg_read->readcount += 4;
dat.l = LittleLong (dat.l);
return dat.f;
}
char *MSG_ReadString (sizebuf_t *msg_read)
{
static char string[2048];
int l,c;
l = 0;
do
{
c = MSG_ReadChar (msg_read);
if (c == -1 || c == 0)
break;
string[l] = c;
l++;
}
while (l < sizeof(string)-1);
string[l] = 0;
return string;
}
char *MSG_ReadStringLine (sizebuf_t *msg_read)
{
static char string[2048];
int l,c;
l = 0;
do
{
c = MSG_ReadChar (msg_read);
if (c == -1 || c == 0 || c == '\n')
break;
string[l] = c;
l++;
}
while (l < sizeof(string)-1);
string[l] = 0;
return string;
}
float MSG_ReadCoord (sizebuf_t *msg_read)
{
return MSG_ReadShort(msg_read) * (0.125f);
}
void MSG_ReadPos (sizebuf_t *msg_read, vec3_t pos)
{
pos[0] = MSG_ReadShort(msg_read) * (0.125f);
pos[1] = MSG_ReadShort(msg_read) * (0.125f);
pos[2] = MSG_ReadShort(msg_read) * (0.125f);
}
float MSG_ReadAngle (sizebuf_t *msg_read)
{
return MSG_ReadChar(msg_read) * 1.40625f;
}
float MSG_ReadAngle16 (sizebuf_t *msg_read)
{
return SHORT2ANGLE(MSG_ReadShort(msg_read));
}
void MSG_ReadDeltaUsercmd (sizebuf_t *msg_read, usercmd_t *from, usercmd_t *move)
{
int bits;
memcpy (move, from, sizeof(*move));
bits = MSG_ReadByte (msg_read);
/* read current angles */
if (bits & CM_ANGLE1)
move->angles[0] = MSG_ReadShort (msg_read);
if (bits & CM_ANGLE2)
move->angles[1] = MSG_ReadShort (msg_read);
if (bits & CM_ANGLE3)
move->angles[2] = MSG_ReadShort (msg_read);
/* read movement */
if (bits & CM_FORWARD)
move->forwardmove = MSG_ReadShort (msg_read);
if (bits & CM_SIDE)
move->sidemove = MSG_ReadShort (msg_read);
if (bits & CM_UP)
move->upmove = MSG_ReadShort (msg_read);
/* read buttons */
if (bits & CM_BUTTONS)
move->buttons = MSG_ReadByte (msg_read);
if (bits & CM_IMPULSE)
move->impulse = MSG_ReadByte (msg_read);
/* read time to run command */
move->msec = MSG_ReadByte (msg_read);
/* read the light level */
move->lightlevel = MSG_ReadByte (msg_read);
}
void MSG_ReadData (sizebuf_t *msg_read, void *data, int len)
{
int i;
for (i=0 ; i<len ; i++)
((byte *)data)[i] = MSG_ReadByte (msg_read);
}

View file

@ -44,8 +44,7 @@ extern cvar_t *logfile_active;
extern jmp_buf abortframe; /* an ERR_DROP occured, exit the entire frame */
extern zhead_t z_chain;
static byte chktbl[1024] =
{
static byte chktbl[1024] = {
0x84, 0x47, 0x51, 0xc1, 0x93, 0x22, 0x21, 0x24, 0x2f, 0x66, 0x60, 0x4d, 0xb0, 0x7c, 0xda,
0x88, 0x54, 0x15, 0x2b, 0xc6, 0x6c, 0x89, 0xc5, 0x9d, 0x48, 0xee, 0xe6, 0x8a, 0xb5, 0xf4,
0xcb, 0xfb, 0xf1, 0x0c, 0x2e, 0xa0, 0xd7, 0xc9, 0x1f, 0xd6, 0x06, 0x9a, 0x09, 0x41, 0x54,
@ -121,7 +120,8 @@ int time_after_ref;
/*
* For proxy protecting
*/
byte COM_BlockSequenceCRCByte (byte *base, int length, int sequence)
byte
COM_BlockSequenceCRCByte(byte *base, int length, int sequence)
{
int n;
int x;
@ -131,12 +131,16 @@ byte COM_BlockSequenceCRCByte (byte *base, int length, int sequence)
byte r;
if (sequence < 0)
{
Sys_Error("sequence < 0, this shouldn't happen\n");
}
p = chktbl + (sequence % (sizeof(chktbl) - 4));
if (length > 60)
{
length = 60;
}
memcpy(chkb, base, length);
@ -150,7 +154,9 @@ byte COM_BlockSequenceCRCByte (byte *base, int length, int sequence)
crc = CRC_Block(chkb, length);
for (x = 0, n = 0; n < length; n++)
{
x += chkb[n];
}
r = (crc ^ x) & 0xff;
@ -166,17 +172,21 @@ void SCR_EndLoadingPlaque (void);
* Just throw a fatal error to
* test error shutdown procedures
*/
void Com_Error_f (void)
void
Com_Error_f(void)
{
Com_Error(ERR_FATAL, "%s", Cmd_Argv(1));
}
void Qcommon_Init (int argc, char **argv)
void
Qcommon_Init(int argc, char **argv)
{
char *s;
if (setjmp(abortframe))
{
Sys_Error("Error during initialization");
}
z_chain.next = z_chain.prev = &z_chain;
@ -224,6 +234,7 @@ void Qcommon_Init (int argc, char **argv)
#ifndef DEDICATED_ONLY
showtrace = Cvar_Get("showtrace", "0", 0);
#endif
#ifdef DEDICATED_ONLY
dedicated = Cvar_Get("dedicated", "1", CVAR_NOSET);
#else
@ -234,7 +245,9 @@ void Qcommon_Init (int argc, char **argv)
Cvar_Get("version", s, CVAR_SERVERINFO | CVAR_NOSET);
if (dedicated->value)
{
Cmd_AddCommand("quit", Com_Quit);
}
Sys_Init();
NET_Init();
@ -249,30 +262,31 @@ void Qcommon_Init (int argc, char **argv)
{
/* if the user didn't give any commands, run default action */
if (!dedicated->value)
{
Cbuf_AddText("d1\n");
}
else
{
Cbuf_AddText("dedicated_start\n");
}
Cbuf_Execute();
}
#ifndef DEDICATED_ONLY
else
{
/* the user asked for something explicit
so drop the loading plaque */
SCR_EndLoadingPlaque();
}
#endif
Com_Printf("==== Yamagi Quake II Initialized ====\n\n");
Com_Printf("*************************************\n\n");
}
void Qcommon_Frame (int msec)
void
Qcommon_Frame(int msec)
{
char *s;
@ -283,7 +297,9 @@ void Qcommon_Frame (int msec)
#endif
if (setjmp(abortframe))
{
return; /* an ERR_DROP was thrown */
}
if (log_stats->modified)
{
@ -300,9 +316,10 @@ void Qcommon_Frame (int msec)
log_stats_file = fopen("stats.log", "w");
if (log_stats_file)
{
fprintf(log_stats_file, "entities,dlights,parts,frame time\n");
}
}
else
{
if (log_stats_file)
@ -314,18 +331,20 @@ void Qcommon_Frame (int msec)
}
if (fixedtime->value)
{
msec = fixedtime->value;
}
else if (timescale->value)
{
msec *= timescale->value;
if (msec < 1)
{
msec = 1;
}
}
#ifndef DEDICATED_ONLY
if (showtrace->value)
{
extern int c_traces, c_brush_traces;
@ -336,7 +355,6 @@ void Qcommon_Frame (int msec)
c_brush_traces = 0;
c_pointcontents = 0;
}
#endif
do
@ -344,25 +362,28 @@ void Qcommon_Frame (int msec)
s = Sys_ConsoleInput();
if (s)
{
Cbuf_AddText(va("%s\n", s));
}
}
while (s);
Cbuf_Execute();
#ifndef DEDICATED_ONLY
if (host_speeds->value)
{
time_before = Sys_Milliseconds();
}
#endif
SV_Frame(msec);
#ifndef DEDICATED_ONLY
if (host_speeds->value)
{
time_between = Sys_Milliseconds();
}
CL_Frame(msec);
@ -381,10 +402,11 @@ void Qcommon_Frame (int msec)
Com_Printf("all:%3i sv:%3i gm:%3i cl:%3i rf:%3i\n",
all, sv, gm, cl, rf);
}
#endif
}
void Qcommon_Shutdown (void)
void
Qcommon_Shutdown(void)
{
}

View file

@ -1,187 +0,0 @@
/*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* =======================================================================
*
* This file implements the the area portals.
*
* =======================================================================
*/
#include "../header/common.h"
#include "../header/cmodel.h"
extern int numareas;
void FloodArea_r (carea_t *area, int floodnum)
{
int i;
dareaportal_t *p;
if (area->floodvalid == floodvalid)
{
if (area->floodnum == floodnum)
return;
Com_Error (ERR_DROP, "FloodArea_r: reflooded");
}
area->floodnum = floodnum;
area->floodvalid = floodvalid;
p = &map_areaportals[area->firstareaportal];
for (i=0 ; i<area->numareaportals ; i++, p++)
{
if (portalopen[LittleLong(p->portalnum)])
FloodArea_r (&map_areas[LittleLong(p->otherarea)], floodnum);
}
}
void FloodAreaConnections (void)
{
int i;
carea_t *area;
int floodnum;
/* all current floods are now invalid */
floodvalid++;
floodnum = 0;
/* area 0 is not used */
for (i=1 ; i<numareas ; i++)
{
area = &map_areas[i];
if (area->floodvalid == floodvalid)
continue; /* already flooded into */
floodnum++;
FloodArea_r (area, floodnum);
}
}
void CM_SetAreaPortalState (int portalnum, qboolean open)
{
if (portalnum > numareaportals)
Com_Error (ERR_DROP, "areaportal > numareaportals");
portalopen[portalnum] = open;
FloodAreaConnections ();
}
qboolean CM_AreasConnected (int area1, int area2)
{
if (map_noareas->value)
return true;
if (area1 > numareas || area2 > numareas)
Com_Error (ERR_DROP, "area > numareas");
if (map_areas[area1].floodnum == map_areas[area2].floodnum)
return true;
return false;
}
/*
* Writes a length byte followed by a bit vector of all the areas
* that area in the same flood as the area parameter
*
* This is used by the client refreshes to cull visibility
*/
int CM_WriteAreaBits (byte *buffer, int area)
{
int i;
int floodnum;
int bytes;
bytes = (numareas+7)>>3;
if (map_noareas->value)
{
/* for debugging, send everything */
memset (buffer, 255, bytes);
}
else
{
memset (buffer, 0, bytes);
floodnum = map_areas[area].floodnum;
for (i=0 ; i<numareas ; i++)
{
if (map_areas[i].floodnum == floodnum || !area)
buffer[i>>3] |= 1<<(i&7);
}
}
return bytes;
}
/*
* Writes the portal state to a savegame file
*/
void CM_WritePortalState (FILE *f)
{
fwrite (portalopen, sizeof(portalopen), 1, f);
}
/*
* Reads the portal state from a savegame file
* and recalculates the area connections
*/
void CM_ReadPortalState (fileHandle_t f)
{
FS_Read (portalopen, sizeof(portalopen), f);
FloodAreaConnections ();
}
/*
* Returns true if any leaf under headnode has a cluster that
* is potentially visible
*/
qboolean CM_HeadnodeVisible (int nodenum, byte *visbits)
{
int leafnum1;
int cluster;
cnode_t *node;
if (nodenum < 0)
{
leafnum1 = -1-nodenum;
cluster = map_leafs[leafnum1].cluster;
if (cluster == -1)
return false;
if (visbits[cluster>>3] & (1<<(cluster&7)))
return true;
return false;
}
node = &map_nodes[nodenum];
if (CM_HeadnodeVisible(node->children[0], visbits))
return true;
return CM_HeadnodeVisible(node->children[1], visbits);
}

View file

@ -1,283 +0,0 @@
/*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* =======================================================================
*
* This files implements collision boxes for models of all kinds but
* mainly the world model
*
* =======================================================================
*/
#include "../header/common.h"
#include "../header/cmodel.h"
extern int numleafs;
cplane_t *box_planes;
int box_headnode;
cbrush_t *box_brush;
cleaf_t *box_leaf;
/*
* Set up the planes and nodes so that the six floats of a bounding box
* can just be stored out and get a proper clipping hull structure.
*/
void CM_InitBoxHull (void)
{
int i;
int side;
cnode_t *c;
cplane_t *p;
cbrushside_t *s;
box_headnode = numnodes;
box_planes = &map_planes[numplanes];
if (numnodes+6 > MAX_MAP_NODES
|| numbrushes+1 > MAX_MAP_BRUSHES
|| numleafbrushes+1 > MAX_MAP_LEAFBRUSHES
|| numbrushsides+6 > MAX_MAP_BRUSHSIDES
|| numplanes+12 > MAX_MAP_PLANES)
Com_Error (ERR_DROP, "Not enough room for box tree");
box_brush = &map_brushes[numbrushes];
box_brush->numsides = 6;
box_brush->firstbrushside = numbrushsides;
box_brush->contents = CONTENTS_MONSTER;
box_leaf = &map_leafs[numleafs];
box_leaf->contents = CONTENTS_MONSTER;
box_leaf->firstleafbrush = numleafbrushes;
box_leaf->numleafbrushes = 1;
map_leafbrushes[numleafbrushes] = numbrushes;
for (i=0 ; i<6 ; i++)
{
side = i&1;
/* brush sides */
s = &map_brushsides[numbrushsides+i];
s->plane = map_planes + (numplanes+i*2+side);
s->surface = &nullsurface;
/* nodes */
c = &map_nodes[box_headnode+i];
c->plane = map_planes + (numplanes+i*2);
c->children[side] = -1 - emptyleaf;
if (i != 5)
c->children[side^1] = box_headnode+i + 1;
else
c->children[side^1] = -1 - numleafs;
/* planes */
p = &box_planes[i*2];
p->type = i>>1;
p->signbits = 0;
VectorClear (p->normal);
p->normal[i>>1] = 1;
p = &box_planes[i*2+1];
p->type = 3 + (i>>1);
p->signbits = 0;
VectorClear (p->normal);
p->normal[i>>1] = -1;
}
}
/*
* To keep everything totally uniform, bounding boxes are turned into
* small BSP trees instead of being compared directly.
*/
int CM_HeadnodeForBox (vec3_t mins, vec3_t maxs)
{
box_planes[0].dist = maxs[0];
box_planes[1].dist = -maxs[0];
box_planes[2].dist = mins[0];
box_planes[3].dist = -mins[0];
box_planes[4].dist = maxs[1];
box_planes[5].dist = -maxs[1];
box_planes[6].dist = mins[1];
box_planes[7].dist = -mins[1];
box_planes[8].dist = maxs[2];
box_planes[9].dist = -maxs[2];
box_planes[10].dist = mins[2];
box_planes[11].dist = -mins[2];
return box_headnode;
}
int CM_PointLeafnum_r (vec3_t p, int num)
{
float d;
cnode_t *node;
cplane_t *plane;
while (num >= 0)
{
node = map_nodes + num;
plane = node->plane;
if (plane->type < 3)
d = p[plane->type] - plane->dist;
else
d = DotProduct (plane->normal, p) - plane->dist;
if (d < 0)
num = node->children[1];
else
num = node->children[0];
}
#ifndef DEDICATED_ONLY
c_pointcontents++; /* optimize counter */
#endif
return -1 - num;
}
int CM_PointLeafnum (vec3_t p)
{
if (!numplanes)
return 0; /* sound may call this without map loaded */
return CM_PointLeafnum_r (p, 0);
}
/*
* Fills in a list of all the leafs touched
*/
int leaf_count, leaf_maxcount;
int *leaf_list;
float *leaf_mins, *leaf_maxs;
int leaf_topnode;
void CM_BoxLeafnums_r (int nodenum)
{
cplane_t *plane;
cnode_t *node;
int s;
while (1)
{
if (nodenum < 0)
{
if (leaf_count >= leaf_maxcount)
{
return;
}
leaf_list[leaf_count++] = -1 - nodenum;
return;
}
node = &map_nodes[nodenum];
plane = node->plane;
s = BOX_ON_PLANE_SIDE(leaf_mins, leaf_maxs, plane);
if (s == 1)
nodenum = node->children[0];
else if (s == 2)
nodenum = node->children[1];
else
{
/* go down both */
if (leaf_topnode == -1)
leaf_topnode = nodenum;
CM_BoxLeafnums_r (node->children[0]);
nodenum = node->children[1];
}
}
}
int CM_BoxLeafnums_headnode (vec3_t mins, vec3_t maxs, int *list, int listsize, int headnode, int *topnode)
{
leaf_list = list;
leaf_count = 0;
leaf_maxcount = listsize;
leaf_mins = mins;
leaf_maxs = maxs;
leaf_topnode = -1;
CM_BoxLeafnums_r (headnode);
if (topnode)
*topnode = leaf_topnode;
return leaf_count;
}
int CM_BoxLeafnums (vec3_t mins, vec3_t maxs, int *list, int listsize, int *topnode)
{
return CM_BoxLeafnums_headnode (mins, maxs, list,
listsize, map_cmodels[0].headnode, topnode);
}
int CM_PointContents (vec3_t p, int headnode)
{
int l;
if (!numnodes) /* map not loaded */
return 0;
l = CM_PointLeafnum_r (p, headnode);
return map_leafs[l].contents;
}
/*
* Handles offseting and rotation of the end points for moving and
* rotating entities
*/
int CM_TransformedPointContents (vec3_t p, int headnode, vec3_t origin, vec3_t angles)
{
vec3_t p_l;
vec3_t temp;
vec3_t forward, right, up;
int l;
/* subtract origin offset */
VectorSubtract (p, origin, p_l);
/* rotate start and end into the models frame of reference */
if (headnode != box_headnode &&
(angles[0] || angles[1] || angles[2]) )
{
AngleVectors (angles, forward, right, up);
VectorCopy (p_l, temp);
p_l[0] = DotProduct (temp, forward);
p_l[1] = -DotProduct (temp, right);
p_l[2] = DotProduct (temp, up);
}
l = CM_PointLeafnum_r (p_l, headnode);
return map_leafs[l].contents;
}

View file

@ -1,552 +0,0 @@
/*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* =======================================================================
*
* This file implements tracing of collision boxes through the world
* model
*
* =======================================================================
*/
#include "../header/common.h"
#include "../header/cmodel.h"
extern int box_headnode;
/* 1/32 epsilon to keep floating point happy */
#define DIST_EPSILON (0.03125f)
vec3_t trace_start, trace_end;
vec3_t trace_mins, trace_maxs;
vec3_t trace_extents;
trace_t trace_trace;
int trace_contents;
qboolean trace_ispoint; /* optimized case */
void CM_ClipBoxToBrush (vec3_t mins, vec3_t maxs, vec3_t p1, vec3_t p2,
trace_t *trace, cbrush_t *brush)
{
int i, j;
cplane_t *plane, *clipplane;
float dist;
float enterfrac, leavefrac;
vec3_t ofs;
float d1, d2;
qboolean getout, startout;
float f;
cbrushside_t *side, *leadside;
enterfrac = -1;
leavefrac = 1;
clipplane = NULL;
if (!brush->numsides)
return;
#ifndef DEDICATED_ONLY
c_brush_traces++;
#endif
getout = false;
startout = false;
leadside = NULL;
for (i=0 ; i<brush->numsides ; i++)
{
side = &map_brushsides[brush->firstbrushside+i];
plane = side->plane;
if (!trace_ispoint)
{
/* general box case
push the plane out
apropriately for mins/maxs */
for (j=0 ; j<3 ; j++)
{
if (plane->normal[j] < 0)
ofs[j] = maxs[j];
else
ofs[j] = mins[j];
}
dist = DotProduct (ofs, plane->normal);
dist = plane->dist - dist;
}
else
{
/* special point case */
dist = plane->dist;
}
d1 = DotProduct (p1, plane->normal) - dist;
d2 = DotProduct (p2, plane->normal) - dist;
if (d2 > 0)
getout = true; /* endpoint is not in solid */
if (d1 > 0)
startout = true;
/* if completely in front of face, no intersection */
if (d1 > 0 && d2 >= d1)
return;
if (d1 <= 0 && d2 <= 0)
continue;
/* crosses face */
if (d1 > d2)
{
/* enter */
f = (d1-DIST_EPSILON) / (d1-d2);
if (f > enterfrac)
{
enterfrac = f;
clipplane = plane;
leadside = side;
}
}
else
{
/* leave */
f = (d1+DIST_EPSILON) / (d1-d2);
if (f < leavefrac)
leavefrac = f;
}
}
if (!startout)
{
/* original point was inside brush */
trace->startsolid = true;
if (!getout)
trace->allsolid = true;
return;
}
if (enterfrac < leavefrac)
{
if (enterfrac > -1 && enterfrac < trace->fraction)
{
if (enterfrac < 0)
enterfrac = 0;
if (clipplane == NULL)
Com_Error(ERR_FATAL, "clipplane was NULL!\n");
trace->fraction = enterfrac;
trace->plane = *clipplane;
trace->surface = &(leadside->surface->c);
trace->contents = brush->contents;
}
}
}
void CM_TestBoxInBrush (vec3_t mins, vec3_t maxs, vec3_t p1,
trace_t *trace, cbrush_t *brush)
{
int i, j;
cplane_t *plane;
float dist;
vec3_t ofs;
float d1;
cbrushside_t *side;
if (!brush->numsides)
return;
for (i=0 ; i<brush->numsides ; i++)
{
side = &map_brushsides[brush->firstbrushside+i];
plane = side->plane;
/* general box case
push the plane out
apropriately for mins/maxs */
for (j=0 ; j<3 ; j++)
{
if (plane->normal[j] < 0)
ofs[j] = maxs[j];
else
ofs[j] = mins[j];
}
dist = DotProduct (ofs, plane->normal);
dist = plane->dist - dist;
d1 = DotProduct (p1, plane->normal) - dist;
/* if completely in front of face, no intersection */
if (d1 > 0)
return;
}
/* inside this brush */
trace->startsolid = trace->allsolid = true;
trace->fraction = 0;
trace->contents = brush->contents;
}
void CM_TraceToLeaf (int leafnum)
{
int k;
int brushnum;
cleaf_t *leaf;
cbrush_t *b;
leaf = &map_leafs[leafnum];
if ( !(leaf->contents & trace_contents))
return;
/* trace line against all brushes in the leaf */
for (k=0 ; k<leaf->numleafbrushes ; k++)
{
brushnum = map_leafbrushes[leaf->firstleafbrush+k];
b = &map_brushes[brushnum];
if (b->checkcount == checkcount)
continue; /* already checked this brush in another leaf */
b->checkcount = checkcount;
if ( !(b->contents & trace_contents))
continue;
CM_ClipBoxToBrush (trace_mins, trace_maxs, trace_start, trace_end, &trace_trace, b);
if (!trace_trace.fraction)
return;
}
}
void CM_TestInLeaf (int leafnum)
{
int k;
int brushnum;
cleaf_t *leaf;
cbrush_t *b;
leaf = &map_leafs[leafnum];
if ( !(leaf->contents & trace_contents))
return;
/* trace line against all brushes in the leaf */
for (k=0 ; k<leaf->numleafbrushes ; k++)
{
brushnum = map_leafbrushes[leaf->firstleafbrush+k];
b = &map_brushes[brushnum];
if (b->checkcount == checkcount)
continue; /* already checked this brush in another leaf */
b->checkcount = checkcount;
if ( !(b->contents & trace_contents))
continue;
CM_TestBoxInBrush (trace_mins, trace_maxs, trace_start, &trace_trace, b);
if (!trace_trace.fraction)
return;
}
}
void CM_RecursiveHullCheck (int num, float p1f, float p2f, vec3_t p1, vec3_t p2)
{
cnode_t *node;
cplane_t *plane;
float t1, t2, offset;
float frac, frac2;
float idist;
int i;
vec3_t mid;
int side;
float midf;
if (trace_trace.fraction <= p1f)
return; /* already hit something nearer */
/* if < 0, we are in a leaf node */
if (num < 0)
{
CM_TraceToLeaf (-1-num);
return;
}
/* find the point distances to the seperating plane
and the offset for the size of the box */
node = map_nodes + num;
plane = node->plane;
if (plane->type < 3)
{
t1 = p1[plane->type] - plane->dist;
t2 = p2[plane->type] - plane->dist;
offset = trace_extents[plane->type];
}
else
{
t1 = DotProduct (plane->normal, p1) - plane->dist;
t2 = DotProduct (plane->normal, p2) - plane->dist;
if (trace_ispoint)
offset = 0;
else
offset = (float)fabs(trace_extents[0]*plane->normal[0]) +
(float)fabs(trace_extents[1]*plane->normal[1]) +
(float)fabs(trace_extents[2]*plane->normal[2]);
}
/* see which sides we need to consider */
if (t1 >= offset && t2 >= offset)
{
CM_RecursiveHullCheck (node->children[0], p1f, p2f, p1, p2);
return;
}
if (t1 < -offset && t2 < -offset)
{
CM_RecursiveHullCheck (node->children[1], p1f, p2f, p1, p2);
return;
}
/* put the crosspoint DIST_EPSILON pixels on the near side */
if (t1 < t2)
{
idist = 1.0f/(t1-t2);
side = 1;
frac2 = (t1 + offset + DIST_EPSILON)*idist;
frac = (t1 - offset + DIST_EPSILON)*idist;
}
else if (t1 > t2)
{
idist = 1.0/(t1-t2);
side = 0;
frac2 = (t1 - offset - DIST_EPSILON)*idist;
frac = (t1 + offset + DIST_EPSILON)*idist;
}
else
{
side = 0;
frac = 1;
frac2 = 0;
}
/* move up to the node */
if (frac < 0)
frac = 0;
if (frac > 1)
frac = 1;
midf = p1f + (p2f - p1f)*frac;
for (i=0 ; i<3 ; i++)
mid[i] = p1[i] + frac*(p2[i] - p1[i]);
CM_RecursiveHullCheck (node->children[side], p1f, midf, p1, mid);
/* go past the node */
if (frac2 < 0)
frac2 = 0;
if (frac2 > 1)
frac2 = 1;
midf = p1f + (p2f - p1f)*frac2;
for (i=0 ; i<3 ; i++)
mid[i] = p1[i] + frac2*(p2[i] - p1[i]);
CM_RecursiveHullCheck (node->children[side^1], midf, p2f, mid, p2);
}
trace_t CM_BoxTrace (vec3_t start, vec3_t end,
vec3_t mins, vec3_t maxs,
int headnode, int brushmask)
{
int i;
checkcount++; /* for multi-check avoidance */
#ifndef DEDICATED_ONLY
c_traces++; /* for statistics, may be zeroed */
#endif
/* fill in a default trace */
memset (&trace_trace, 0, sizeof(trace_trace));
trace_trace.fraction = 1;
trace_trace.surface = &(nullsurface.c);
if (!numnodes) /* map not loaded */
return trace_trace;
trace_contents = brushmask;
VectorCopy (start, trace_start);
VectorCopy (end, trace_end);
VectorCopy (mins, trace_mins);
VectorCopy (maxs, trace_maxs);
/* check for position test special case */
if (start[0] == end[0] && start[1] == end[1] && start[2] == end[2])
{
int leafs[1024];
int i, numleafs;
vec3_t c1, c2;
int topnode;
VectorAdd (start, mins, c1);
VectorAdd (start, maxs, c2);
for (i=0 ; i<3 ; i++)
{
c1[i] -= 1;
c2[i] += 1;
}
numleafs = CM_BoxLeafnums_headnode (c1, c2, leafs, 1024, headnode, &topnode);
for (i=0 ; i<numleafs ; i++)
{
CM_TestInLeaf (leafs[i]);
if (trace_trace.allsolid)
break;
}
VectorCopy (start, trace_trace.endpos);
return trace_trace;
}
/* check for point special case */
if (mins[0] == 0 && mins[1] == 0 && mins[2] == 0
&& maxs[0] == 0 && maxs[1] == 0 && maxs[2] == 0)
{
trace_ispoint = true;
VectorClear (trace_extents);
}
else
{
trace_ispoint = false;
trace_extents[0] = -mins[0] > maxs[0] ? -mins[0] : maxs[0];
trace_extents[1] = -mins[1] > maxs[1] ? -mins[1] : maxs[1];
trace_extents[2] = -mins[2] > maxs[2] ? -mins[2] : maxs[2];
}
/* general sweeping through world */
CM_RecursiveHullCheck (headnode, 0, 1, start, end);
if (trace_trace.fraction == 1)
{
VectorCopy (end, trace_trace.endpos);
}
else
{
for (i=0 ; i<3 ; i++)
trace_trace.endpos[i] = start[i] + trace_trace.fraction * (end[i] - start[i]);
}
return trace_trace;
}
/*
* Handles offseting and rotation of the end points for moving and
* rotating entities
*/
trace_t CM_TransformedBoxTrace (vec3_t start, vec3_t end,
vec3_t mins, vec3_t maxs,
int headnode, int brushmask,
vec3_t origin, vec3_t angles)
{
trace_t trace;
vec3_t start_l, end_l;
vec3_t a;
vec3_t forward, right, up;
vec3_t temp;
qboolean rotated;
/* subtract origin offset */
VectorSubtract (start, origin, start_l);
VectorSubtract (end, origin, end_l);
/* rotate start and end into the models frame of reference */
if (headnode != box_headnode &&
(angles[0] || angles[1] || angles[2]) )
rotated = true;
else
rotated = false;
if (rotated)
{
AngleVectors (angles, forward, right, up);
VectorCopy (start_l, temp);
start_l[0] = DotProduct (temp, forward);
start_l[1] = -DotProduct (temp, right);
start_l[2] = DotProduct (temp, up);
VectorCopy (end_l, temp);
end_l[0] = DotProduct (temp, forward);
end_l[1] = -DotProduct (temp, right);
end_l[2] = DotProduct (temp, up);
}
/* sweep the box through the model */
trace = CM_BoxTrace (start_l, end_l, mins, maxs, headnode, brushmask);
if (rotated && trace.fraction != 1.0)
{
VectorNegate (angles, a);
AngleVectors (a, forward, right, up);
VectorCopy (trace.plane.normal, temp);
trace.plane.normal[0] = DotProduct (temp, forward);
trace.plane.normal[1] = -DotProduct (temp, right);
trace.plane.normal[2] = DotProduct (temp, up);
}
trace.endpos[0] = start[0] + trace.fraction * (end[0] - start[0]);
trace.endpos[1] = start[1] + trace.fraction * (end[1] - start[1]);
trace.endpos[2] = start[2] + trace.fraction * (end[2] - start[2]);
return trace;
}

View file

@ -1,549 +0,0 @@
/*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* =======================================================================
*
* This file implements loading and parsing of BSP files and trees.
*
* =======================================================================
*/
#include "../header/common.h"
#include "../header/cmodel.h"
extern dvis_t *map_vis;
int numleafs = 1; /* allow leaf funcs to be called without a map */
int numclusters = 1;
int numareas = 1;
byte *cmod_base;
void CMod_LoadSubmodels (lump_t *l)
{
dmodel_t *in;
cmodel_t *out;
int i, j, count;
in = (void *)(cmod_base + l->fileofs);
if (l->filelen % sizeof(*in))
Com_Error (ERR_DROP, "MOD_LoadBmodel: funny lump size");
count = l->filelen / sizeof(*in);
if (count < 1)
Com_Error (ERR_DROP, "Map with no models");
if (count > MAX_MAP_MODELS)
Com_Error (ERR_DROP, "Map has too many models");
numcmodels = count;
for ( i=0 ; i<count ; i++, in++, out++)
{
out = &map_cmodels[i];
for (j=0 ; j<3 ; j++)
{
/* spread the mins / maxs by a pixel */
out->mins[j] = LittleFloat (in->mins[j]) - 1;
out->maxs[j] = LittleFloat (in->maxs[j]) + 1;
out->origin[j] = LittleFloat (in->origin[j]);
}
out->headnode = LittleLong (in->headnode);
}
}
void CMod_LoadSurfaces (lump_t *l)
{
texinfo_t *in;
mapsurface_t *out;
int i, count;
in = (void *)(cmod_base + l->fileofs);
if (l->filelen % sizeof(*in))
Com_Error (ERR_DROP, "MOD_LoadBmodel: funny lump size");
count = l->filelen / sizeof(*in);
if (count < 1)
Com_Error (ERR_DROP, "Map with no surfaces");
if (count > MAX_MAP_TEXINFO)
Com_Error (ERR_DROP, "Map has too many surfaces");
numtexinfo = count;
out = map_surfaces;
for ( i=0 ; i<count ; i++, in++, out++)
{
strncpy (out->c.name, in->texture, sizeof(out->c.name)-1);
strncpy (out->rname, in->texture, sizeof(out->rname)-1);
out->c.flags = LittleLong (in->flags);
out->c.value = LittleLong (in->value);
}
}
void CMod_LoadNodes (lump_t *l)
{
dnode_t *in;
int child;
cnode_t *out;
int i, j, count;
in = (void *)(cmod_base + l->fileofs);
if (l->filelen % sizeof(*in))
Com_Error (ERR_DROP, "MOD_LoadBmodel: funny lump size");
count = l->filelen / sizeof(*in);
if (count < 1)
Com_Error (ERR_DROP, "Map has no nodes");
if (count > MAX_MAP_NODES)
Com_Error (ERR_DROP, "Map has too many nodes");
out = map_nodes;
numnodes = count;
for (i=0 ; i<count ; i++, out++, in++)
{
out->plane = map_planes + LittleLong(in->planenum);
for (j=0 ; j<2 ; j++)
{
child = LittleLong (in->children[j]);
out->children[j] = child;
}
}
}
void CMod_LoadBrushes (lump_t *l)
{
dbrush_t *in;
cbrush_t *out;
int i, count;
in = (void *)(cmod_base + l->fileofs);
if (l->filelen % sizeof(*in))
Com_Error (ERR_DROP, "MOD_LoadBmodel: funny lump size");
count = l->filelen / sizeof(*in);
if (count > MAX_MAP_BRUSHES)
Com_Error (ERR_DROP, "Map has too many brushes");
out = map_brushes;
numbrushes = count;
for (i=0 ; i<count ; i++, out++, in++)
{
out->firstbrushside = LittleLong(in->firstside);
out->numsides = LittleLong(in->numsides);
out->contents = LittleLong(in->contents);
}
}
void CMod_LoadLeafs (lump_t *l)
{
int i;
cleaf_t *out;
dleaf_t *in;
int count;
in = (void *)(cmod_base + l->fileofs);
if (l->filelen % sizeof(*in))
Com_Error (ERR_DROP, "MOD_LoadBmodel: funny lump size");
count = l->filelen / sizeof(*in);
if (count < 1)
Com_Error (ERR_DROP, "Map with no leafs");
/* need to save space for box planes */
if (count > MAX_MAP_PLANES)
Com_Error (ERR_DROP, "Map has too many planes");
out = map_leafs;
numleafs = count;
numclusters = 0;
for ( i=0 ; i<count ; i++, in++, out++)
{
out->contents = LittleLong (in->contents);
out->cluster = LittleShort (in->cluster);
out->area = LittleShort (in->area);
out->firstleafbrush = LittleShort (in->firstleafbrush);
out->numleafbrushes = LittleShort (in->numleafbrushes);
if (out->cluster >= numclusters)
numclusters = out->cluster + 1;
}
if (map_leafs[0].contents != CONTENTS_SOLID)
Com_Error (ERR_DROP, "Map leaf 0 is not CONTENTS_SOLID");
solidleaf = 0;
emptyleaf = -1;
for (i=1 ; i<numleafs ; i++)
{
if (!map_leafs[i].contents)
{
emptyleaf = i;
break;
}
}
if (emptyleaf == -1)
Com_Error (ERR_DROP, "Map does not have an empty leaf");
}
void CMod_LoadPlanes (lump_t *l)
{
int i, j;
cplane_t *out;
dplane_t *in;
int count;
int bits;
in = (void *)(cmod_base + l->fileofs);
if (l->filelen % sizeof(*in))
Com_Error (ERR_DROP, "MOD_LoadBmodel: funny lump size");
count = l->filelen / sizeof(*in);
if (count < 1)
Com_Error (ERR_DROP, "Map with no planes");
/* need to save space for box planes */
if (count > MAX_MAP_PLANES)
Com_Error (ERR_DROP, "Map has too many planes");
out = map_planes;
numplanes = count;
for ( i=0 ; i<count ; i++, in++, out++)
{
bits = 0;
for (j=0 ; j<3 ; j++)
{
out->normal[j] = LittleFloat (in->normal[j]);
if (out->normal[j] < 0)
bits |= 1<<j;
}
out->dist = LittleFloat (in->dist);
out->type = LittleLong (in->type);
out->signbits = bits;
}
}
void CMod_LoadLeafBrushes (lump_t *l)
{
int i;
unsigned short *out;
unsigned short *in;
int count;
in = (void *)(cmod_base + l->fileofs);
if (l->filelen % sizeof(*in))
Com_Error (ERR_DROP, "MOD_LoadBmodel: funny lump size");
count = l->filelen / sizeof(*in);
if (count < 1)
Com_Error (ERR_DROP, "Map with no planes");
/* need to save space for box planes */
if (count > MAX_MAP_LEAFBRUSHES)
Com_Error (ERR_DROP, "Map has too many leafbrushes");
out = map_leafbrushes;
numleafbrushes = count;
for ( i=0 ; i<count ; i++, in++, out++)
*out = LittleShort (*in);
}
void CMod_LoadBrushSides (lump_t *l)
{
int i, j;
cbrushside_t *out;
dbrushside_t *in;
int count;
int num;
in = (void *)(cmod_base + l->fileofs);
if (l->filelen % sizeof(*in))
Com_Error (ERR_DROP, "MOD_LoadBmodel: funny lump size");
count = l->filelen / sizeof(*in);
/* need to save space for box planes */
if (count > MAX_MAP_BRUSHSIDES)
Com_Error (ERR_DROP, "Map has too many planes");
out = map_brushsides;
numbrushsides = count;
for ( i=0 ; i<count ; i++, in++, out++)
{
num = LittleShort (in->planenum);
out->plane = &map_planes[num];
j = LittleShort (in->texinfo);
if (j >= numtexinfo)
Com_Error (ERR_DROP, "Bad brushside texinfo");
out->surface = &map_surfaces[j];
}
}
void CMod_LoadAreas (lump_t *l)
{
int i;
carea_t *out;
darea_t *in;
int count;
in = (void *)(cmod_base + l->fileofs);
if (l->filelen % sizeof(*in))
Com_Error (ERR_DROP, "MOD_LoadBmodel: funny lump size");
count = l->filelen / sizeof(*in);
if (count > MAX_MAP_AREAS)
Com_Error (ERR_DROP, "Map has too many areas");
out = map_areas;
numareas = count;
for ( i=0 ; i<count ; i++, in++, out++)
{
out->numareaportals = LittleLong (in->numareaportals);
out->firstareaportal = LittleLong (in->firstareaportal);
out->floodvalid = 0;
out->floodnum = 0;
}
}
void CMod_LoadAreaPortals (lump_t *l)
{
dareaportal_t *out;
dareaportal_t *in;
int count;
in = (void *)(cmod_base + l->fileofs);
if (l->filelen % sizeof(*in))
Com_Error (ERR_DROP, "MOD_LoadBmodel: funny lump size");
count = l->filelen / sizeof(*in);
if (count > MAX_MAP_AREAS)
Com_Error (ERR_DROP, "Map has too many areas");
out = map_areaportals;
numareaportals = count;
memcpy (out, in, sizeof(dareaportal_t)*count);
}
void CMod_LoadVisibility (lump_t *l)
{
numvisibility = l->filelen;
if (l->filelen > MAX_MAP_VISIBILITY)
Com_Error (ERR_DROP, "Map has too large visibility lump");
memcpy (map_visibility, cmod_base + l->fileofs, l->filelen);
map_vis->numclusters = LittleLong (map_vis->numclusters);
}
void CMod_LoadEntityString (lump_t *l)
{
numentitychars = l->filelen;
if (l->filelen > MAX_MAP_ENTSTRING)
Com_Error (ERR_DROP, "Map has too large entity lump");
memcpy (map_entitystring, cmod_base + l->fileofs, l->filelen);
}
/*
* Loads in the map and all submodels
*/
cmodel_t *CM_LoadMap (char *name, qboolean clientload, unsigned *checksum)
{
unsigned *buf;
int i;
dheader_t header;
int length;
static unsigned last_checksum;
map_noareas = Cvar_Get ("map_noareas", "0", 0);
if ( !strcmp (map_name, name) && (clientload || !Cvar_VariableValue ("flushmap")) )
{
*checksum = last_checksum;
if (!clientload)
{
memset (portalopen, 0, sizeof(portalopen));
FloodAreaConnections ();
}
return &map_cmodels[0]; /* still have the right version */
}
/* free old stuff */
numplanes = 0;
numnodes = 0;
numleafs = 0;
numcmodels = 0;
numvisibility = 0;
numentitychars = 0;
map_entitystring[0] = 0;
map_name[0] = 0;
if (!name || !name[0])
{
numleafs = 1;
numclusters = 1;
numareas = 1;
*checksum = 0;
return &map_cmodels[0]; /* cinematic servers won't have anything at all */
}
length = FS_LoadFile (name, (void **)&buf);
if (!buf)
Com_Error (ERR_DROP, "Couldn't load %s", name);
last_checksum = LittleLong (Com_BlockChecksum (buf, length));
*checksum = last_checksum;
header = *(dheader_t *)buf;
for (i=0 ; i<sizeof(dheader_t)/4 ; i++)
((int *)&header)[i] = LittleLong ( ((int *)&header)[i]);
if (header.version != BSPVERSION)
Com_Error (ERR_DROP, "CMod_LoadBrushModel: %s has wrong version number (%i should be %i)"
, name, header.version, BSPVERSION);
cmod_base = (byte *)buf;
/* load into heap */
CMod_LoadSurfaces (&header.lumps[LUMP_TEXINFO]);
CMod_LoadLeafs (&header.lumps[LUMP_LEAFS]);
CMod_LoadLeafBrushes (&header.lumps[LUMP_LEAFBRUSHES]);
CMod_LoadPlanes (&header.lumps[LUMP_PLANES]);
CMod_LoadBrushes (&header.lumps[LUMP_BRUSHES]);
CMod_LoadBrushSides (&header.lumps[LUMP_BRUSHSIDES]);
CMod_LoadSubmodels (&header.lumps[LUMP_MODELS]);
CMod_LoadNodes (&header.lumps[LUMP_NODES]);
CMod_LoadAreas (&header.lumps[LUMP_AREAS]);
CMod_LoadAreaPortals (&header.lumps[LUMP_AREAPORTALS]);
CMod_LoadVisibility (&header.lumps[LUMP_VISIBILITY]);
CMod_LoadEntityString (&header.lumps[LUMP_ENTITIES]);
FS_FreeFile (buf);
CM_InitBoxHull ();
memset (portalopen, 0, sizeof(portalopen));
FloodAreaConnections ();
strcpy (map_name, name);
return &map_cmodels[0];
}
cmodel_t *CM_InlineModel (char *name)
{
int num;
if (!name || name[0] != '*')
Com_Error (ERR_DROP, "CM_InlineModel: bad name");
num = (int)strtol(name+1, (char **)NULL, 10);
if (num < 1 || num >= numcmodels)
Com_Error (ERR_DROP, "CM_InlineModel: bad number");
return &map_cmodels[num];
}
int CM_NumClusters (void)
{
return numclusters;
}
int CM_NumInlineModels (void)
{
return numcmodels;
}
char *CM_EntityString (void)
{
return map_entitystring;
}
int CM_LeafContents (int leafnum)
{
if (leafnum < 0 || leafnum >= numleafs)
Com_Error (ERR_DROP, "CM_LeafContents: bad number");
return map_leafs[leafnum].contents;
}
int CM_LeafCluster (int leafnum)
{
if (leafnum < 0 || leafnum >= numleafs)
Com_Error (ERR_DROP, "CM_LeafCluster: bad number");
return map_leafs[leafnum].cluster;
}
int CM_LeafArea (int leafnum)
{
if (leafnum < 0 || leafnum >= numleafs)
Com_Error (ERR_DROP, "CM_LeafArea: bad number");
return map_leafs[leafnum].area;
}

View file

@ -1,104 +0,0 @@
/*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* =======================================================================
*
* This file implements loading an parsing of the vis of a map or model
*
* =======================================================================
*/
#include "../header/common.h"
#include "../header/cmodel.h"
extern int numclusters;
dvis_t *map_vis = (dvis_t *)map_visibility;
void CM_DecompressVis (byte *in, byte *out)
{
int c;
byte *out_p;
int row;
row = (numclusters+7)>>3;
out_p = out;
if (!in || !numvisibility)
{
/* no vis info, so make all visible */
while (row)
{
*out_p++ = 0xff;
row--;
}
return;
}
do
{
if (*in)
{
*out_p++ = *in++;
continue;
}
c = in[1];
in += 2;
if ((out_p - out) + c > row)
{
c = row - (out_p - out);
Com_DPrintf ("warning: Vis decompression overrun\n");
}
while (c)
{
*out_p++ = 0;
c--;
}
}
while (out_p - out < row);
}
byte pvsrow[MAX_MAP_LEAFS/8];
byte phsrow[MAX_MAP_LEAFS/8];
byte *CM_ClusterPVS (int cluster)
{
if (cluster == -1)
memset (pvsrow, 0, (numclusters+7)>>3);
else
CM_DecompressVis (map_visibility + LittleLong(map_vis->bitofs[cluster][DVIS_PVS]), pvsrow);
return pvsrow;
}
byte *CM_ClusterPHS (int cluster)
{
if (cluster == -1)
memset (phsrow, 0, (numclusters+7)>>3);
else
CM_DecompressVis (map_visibility + LittleLong(map_vis->bitofs[cluster][DVIS_PHS]), phsrow);
return phsrow;
}

View file

@ -19,15 +19,14 @@
*
* =======================================================================
*
* Client / Server interactions
* Movement message (forward, backward, left, right, etc) handling.
*
* =======================================================================
*/
#include "../header/common.h"
#include "header/common.h"
vec3_t bytedirs[NUMVERTEXNORMALS] =
{
vec3_t bytedirs[NUMVERTEXNORMALS] = {
{-0.525731, 0.000000, 0.850651},
{-0.442863, 0.238856, 0.864188},
{-0.295242, 0.000000, 0.955423},
@ -192,7 +191,8 @@ vec3_t bytedirs[NUMVERTEXNORMALS] =
{-0.688191, -0.587785, -0.425325}
};
void MSG_WriteChar (sizebuf_t *sb, int c)
void
MSG_WriteChar(sizebuf_t *sb, int c)
{
byte *buf;
@ -200,7 +200,8 @@ void MSG_WriteChar (sizebuf_t *sb, int c)
buf[0] = c;
}
void MSG_WriteByte (sizebuf_t *sb, int c)
void
MSG_WriteByte(sizebuf_t *sb, int c)
{
byte *buf;
@ -208,7 +209,8 @@ void MSG_WriteByte (sizebuf_t *sb, int c)
buf[0] = c;
}
void MSG_WriteShort (sizebuf_t *sb, int c)
void
MSG_WriteShort(sizebuf_t *sb, int c)
{
byte *buf;
@ -217,7 +219,8 @@ void MSG_WriteShort (sizebuf_t *sb, int c)
buf[1] = c >> 8;
}
void MSG_WriteLong (sizebuf_t *sb, int c)
void
MSG_WriteLong(sizebuf_t *sb, int c)
{
byte *buf;
@ -228,7 +231,8 @@ void MSG_WriteLong (sizebuf_t *sb, int c)
buf[3] = c >> 24;
}
void MSG_WriteFloat (sizebuf_t *sb, float f)
void
MSG_WriteFloat(sizebuf_t *sb, float f)
{
union
{
@ -236,45 +240,54 @@ void MSG_WriteFloat (sizebuf_t *sb, float f)
int l;
} dat;
dat.f = f;
dat.l = LittleLong(dat.l);
SZ_Write(sb, &dat.l, 4);
}
void MSG_WriteString (sizebuf_t *sb, char *s)
void
MSG_WriteString(sizebuf_t *sb, char *s)
{
if (!s)
{
SZ_Write(sb, "", 1);
else
SZ_Write (sb, s, (int)strlen(s)+1);
}
void MSG_WriteCoord (sizebuf_t *sb, float f)
else
{
SZ_Write(sb, s, (int)strlen(s) + 1);
}
}
void
MSG_WriteCoord(sizebuf_t *sb, float f)
{
MSG_WriteShort(sb, (int)(f * 8));
}
void MSG_WritePos (sizebuf_t *sb, vec3_t pos)
void
MSG_WritePos(sizebuf_t *sb, vec3_t pos)
{
MSG_WriteShort(sb, (int)(pos[0] * 8));
MSG_WriteShort(sb, (int)(pos[1] * 8));
MSG_WriteShort(sb, (int)(pos[2] * 8));
}
void MSG_WriteAngle (sizebuf_t *sb, float f)
void
MSG_WriteAngle(sizebuf_t *sb, float f)
{
MSG_WriteByte(sb, (int)(f * 256 / 360) & 255);
}
void MSG_WriteAngle16 (sizebuf_t *sb, float f)
void
MSG_WriteAngle16(sizebuf_t *sb, float f)
{
MSG_WriteShort(sb, ANGLE2SHORT(f));
}
void MSG_WriteDeltaUsercmd (sizebuf_t *buf, usercmd_t *from, usercmd_t *cmd)
void
MSG_WriteDeltaUsercmd(sizebuf_t *buf, usercmd_t *from, usercmd_t *cmd)
{
int bits;
@ -282,60 +295,93 @@ void MSG_WriteDeltaUsercmd (sizebuf_t *buf, usercmd_t *from, usercmd_t *cmd)
bits = 0;
if (cmd->angles[0] != from->angles[0])
{
bits |= CM_ANGLE1;
}
if (cmd->angles[1] != from->angles[1])
{
bits |= CM_ANGLE2;
}
if (cmd->angles[2] != from->angles[2])
{
bits |= CM_ANGLE3;
}
if (cmd->forwardmove != from->forwardmove)
{
bits |= CM_FORWARD;
}
if (cmd->sidemove != from->sidemove)
{
bits |= CM_SIDE;
}
if (cmd->upmove != from->upmove)
{
bits |= CM_UP;
}
if (cmd->buttons != from->buttons)
{
bits |= CM_BUTTONS;
}
if (cmd->impulse != from->impulse)
{
bits |= CM_IMPULSE;
}
MSG_WriteByte(buf, bits);
if (bits & CM_ANGLE1)
{
MSG_WriteShort(buf, cmd->angles[0]);
}
if (bits & CM_ANGLE2)
{
MSG_WriteShort(buf, cmd->angles[1]);
}
if (bits & CM_ANGLE3)
{
MSG_WriteShort(buf, cmd->angles[2]);
}
if (bits & CM_FORWARD)
{
MSG_WriteShort(buf, cmd->forwardmove);
}
if (bits & CM_SIDE)
{
MSG_WriteShort(buf, cmd->sidemove);
}
if (bits & CM_UP)
{
MSG_WriteShort(buf, cmd->upmove);
}
if (bits & CM_BUTTONS)
{
MSG_WriteByte(buf, cmd->buttons);
}
if (bits & CM_IMPULSE)
{
MSG_WriteByte(buf, cmd->impulse);
}
MSG_WriteByte(buf, cmd->msec);
MSG_WriteByte(buf, cmd->lightlevel);
}
void MSG_WriteDir (sizebuf_t *sb, vec3_t dir)
void
MSG_WriteDir(sizebuf_t *sb, vec3_t dir)
{
int i, best;
float d, bestd;
@ -363,14 +409,17 @@ void MSG_WriteDir (sizebuf_t *sb, vec3_t dir)
MSG_WriteByte(sb, best);
}
void MSG_ReadDir (sizebuf_t *sb, vec3_t dir)
void
MSG_ReadDir(sizebuf_t *sb, vec3_t dir)
{
int b;
b = MSG_ReadByte(sb);
if (b >= NUMVERTEXNORMALS)
{
Com_Error(ERR_DROP, "MSF_ReadDir: out of range");
}
VectorCopy(bytedirs[b], dir);
}
@ -379,122 +428,191 @@ void MSG_ReadDir (sizebuf_t *sb, vec3_t dir)
* Writes part of a packetentities message.
* Can delta from either a baseline or a previous packet_entity
*/
void MSG_WriteDeltaEntity (entity_state_t *from, entity_state_t *to, sizebuf_t *msg, qboolean force, qboolean newentity)
void
MSG_WriteDeltaEntity(entity_state_t *from,
entity_state_t *to,
sizebuf_t *msg,
qboolean force,
qboolean newentity)
{
int bits;
if (!to->number)
{
Com_Error(ERR_FATAL, "Unset entity number");
}
if (to->number >= MAX_EDICTS)
{
Com_Error(ERR_FATAL, "Entity number >= MAX_EDICTS");
}
/* send an update */
bits = 0;
if (to->number >= 256)
{
bits |= U_NUMBER16; /* number8 is implicit otherwise */
}
if (to->origin[0] != from->origin[0])
{
bits |= U_ORIGIN1;
}
if (to->origin[1] != from->origin[1])
{
bits |= U_ORIGIN2;
}
if (to->origin[2] != from->origin[2])
{
bits |= U_ORIGIN3;
}
if (to->angles[0] != from->angles[0])
{
bits |= U_ANGLE1;
}
if (to->angles[1] != from->angles[1])
{
bits |= U_ANGLE2;
}
if (to->angles[2] != from->angles[2])
{
bits |= U_ANGLE3;
}
if (to->skinnum != from->skinnum)
{
if ((unsigned)to->skinnum < 256)
{
bits |= U_SKIN8;
}
else if ((unsigned)to->skinnum < 0x10000)
{
bits |= U_SKIN16;
}
else
{
bits |= (U_SKIN8 | U_SKIN16);
}
}
if (to->frame != from->frame)
{
if (to->frame < 256)
{
bits |= U_FRAME8;
}
else
{
bits |= U_FRAME16;
}
}
if (to->effects != from->effects)
{
if (to->effects < 256)
{
bits |= U_EFFECTS8;
}
else if (to->effects < 0x8000)
{
bits |= U_EFFECTS16;
}
else
{
bits |= U_EFFECTS8 | U_EFFECTS16;
}
}
if (to->renderfx != from->renderfx)
{
if (to->renderfx < 256)
{
bits |= U_RENDERFX8;
}
else if (to->renderfx < 0x8000)
{
bits |= U_RENDERFX16;
}
else
{
bits |= U_RENDERFX8 | U_RENDERFX16;
}
}
if (to->solid != from->solid)
{
bits |= U_SOLID;
}
/* event is not delta compressed, just 0 compressed */
if (to->event)
{
bits |= U_EVENT;
}
if (to->modelindex != from->modelindex)
{
bits |= U_MODEL;
}
if (to->modelindex2 != from->modelindex2)
{
bits |= U_MODEL2;
}
if (to->modelindex3 != from->modelindex3)
{
bits |= U_MODEL3;
}
if (to->modelindex4 != from->modelindex4)
{
bits |= U_MODEL4;
}
if (to->sound != from->sound)
{
bits |= U_SOUND;
}
if (newentity || (to->renderfx & RF_BEAM))
{
bits |= U_OLDORIGIN;
}
/* write the message */
if (!bits && !force)
{
return; /* nothing to send! */
}
if (bits & 0xff000000)
{
bits |= U_MOREBITS3 | U_MOREBITS2 | U_MOREBITS1;
}
else if (bits & 0x00ff0000)
{
bits |= U_MOREBITS2 | U_MOREBITS1;
}
else if (bits & 0x0000ff00)
{
bits |= U_MOREBITS1;
}
MSG_WriteByte(msg, bits & 255);
@ -517,73 +635,119 @@ void MSG_WriteDeltaEntity (entity_state_t *from, entity_state_t *to, sizebuf_t *
}
if (bits & U_NUMBER16)
{
MSG_WriteShort(msg, to->number);
}
else
{
MSG_WriteByte(msg, to->number);
}
if (bits & U_MODEL)
{
MSG_WriteByte(msg, to->modelindex);
}
if (bits & U_MODEL2)
{
MSG_WriteByte(msg, to->modelindex2);
}
if (bits & U_MODEL3)
{
MSG_WriteByte(msg, to->modelindex3);
}
if (bits & U_MODEL4)
{
MSG_WriteByte(msg, to->modelindex4);
}
if (bits & U_FRAME8)
{
MSG_WriteByte(msg, to->frame);
}
if (bits & U_FRAME16)
{
MSG_WriteShort(msg, to->frame);
}
if ((bits & U_SKIN8) && (bits & U_SKIN16)) /*used for laser colors */
{
MSG_WriteLong(msg, to->skinnum);
}
else if (bits & U_SKIN8)
{
MSG_WriteByte(msg, to->skinnum);
}
else if (bits & U_SKIN16)
{
MSG_WriteShort(msg, to->skinnum);
}
if ((bits & (U_EFFECTS8 | U_EFFECTS16)) == (U_EFFECTS8 | U_EFFECTS16))
{
MSG_WriteLong(msg, to->effects);
}
else if (bits & U_EFFECTS8)
{
MSG_WriteByte(msg, to->effects);
}
else if (bits & U_EFFECTS16)
{
MSG_WriteShort(msg, to->effects);
}
if ((bits & (U_RENDERFX8 | U_RENDERFX16)) == (U_RENDERFX8 | U_RENDERFX16))
{
MSG_WriteLong(msg, to->renderfx);
}
else if (bits & U_RENDERFX8)
{
MSG_WriteByte(msg, to->renderfx);
}
else if (bits & U_RENDERFX16)
{
MSG_WriteShort(msg, to->renderfx);
}
if (bits & U_ORIGIN1)
{
MSG_WriteCoord(msg, to->origin[0]);
}
if (bits & U_ORIGIN2)
{
MSG_WriteCoord(msg, to->origin[1]);
}
if (bits & U_ORIGIN3)
{
MSG_WriteCoord(msg, to->origin[2]);
}
if (bits & U_ANGLE1)
{
MSG_WriteAngle(msg, to->angles[0]);
}
if (bits & U_ANGLE2)
{
MSG_WriteAngle(msg, to->angles[1]);
}
if (bits & U_ANGLE3)
{
MSG_WriteAngle(msg, to->angles[2]);
}
if (bits & U_OLDORIGIN)
{
@ -593,11 +757,288 @@ void MSG_WriteDeltaEntity (entity_state_t *from, entity_state_t *to, sizebuf_t *
}
if (bits & U_SOUND)
{
MSG_WriteByte(msg, to->sound);
}
if (bits & U_EVENT)
{
MSG_WriteByte(msg, to->event);
}
if (bits & U_SOLID)
{
MSG_WriteShort(msg, to->solid);
}
}
void
MSG_BeginReading(sizebuf_t *msg)
{
msg->readcount = 0;
}
int
MSG_ReadChar(sizebuf_t *msg_read)
{
int c;
if (msg_read->readcount + 1 > msg_read->cursize)
{
c = -1;
}
else
{
c = (signed char)msg_read->data[msg_read->readcount];
}
msg_read->readcount++;
return c;
}
int
MSG_ReadByte(sizebuf_t *msg_read)
{
int c;
if (msg_read->readcount + 1 > msg_read->cursize)
{
c = -1;
}
else
{
c = (unsigned char)msg_read->data[msg_read->readcount];
}
msg_read->readcount++;
return c;
}
int
MSG_ReadShort(sizebuf_t *msg_read)
{
int c;
if (msg_read->readcount + 2 > msg_read->cursize)
{
c = -1;
}
else
{
c = (short)(msg_read->data[msg_read->readcount]
+ (msg_read->data[msg_read->readcount + 1] << 8));
}
msg_read->readcount += 2;
return c;
}
int
MSG_ReadLong(sizebuf_t *msg_read)
{
int c;
if (msg_read->readcount + 4 > msg_read->cursize)
{
c = -1;
}
else
{
c = msg_read->data[msg_read->readcount]
+ (msg_read->data[msg_read->readcount + 1] << 8)
+ (msg_read->data[msg_read->readcount + 2] << 16)
+ (msg_read->data[msg_read->readcount + 3] << 24);
}
msg_read->readcount += 4;
return c;
}
float
MSG_ReadFloat(sizebuf_t *msg_read)
{
union
{
byte b[4];
float f;
int l;
} dat;
if (msg_read->readcount + 4 > msg_read->cursize)
{
dat.f = -1;
}
else
{
dat.b[0] = msg_read->data[msg_read->readcount];
dat.b[1] = msg_read->data[msg_read->readcount + 1];
dat.b[2] = msg_read->data[msg_read->readcount + 2];
dat.b[3] = msg_read->data[msg_read->readcount + 3];
}
msg_read->readcount += 4;
dat.l = LittleLong(dat.l);
return dat.f;
}
char *
MSG_ReadString(sizebuf_t *msg_read)
{
static char string[2048];
int l, c;
l = 0;
do
{
c = MSG_ReadChar(msg_read);
if ((c == -1) || (c == 0))
{
break;
}
string[l] = c;
l++;
}
while (l < sizeof(string) - 1);
string[l] = 0;
return string;
}
char *
MSG_ReadStringLine(sizebuf_t *msg_read)
{
static char string[2048];
int l, c;
l = 0;
do
{
c = MSG_ReadChar(msg_read);
if ((c == -1) || (c == 0) || (c == '\n'))
{
break;
}
string[l] = c;
l++;
}
while (l < sizeof(string) - 1);
string[l] = 0;
return string;
}
float
MSG_ReadCoord(sizebuf_t *msg_read)
{
return MSG_ReadShort(msg_read) * (0.125f);
}
void
MSG_ReadPos(sizebuf_t *msg_read, vec3_t pos)
{
pos[0] = MSG_ReadShort(msg_read) * (0.125f);
pos[1] = MSG_ReadShort(msg_read) * (0.125f);
pos[2] = MSG_ReadShort(msg_read) * (0.125f);
}
float
MSG_ReadAngle(sizebuf_t *msg_read)
{
return MSG_ReadChar(msg_read) * 1.40625f;
}
float
MSG_ReadAngle16(sizebuf_t *msg_read)
{
return SHORT2ANGLE(MSG_ReadShort(msg_read));
}
void
MSG_ReadDeltaUsercmd(sizebuf_t *msg_read, usercmd_t *from, usercmd_t *move)
{
int bits;
memcpy(move, from, sizeof(*move));
bits = MSG_ReadByte(msg_read);
/* read current angles */
if (bits & CM_ANGLE1)
{
move->angles[0] = MSG_ReadShort(msg_read);
}
if (bits & CM_ANGLE2)
{
move->angles[1] = MSG_ReadShort(msg_read);
}
if (bits & CM_ANGLE3)
{
move->angles[2] = MSG_ReadShort(msg_read);
}
/* read movement */
if (bits & CM_FORWARD)
{
move->forwardmove = MSG_ReadShort(msg_read);
}
if (bits & CM_SIDE)
{
move->sidemove = MSG_ReadShort(msg_read);
}
if (bits & CM_UP)
{
move->upmove = MSG_ReadShort(msg_read);
}
/* read buttons */
if (bits & CM_BUTTONS)
{
move->buttons = MSG_ReadByte(msg_read);
}
if (bits & CM_IMPULSE)
{
move->impulse = MSG_ReadByte(msg_read);
}
/* read time to run command */
move->msec = MSG_ReadByte(msg_read);
/* read the light level */
move->lightlevel = MSG_ReadByte(msg_read);
}
void
MSG_ReadData(sizebuf_t *msg_read, void *data, int len)
{
int i;
for (i = 0; i < len; i++)
{
((byte *)data)[i] = MSG_ReadByte(msg_read);
}
}

View file

@ -19,7 +19,7 @@
*
* =======================================================================
*
* The low level network code
* The low level, platform independant network code
*
* =======================================================================
*/
@ -89,7 +89,8 @@ netadr_t net_from;
sizebuf_t net_message;
byte net_message_buffer[MAX_MSGLEN];
void Netchan_Init (void)
void
Netchan_Init(void)
{
int port;
@ -104,7 +105,8 @@ void Netchan_Init (void)
/*
* Sends an out-of-band datagram
*/
void Netchan_OutOfBand (int net_socket, netadr_t adr, int length, byte *data)
void
Netchan_OutOfBand(int net_socket, netadr_t adr, int length, byte *data)
{
sizebuf_t send;
byte send_buf[MAX_MSGLEN];
@ -122,7 +124,8 @@ void Netchan_OutOfBand (int net_socket, netadr_t adr, int length, byte *data)
/*
* Sends a text message in an out-of-band datagram
*/
void Netchan_OutOfBandPrint (int net_socket, netadr_t adr, char *format, ...)
void
Netchan_OutOfBandPrint(int net_socket, netadr_t adr, char *format, ...)
{
va_list argptr;
static char string[MAX_MSGLEN - 4];
@ -137,7 +140,8 @@ void Netchan_OutOfBandPrint (int net_socket, netadr_t adr, char *format, ...)
/*
* called to open a channel to a remote system
*/
void Netchan_Setup (netsrc_t sock, netchan_t *chan, netadr_t adr, int qport)
void
Netchan_Setup(netsrc_t sock, netchan_t *chan, netadr_t adr, int qport)
{
memset(chan, 0, sizeof(*chan));
@ -155,24 +159,30 @@ void Netchan_Setup (netsrc_t sock, netchan_t *chan, netadr_t adr, int qport)
/*
* Returns true if the last reliable message has acked
*/
qboolean Netchan_CanReliable (netchan_t *chan)
qboolean
Netchan_CanReliable(netchan_t *chan)
{
if (chan->reliable_length)
{
return false; /* waiting for ack */
}
return true;
}
qboolean Netchan_NeedReliable (netchan_t *chan)
qboolean
Netchan_NeedReliable(netchan_t *chan)
{
qboolean send_reliable;
/* if the remote side dropped the last reliable message, resend it */
send_reliable = false;
if (chan->incoming_acknowledged > chan->last_reliable_sequence
&& chan->incoming_reliable_acknowledged != chan->reliable_sequence)
if ((chan->incoming_acknowledged > chan->last_reliable_sequence) &&
(chan->incoming_reliable_acknowledged != chan->reliable_sequence))
{
send_reliable = true;
}
/* if the reliable transmit buffer is empty, copy the current message out */
if (!chan->reliable_length && chan->message.cursize)
@ -189,7 +199,8 @@ qboolean Netchan_NeedReliable (netchan_t *chan)
*
* A 0 length will still generate a packet and deal with the reliable messages.
*/
void Netchan_Transmit (netchan_t *chan, int length, byte *data)
void
Netchan_Transmit(netchan_t *chan, int length, byte *data)
{
sizebuf_t send;
byte send_buf[MAX_MSGLEN];
@ -200,8 +211,8 @@ void Netchan_Transmit (netchan_t *chan, int length, byte *data)
if (chan->message.overflowed)
{
chan->fatal_error = true;
Com_Printf ("%s:Outgoing message overflow\n"
, NET_AdrToString (chan->remote_address));
Com_Printf("%s:Outgoing message overflow\n",
NET_AdrToString(chan->remote_address));
return;
}
@ -219,7 +230,9 @@ void Netchan_Transmit (netchan_t *chan, int length, byte *data)
SZ_Init(&send, send_buf, sizeof(send_buf));
w1 = (chan->outgoing_sequence & ~(1 << 31)) | (send_reliable << 31);
w2 = ( chan->incoming_sequence & ~(1<<31) ) | (chan->incoming_reliable_sequence<<31);
w2 =
(chan->incoming_sequence &
~(1 << 31)) | (chan->incoming_reliable_sequence << 31);
chan->outgoing_sequence++;
chan->last_sent = curtime;
@ -229,7 +242,9 @@ void Netchan_Transmit (netchan_t *chan, int length, byte *data)
/* send the qport if we are a client */
if (chan->sock == NS_CLIENT)
{
MSG_WriteShort(&send, qport->value);
}
/* copy the reliable message to the packet first */
if (send_reliable)
@ -240,9 +255,13 @@ void Netchan_Transmit (netchan_t *chan, int length, byte *data)
/* add the unreliable part if space is available */
if (send.maxsize - send.cursize >= length)
{
SZ_Write(&send, data, length);
}
else
{
Com_Printf("Netchan_Transmit: dumped unreliable\n");
}
/* send the datagram */
NET_SendPacket(chan->sock, send.cursize, send.data, chan->remote_address);
@ -250,18 +269,19 @@ void Netchan_Transmit (netchan_t *chan, int length, byte *data)
if (showpackets->value)
{
if (send_reliable)
Com_Printf ("send %4i : s=%i reliable=%i ack=%i rack=%i\n"
, send.cursize
, chan->outgoing_sequence - 1
, chan->reliable_sequence
, chan->incoming_sequence
, chan->incoming_reliable_sequence);
{
Com_Printf("send %4i : s=%i reliable=%i ack=%i rack=%i\n",
send.cursize, chan->outgoing_sequence - 1,
chan->reliable_sequence, chan->incoming_sequence,
chan->incoming_reliable_sequence);
}
else
Com_Printf ("send %4i : s=%i ack=%i rack=%i\n"
, send.cursize
, chan->outgoing_sequence - 1
, chan->incoming_sequence
, chan->incoming_reliable_sequence);
{
Com_Printf("send %4i : s=%i ack=%i rack=%i\n",
send.cursize, chan->outgoing_sequence - 1,
chan->incoming_sequence,
chan->incoming_reliable_sequence);
}
}
}
@ -269,7 +289,8 @@ void Netchan_Transmit (netchan_t *chan, int length, byte *data)
* called when the current net_message is from remote_address
* modifies net_message so that it points to the packet payload
*/
qboolean Netchan_Process (netchan_t *chan, sizebuf_t *msg)
qboolean
Netchan_Process(netchan_t *chan, sizebuf_t *msg)
{
unsigned sequence, sequence_ack;
unsigned reliable_ack, reliable_message;
@ -281,7 +302,9 @@ qboolean Netchan_Process (netchan_t *chan, sizebuf_t *msg)
/* read the qport if we are a server */
if (chan->sock == NS_SERVER)
{
(void)MSG_ReadShort(msg);
}
reliable_message = sequence >> 31;
reliable_ack = sequence_ack >> 31;
@ -292,28 +315,29 @@ qboolean Netchan_Process (netchan_t *chan, sizebuf_t *msg)
if (showpackets->value)
{
if (reliable_message)
Com_Printf ("recv %4i : s=%i reliable=%i ack=%i rack=%i\n"
, msg->cursize
, sequence
, chan->incoming_reliable_sequence ^ 1
, sequence_ack
, reliable_ack);
{
Com_Printf("recv %4i : s=%i reliable=%i ack=%i rack=%i\n",
msg->cursize, sequence,
chan->incoming_reliable_sequence ^ 1,
sequence_ack, reliable_ack);
}
else
Com_Printf ("recv %4i : s=%i ack=%i rack=%i\n"
, msg->cursize
, sequence
, sequence_ack
, reliable_ack);
{
Com_Printf("recv %4i : s=%i ack=%i rack=%i\n",
msg->cursize, sequence, sequence_ack,
reliable_ack);
}
}
/* discard stale or duplicated packets */
if (sequence <= chan->incoming_sequence)
{
if (showdrop->value)
Com_Printf ("%s:Out of order packet %i at %i\n"
, NET_AdrToString (chan->remote_address)
, sequence
, chan->incoming_sequence);
{
Com_Printf("%s:Out of order packet %i at %i\n",
NET_AdrToString(chan->remote_address),
sequence, chan->incoming_sequence);
}
return false;
}
@ -324,16 +348,19 @@ qboolean Netchan_Process (netchan_t *chan, sizebuf_t *msg)
if (chan->dropped > 0)
{
if (showdrop->value)
Com_Printf ("%s:Dropped %i packets at %i\n"
, NET_AdrToString (chan->remote_address)
, chan->dropped
, sequence);
{
Com_Printf("%s:Dropped %i packets at %i\n",
NET_AdrToString(chan->remote_address),
chan->dropped, sequence);
}
}
/* if the current outgoing reliable message has been acknowledged
clear the buffer to make way for the next */
* clear the buffer to make way for the next */
if (reliable_ack == chan->reliable_sequence)
{
chan->reliable_length = 0; /* it has been received */
}
/* if this message contains a reliable message, bump incoming_reliable_sequence */
chan->incoming_sequence = sequence;
@ -350,3 +377,4 @@ qboolean Netchan_Process (netchan_t *chan, sizebuf_t *msg)
return true;
}

View file

@ -35,8 +35,8 @@ void AL_Overwater();
#define STEPSIZE 18
/* all of the locals will be zeroed before each
pmove, just to make damn sure we don't have
any differences when running on client or server */
* pmove, just to make damn sure we don't have
* any differences when running on client or server */
typedef struct
{
@ -46,7 +46,6 @@ typedef struct
vec3_t forward, right, up;
float frametime;
csurface_t *groundsurface;
cplane_t groundplane;
int groundcontents;
@ -69,14 +68,12 @@ float pm_friction = 6;
float pm_waterfriction = 1;
float pm_waterspeed = 400;
/*
* Slide off of the impacting object
* returns the blocked flags (1 = floor, 2 = step / wall)
*/
#define STOP_EPSILON 0.1 /* Slide off of the impacting object returns the blocked flags (1 = floor, 2 = step / wall) */
#define MIN_STEP_NORMAL 0.7 /* can't step up onto very steep slopes */
#define MAX_CLIP_PLANES 5
#define STOP_EPSILON 0.1
void PM_ClipVelocity (vec3_t in, vec3_t normal, vec3_t out, float overbounce)
void
PM_ClipVelocity(vec3_t in, vec3_t normal, vec3_t out, float overbounce)
{
float backoff;
float change;
@ -89,10 +86,12 @@ void PM_ClipVelocity (vec3_t in, vec3_t normal, vec3_t out, float overbounce)
change = normal[i] * backoff;
out[i] = in[i] - change;
if (out[i] > -STOP_EPSILON && out[i] < STOP_EPSILON)
if ((out[i] > -STOP_EPSILON) && (out[i] < STOP_EPSILON))
{
out[i] = 0;
}
}
}
/*
* Each intersection will try to step over the obstruction instead of
@ -101,9 +100,8 @@ void PM_ClipVelocity (vec3_t in, vec3_t normal, vec3_t out, float overbounce)
* Returns a new origin, velocity, and contact entity
* Does not modify any world state?
*/
#define MIN_STEP_NORMAL 0.7 /* can't step up onto very steep slopes */
#define MAX_CLIP_PLANES 5
void PM_StepSlideMove_ (void)
void
PM_StepSlideMove_(void)
{
int bumpcount, numbumps;
vec3_t dir;
@ -126,7 +124,9 @@ void PM_StepSlideMove_ (void)
for (bumpcount = 0; bumpcount < numbumps; bumpcount++)
{
for (i = 0; i < 3; i++)
{
end[i] = pml.origin[i] + time_left * pml.velocity[i];
}
trace = pm->trace(pml.origin, pm->mins, pm->maxs, end);
@ -145,10 +145,12 @@ void PM_StepSlideMove_ (void)
}
if (trace.fraction == 1)
{
break; /* moved the entire distance */
}
/* save entity for contact */
if (pm->numtouch < MAXTOUCH && trace.ent)
if ((pm->numtouch < MAXTOUCH) && trace.ent)
{
pm->touchents[pm->numtouch] = trace.ent;
pm->numtouch++;
@ -173,15 +175,21 @@ void PM_StepSlideMove_ (void)
PM_ClipVelocity(pml.velocity, planes[i], pml.velocity, 1.01f);
for (j = 0; j < numplanes; j++)
{
if (j != i)
{
if (DotProduct(pml.velocity, planes[j]) < 0)
{
break; /* not ok */
}
}
}
if (j == numplanes)
{
break;
}
}
if (i != numplanes)
{
@ -216,7 +224,8 @@ void PM_StepSlideMove_ (void)
}
}
void PM_StepSlideMove (void)
void
PM_StepSlideMove(void)
{
vec3_t start_o, start_v;
vec3_t down_o, down_v;
@ -238,7 +247,9 @@ void PM_StepSlideMove (void)
trace = pm->trace(up, pm->mins, pm->maxs, up);
if (trace.allsolid)
{
return; /* can't step up */
}
/* try sliding above */
VectorCopy(up, pml.origin);
@ -264,7 +275,7 @@ void PM_StepSlideMove (void)
up_dist = (up[0] - start_o[0]) * (up[0] - start_o[0])
+ (up[1] - start_o[1]) * (up[1] - start_o[1]);
if (down_dist > up_dist || trace.plane.normal[2] < MIN_STEP_NORMAL)
if ((down_dist > up_dist) || (trace.plane.normal[2] < MIN_STEP_NORMAL))
{
VectorCopy(down_o, pml.origin);
VectorCopy(down_v, pml.velocity);
@ -277,7 +288,8 @@ void PM_StepSlideMove (void)
/*
* Handles both ground friction and water friction
*/
void PM_Friction (void)
void
PM_Friction(void)
{
float *vel;
float speed, newspeed, control;
@ -298,7 +310,8 @@ void PM_Friction (void)
drop = 0;
/* apply ground friction */
if ((pm->groundentity && pml.groundsurface && !(pml.groundsurface->flags & SURF_SLICK) ) || (pml.ladder) )
if ((pm->groundentity && pml.groundsurface &&
!(pml.groundsurface->flags & SURF_SLICK)) || (pml.ladder))
{
friction = pm_friction;
control = speed < pm_stopspeed ? pm_stopspeed : speed;
@ -307,7 +320,9 @@ void PM_Friction (void)
/* apply water friction */
if (pm->waterlevel && !pml.ladder)
{
drop += speed * pm_waterfriction * pm->waterlevel * pml.frametime;
}
/* scale the velocity */
newspeed = speed - drop;
@ -327,7 +342,8 @@ void PM_Friction (void)
/*
* Handles user intended acceleration
*/
void PM_Accelerate (vec3_t wishdir, float wishspeed, float accel)
void
PM_Accelerate(vec3_t wishdir, float wishspeed, float accel)
{
int i;
float addspeed, accelspeed, currentspeed;
@ -336,76 +352,104 @@ void PM_Accelerate (vec3_t wishdir, float wishspeed, float accel)
addspeed = wishspeed - currentspeed;
if (addspeed <= 0)
{
return;
}
accelspeed = accel * pml.frametime * wishspeed;
if (accelspeed > addspeed)
{
accelspeed = addspeed;
for (i=0 ; i<3 ; i++)
pml.velocity[i] += accelspeed*wishdir[i];
}
void PM_AirAccelerate (vec3_t wishdir, float wishspeed, float accel)
for (i = 0; i < 3; i++)
{
pml.velocity[i] += accelspeed * wishdir[i];
}
}
void
PM_AirAccelerate(vec3_t wishdir, float wishspeed, float accel)
{
int i;
float addspeed, accelspeed, currentspeed, wishspd = wishspeed;
if (wishspd > 30)
{
wishspd = 30;
}
currentspeed = DotProduct(pml.velocity, wishdir);
addspeed = wishspd - currentspeed;
if (addspeed <= 0)
{
return;
}
accelspeed = accel * wishspeed * pml.frametime;
if (accelspeed > addspeed)
{
accelspeed = addspeed;
for (i=0 ; i<3 ; i++)
pml.velocity[i] += accelspeed*wishdir[i];
}
void PM_AddCurrents (vec3_t wishvel)
for (i = 0; i < 3; i++)
{
pml.velocity[i] += accelspeed * wishdir[i];
}
}
void
PM_AddCurrents(vec3_t wishvel)
{
vec3_t v;
float s;
/* account for ladders */
if (pml.ladder && fabs(pml.velocity[2]) <= 200)
if (pml.ladder && (fabs(pml.velocity[2]) <= 200))
{
if ((pm->viewangles[PITCH] <= -15) && (pm->cmd.forwardmove > 0))
{
wishvel[2] = 200;
}
else if ((pm->viewangles[PITCH] >= 15) && (pm->cmd.forwardmove > 0))
{
wishvel[2] = -200;
}
else if (pm->cmd.upmove > 0)
{
wishvel[2] = 200;
}
else if (pm->cmd.upmove < 0)
{
wishvel[2] = -200;
}
else
{
wishvel[2] = 0;
}
/* limit horizontal speed when on a ladder */
if (wishvel[0] < -25)
{
wishvel[0] = -25;
}
else if (wishvel[0] > 25)
{
wishvel[0] = 25;
}
if (wishvel[1] < -25)
{
wishvel[1] = -25;
}
else if (wishvel[1] > 25)
{
wishvel[1] = 25;
}
}
/* add water currents */
if (pm->watertype & MASK_CURRENT)
@ -413,27 +457,41 @@ void PM_AddCurrents (vec3_t wishvel)
VectorClear(v);
if (pm->watertype & CONTENTS_CURRENT_0)
{
v[0] += 1;
}
if (pm->watertype & CONTENTS_CURRENT_90)
{
v[1] += 1;
}
if (pm->watertype & CONTENTS_CURRENT_180)
{
v[0] -= 1;
}
if (pm->watertype & CONTENTS_CURRENT_270)
{
v[1] -= 1;
}
if (pm->watertype & CONTENTS_CURRENT_UP)
{
v[2] += 1;
}
if (pm->watertype & CONTENTS_CURRENT_DOWN)
{
v[2] -= 1;
}
s = pm_waterspeed;
if ((pm->waterlevel == 1) && (pm->groundentity))
{
s /= 2;
}
VectorMA(wishvel, s, v, wishvel);
}
@ -444,28 +502,41 @@ void PM_AddCurrents (vec3_t wishvel)
VectorClear(v);
if (pml.groundcontents & CONTENTS_CURRENT_0)
{
v[0] += 1;
}
if (pml.groundcontents & CONTENTS_CURRENT_90)
{
v[1] += 1;
}
if (pml.groundcontents & CONTENTS_CURRENT_180)
{
v[0] -= 1;
}
if (pml.groundcontents & CONTENTS_CURRENT_270)
{
v[1] -= 1;
}
if (pml.groundcontents & CONTENTS_CURRENT_UP)
{
v[2] += 1;
}
if (pml.groundcontents & CONTENTS_CURRENT_DOWN)
{
v[2] -= 1;
}
VectorMA(wishvel, 100, v, wishvel);
}
}
void PM_WaterMove (void)
void
PM_WaterMove(void)
{
int i;
vec3_t wishvel;
@ -474,13 +545,19 @@ void PM_WaterMove (void)
/* user intentions */
for (i = 0; i < 3; i++)
wishvel[i] = pml.forward[i]*pm->cmd.forwardmove + pml.right[i]*pm->cmd.sidemove;
{
wishvel[i] = pml.forward[i] * pm->cmd.forwardmove +
pml.right[i] * pm->cmd.sidemove;
}
if (!pm->cmd.forwardmove && !pm->cmd.sidemove && !pm->cmd.upmove)
{
wishvel[2] -= 60; /* drift towards bottom */
}
else
{
wishvel[2] += pm->cmd.upmove;
}
PM_AddCurrents(wishvel);
@ -500,7 +577,8 @@ void PM_WaterMove (void)
PM_StepSlideMove();
}
void PM_AirMove (void)
void
PM_AirMove(void)
{
int i;
vec3_t wishvel;
@ -513,7 +591,9 @@ void PM_AirMove (void)
smove = pm->cmd.sidemove;
for (i = 0; i < 2; i++)
{
wishvel[i] = pml.forward[i] * fmove + pml.right[i] * smove;
}
wishvel[2] = 0;
@ -542,21 +622,23 @@ void PM_AirMove (void)
pml.velocity[2] -= pm->s.gravity * pml.frametime;
if (pml.velocity[2] < 0)
{
pml.velocity[2] = 0;
}
}
else
{
pml.velocity[2] += pm->s.gravity * pml.frametime;
if (pml.velocity[2] > 0)
{
pml.velocity[2] = 0;
}
}
}
PM_StepSlideMove();
}
else if (pm->groundentity)
{
/* walking on ground */
@ -564,25 +646,32 @@ void PM_AirMove (void)
PM_Accelerate(wishdir, wishspeed, pm_accelerate);
if (pm->s.gravity > 0)
{
pml.velocity[2] = 0;
}
else
{
pml.velocity[2] -= pm->s.gravity * pml.frametime;
}
if (!pml.velocity[0] && !pml.velocity[1])
{
return;
}
PM_StepSlideMove();
}
else
{
/* not on ground, so little effect on velocity */
if (pm_airaccelerate)
{
PM_AirAccelerate(wishdir, wishspeed, pm_accelerate);
}
else
{
PM_Accelerate(wishdir, wishspeed, 1);
}
/* add gravity */
pml.velocity[2] -= pm->s.gravity * pml.frametime;
@ -590,7 +679,8 @@ void PM_AirMove (void)
}
}
void PM_CatagorizePosition (void)
void
PM_CatagorizePosition(void)
{
vec3_t point;
int cont;
@ -611,7 +701,6 @@ void PM_CatagorizePosition (void)
pm->s.pm_flags &= ~PMF_ON_GROUND;
pm->groundentity = NULL;
}
else
{
trace = pm->trace(pml.origin, pm->mins, pm->maxs, point);
@ -619,12 +708,11 @@ void PM_CatagorizePosition (void)
pml.groundsurface = trace.surface;
pml.groundcontents = trace.contents;
if (!trace.ent || (trace.plane.normal[2] < 0.7 && !trace.startsolid) )
if (!trace.ent || ((trace.plane.normal[2] < 0.7) && !trace.startsolid))
{
pm->groundentity = NULL;
pm->s.pm_flags &= ~PMF_ON_GROUND;
}
else
{
pm->groundentity = trace.ent;
@ -632,7 +720,8 @@ void PM_CatagorizePosition (void)
/* hitting solid ground will end a waterjump */
if (pm->s.pm_flags & PMF_TIME_WATERJUMP)
{
pm->s.pm_flags &= ~(PMF_TIME_WATERJUMP | PMF_TIME_LAND | PMF_TIME_TELEPORT);
pm->s.pm_flags &=
~(PMF_TIME_WATERJUMP | PMF_TIME_LAND | PMF_TIME_TELEPORT);
pm->s.pm_time = 0;
}
@ -648,15 +737,18 @@ void PM_CatagorizePosition (void)
/* don't allow another jump for a little while */
if (pml.velocity[2] < -400)
{
pm->s.pm_time = 25;
}
else
{
pm->s.pm_time = 18;
}
}
}
}
if (pm->numtouch < MAXTOUCH && trace.ent)
if ((pm->numtouch < MAXTOUCH) && trace.ent)
{
pm->touchents[pm->numtouch] = trace.ent;
pm->numtouch++;
@ -687,13 +779,15 @@ void PM_CatagorizePosition (void)
cont = pm->pointcontents(point);
if (cont & MASK_WATER)
{
pm->waterlevel = 3;
}
}
}
}
void PM_CheckJump (void)
void
PM_CheckJump(void)
{
if (pm->s.pm_flags & PMF_TIME_LAND)
{
@ -710,10 +804,14 @@ void PM_CheckJump (void)
/* must wait for jump to be released */
if (pm->s.pm_flags & PMF_JUMP_HELD)
{
return;
}
if (pm->s.pm_type == PM_DEAD)
{
return;
}
if (pm->waterlevel >= 2)
{
@ -721,22 +819,30 @@ void PM_CheckJump (void)
pm->groundentity = NULL;
if (pml.velocity[2] <= -300)
{
return;
}
if (pm->watertype == CONTENTS_WATER)
{
pml.velocity[2] = 100;
}
else if (pm->watertype == CONTENTS_SLIME)
{
pml.velocity[2] = 80;
}
else
{
pml.velocity[2] = 50;
}
return;
}
if (pm->groundentity == NULL)
{
return; /* in air, so no effect */
}
pm->s.pm_flags |= PMF_JUMP_HELD;
@ -744,10 +850,13 @@ void PM_CheckJump (void)
pml.velocity[2] += 270;
if (pml.velocity[2] < 270)
{
pml.velocity[2] = 270;
}
}
void PM_CheckSpecialMovement (void)
void
PM_CheckSpecialMovement(void)
{
vec3_t spot;
int cont;
@ -755,7 +864,9 @@ void PM_CheckSpecialMovement (void)
trace_t trace;
if (pm->s.pm_time)
{
return;
}
pml.ladder = false;
@ -769,24 +880,32 @@ void PM_CheckSpecialMovement (void)
trace = pm->trace(pml.origin, pm->mins, pm->maxs, spot);
if ((trace.fraction < 1) && (trace.contents & CONTENTS_LADDER))
{
pml.ladder = true;
}
/* check for water jump */
if (pm->waterlevel != 2)
{
return;
}
VectorMA(pml.origin, 30, flatforward, spot);
spot[2] += 4;
cont = pm->pointcontents(spot);
if (!(cont & CONTENTS_SOLID))
{
return;
}
spot[2] += 16;
cont = pm->pointcontents(spot);
if (cont)
{
return;
}
/* jump out of water */
VectorScale(flatforward, 50, pml.velocity);
@ -796,7 +915,8 @@ void PM_CheckSpecialMovement (void)
pm->s.pm_time = 255;
}
void PM_FlyMove (qboolean doclip)
void
PM_FlyMove(qboolean doclip)
{
float speed, drop, friction, control, newspeed;
float currentspeed, addspeed, accelspeed;
@ -817,7 +937,6 @@ void PM_FlyMove (qboolean doclip)
{
VectorCopy(vec3_origin, pml.velocity);
}
else
{
drop = 0;
@ -830,7 +949,9 @@ void PM_FlyMove (qboolean doclip)
newspeed = speed - drop;
if (newspeed < 0)
{
newspeed = 0;
}
newspeed /= speed;
@ -845,7 +966,9 @@ void PM_FlyMove (qboolean doclip)
VectorNormalize(pml.right);
for (i = 0; i < 3; i++)
{
wishvel[i] = pml.forward[i] * fmove + pml.right[i] * smove;
}
wishvel[2] += pm->cmd.upmove;
@ -863,26 +986,33 @@ void PM_FlyMove (qboolean doclip)
addspeed = wishspeed - currentspeed;
if (addspeed <= 0)
{
return;
}
accelspeed = pm_accelerate * pml.frametime * wishspeed;
if (accelspeed > addspeed)
{
accelspeed = addspeed;
}
for (i = 0; i < 3; i++)
{
pml.velocity[i] += accelspeed * wishdir[i];
}
if (doclip)
{
for (i = 0; i < 3; i++)
{
end[i] = pml.origin[i] + pml.frametime * pml.velocity[i];
}
trace = pm->trace(pml.origin, pm->mins, pm->maxs, end);
VectorCopy(trace.endpos, pml.origin);
}
else
{
/* move */
@ -893,7 +1023,8 @@ void PM_FlyMove (qboolean doclip)
/*
* Sets mins, maxs, and pm->viewheight
*/
void PM_CheckDuck (void)
void
PM_CheckDuck(void)
{
trace_t trace;
@ -917,13 +1048,11 @@ void PM_CheckDuck (void)
{
pm->s.pm_flags |= PMF_DUCKED;
}
else if (pm->cmd.upmove < 0 && (pm->s.pm_flags & PMF_ON_GROUND) )
else if ((pm->cmd.upmove < 0) && (pm->s.pm_flags & PMF_ON_GROUND))
{
/* duck */
pm->s.pm_flags |= PMF_DUCKED;
}
else
{
/* stand up if possible */
@ -934,16 +1063,17 @@ void PM_CheckDuck (void)
trace = pm->trace(pml.origin, pm->mins, pm->maxs, pml.origin);
if (!trace.allsolid)
{
pm->s.pm_flags &= ~PMF_DUCKED;
}
}
}
if (pm->s.pm_flags & PMF_DUCKED)
{
pm->maxs[2] = 4;
pm->viewheight = -2;
}
else
{
pm->maxs[2] = 32;
@ -951,12 +1081,15 @@ void PM_CheckDuck (void)
}
}
void PM_DeadMove (void)
void
PM_DeadMove(void)
{
float forward;
if (!pm->groundentity)
{
return;
}
/* extra friction */
forward = VectorLength(pml.velocity);
@ -966,7 +1099,6 @@ void PM_DeadMove (void)
{
VectorClear(pml.velocity);
}
else
{
VectorNormalize(pml.velocity);
@ -974,17 +1106,22 @@ void PM_DeadMove (void)
}
}
qboolean PM_GoodPosition (void)
qboolean
PM_GoodPosition(void)
{
trace_t trace;
vec3_t origin, end;
int i;
if (pm->s.pm_type == PM_SPECTATOR)
{
return true;
}
for (i = 0; i < 3; i++)
{
origin[i] = end[i] = pm->s.origin[i] * 0.125f;
}
trace = pm->trace(origin, pm->mins, pm->maxs, end);
@ -995,7 +1132,8 @@ qboolean PM_GoodPosition (void)
* On exit, the origin will have a value that is pre-quantized to the 0.125
* precision of the network channel and in a valid position.
*/
void PM_SnapPosition (void)
void
PM_SnapPosition(void)
{
int sign[3];
int i, j, bits;
@ -1005,21 +1143,28 @@ void PM_SnapPosition (void)
/* snap velocity to eigths */
for (i = 0; i < 3; i++)
{
pm->s.velocity[i] = (int)(pml.velocity[i] * 8);
}
for (i = 0; i < 3; i++)
{
if (pml.origin[i] >= 0)
{
sign[i] = 1;
}
else
{
sign[i] = -1;
}
pm->s.origin[i] = (int)(pml.origin[i] * 8);
if (pm->s.origin[i] * 0.125f == pml.origin[i])
{
sign[i] = 0;
}
}
VectorCopy(pm->s.origin, base);
@ -1030,18 +1175,25 @@ void PM_SnapPosition (void)
VectorCopy(base, pm->s.origin);
for (i = 0; i < 3; i++)
{
if (bits & (1 << i))
{
pm->s.origin[i] += sign[i];
}
}
if (PM_GoodPosition())
{
return;
}
}
/* go back to the last position */
VectorCopy(pml.previous_origin, pm->s.origin);
}
void PM_InitialSnapPosition(void)
void
PM_InitialSnapPosition(void)
{
int x, y, z;
short base[3];
@ -1076,18 +1228,19 @@ void PM_InitialSnapPosition(void)
Com_DPrintf("Bad InitialSnapPosition\n");
}
void PM_ClampAngles (void)
void
PM_ClampAngles(void)
{
short temp;
int i;
if (pm->s.pm_flags & PMF_TIME_TELEPORT)
{
pm->viewangles[YAW] = SHORT2ANGLE(pm->cmd.angles[YAW] + pm->s.delta_angles[YAW]);
pm->viewangles[YAW] = SHORT2ANGLE(
pm->cmd.angles[YAW] + pm->s.delta_angles[YAW]);
pm->viewangles[PITCH] = 0;
pm->viewangles[ROLL] = 0;
}
else
{
/* circularly clamp the angles with deltas */
@ -1098,12 +1251,15 @@ void PM_ClampAngles (void)
}
/* don't let the player look up or down more than 90 degrees */
if (pm->viewangles[PITCH] > 89 && pm->viewangles[PITCH] < 180)
if ((pm->viewangles[PITCH] > 89) && (pm->viewangles[PITCH] < 180))
{
pm->viewangles[PITCH] = 89;
else if (pm->viewangles[PITCH] < 271 && pm->viewangles[PITCH] >= 180)
}
else if ((pm->viewangles[PITCH] < 271) && (pm->viewangles[PITCH] >= 180))
{
pm->viewangles[PITCH] = 271;
}
}
AngleVectors(pm->viewangles, pml.forward, pml.right, pml.up);
}
@ -1111,7 +1267,8 @@ void PM_ClampAngles (void)
/*
* Can be called by either the server or the client
*/
void Pmove (pmove_t *pmove)
void
Pmove(pmove_t *pmove)
{
#if !defined(DEDICATED_ONLY) && defined(USE_OPENAL)
static int underwater;
@ -1161,19 +1318,25 @@ void Pmove (pmove_t *pmove)
}
if (pm->s.pm_type == PM_FREEZE)
{
return; /* no movement at all */
}
/* set mins, maxs, and viewheight */
PM_CheckDuck();
if (pm->snapinitial)
{
PM_InitialSnapPosition();
}
/* set groundentity, watertype, and waterlevel */
PM_CatagorizePosition();
if (pm->s.pm_type == PM_DEAD)
{
PM_DeadMove();
}
PM_CheckSpecialMovement();
@ -1185,17 +1348,21 @@ void Pmove (pmove_t *pmove)
msec = pm->cmd.msec >> 3;
if (!msec)
{
msec = 1;
}
if (msec >= pm->s.pm_time)
{
pm->s.pm_flags &= ~(PMF_TIME_WATERJUMP | PMF_TIME_LAND | PMF_TIME_TELEPORT);
pm->s.pm_flags &=
~(PMF_TIME_WATERJUMP | PMF_TIME_LAND | PMF_TIME_TELEPORT);
pm->s.pm_time = 0;
}
else
{
pm->s.pm_time -= msec;
}
}
if (pm->s.pm_flags & PMF_TIME_TELEPORT)
{
@ -1222,8 +1389,9 @@ void Pmove (pmove_t *pmove)
PM_Friction();
if (pm->waterlevel >= 2)
{
PM_WaterMove();
}
else
{
vec3_t angles;
@ -1231,7 +1399,9 @@ void Pmove (pmove_t *pmove)
VectorCopy(pm->viewangles, angles);
if (angles[PITCH] > 180)
{
angles[PITCH] = angles[PITCH] - 360;
}
angles[PITCH] /= 3;
@ -1251,7 +1421,7 @@ void Pmove (pmove_t *pmove)
AL_Underwater();
}
if ((pm->waterlevel < 3 && underwater))
if (((pm->waterlevel < 3) && underwater))
{
underwater = 0;
AL_Overwater();
@ -1260,3 +1430,4 @@ void Pmove (pmove_t *pmove)
PM_SnapPosition();
}

View file

@ -26,30 +26,38 @@
#include "header/common.h"
void SZ_Init (sizebuf_t *buf, byte *data, int length)
void
SZ_Init(sizebuf_t *buf, byte *data, int length)
{
memset(buf, 0, sizeof(*buf));
buf->data = data;
buf->maxsize = length;
}
void SZ_Clear (sizebuf_t *buf)
void
SZ_Clear(sizebuf_t *buf)
{
buf->cursize = 0;
buf->overflowed = false;
}
void *SZ_GetSpace (sizebuf_t *buf, int length)
void *
SZ_GetSpace(sizebuf_t *buf, int length)
{
void *data;
if (buf->cursize + length > buf->maxsize)
{
if (!buf->allowoverflow)
{
Com_Error(ERR_FATAL, "SZ_GetSpace: overflow without allowoverflow set");
}
if (length > buf->maxsize)
Com_Error (ERR_FATAL, "SZ_GetSpace: %i is > full buffer size", length);
{
Com_Error(ERR_FATAL, "SZ_GetSpace: %i is > full buffer size",
length);
}
SZ_Clear(buf);
buf->overflowed = true;
@ -62,12 +70,14 @@ void *SZ_GetSpace (sizebuf_t *buf, int length)
return data;
}
void SZ_Write (sizebuf_t *buf, void *data, int length)
void
SZ_Write(sizebuf_t *buf, void *data, int length)
{
memcpy(SZ_GetSpace(buf, length), data, length);
}
void SZ_Print (sizebuf_t *buf, char *data)
void
SZ_Print(sizebuf_t *buf, char *data)
{
int len;
@ -76,12 +86,17 @@ void SZ_Print (sizebuf_t *buf, char *data)
if (buf->cursize)
{
if (buf->data[buf->cursize - 1])
{
memcpy((byte *)SZ_GetSpace(buf, len), data, len); /* no trailing 0 */
}
else
{
memcpy((byte *)SZ_GetSpace(buf, len - 1) - 1, data, len); /* write over trailing 0 */
}
}
else
{
memcpy((byte *)SZ_GetSpace(buf, len), data, len);
}
}

View file

@ -19,7 +19,7 @@
*
* =======================================================================
*
* Zone malloc. It's just a normal mallic with counter.
* Zone malloc. It's just a normal malloc with tags.
*
* =======================================================================
*/
@ -32,7 +32,8 @@
zhead_t z_chain;
int z_count, z_bytes;
void Z_Free (void *ptr)
void
Z_Free(void *ptr)
{
zhead_t *z;
@ -53,12 +54,14 @@ void Z_Free (void *ptr)
free(z);
}
void Z_Stats_f (void)
void
Z_Stats_f(void)
{
Com_Printf("%i bytes in %i blocks\n", z_bytes, z_count);
}
void Z_FreeTags (int tag)
void
Z_FreeTags(int tag)
{
zhead_t *z, *next;
@ -67,11 +70,14 @@ void Z_FreeTags (int tag)
next = z->next;
if (z->tag == tag)
{
Z_Free((void *)(z + 1));
}
}
}
void *Z_TagMalloc (int size, int tag)
void *
Z_TagMalloc(int size, int tag)
{
zhead_t *z;
@ -79,7 +85,9 @@ void *Z_TagMalloc (int size, int tag)
z = malloc(size);
if (!z)
{
Com_Error(ERR_FATAL, "Z_Malloc: failed on allocation of %i bytes", size);
}
memset(z, 0, size);
z_count++;
@ -96,7 +104,9 @@ void *Z_TagMalloc (int size, int tag)
return (void *)(z + 1);
}
void *Z_Malloc (int size)
void *
Z_Malloc(int size)
{
return Z_TagMalloc(size, 0);
}

View file

@ -110,7 +110,8 @@ CDAudio_Play ( int track, qboolean looping )
if (SDL_CDPlay(cd_id, cd_id->track[track].offset,
cd_id->track[track].length))
{
Com_DPrintf( "CDAudio_Play: Unable to play track: %d (%s)\n", track + 1, SDL_GetError() );
Com_DPrintf("CDAudio_Play: Unable to play track: %d (%s)\n",
track + 1, SDL_GetError());
return;
}
@ -319,21 +320,21 @@ CDAudio_Init ()
if (initialized)
{
return ( 0 );
return 0;
}
cv = Cvar_Get("nocdaudio", "0", CVAR_NOSET);
if (cv->value)
{
return ( -1 );
return -1;
}
cd_nocd = Cvar_Get("cd_nocd", "0", CVAR_ARCHIVE);
if (cd_nocd->value)
{
return ( -1 );
return -1;
}
cd_volume = Cvar_Get("cd_volume", "1", CVAR_ARCHIVE);
@ -343,7 +344,7 @@ CDAudio_Init ()
if (SDL_Init(SDL_INIT_CDROM) < 0)
{
Com_Printf("Couldn't init SDL cdrom: %s\n", SDL_GetError());
return ( -1 );
return -1;
}
}
else if (SDL_WasInit(SDL_INIT_CDROM) == 0)
@ -351,7 +352,7 @@ CDAudio_Init ()
if (SDL_InitSubSystem(SDL_INIT_CDROM) < 0)
{
Com_Printf("Couldn't init SDL cdrom: %s\n", SDL_GetError());
return ( -1 );
return -1;
}
}
@ -361,7 +362,7 @@ CDAudio_Init ()
{
Com_Printf("CDAudio_Init: Unable to open default CD-ROM drive: %s\n",
SDL_GetError());
return ( -1 );
return -1;
}
initialized = true;
@ -382,7 +383,7 @@ CDAudio_Init ()
Cmd_AddCommand("cd", CD_f);
Com_Printf("CD Audio Initialized.\n");
return ( 0 );
return 0;
}
void

View file

@ -86,96 +86,221 @@ IN_TranslateSDLtoQ2Key(unsigned int keysym)
{
int key = 0;
if( keysym >= SDLK_SPACE && keysym < SDLK_DELETE )
if ((keysym >= SDLK_SPACE) && (keysym < SDLK_DELETE))
{
/* These happen to match the ASCII chars */
/* These happen to match
the ASCII chars */
key = (int)keysym;
}
else
{
switch (keysym)
{
case SDLK_PAGEUP: key = K_PGUP; break;
case SDLK_KP9: key = K_KP_PGUP; break;
case SDLK_PAGEDOWN: key = K_PGDN; break;
case SDLK_KP3: key = K_KP_PGDN; break;
case SDLK_KP7: key = K_KP_HOME; break;
case SDLK_HOME: key = K_HOME; break;
case SDLK_KP1: key = K_KP_END; break;
case SDLK_END: key = K_END; break;
case SDLK_KP4: key = K_KP_LEFTARROW; break;
case SDLK_LEFT: key = K_LEFTARROW; break;
case SDLK_KP6: key = K_KP_RIGHTARROW; break;
case SDLK_RIGHT: key = K_RIGHTARROW; break;
case SDLK_KP2: key = K_KP_DOWNARROW; break;
case SDLK_DOWN: key = K_DOWNARROW; break;
case SDLK_KP8: key = K_KP_UPARROW; break;
case SDLK_UP: key = K_UPARROW; break;
case SDLK_ESCAPE: key = K_ESCAPE; break;
case SDLK_KP_ENTER: key = K_KP_ENTER; break;
case SDLK_RETURN: key = K_ENTER; break;
case SDLK_TAB: key = K_TAB; break;
case SDLK_F1: key = K_F1; break;
case SDLK_F2: key = K_F2; break;
case SDLK_F3: key = K_F3; break;
case SDLK_F4: key = K_F4; break;
case SDLK_F5: key = K_F5; break;
case SDLK_F6: key = K_F6; break;
case SDLK_F7: key = K_F7; break;
case SDLK_F8: key = K_F8; break;
case SDLK_F9: key = K_F9; break;
case SDLK_F10: key = K_F10; break;
case SDLK_F11: key = K_F11; break;
case SDLK_F12: key = K_F12; break;
case SDLK_F13: key = K_F13; break;
case SDLK_F14: key = K_F14; break;
case SDLK_F15: key = K_F15; break;
case SDLK_BACKSPACE: key = K_BACKSPACE; break;
case SDLK_KP_PERIOD: key = K_KP_DEL; break;
case SDLK_DELETE: key = K_DEL; break;
case SDLK_PAUSE: key = K_PAUSE; break;
case SDLK_PAGEUP:
key = K_PGUP;
break;
case SDLK_KP9:
key = K_KP_PGUP;
break;
case SDLK_PAGEDOWN:
key = K_PGDN;
break;
case SDLK_KP3:
key = K_KP_PGDN;
break;
case SDLK_KP7:
key = K_KP_HOME;
break;
case SDLK_HOME:
key = K_HOME;
break;
case SDLK_KP1:
key = K_KP_END;
break;
case SDLK_END:
key = K_END;
break;
case SDLK_KP4:
key = K_KP_LEFTARROW;
break;
case SDLK_LEFT:
key = K_LEFTARROW;
break;
case SDLK_KP6:
key = K_KP_RIGHTARROW;
break;
case SDLK_RIGHT:
key = K_RIGHTARROW;
break;
case SDLK_KP2:
key = K_KP_DOWNARROW;
break;
case SDLK_DOWN:
key = K_DOWNARROW;
break;
case SDLK_KP8:
key = K_KP_UPARROW;
break;
case SDLK_UP:
key = K_UPARROW;
break;
case SDLK_ESCAPE:
key = K_ESCAPE;
break;
case SDLK_KP_ENTER:
key = K_KP_ENTER;
break;
case SDLK_RETURN:
key = K_ENTER;
break;
case SDLK_TAB:
key = K_TAB;
break;
case SDLK_F1:
key = K_F1;
break;
case SDLK_F2:
key = K_F2;
break;
case SDLK_F3:
key = K_F3;
break;
case SDLK_F4:
key = K_F4;
break;
case SDLK_F5:
key = K_F5;
break;
case SDLK_F6:
key = K_F6;
break;
case SDLK_F7:
key = K_F7;
break;
case SDLK_F8:
key = K_F8;
break;
case SDLK_F9:
key = K_F9;
break;
case SDLK_F10:
key = K_F10;
break;
case SDLK_F11:
key = K_F11;
break;
case SDLK_F12:
key = K_F12;
break;
case SDLK_F13:
key = K_F13;
break;
case SDLK_F14:
key = K_F14;
break;
case SDLK_F15:
key = K_F15;
break;
case SDLK_BACKSPACE:
key = K_BACKSPACE;
break;
case SDLK_KP_PERIOD:
key = K_KP_DEL;
break;
case SDLK_DELETE:
key = K_DEL;
break;
case SDLK_PAUSE:
key = K_PAUSE;
break;
case SDLK_LSHIFT:
case SDLK_RSHIFT: key = K_SHIFT; break;
case SDLK_RSHIFT:
key = K_SHIFT;
break;
case SDLK_LCTRL:
case SDLK_RCTRL: key = K_CTRL; break;
case SDLK_RCTRL:
key = K_CTRL;
break;
case SDLK_RMETA:
case SDLK_LMETA: key = K_COMMAND; break;
case SDLK_LMETA:
key = K_COMMAND;
break;
case SDLK_RALT:
case SDLK_LALT: key = K_ALT; break;
case SDLK_LALT:
key = K_ALT;
break;
case SDLK_LSUPER:
case SDLK_RSUPER: key = K_SUPER; break;
case SDLK_KP5: key = K_KP_5; break;
case SDLK_INSERT: key = K_INS; break;
case SDLK_KP0: key = K_KP_INS; break;
case SDLK_KP_MULTIPLY: key = K_KP_STAR; break;
case SDLK_KP_PLUS: key = K_KP_PLUS; break;
case SDLK_KP_MINUS: key = K_KP_MINUS; break;
case SDLK_KP_DIVIDE: key = K_KP_SLASH; break;
case SDLK_MODE: key = K_MODE; break;
case SDLK_COMPOSE: key = K_COMPOSE; break;
case SDLK_HELP: key = K_HELP; break;
case SDLK_PRINT: key = K_PRINT; break;
case SDLK_SYSREQ: key = K_SYSREQ; break;
case SDLK_BREAK: key = K_BREAK; break;
case SDLK_MENU: key = K_MENU; break;
case SDLK_POWER: key = K_POWER; break;
case SDLK_EURO: key = K_EURO; break;
case SDLK_UNDO: key = K_UNDO; break;
case SDLK_SCROLLOCK: key = K_SCROLLOCK; break;
case SDLK_NUMLOCK: key = K_KP_NUMLOCK; break;
case SDLK_CAPSLOCK: key = K_CAPSLOCK; break;
case SDLK_RSUPER:
key = K_SUPER;
break;
case SDLK_KP5:
key = K_KP_5;
break;
case SDLK_INSERT:
key = K_INS;
break;
case SDLK_KP0:
key = K_KP_INS;
break;
case SDLK_KP_MULTIPLY:
key = K_KP_STAR;
break;
case SDLK_KP_PLUS:
key = K_KP_PLUS;
break;
case SDLK_KP_MINUS:
key = K_KP_MINUS;
break;
case SDLK_KP_DIVIDE:
key = K_KP_SLASH;
break;
case SDLK_MODE:
key = K_MODE;
break;
case SDLK_COMPOSE:
key = K_COMPOSE;
break;
case SDLK_HELP:
key = K_HELP;
break;
case SDLK_PRINT:
key = K_PRINT;
break;
case SDLK_SYSREQ:
key = K_SYSREQ;
break;
case SDLK_BREAK:
key = K_BREAK;
break;
case SDLK_MENU:
key = K_MENU;
break;
case SDLK_POWER:
key = K_POWER;
break;
case SDLK_EURO:
key = K_EURO;
break;
case SDLK_UNDO:
key = K_UNDO;
break;
case SDLK_SCROLLOCK:
key = K_SCROLLOCK;
break;
case SDLK_NUMLOCK:
key = K_KP_NUMLOCK;
break;
case SDLK_CAPSLOCK:
key = K_CAPSLOCK;
break;
default:
if( keysym >= SDLK_WORLD_0 && keysym <= SDLK_WORLD_95 )
if ((keysym >= SDLK_WORLD_0) && (keysym <= SDLK_WORLD_95))
{
key = (keysym - SDLK_WORLD_0) + K_WORLD_0;
}
break;
}
}
@ -195,6 +320,7 @@ IN_GetEvent(SDL_Event *event)
{
/* The mouse wheel */
case SDL_MOUSEBUTTONDOWN:
if (event->button.button == 4)
{
keyq[keyq_head].key = K_MWHEELUP;
@ -213,6 +339,7 @@ IN_GetEvent(SDL_Event *event)
keyq[keyq_head].down = false;
keyq_head = (keyq_head + 1) & 127;
}
break;
case SDL_MOUSEBUTTONUP:
@ -220,8 +347,11 @@ IN_GetEvent(SDL_Event *event)
/* The user pressed a button */
case SDL_KEYDOWN:
/* Fullscreen switch via Alt-Return */
if ( (KeyStates[SDLK_LALT] || KeyStates[SDLK_RALT]) && (event->key.keysym.sym == SDLK_RETURN) )
if ((KeyStates[SDLK_LALT] ||
KeyStates[SDLK_RALT]) &&
(event->key.keysym.sym == SDLK_RETURN))
{
cvar_t *fullscreen;
@ -246,22 +376,26 @@ IN_GetEvent(SDL_Event *event)
/* Get the pressed key and add it to the key list */
key = IN_TranslateSDLtoQ2Key(event->key.keysym.sym);
if (key)
{
keyq[keyq_head].key = key;
keyq[keyq_head].down = true;
keyq_head = (keyq_head + 1) & 127;
}
break;
/* The user released a key */
case SDL_KEYUP:
if (KeyStates[event->key.keysym.sym])
{
KeyStates[event->key.keysym.sym] = 0;
/* Get the pressed key and remove it from the key list */
key = IN_TranslateSDLtoQ2Key(event->key.keysym.sym);
if (key)
{
keyq[keyq_head].key = key;
@ -269,6 +403,7 @@ IN_GetEvent(SDL_Event *event)
keyq_head = (keyq_head + 1) & 127;
}
}
break;
}
}
@ -276,7 +411,8 @@ IN_GetEvent(SDL_Event *event)
/*
* Updates the state of the input queue
*/
void IN_Update(void)
void
IN_Update(void)
{
SDL_Event event;
static int IN_Update_Flag;
@ -298,7 +434,6 @@ void IN_Update(void)
/* Mouse button processing. Button 4
and 5 are the mousewheel and thus
not processed here. */
if (!mx && !my)
{
SDL_GetRelativeMouseState(&mx, &my);
@ -333,7 +468,7 @@ void IN_Update(void)
}
/* Grab and ungrab the mouse if the
console is opened */
* console is opened */
if (in_grab->value == 2)
{
if (old_windowed_mouse != windowed_mouse->value)
@ -373,7 +508,8 @@ void IN_Update(void)
* Closes all inputs and clears
* the input queue.
*/
void IN_Close(void)
void
IN_Close(void)
{
keyq_head = 0;
keyq_tail = 0;
@ -384,7 +520,9 @@ void IN_Close(void)
/*
* Gets the mouse state
*/
void IN_GetMouseState(int *x, int *y, int *state) {
void
IN_GetMouseState(int *x, int *y, int *state)
{
*x = mx;
*y = my;
*state = mouse_buttonstate;
@ -393,7 +531,8 @@ void IN_GetMouseState(int *x, int *y, int *state) {
/*
* Cleares the mouse state
*/
void IN_ClearMouseState()
void
IN_ClearMouseState()
{
mx = my = 0;
}
@ -466,7 +605,8 @@ IN_BackendInit ( in_state_t *in_state_p )
SDL_EnableUNICODE(0);
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
windowed_mouse = ri.Cvar_Get ("windowed_mouse", "1", CVAR_USERINFO | CVAR_ARCHIVE);
windowed_mouse = ri.Cvar_Get("windowed_mouse", "1",
CVAR_USERINFO | CVAR_ARCHIVE);
in_grab = ri.Cvar_Get("in_grab", "2", CVAR_ARCHIVE);
Com_Printf("Input initialized.\n");
@ -544,6 +684,7 @@ IN_BackendMove ( usercmd_t *cmd )
{
mouse_x = (mouse_x + old_mouse_x) * 0.5;
}
if ((mouse_y > 1) || (mouse_y < -1))
{
mouse_y = (mouse_y + old_mouse_y) * 0.5;
@ -612,3 +753,4 @@ IN_BackendMove ( usercmd_t *cmd )
IN_ClearMouseState();
}
}

View file

@ -62,7 +62,8 @@ XF86VidModeGamma x11_oldgamma;
/*
* Initialzes the SDL OpenGL context
*/
int GLimp_Init(void)
int
GLimp_Init(void)
{
if (!SDL_WasInit(SDL_INIT_VIDEO))
{
@ -70,9 +71,11 @@ int GLimp_Init(void)
if (SDL_Init(SDL_INIT_VIDEO) == -1)
{
ri.Con_Printf( PRINT_ALL, "Couldn't init SDL video: %s.\n", SDL_GetError());
ri.Con_Printf(PRINT_ALL, "Couldn't init SDL video: %s.\n",
SDL_GetError());
return false;
}
SDL_VideoDriverName(driverName, sizeof(driverName) - 1);
ri.Con_Printf(PRINT_ALL, "SDL video driver is \"%s\".\n", driverName);
}
@ -83,7 +86,8 @@ int GLimp_Init(void)
/*
* Sets the window icon
*/
static void SetSDLIcon()
static void
SetSDLIcon()
{
SDL_Surface *icon;
SDL_Color color;
@ -91,7 +95,9 @@ static void SetSDLIcon()
int i;
int mask;
icon = SDL_CreateRGBSurface(SDL_SWSURFACE, q2icon_width, q2icon_height, 8, 0, 0, 0, 0);
icon = SDL_CreateRGBSurface(SDL_SWSURFACE,
q2icon_width, q2icon_height, 8,
0, 0, 0, 0);
if (icon == NULL)
{
@ -116,7 +122,8 @@ static void SetSDLIcon()
for (i = 0; i < sizeof(q2icon_bits); i++)
{
for (mask = 1; mask != 0x100; mask <<= 1) {
for (mask = 1; mask != 0x100; mask <<= 1)
{
*ptr = (q2icon_bits[i] & mask) ? 1 : 0;
ptr++;
}
@ -147,6 +154,7 @@ UpdateHardwareGamma(void)
/* This forces X11 to update the gamma tables */
XF86VidModeGetGamma(dpy, screen, &x11_gamma);
}
#else
void
UpdateHardwareGamma(void)
@ -161,7 +169,8 @@ UpdateHardwareGamma(void)
/*
* Initializes the OpenGL window
*/
static qboolean GLimp_InitGraphics( qboolean fullscreen )
static qboolean
GLimp_InitGraphics(qboolean fullscreen)
{
int counter = 0;
int flags;
@ -217,7 +226,8 @@ static qboolean GLimp_InitGraphics( qboolean fullscreen )
while (1)
{
if ((surface = SDL_SetVideoMode(vid.width, vid.height, 0, flags)) == NULL)
if ((surface =
SDL_SetVideoMode(vid.width, vid.height, 0, flags)) == NULL)
{
if (counter == 1)
{
@ -225,7 +235,8 @@ static qboolean GLimp_InitGraphics( qboolean fullscreen )
return false;
}
ri.Con_Printf(PRINT_ALL, "SDL SetVideoMode failed: %s\n", SDL_GetError());
ri.Con_Printf(PRINT_ALL, "SDL SetVideoMode failed: %s\n",
SDL_GetError());
ri.Con_Printf(PRINT_ALL, "Reverting to gl_mode 4 (640x480) and windowed mode.\n");
/* Try to recover */
@ -293,7 +304,8 @@ static qboolean GLimp_InitGraphics( qboolean fullscreen )
/*
* Swaps the buffers to show the new frame
*/
void GLimp_EndFrame (void)
void
GLimp_EndFrame(void)
{
SDL_GL_SwapBuffers();
}
@ -301,13 +313,14 @@ void GLimp_EndFrame (void)
/*
* Changes the video mode
*/
int GLimp_SetMode( int *pwidth, int *pheight, int mode, qboolean fullscreen )
int
GLimp_SetMode(int *pwidth, int *pheight, int mode, qboolean fullscreen)
{
ri.Con_Printf(PRINT_ALL, "setting mode %d:", mode);
/* mode -1 is not in the vid mode table - so we keep the values in pwidth
and pheight and don't even try to look up the mode info */
if ( mode != -1 && !ri.Vid_GetModeInfo( pwidth, pheight, mode ) )
if ((mode != -1) && !ri.Vid_GetModeInfo(pwidth, pheight, mode))
{
ri.Con_Printf(PRINT_ALL, " invalid mode\n");
return rserr_invalid_mode;
@ -326,7 +339,8 @@ int GLimp_SetMode( int *pwidth, int *pheight, int mode, qboolean fullscreen )
/*
* Shuts the SDL render backend down
*/
void GLimp_Shutdown( void )
void
GLimp_Shutdown(void)
{
if (surface)
{
@ -356,3 +370,4 @@ void GLimp_Shutdown( void )
gl_state.hwgamma = false;
}

View file

@ -272,3 +272,4 @@ SNDDMA_BeginPainting(void)
{
SDL_LockAudio();
}

View file

@ -35,7 +35,7 @@
#include <AL/efx.h>
/* Function pointers used to tie
the qal API to the OpenAL API */
* the qal API to the OpenAL API */
extern LPALENABLE qalEnable;
extern LPALDISABLE qalDisable;
extern LPALISENABLED qalIsEnabled;

View file

@ -24,7 +24,6 @@
* =======================================================================
*/
/* For mremap() - must be before sys/mman.h include! */
#if defined(__linux__) && !defined(_GNU_SOURCE)
#define _GNU_SOURCE
@ -41,7 +40,6 @@
#define MAP_ANONYMOUS MAP_ANON
#endif
byte *membase;
int maxhunksize;
int curhunksize;
@ -63,7 +61,7 @@ Hunk_Begin ( int maxsize )
*((int *)membase) = curhunksize;
return ( membase + sizeof ( int ) );
return membase + sizeof(int);
}
void *
@ -81,7 +79,7 @@ Hunk_Alloc ( int size )
buf = membase + sizeof(int) + curhunksize;
curhunksize += size;
return ( buf );
return buf;
}
int
@ -108,7 +106,6 @@ Hunk_End ( void )
unmap_len = old_size - new_size;
n = munmap(unmap_base, unmap_len) + membase;
}
#endif
#if defined(__linux__)
@ -122,7 +119,7 @@ Hunk_End ( void )
*((int *)membase) = curhunksize + sizeof(int);
return ( curhunksize );
return curhunksize;
}
void
@ -140,3 +137,4 @@ Hunk_Free ( void *base )
}
}
}

View file

@ -126,3 +126,4 @@ main ( int argc, char **argv )
return 0;
}

View file

@ -91,7 +91,8 @@ NetadrToSockadr ( netadr_t *a, struct sockaddr_storage *s )
if (inet_pton(AF_INET6, QUAKE2MCAST, &s6->sin6_addr.s6_addr) != 1)
{
Com_Printf("NET_NetadrToSockadr: inet_pton: %s\n", strerror(errno));
Com_Printf("NET_NetadrToSockadr: inet_pton: %s\n",
strerror(errno));
return;
}
@ -102,12 +103,13 @@ NetadrToSockadr ( netadr_t *a, struct sockaddr_storage *s )
#endif
/* scope_id is important for
link-local destination.*/
* link-local destination.*/
s6->sin6_scope_id = a->scope_id;
break;
case NA_IP6:
if (IN6_IS_ADDR_V4MAPPED((struct in6_addr *)a->ip))
{
#ifdef __FreeBSD__
@ -131,7 +133,7 @@ NetadrToSockadr ( netadr_t *a, struct sockaddr_storage *s )
#endif
/* scope_id is important for
link-local destination. */
* link-local destination. */
s6->sin6_scope_id = a->scope_id;
}
@ -317,7 +319,9 @@ NET_BaseAdrToString(netadr_t a)
#else
socklen_t const salen = sizeof(ss);
#endif
if (getnameinfo((struct sockaddr*)&ss, salen, s, sizeof(s), NULL, 0, NI_NUMERICHOST))
if (getnameinfo((struct sockaddr *)&ss, salen, s, sizeof(s), NULL,
0, NI_NUMERICHOST))
{
Com_sprintf(s, sizeof(s), "<invalid>");
}
@ -325,7 +329,8 @@ NET_BaseAdrToString(netadr_t a)
else
{
if ((a.type == NA_MULTICAST6) ||
IN6_IS_ADDR_LINKLOCAL(&((struct sockaddr_in6 *)&ss)-> sin6_addr))
IN6_IS_ADDR_LINKLOCAL(&((struct sockaddr_in6 *)&ss)->
sin6_addr))
{
/* If the address is multicast (link) or a
link-local, need to carry the scope. The string
@ -406,7 +411,8 @@ NET_StringToSockaddr ( char *s, struct sockaddr_storage *sadr )
if ((err = getaddrinfo(addrs, ports, &hints, &resultp)))
{
/* Error */
Com_Printf("NET_StringToSockaddr: string %s:\n%s\n", s, gai_strerror(err));
Com_Printf("NET_StringToSockaddr: string %s:\n%s\n", s,
gai_strerror(err));
return 0;
}
@ -459,7 +465,7 @@ NET_StringToAdr ( char *s, netadr_t *a )
qboolean
NET_IsLocalAddress(netadr_t adr)
{
return ( NET_CompareAdr( adr, net_local_adr ) );
return NET_CompareAdr(adr, net_local_adr);
}
qboolean
@ -477,7 +483,7 @@ NET_GetLoopPacket ( netsrc_t sock, netadr_t *net_from, sizebuf_t *net_message )
if (loop->get >= loop->send)
{
return ( false );
return false;
}
i = loop->get & (MAX_LOOPBACK - 1);
@ -486,7 +492,7 @@ NET_GetLoopPacket ( netsrc_t sock, netadr_t *net_from, sizebuf_t *net_message )
memcpy(net_message->data, loop->msgs[i].data, loop->msgs[i].datalen);
net_message->cursize = loop->msgs[i].datalen;
*net_from = net_local_adr;
return ( true );
return true;
}
void
@ -668,13 +674,15 @@ NET_SendPacket ( netsrc_t sock, int length, void *data, netadr_t to )
error = getnameinfo((struct sockaddr *)s6, s6->sin6_len, tmp,
sizeof(tmp), NULL, 0, NI_NUMERICHOST);
#else
error = getnameinfo((struct sockaddr *)s6, sizeof(struct sockaddr_in6),
error = getnameinfo((struct sockaddr *)s6,
sizeof(struct sockaddr_in6),
tmp, sizeof(tmp), NULL, 0, NI_NUMERICHOST);
#endif
if (error)
{
Com_Printf("NET_SendPacket: getnameinfo: %s\n", gai_strerror(error));
Com_Printf("NET_SendPacket: getnameinfo: %s\n",
gai_strerror(error));
return;
}
@ -691,7 +699,8 @@ NET_SendPacket ( netsrc_t sock, int length, void *data, netadr_t to )
if (error)
{
Com_Printf("NET_SendPacket: getaddrinfo: %s\n", gai_strerror(error));
Com_Printf("NET_SendPacket: getaddrinfo: %s\n",
gai_strerror(error));
return;
}
@ -707,7 +716,12 @@ NET_SendPacket ( netsrc_t sock, int length, void *data, netadr_t to )
}
}
ret = sendto(net_socket, data, length, 0, (struct sockaddr *)&addr, addr_size);
ret = sendto(net_socket,
data,
length,
0,
(struct sockaddr *)&addr,
addr_size);
if (ret == -1)
{
@ -836,7 +850,8 @@ NET_Socket ( char *net_interface, int port, netsrc_t type, int family )
for (ai = res; ai != NULL; ai = ai->ai_next)
{
if ((newsocket = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol)) == -1)
if ((newsocket =
socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol)) == -1)
{
Com_Printf("NET_Socket: socket: %s\n", strerror(errno));
continue;
@ -852,7 +867,8 @@ NET_Socket ( char *net_interface, int port, netsrc_t type, int family )
if (family == AF_INET)
{
/* make it broadcast capable */
if (setsockopt(newsocket, SOL_SOCKET, SO_BROADCAST, (char *)&i, sizeof(i)) == -1)
if (setsockopt(newsocket, SOL_SOCKET, SO_BROADCAST, (char *)&i,
sizeof(i)) == -1)
{
Com_Printf("ERROR: NET_Socket: setsockopt SO_BROADCAST:%s\n",
NET_ErrorString());
@ -861,7 +877,8 @@ NET_Socket ( char *net_interface, int port, netsrc_t type, int family )
}
/* make it reusable */
if (setsockopt(newsocket, SOL_SOCKET, SO_REUSEADDR, (char *)&i, sizeof(i)) == -1)
if (setsockopt(newsocket, SOL_SOCKET, SO_REUSEADDR, (char *)&i,
sizeof(i)) == -1)
{
Com_Printf("ERROR: NET_Socket: setsockopt SO_REUSEADDR:%s\n",
NET_ErrorString());
@ -895,37 +912,47 @@ NET_Socket ( char *net_interface, int port, netsrc_t type, int family )
break;
case AF_INET6:
/* Multicast outgoing interface is specified for
client and server (+set multicast <ifname>) */
mcast = Cvar_Get("multicast", "NULL", CVAR_NOSET);
multicast_interface = (strcmp(mcast->string, "NULL") ? mcast->string : NULL);
multicast_interface =
(strcmp(mcast->string, "NULL") ? mcast->string : NULL);
if (multicast_interface != NULL)
{
/* multicast_interface is a global variable.
Also used in NET_SendPacket() */
if ((mreq.ipv6mr_interface = if_nametoindex(multicast_interface)) == 0)
if ((mreq.ipv6mr_interface =
if_nametoindex(multicast_interface)) == 0)
{
Com_Printf("NET_Socket: invalid interface: %s\n", multicast_interface);
Com_Printf("NET_Socket: invalid interface: %s\n",
multicast_interface);
}
if (setsockopt(newsocket, IPPROTO_IPV6, IPV6_MULTICAST_IF,
&mreq.ipv6mr_interface, sizeof(mreq.ipv6mr_interface)) < 0)
&mreq.ipv6mr_interface,
sizeof(mreq.ipv6mr_interface)) < 0)
{
Com_Printf("NET_Socket: IPV6_MULTICAST_IF: %s\n", strerror(errno));
Com_Printf("NET_Socket: IPV6_MULTICAST_IF: %s\n",
strerror(errno));
}
/* Join multicast group ONLY if server */
if (type == NS_SERVER)
{
if (inet_pton(AF_INET6, QUAKE2MCAST, &mreq.ipv6mr_multiaddr.s6_addr) != 1)
if (inet_pton(AF_INET6, QUAKE2MCAST,
&mreq.ipv6mr_multiaddr.s6_addr) != 1)
{
Com_Printf("NET_Socket: inet_pton: %s\n", strerror(errno));
Com_Printf("NET_Socket: inet_pton: %s\n",
strerror(errno));
}
if (setsockopt(newsocket, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq, sizeof(mreq)) < 0)
if (setsockopt(newsocket, IPPROTO_IPV6, IPV6_JOIN_GROUP,
&mreq, sizeof(mreq)) < 0)
{
Com_Printf("NET_Socket: IPV6_JOIN_GROUP: %s\n", strerror(errno));
Com_Printf("NET_Socket: IPV6_JOIN_GROUP: %s\n",
strerror(errno));
}
}
}
@ -948,7 +975,7 @@ NET_ErrorString ( void )
int code;
code = errno;
return ( strerror( code ) );
return strerror(code);
}
/*
@ -962,7 +989,8 @@ NET_Sleep ( int msec )
extern cvar_t *dedicated;
extern qboolean stdin_active;
if ((!ip_sockets[NS_SERVER] && !ip6_sockets[NS_SERVER]) || (dedicated && !dedicated->value))
if ((!ip_sockets[NS_SERVER] &&
!ip6_sockets[NS_SERVER]) || (dedicated && !dedicated->value))
{
return; /* we're not a server, just run full speed */
}
@ -978,5 +1006,7 @@ NET_Sleep ( int msec )
FD_SET(ip6_sockets[NS_SERVER], &fdset); /* IPv6 network socket */
timeout.tv_sec = msec / 1000;
timeout.tv_usec = (msec % 1000) * 1000;
select(MAX(ip_sockets[NS_SERVER], ip6_sockets[NS_SERVER]) + 1, &fdset, NULL, NULL, &timeout);
select(MAX(ip_sockets[NS_SERVER],
ip6_sockets[NS_SERVER]) + 1, &fdset, NULL, NULL, &timeout);
}

File diff suppressed because it is too large Load diff

View file

@ -70,27 +70,27 @@ CompareAttributes ( char *path, char *name, unsigned musthave, unsigned canthave
/* . and .. never match */
if ((strcmp(name, ".") == 0) || (strcmp(name, "..") == 0))
{
return ( false );
return false;
}
return ( true );
return true;
if (stat(fn, &st) == -1)
{
return ( false ); /* shouldn't happen */
return false; /* shouldn't happen */
}
if ((st.st_mode & S_IFDIR) && (canthave & SFF_SUBDIR))
{
return ( false );
return false;
}
if ((musthave & SFF_SUBDIR) && !(st.st_mode & S_IFDIR))
{
return ( false );
return false;
}
return ( true );
return true;
}
void
@ -110,12 +110,12 @@ Sys_Milliseconds ( void )
if (!secbase)
{
secbase = tp.tv_sec;
return ( tp.tv_usec / 1000 );
return tp.tv_usec / 1000;
}
curtime = (tp.tv_sec - secbase) * 1000 + tp.tv_usec / 1000;
return ( curtime );
return curtime;
}
void
@ -134,7 +134,7 @@ Sys_GetCurrentDirectory ( void )
Sys_Error("Couldn't get current working directory");
}
return ( dir );
return dir;
}
char *
@ -167,7 +167,7 @@ Sys_FindFirst ( char *path, unsigned musthave, unsigned canhave )
if ((fdir = opendir(findbase)) == NULL)
{
return ( NULL );
return NULL;
}
while ((d = readdir(fdir)) != NULL)
@ -177,12 +177,12 @@ Sys_FindFirst ( char *path, unsigned musthave, unsigned canhave )
if (CompareAttributes(findbase, d->d_name, musthave, canhave))
{
sprintf(findpath, "%s/%s", findbase, d->d_name);
return ( findpath );
return findpath;
}
}
}
return ( NULL );
return NULL;
}
char *
@ -192,7 +192,7 @@ Sys_FindNext ( unsigned musthave, unsigned canhave )
if (fdir == NULL)
{
return ( NULL );
return NULL;
}
while ((d = readdir(fdir)) != NULL)
@ -202,12 +202,12 @@ Sys_FindNext ( unsigned musthave, unsigned canhave )
if (CompareAttributes(findbase, d->d_name, musthave, canhave))
{
sprintf(findpath, "%s/%s", findbase, d->d_name);
return ( findpath );
return findpath;
}
}
}
return ( NULL );
return NULL;
}
void
@ -227,6 +227,32 @@ Sys_ConsoleOutput ( char *string )
fputs(string, stdout);
}
void
Sys_Printf(char *fmt, ...)
{
va_list argptr;
char text[1024];
unsigned char *p;
va_start(argptr, fmt);
vsnprintf(text, 1024, fmt, argptr);
va_end(argptr);
for (p = (unsigned char *)text; *p; p++)
{
*p &= 0x7f;
if (((*p > 128) || (*p < 32)) && (*p != 10) && (*p != 13) && (*p != 9))
{
printf("[%02x]", *p);
}
else
{
putc(*p, stdout);
}
}
}
void
Sys_Quit(void)
{
@ -280,10 +306,10 @@ Sys_FileTime ( char *path )
if (stat(path, &buf) == -1)
{
return ( -1 );
return -1;
}
return ( buf.st_mtime );
return buf.st_mtime;
}
void
@ -302,12 +328,12 @@ Sys_ConsoleInput ( void )
if (!dedicated || !dedicated->value)
{
return ( NULL );
return NULL;
}
if (!stdin_active)
{
return ( NULL );
return NULL;
}
FD_ZERO(&fdset);
@ -317,7 +343,7 @@ Sys_ConsoleInput ( void )
if ((select(1, &fdset, NULL, NULL, &timeout) == -1) || !FD_ISSET(0, &fdset))
{
return ( NULL );
return NULL;
}
len = read(0, text, sizeof(text));
@ -325,17 +351,17 @@ Sys_ConsoleInput ( void )
if (len == 0) /* eof! */
{
stdin_active = false;
return ( NULL );
return NULL;
}
if (len < 1)
{
return ( NULL );
return NULL;
}
text[len - 1] = 0; /* rip off the /n and terminate */
return ( text );
return text;
}
void
@ -382,7 +408,7 @@ Sys_GetGameAPI ( void *parms )
if (!path)
{
return ( NULL ); /* couldn't find one anywhere */
return NULL; /* couldn't find one anywhere */
}
snprintf(name, MAX_OSPATH, "%s/%s", path, gamename);
@ -422,7 +448,7 @@ Sys_GetGameAPI ( void *parms )
Com_Printf("%s\n", str_p);
return ( NULL );
return NULL;
}
}
@ -431,22 +457,20 @@ Sys_GetGameAPI ( void *parms )
if (!GetGameAPI)
{
Sys_UnloadGame();
return ( NULL );
return NULL;
}
return ( GetGameAPI( parms ) );
return GetGameAPI(parms);
}
void
Sys_SendKeyEvents(void)
{
#ifndef DEDICATED_ONLY
if (IN_Update_fp)
{
IN_Update_fp();
}
#endif
/* grab frame time */

View file

@ -60,6 +60,7 @@ qboolean reflib_active = 0;
/* INPUT */
void Do_Key_Event(int key, qboolean down);
void (*IN_Update_fp)(void);
void (*IN_KeyboardInit_fp)(Key_Event_fp_t fp);
void (*IN_Close_fp)(void);
@ -160,13 +161,13 @@ VID_GetModeInfo ( int *width, int *height, int mode )
{
if ((mode < 0) || (mode >= VID_NUM_MODES))
{
return ( false );
return false;
}
*width = vid_modes[mode].width;
*height = vid_modes[mode].height;
return ( true );
return true;
}
void
@ -242,13 +243,13 @@ VID_LoadRefresh ( char *name )
if (stat(fn, &st) == -1)
{
Com_Printf("LoadLibrary(\"%s\") failed: %s\n", name, strerror(errno));
return ( false );
return false;
}
if ((reflib_library = dlopen(fn, RTLD_LAZY)) == 0)
{
Com_Printf("LoadLibrary(\"%s\") failed: %s\n", name, dlerror());
return ( false );
return false;
}
Com_Printf("LoadLibrary(\"%s\")\n", fn);
@ -308,7 +309,7 @@ VID_LoadRefresh ( char *name )
{
re.Shutdown();
VID_FreeReflib();
return ( false );
return false;
}
/* Init IN */
@ -324,7 +325,7 @@ VID_LoadRefresh ( char *name )
Com_Printf("------------------------------------\n\n");
reflib_active = true;
return ( true );
return true;
}
/*
@ -362,7 +363,6 @@ VID_CheckChanges ( void )
}
}
void
VID_Init(void)
{
@ -422,11 +422,11 @@ VID_CheckRefExists ( const char *ref )
if (stat(fn, &st) == 0)
{
return ( true );
return true;
}
else
{
return ( false );
return false;
}
}
@ -463,3 +463,4 @@ Do_Key_Event ( int key, qboolean down )
{
Key_Event(key, down, Sys_Milliseconds());
}