mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-22 12:41:21 +00:00
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:
commit
7ac71db523
44 changed files with 10379 additions and 9120 deletions
34
Makefile
34
Makefile
|
@ -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 \
|
||||
|
|
|
@ -24,134 +24,167 @@
|
|||
* =======================================================================
|
||||
*/
|
||||
|
||||
#include "../header/common.h"
|
||||
#include "header/common.h"
|
||||
|
||||
#define MAX_NUM_ARGVS 50
|
||||
#define MAX_NUM_ARGVS 50
|
||||
|
||||
int com_argc;
|
||||
char *com_argv[MAX_NUM_ARGVS+1];
|
||||
int com_argc;
|
||||
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;
|
||||
int i;
|
||||
|
||||
for (i=1 ; i<com_argc ; i++)
|
||||
for (i = 1; i < com_argc; i++)
|
||||
{
|
||||
if (!strcmp (parm,com_argv[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;
|
||||
int i;
|
||||
|
||||
if (argc > MAX_NUM_ARGVS)
|
||||
Com_Error (ERR_FATAL, "argc > MAX_NUM_ARGVS");
|
||||
{
|
||||
Com_Error(ERR_FATAL, "argc > MAX_NUM_ARGVS");
|
||||
}
|
||||
|
||||
com_argc = argc;
|
||||
|
||||
for (i=0 ; i<argc ; i++)
|
||||
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_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;
|
||||
int i;
|
||||
|
||||
for (i=0 ; i<count ; 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;
|
||||
char *out;
|
||||
|
||||
out = Z_Malloc ((int)strlen(in)+1);
|
||||
strcpy (out, in);
|
||||
out = Z_Malloc((int)strlen(in) + 1);
|
||||
strcpy(out, in);
|
||||
return out;
|
||||
}
|
||||
|
||||
void Info_Print (char *s)
|
||||
void
|
||||
Info_Print(char *s)
|
||||
{
|
||||
char key[512];
|
||||
char value[512];
|
||||
char *o;
|
||||
int l;
|
||||
char key[512];
|
||||
char value[512];
|
||||
char *o;
|
||||
int l;
|
||||
|
||||
if (*s == '\\')
|
||||
{
|
||||
s++;
|
||||
}
|
||||
|
||||
while (*s)
|
||||
{
|
||||
o = key;
|
||||
|
||||
while (*s && *s != '\\')
|
||||
{
|
||||
*o++ = *s++;
|
||||
}
|
||||
|
||||
l = o - key;
|
||||
|
||||
if (l < 20)
|
||||
{
|
||||
memset (o, ' ', 20-l);
|
||||
memset(o, ' ', 20 - l);
|
||||
key[20] = 0;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
*o = 0;
|
||||
}
|
||||
|
||||
Com_Printf ("%s", key);
|
||||
Com_Printf("%s", key);
|
||||
|
||||
if (!*s)
|
||||
{
|
||||
Com_Printf ("MISSING VALUE\n");
|
||||
Com_Printf("MISSING VALUE\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
Com_Printf("%s\n", value);
|
||||
}
|
||||
}
|
||||
|
|
@ -24,26 +24,29 @@
|
|||
* =======================================================================
|
||||
*/
|
||||
|
||||
#include "../header/common.h"
|
||||
#include "header/common.h"
|
||||
#include <stdlib.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#define MAXPRINTMSG 4096
|
||||
#define MAXPRINTMSG 4096
|
||||
|
||||
FILE *logfile;
|
||||
cvar_t *logfile_active; /* 1 = buffer log, 2 = flush after each print */
|
||||
FILE *logfile;
|
||||
cvar_t *logfile_active; /* 1 = buffer log, 2 = flush after each print */
|
||||
jmp_buf abortframe; /* an ERR_DROP occured, exit the entire frame */
|
||||
int server_state;
|
||||
int server_state;
|
||||
|
||||
static int rd_target;
|
||||
static char *rd_buffer;
|
||||
static int rd_buffersize;
|
||||
static void (*rd_flush)(int target, char *buffer);
|
||||
static int rd_target;
|
||||
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,91 +71,106 @@ 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];
|
||||
va_list argptr;
|
||||
char msg[MAXPRINTMSG];
|
||||
|
||||
va_start (argptr,fmt);
|
||||
vsnprintf (msg,MAXPRINTMSG,fmt,argptr);
|
||||
va_end (argptr);
|
||||
va_start(argptr, fmt);
|
||||
vsnprintf(msg, MAXPRINTMSG, fmt, argptr);
|
||||
va_end(argptr);
|
||||
|
||||
if (rd_target)
|
||||
{
|
||||
if ((strlen (msg) + strlen(rd_buffer)) > (rd_buffersize - 1))
|
||||
if ((strlen(msg) + strlen(rd_buffer)) > (rd_buffersize - 1))
|
||||
{
|
||||
rd_flush(rd_target, rd_buffer);
|
||||
*rd_buffer = 0;
|
||||
}
|
||||
|
||||
strcat (rd_buffer, msg);
|
||||
strcat(rd_buffer, msg);
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef DEDICATED_ONLY
|
||||
Con_Print (msg);
|
||||
Con_Print(msg);
|
||||
#endif
|
||||
|
||||
/* also echo to debugging console */
|
||||
Sys_ConsoleOutput (msg);
|
||||
Sys_ConsoleOutput(msg);
|
||||
|
||||
/* logfile */
|
||||
if (logfile_active && logfile_active->value)
|
||||
{
|
||||
char name[MAX_QPATH];
|
||||
char name[MAX_QPATH];
|
||||
|
||||
if (!logfile)
|
||||
{
|
||||
Com_sprintf (name, sizeof(name), "%s/qconsole.log", FS_Gamedir ());
|
||||
Com_sprintf(name, sizeof(name), "%s/qconsole.log", FS_Gamedir());
|
||||
|
||||
if (logfile_active->value > 2)
|
||||
logfile = fopen (name, "a");
|
||||
{
|
||||
logfile = fopen(name, "a");
|
||||
}
|
||||
|
||||
else
|
||||
logfile = fopen (name, "w");
|
||||
{
|
||||
logfile = fopen(name, "w");
|
||||
}
|
||||
}
|
||||
|
||||
if (logfile)
|
||||
fprintf (logfile, "%s", msg);
|
||||
{
|
||||
fprintf(logfile, "%s", msg);
|
||||
}
|
||||
|
||||
if (logfile_active->value > 1)
|
||||
fflush (logfile); /* force it to save every time */
|
||||
{
|
||||
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];
|
||||
va_list argptr;
|
||||
char msg[MAXPRINTMSG];
|
||||
|
||||
if (!developer || !developer->value)
|
||||
return; /* don't confuse non-developers with techie stuff... */
|
||||
{
|
||||
return; /* don't confuse non-developers with techie stuff... */
|
||||
}
|
||||
|
||||
va_start (argptr,fmt);
|
||||
vsnprintf (msg,MAXPRINTMSG,fmt,argptr);
|
||||
va_end (argptr);
|
||||
va_start(argptr, fmt);
|
||||
vsnprintf(msg, MAXPRINTMSG, fmt, argptr);
|
||||
va_end(argptr);
|
||||
|
||||
Com_Printf ("%s", msg);
|
||||
Com_Printf("%s", msg);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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))
|
||||
if ((!modder || !modder->value) && (!developer || !developer->value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
va_start (argptr,fmt);
|
||||
vsnprintf (msg,MAXPRINTMSG,fmt,argptr);
|
||||
va_end (argptr);
|
||||
va_start(argptr, fmt);
|
||||
vsnprintf(msg, MAXPRINTMSG, fmt, argptr);
|
||||
va_end(argptr);
|
||||
|
||||
Com_Printf("%s", msg);
|
||||
}
|
||||
|
@ -160,56 +179,60 @@ 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;
|
||||
va_list argptr;
|
||||
static char msg[MAXPRINTMSG];
|
||||
static qboolean recursive;
|
||||
|
||||
if (recursive)
|
||||
Sys_Error ("recursive error after: %s", msg);
|
||||
{
|
||||
Sys_Error("recursive error after: %s", msg);
|
||||
}
|
||||
|
||||
recursive = true;
|
||||
|
||||
va_start (argptr,fmt);
|
||||
vsnprintf (msg,MAXPRINTMSG,fmt,argptr);
|
||||
va_end (argptr);
|
||||
va_start(argptr, fmt);
|
||||
vsnprintf(msg, MAXPRINTMSG, fmt, argptr);
|
||||
va_end(argptr);
|
||||
|
||||
if (code == ERR_DISCONNECT)
|
||||
{
|
||||
#ifndef DEDICATED_ONLY
|
||||
CL_Drop ();
|
||||
CL_Drop();
|
||||
#endif
|
||||
recursive = false;
|
||||
longjmp (abortframe, -1);
|
||||
longjmp(abortframe, -1);
|
||||
}
|
||||
|
||||
else if (code == ERR_DROP)
|
||||
{
|
||||
Com_Printf ("********************\nERROR: %s\n********************\n", msg);
|
||||
SV_Shutdown (va("Server crashed: %s\n", msg), false);
|
||||
Com_Printf("********************\nERROR: %s\n********************\n",
|
||||
msg);
|
||||
SV_Shutdown(va("Server crashed: %s\n", msg), false);
|
||||
#ifndef DEDICATED_ONLY
|
||||
CL_Drop ();
|
||||
CL_Drop();
|
||||
#endif
|
||||
recursive = false;
|
||||
longjmp (abortframe, -1);
|
||||
longjmp(abortframe, -1);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
SV_Shutdown (va("Server fatal crashed: %s\n", msg), false);
|
||||
SV_Shutdown(va("Server fatal crashed: %s\n", msg), false);
|
||||
#ifndef DEDICATED_ONLY
|
||||
CL_Shutdown ();
|
||||
CL_Shutdown();
|
||||
#endif
|
||||
}
|
||||
|
||||
if (logfile)
|
||||
{
|
||||
fclose (logfile);
|
||||
fclose(logfile);
|
||||
logfile = NULL;
|
||||
}
|
||||
|
||||
Sys_Error ("%s", msg);
|
||||
Sys_Error("%s", msg);
|
||||
recursive = false;
|
||||
}
|
||||
|
||||
|
@ -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 ();
|
||||
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
1004
src/common/cmdparser.c
Normal file
File diff suppressed because it is too large
Load diff
1876
src/common/collision.c
Normal file
1876
src/common/collision.c
Normal file
File diff suppressed because it is too large
Load diff
|
@ -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 );
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -28,68 +28,74 @@
|
|||
|
||||
#include "header/common.h"
|
||||
|
||||
#define CRC_INIT_VALUE 0xffff
|
||||
#define CRC_XOR_VALUE 0x0000
|
||||
#define CRC_INIT_VALUE 0xffff
|
||||
#define CRC_XOR_VALUE 0x0000
|
||||
|
||||
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,
|
||||
0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
|
||||
0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
|
||||
0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
|
||||
0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
|
||||
0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
|
||||
0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
|
||||
0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
|
||||
0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
|
||||
0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
|
||||
0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
|
||||
0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
|
||||
0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
|
||||
0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
|
||||
0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
|
||||
0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
|
||||
0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
|
||||
0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
|
||||
0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
|
||||
0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
|
||||
0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
|
||||
0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
|
||||
0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
|
||||
0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
|
||||
0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
|
||||
0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
|
||||
0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
|
||||
0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
|
||||
0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
|
||||
0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
|
||||
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,
|
||||
0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
|
||||
0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
|
||||
0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
|
||||
0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
|
||||
0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
|
||||
0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
|
||||
0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
|
||||
0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
|
||||
0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
|
||||
0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
|
||||
0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
|
||||
0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
|
||||
0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
|
||||
0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
|
||||
0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
|
||||
0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
|
||||
0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
|
||||
0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
|
||||
0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
|
||||
0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
|
||||
0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
|
||||
0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
|
||||
0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
|
||||
0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
|
||||
0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
|
||||
0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
|
||||
0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
|
||||
0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
|
||||
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;
|
||||
unsigned short crc;
|
||||
|
||||
CRC_Init (&crc);
|
||||
CRC_Init(&crc);
|
||||
|
||||
while (count--)
|
||||
{
|
||||
crc = (crc << 8) ^ crctable[(crc >> 8) ^ *start++];
|
||||
}
|
||||
|
||||
return crc;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,83 +19,112 @@
|
|||
*
|
||||
* =======================================================================
|
||||
*
|
||||
* The Quake II CVAR subsystem. Implements dynamic variable tracking.
|
||||
* The Quake II CVAR subsystem. Implements dynamic variable handling.
|
||||
*
|
||||
* =======================================================================
|
||||
*/
|
||||
|
||||
#include "header/common.h"
|
||||
|
||||
cvar_t *cvar_vars;
|
||||
cvar_t *cvar_vars;
|
||||
|
||||
static qboolean Cvar_InfoValidate (char *s)
|
||||
static qboolean
|
||||
Cvar_InfoValidate(char *s)
|
||||
{
|
||||
if (strstr (s, "\\"))
|
||||
if (strstr(s, "\\"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strstr (s, "\""))
|
||||
if (strstr(s, "\""))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strstr (s, ";"))
|
||||
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;
|
||||
cvar_t *var;
|
||||
|
||||
for (var=cvar_vars ; var ; var=var->next)
|
||||
if (!strcmp (var_name, var->name))
|
||||
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;
|
||||
cvar_t *var;
|
||||
|
||||
var = Cvar_FindVar (var_name);
|
||||
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);
|
||||
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;
|
||||
cvar_t *cvar;
|
||||
int len;
|
||||
|
||||
len = (int)strlen(partial);
|
||||
|
||||
if (!len)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* check exact match */
|
||||
for (cvar=cvar_vars ; cvar ; cvar=cvar->next)
|
||||
if (!strcmp (partial,cvar->name))
|
||||
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))
|
||||
for (cvar = cvar_vars; cvar; cvar = cvar->next)
|
||||
{
|
||||
if (!strncmp(partial, cvar->name, len))
|
||||
{
|
||||
return cvar->name;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -104,20 +133,21 @@ 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;
|
||||
cvar_t *var;
|
||||
|
||||
if (flags & (CVAR_USERINFO | CVAR_SERVERINFO))
|
||||
{
|
||||
if (!Cvar_InfoValidate (var_name))
|
||||
if (!Cvar_InfoValidate(var_name))
|
||||
{
|
||||
Com_Printf("invalid info cvar name\n");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
var = Cvar_FindVar (var_name);
|
||||
var = Cvar_FindVar(var_name);
|
||||
|
||||
if (var)
|
||||
{
|
||||
|
@ -126,20 +156,22 @@ cvar_t *Cvar_Get (char *var_name, char *var_value, int flags)
|
|||
}
|
||||
|
||||
if (!var_value)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (flags & (CVAR_USERINFO | CVAR_SERVERINFO))
|
||||
{
|
||||
if (!Cvar_InfoValidate (var_value))
|
||||
if (!Cvar_InfoValidate(var_value))
|
||||
{
|
||||
Com_Printf("invalid info cvar value\n");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
var = Z_Malloc (sizeof(*var));
|
||||
var->name = CopyString (var_name);
|
||||
var->string = CopyString (var_value);
|
||||
var = Z_Malloc(sizeof(*var));
|
||||
var->name = CopyString(var_name);
|
||||
var->string = CopyString(var_value);
|
||||
var->modified = true;
|
||||
var->value = strtod(var->string, (char **)NULL);
|
||||
|
||||
|
@ -152,20 +184,21 @@ 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;
|
||||
cvar_t *var;
|
||||
|
||||
var = Cvar_FindVar (var_name);
|
||||
var = Cvar_FindVar(var_name);
|
||||
|
||||
if (!var)
|
||||
{
|
||||
return Cvar_Get (var_name, value, 0);
|
||||
return Cvar_Get(var_name, value, 0);
|
||||
}
|
||||
|
||||
if (var->flags & (CVAR_USERINFO | CVAR_SERVERINFO))
|
||||
{
|
||||
if (!Cvar_InfoValidate (value))
|
||||
if (!Cvar_InfoValidate(value))
|
||||
{
|
||||
Com_Printf("invalid info cvar value\n");
|
||||
return var;
|
||||
|
@ -176,7 +209,7 @@ cvar_t *Cvar_Set2 (char *var_name, char *value, qboolean force)
|
|||
{
|
||||
if (var->flags & CVAR_NOSET)
|
||||
{
|
||||
Com_Printf ("%s is write protected.\n", var_name);
|
||||
Com_Printf("%s is write protected.\n", var_name);
|
||||
return var;
|
||||
}
|
||||
|
||||
|
@ -185,20 +218,24 @@ 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);
|
||||
Z_Free(var->latched_string);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (strcmp(value, var->string) == 0)
|
||||
{
|
||||
return var;
|
||||
}
|
||||
}
|
||||
|
||||
if (Com_ServerState())
|
||||
{
|
||||
Com_Printf ("%s will be changed for next game.\n", var_name);
|
||||
Com_Printf("%s will be changed for next game.\n", var_name);
|
||||
var->latched_string = CopyString(value);
|
||||
}
|
||||
|
||||
|
@ -209,8 +246,8 @@ cvar_t *Cvar_Set2 (char *var_name, char *value, qboolean force)
|
|||
|
||||
if (!strcmp(var->name, "game"))
|
||||
{
|
||||
FS_SetGamedir (var->string);
|
||||
FS_ExecAutoexec ();
|
||||
FS_SetGamedir(var->string);
|
||||
FS_ExecAutoexec();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -222,20 +259,24 @@ cvar_t *Cvar_Set2 (char *var_name, char *value, qboolean force)
|
|||
{
|
||||
if (var->latched_string)
|
||||
{
|
||||
Z_Free (var->latched_string);
|
||||
Z_Free(var->latched_string);
|
||||
var->latched_string = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!strcmp(value, var->string))
|
||||
{
|
||||
return var;
|
||||
}
|
||||
|
||||
var->modified = true;
|
||||
|
||||
if (var->flags & CVAR_USERINFO)
|
||||
{
|
||||
userinfo_modified = true;
|
||||
}
|
||||
|
||||
Z_Free (var->string);
|
||||
Z_Free(var->string);
|
||||
|
||||
var->string = CopyString(value);
|
||||
var->value = strtod(var->string, (char **)NULL);
|
||||
|
@ -243,33 +284,38 @@ 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);
|
||||
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);
|
||||
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;
|
||||
cvar_t *var;
|
||||
|
||||
var = Cvar_FindVar (var_name);
|
||||
var = Cvar_FindVar(var_name);
|
||||
|
||||
if (!var)
|
||||
{
|
||||
return Cvar_Get (var_name, value, flags);
|
||||
return Cvar_Get(var_name, value, flags);
|
||||
}
|
||||
|
||||
var->modified = true;
|
||||
|
||||
if (var->flags & CVAR_USERINFO)
|
||||
{
|
||||
userinfo_modified = true;
|
||||
}
|
||||
|
||||
Z_Free (var->string);
|
||||
Z_Free(var->string);
|
||||
|
||||
var->string = CopyString(value);
|
||||
var->value = (float)strtod(var->string, (char **)NULL);
|
||||
|
@ -279,40 +325,48 @@ 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];
|
||||
char val[32];
|
||||
|
||||
if (value == (int)value)
|
||||
Com_sprintf (val, sizeof(val), "%i",(int)value);
|
||||
{
|
||||
Com_sprintf(val, sizeof(val), "%i", (int)value);
|
||||
}
|
||||
|
||||
else
|
||||
Com_sprintf (val, sizeof(val), "%f",value);
|
||||
{
|
||||
Com_sprintf(val, sizeof(val), "%f", value);
|
||||
}
|
||||
|
||||
Cvar_Set (var_name, val);
|
||||
Cvar_Set(var_name, val);
|
||||
}
|
||||
|
||||
/*
|
||||
* Any variables with latched values will now be updated
|
||||
*/
|
||||
void Cvar_GetLatchedVars (void)
|
||||
void
|
||||
Cvar_GetLatchedVars(void)
|
||||
{
|
||||
cvar_t *var;
|
||||
cvar_t *var;
|
||||
|
||||
for (var = cvar_vars ; var ; var = var->next)
|
||||
for (var = cvar_vars; var; var = var->next)
|
||||
{
|
||||
if (!var->latched_string)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Z_Free (var->string);
|
||||
Z_Free(var->string);
|
||||
var->string = var->latched_string;
|
||||
var->latched_string = NULL;
|
||||
var->value = strtod(var->string, (char **)NULL);
|
||||
|
||||
if (!strcmp(var->name, "game"))
|
||||
{
|
||||
FS_SetGamedir (var->string);
|
||||
FS_ExecAutoexec ();
|
||||
FS_SetGamedir(var->string);
|
||||
FS_ExecAutoexec();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -320,143 +374,177 @@ void Cvar_GetLatchedVars (void)
|
|||
/*
|
||||
* Handles variable inspection and changing from the console
|
||||
*/
|
||||
qboolean Cvar_Command (void)
|
||||
qboolean
|
||||
Cvar_Command(void)
|
||||
{
|
||||
cvar_t *v;
|
||||
cvar_t *v;
|
||||
|
||||
/* check variables */
|
||||
v = Cvar_FindVar (Cmd_Argv(0));
|
||||
v = Cvar_FindVar(Cmd_Argv(0));
|
||||
|
||||
if (!v)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/* perform a variable print or set */
|
||||
if (Cmd_Argc() == 1)
|
||||
{
|
||||
Com_Printf ("\"%s\" is \"%s\"\n", v->name, v->string);
|
||||
Com_Printf("\"%s\" is \"%s\"\n", v->name, v->string);
|
||||
return true;
|
||||
}
|
||||
|
||||
Cvar_Set (v->name, Cmd_Argv(1));
|
||||
Cvar_Set(v->name, Cmd_Argv(1));
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Allows setting and defining of arbitrary cvars from console
|
||||
*/
|
||||
void Cvar_Set_f (void)
|
||||
void
|
||||
Cvar_Set_f(void)
|
||||
{
|
||||
int c;
|
||||
int flags;
|
||||
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");
|
||||
Com_Printf("usage: set <variable> <value> [u / s]\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (c == 4)
|
||||
{
|
||||
if (!strcmp(Cmd_Argv(3), "u"))
|
||||
{
|
||||
flags = CVAR_USERINFO;
|
||||
}
|
||||
|
||||
else if (!strcmp(Cmd_Argv(3), "s"))
|
||||
{
|
||||
flags = CVAR_SERVERINFO;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
Com_Printf ("flags can only be 'u' or 's'\n");
|
||||
Com_Printf("flags can only be 'u' or 's'\n");
|
||||
return;
|
||||
}
|
||||
|
||||
Cvar_FullSet (Cmd_Argv(1), Cmd_Argv(2), flags);
|
||||
Cvar_FullSet(Cmd_Argv(1), Cmd_Argv(2), flags);
|
||||
}
|
||||
|
||||
else
|
||||
Cvar_Set (Cmd_Argv(1), Cmd_Argv(2));
|
||||
{
|
||||
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];
|
||||
FILE *f;
|
||||
cvar_t *var;
|
||||
char buffer[1024];
|
||||
FILE *f;
|
||||
|
||||
f = fopen (path, "a");
|
||||
f = fopen(path, "a");
|
||||
|
||||
for (var = cvar_vars ; var ; var = var->next)
|
||||
for (var = cvar_vars; var; var = var->next)
|
||||
{
|
||||
if (var->flags & CVAR_ARCHIVE)
|
||||
{
|
||||
Com_sprintf (buffer, sizeof(buffer), "set %s \"%s\"\n", var->name, var->string);
|
||||
fprintf (f, "%s", buffer);
|
||||
Com_sprintf(buffer, sizeof(buffer), "set %s \"%s\"\n",
|
||||
var->name, var->string);
|
||||
fprintf(f, "%s", buffer);
|
||||
}
|
||||
}
|
||||
|
||||
fclose (f);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
void Cvar_List_f (void)
|
||||
void
|
||||
Cvar_List_f(void)
|
||||
{
|
||||
cvar_t *var;
|
||||
int i;
|
||||
cvar_t *var;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
|
||||
for (var = cvar_vars ; var ; var = var->next, i++)
|
||||
for (var = cvar_vars; var; var = var->next, i++)
|
||||
{
|
||||
if (var->flags & CVAR_ARCHIVE)
|
||||
Com_Printf ("*");
|
||||
{
|
||||
Com_Printf("*");
|
||||
}
|
||||
|
||||
else
|
||||
Com_Printf (" ");
|
||||
{
|
||||
Com_Printf(" ");
|
||||
}
|
||||
|
||||
if (var->flags & CVAR_USERINFO)
|
||||
Com_Printf ("U");
|
||||
{
|
||||
Com_Printf("U");
|
||||
}
|
||||
|
||||
else
|
||||
Com_Printf (" ");
|
||||
{
|
||||
Com_Printf(" ");
|
||||
}
|
||||
|
||||
if (var->flags & CVAR_SERVERINFO)
|
||||
Com_Printf ("S");
|
||||
{
|
||||
Com_Printf("S");
|
||||
}
|
||||
|
||||
else
|
||||
Com_Printf (" ");
|
||||
{
|
||||
Com_Printf(" ");
|
||||
}
|
||||
|
||||
if (var->flags & CVAR_NOSET)
|
||||
Com_Printf ("-");
|
||||
{
|
||||
Com_Printf("-");
|
||||
}
|
||||
|
||||
else if (var->flags & CVAR_LATCH)
|
||||
Com_Printf ("L");
|
||||
{
|
||||
Com_Printf("L");
|
||||
}
|
||||
|
||||
else
|
||||
Com_Printf (" ");
|
||||
{
|
||||
Com_Printf(" ");
|
||||
}
|
||||
|
||||
Com_Printf (" %s \"%s\"\n", var->name, var->string);
|
||||
Com_Printf(" %s \"%s\"\n", var->name, var->string);
|
||||
}
|
||||
|
||||
Com_Printf ("%i cvars\n", i);
|
||||
Com_Printf("%i cvars\n", i);
|
||||
}
|
||||
|
||||
qboolean userinfo_modified;
|
||||
|
||||
char *Cvar_BitInfo (int bit)
|
||||
char *
|
||||
Cvar_BitInfo(int bit)
|
||||
{
|
||||
static char info[MAX_INFO_STRING];
|
||||
cvar_t *var;
|
||||
static char info[MAX_INFO_STRING];
|
||||
cvar_t *var;
|
||||
|
||||
info[0] = 0;
|
||||
|
||||
for (var = cvar_vars ; var ; var = var->next)
|
||||
for (var = cvar_vars; var; var = var->next)
|
||||
{
|
||||
if (var->flags & bit)
|
||||
Info_SetValueForKey (info, var->name, var->string);
|
||||
{
|
||||
Info_SetValueForKey(info, var->name, var->string);
|
||||
}
|
||||
}
|
||||
|
||||
return info;
|
||||
|
@ -466,26 +554,29 @@ 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);
|
||||
return Cvar_BitInfo(CVAR_USERINFO);
|
||||
}
|
||||
|
||||
/*
|
||||
* returns an info string containing
|
||||
* all the CVAR_SERVERINFO cvars
|
||||
*/
|
||||
char *Cvar_Serverinfo (void)
|
||||
char *
|
||||
Cvar_Serverinfo(void)
|
||||
{
|
||||
return Cvar_BitInfo (CVAR_SERVERINFO);
|
||||
return Cvar_BitInfo(CVAR_SERVERINFO);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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);
|
||||
|
||||
Cmd_AddCommand("set", Cvar_Set_f);
|
||||
Cmd_AddCommand("cvarlist", Cvar_List_f);
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -31,25 +31,25 @@
|
|||
* Like glob_match, but match PATTERN against any final segment of TEXT.
|
||||
*/
|
||||
static int
|
||||
glob_match_after_star ( char *pattern, char *text )
|
||||
glob_match_after_star(char *pattern, char *text)
|
||||
{
|
||||
register char *p = pattern, *t = text;
|
||||
register char c, c1;
|
||||
|
||||
while ( ( c = *p++ ) == '?' || c == '*' )
|
||||
while ((c = *p++) == '?' || c == '*')
|
||||
{
|
||||
if ( ( c == '?' ) && ( *t++ == '\0' ) )
|
||||
if ((c == '?') && (*t++ == '\0'))
|
||||
{
|
||||
return ( 0 );
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if ( c == '\0' )
|
||||
if (c == '\0')
|
||||
{
|
||||
return ( 1 );
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ( c == '\\' )
|
||||
if (c == '\\')
|
||||
{
|
||||
c1 = *p;
|
||||
}
|
||||
|
@ -58,16 +58,16 @@ glob_match_after_star ( char *pattern, char *text )
|
|||
c1 = c;
|
||||
}
|
||||
|
||||
while ( 1 )
|
||||
while (1)
|
||||
{
|
||||
if ( ( ( c == '[' ) || ( *t == c1 ) ) && glob_match( p - 1, t ) )
|
||||
if (((c == '[') || (*t == c1)) && glob_match(p - 1, t))
|
||||
{
|
||||
return ( 1 );
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ( *t++ == '\0' )
|
||||
if (*t++ == '\0')
|
||||
{
|
||||
return ( 0 );
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -90,20 +90,20 @@ glob_match_after_star ( char *pattern, char *text )
|
|||
* and match the character exactly, precede it with a `\'.
|
||||
*/
|
||||
int
|
||||
glob_match ( char *pattern, char *text )
|
||||
glob_match(char *pattern, char *text)
|
||||
{
|
||||
register char *p = pattern, *t = text;
|
||||
register char c;
|
||||
|
||||
while ( ( c = *p++ ) != '\0' )
|
||||
while ((c = *p++) != '\0')
|
||||
{
|
||||
switch ( c )
|
||||
switch (c)
|
||||
{
|
||||
case '?':
|
||||
|
||||
if ( *t == '\0' )
|
||||
if (*t == '\0')
|
||||
{
|
||||
return ( 0 );
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -114,83 +114,83 @@ glob_match ( char *pattern, char *text )
|
|||
|
||||
case '\\':
|
||||
|
||||
if ( *p++ != *t++ )
|
||||
if (*p++ != *t++)
|
||||
{
|
||||
return ( 0 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case '*':
|
||||
return ( glob_match_after_star( p, t ) );
|
||||
return glob_match_after_star(p, t);
|
||||
|
||||
case '[':
|
||||
{
|
||||
register char c1 = *t++;
|
||||
int invert;
|
||||
|
||||
if ( !c1 )
|
||||
if (!c1)
|
||||
{
|
||||
return ( 0 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
invert = ( ( *p == '!' ) || ( *p == '^' ) );
|
||||
invert = ((*p == '!') || (*p == '^'));
|
||||
|
||||
if ( invert )
|
||||
if (invert)
|
||||
{
|
||||
p++;
|
||||
}
|
||||
|
||||
c = *p++;
|
||||
|
||||
while ( 1 )
|
||||
while (1)
|
||||
{
|
||||
register char cstart = c, cend = c;
|
||||
|
||||
if ( c == '\\' )
|
||||
if (c == '\\')
|
||||
{
|
||||
cstart = *p++;
|
||||
cend = cstart;
|
||||
}
|
||||
|
||||
if ( c == '\0' )
|
||||
if (c == '\0')
|
||||
{
|
||||
return ( 0 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
c = *p++;
|
||||
|
||||
if ( ( c == '-' ) && ( *p != ']' ) )
|
||||
if ((c == '-') && (*p != ']'))
|
||||
{
|
||||
cend = *p++;
|
||||
|
||||
if ( cend == '\\' )
|
||||
if (cend == '\\')
|
||||
{
|
||||
cend = *p++;
|
||||
}
|
||||
|
||||
if ( cend == '\0' )
|
||||
if (cend == '\0')
|
||||
{
|
||||
return ( 0 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
c = *p++;
|
||||
}
|
||||
|
||||
if ( ( c1 >= cstart ) && ( c1 <= cend ) )
|
||||
if ((c1 >= cstart) && (c1 <= cend))
|
||||
{
|
||||
goto match;
|
||||
}
|
||||
|
||||
if ( c == ']' )
|
||||
if (c == ']')
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !invert )
|
||||
if (!invert)
|
||||
{
|
||||
return ( 0 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -198,28 +198,28 @@ glob_match ( char *pattern, char *text )
|
|||
match:
|
||||
|
||||
/* Skip the rest of the [...] construct that already matched. */
|
||||
while ( c != ']' )
|
||||
while (c != ']')
|
||||
{
|
||||
if ( c == '\0' )
|
||||
if (c == '\0')
|
||||
{
|
||||
return ( 0 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
c = *p++;
|
||||
|
||||
if ( c == '\0' )
|
||||
if (c == '\0')
|
||||
{
|
||||
return ( 0 );
|
||||
return 0;
|
||||
}
|
||||
else if ( c == '\\' )
|
||||
else if (c == '\\')
|
||||
{
|
||||
++p;
|
||||
}
|
||||
}
|
||||
|
||||
if ( invert )
|
||||
if (invert)
|
||||
{
|
||||
return ( 0 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -227,12 +227,13 @@ glob_match ( char *pattern, char *text )
|
|||
|
||||
default:
|
||||
|
||||
if ( c != *t++ )
|
||||
if (c != *t++)
|
||||
{
|
||||
return ( 0 );
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ( *t == '\0' );
|
||||
return *t == '\0';
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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
|
File diff suppressed because it is too large
Load diff
|
@ -30,6 +30,6 @@
|
|||
void CRC_Init(unsigned short *crcvalue);
|
||||
void CRC_ProcessByte(unsigned short *crcvalue, byte data);
|
||||
unsigned short CRC_Value(unsigned short crcvalue);
|
||||
unsigned short CRC_Block (byte *start, int count);
|
||||
unsigned short CRC_Block(byte *start, int count);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -29,405 +29,400 @@
|
|||
|
||||
/* The .pak files are just a linear collapse of a directory tree */
|
||||
|
||||
#define IDPAKHEADER (('K'<<24)+('C'<<16)+('A'<<8)+'P')
|
||||
#define IDPAKHEADER (('K' << 24) + ('C' << 16) + ('A' << 8) + 'P')
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char name[56];
|
||||
int filepos, filelen;
|
||||
char name[56];
|
||||
int filepos, filelen;
|
||||
} dpackfile_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int ident; /* == IDPAKHEADER */
|
||||
int dirofs;
|
||||
int dirlen;
|
||||
int ident; /* == IDPAKHEADER */
|
||||
int dirofs;
|
||||
int dirlen;
|
||||
} dpackheader_t;
|
||||
|
||||
#define MAX_FILES_IN_PACK 4096
|
||||
|
||||
#define MAX_FILES_IN_PACK 4096
|
||||
|
||||
/* PCX files are used for as many images as possible */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char manufacturer;
|
||||
char version;
|
||||
char encoding;
|
||||
char bits_per_pixel;
|
||||
unsigned short xmin,ymin,xmax,ymax;
|
||||
unsigned short hres,vres;
|
||||
unsigned char palette[48];
|
||||
char reserved;
|
||||
char color_planes;
|
||||
unsigned short bytes_per_line;
|
||||
unsigned short palette_type;
|
||||
char filler[58];
|
||||
unsigned char data; /* unbounded */
|
||||
char manufacturer;
|
||||
char version;
|
||||
char encoding;
|
||||
char bits_per_pixel;
|
||||
unsigned short xmin, ymin, xmax, ymax;
|
||||
unsigned short hres, vres;
|
||||
unsigned char palette[48];
|
||||
char reserved;
|
||||
char color_planes;
|
||||
unsigned short bytes_per_line;
|
||||
unsigned short palette_type;
|
||||
char filler[58];
|
||||
unsigned char data; /* unbounded */
|
||||
} pcx_t;
|
||||
|
||||
|
||||
/* .MD2 triangle model file format */
|
||||
|
||||
#define IDALIASHEADER (('2'<<24)+('P'<<16)+('D'<<8)+'I')
|
||||
#define ALIAS_VERSION 8
|
||||
#define IDALIASHEADER (('2' << 24) + ('P' << 16) + ('D' << 8) + 'I')
|
||||
#define ALIAS_VERSION 8
|
||||
|
||||
#define MAX_TRIANGLES 4096
|
||||
#define MAX_VERTS 2048
|
||||
#define MAX_FRAMES 512
|
||||
#define MAX_MD2SKINS 32
|
||||
#define MAX_SKINNAME 64
|
||||
#define MAX_TRIANGLES 4096
|
||||
#define MAX_VERTS 2048
|
||||
#define MAX_FRAMES 512
|
||||
#define MAX_MD2SKINS 32
|
||||
#define MAX_SKINNAME 64
|
||||
|
||||
typedef struct
|
||||
{
|
||||
short s;
|
||||
short t;
|
||||
short s;
|
||||
short t;
|
||||
} dstvert_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
short index_xyz[3];
|
||||
short index_st[3];
|
||||
short index_xyz[3];
|
||||
short index_st[3];
|
||||
} dtriangle_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
byte v[3]; /* scaled byte to fit in frame mins/maxs */
|
||||
byte lightnormalindex;
|
||||
byte v[3]; /* scaled byte to fit in frame mins/maxs */
|
||||
byte lightnormalindex;
|
||||
} dtrivertx_t;
|
||||
|
||||
#define DTRIVERTX_V0 0
|
||||
#define DTRIVERTX_V1 1
|
||||
#define DTRIVERTX_V2 2
|
||||
#define DTRIVERTX_LNI 3
|
||||
#define DTRIVERTX_V0 0
|
||||
#define DTRIVERTX_V1 1
|
||||
#define DTRIVERTX_V2 2
|
||||
#define DTRIVERTX_LNI 3
|
||||
#define DTRIVERTX_SIZE 4
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float scale[3]; /* multiply byte verts by this */
|
||||
float translate[3]; /* then add this */
|
||||
char name[16]; /* frame name from grabbing */
|
||||
dtrivertx_t verts[1]; /* variable sized */
|
||||
float scale[3]; /* multiply byte verts by this */
|
||||
float translate[3]; /* then add this */
|
||||
char name[16]; /* frame name from grabbing */
|
||||
dtrivertx_t verts[1]; /* variable sized */
|
||||
} 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
|
||||
{
|
||||
int ident;
|
||||
int version;
|
||||
int ident;
|
||||
int version;
|
||||
|
||||
int skinwidth;
|
||||
int skinheight;
|
||||
int framesize; /* byte size of each frame */
|
||||
int skinwidth;
|
||||
int skinheight;
|
||||
int framesize; /* byte size of each frame */
|
||||
|
||||
int num_skins;
|
||||
int num_xyz;
|
||||
int num_st; /* greater than num_xyz for seams */
|
||||
int num_tris;
|
||||
int num_glcmds; /* dwords in strip/fan command list */
|
||||
int num_frames;
|
||||
|
||||
int ofs_skins; /* each skin is a MAX_SKINNAME string */
|
||||
int ofs_st; /* byte offset from start for stverts */
|
||||
int ofs_tris; /* offset for dtriangles */
|
||||
int ofs_frames; /* offset for first frame */
|
||||
int ofs_glcmds;
|
||||
int ofs_end; /* end of file */
|
||||
int num_skins;
|
||||
int num_xyz;
|
||||
int num_st; /* greater than num_xyz for seams */
|
||||
int num_tris;
|
||||
int num_glcmds; /* dwords in strip/fan command list */
|
||||
int num_frames;
|
||||
|
||||
int ofs_skins; /* each skin is a MAX_SKINNAME string */
|
||||
int ofs_st; /* byte offset from start for stverts */
|
||||
int ofs_tris; /* offset for dtriangles */
|
||||
int ofs_frames; /* offset for first frame */
|
||||
int ofs_glcmds;
|
||||
int ofs_end; /* end of file */
|
||||
} dmdl_t;
|
||||
|
||||
/* .SP2 sprite file format */
|
||||
|
||||
#define IDSPRITEHEADER (('2'<<24)+('S'<<16)+('D'<<8)+'I') /* little-endian "IDS2" */
|
||||
#define SPRITE_VERSION 2
|
||||
#define IDSPRITEHEADER (('2' << 24) + ('S' << 16) + ('D' << 8) + 'I') /* little-endian "IDS2" */
|
||||
#define SPRITE_VERSION 2
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int width, height;
|
||||
int origin_x, origin_y; /* raster coordinates inside pic */
|
||||
char name[MAX_SKINNAME]; /* name of pcx file */
|
||||
int width, height;
|
||||
int origin_x, origin_y; /* raster coordinates inside pic */
|
||||
char name[MAX_SKINNAME]; /* name of pcx file */
|
||||
} dsprframe_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int ident;
|
||||
int version;
|
||||
int numframes;
|
||||
dsprframe_t frames[1]; /* variable sized */
|
||||
int ident;
|
||||
int version;
|
||||
int numframes;
|
||||
dsprframe_t frames[1]; /* variable sized */
|
||||
} dsprite_t;
|
||||
|
||||
/* .WAL texture file format */
|
||||
|
||||
#define MIPLEVELS 4
|
||||
#define MIPLEVELS 4
|
||||
typedef struct miptex_s
|
||||
{
|
||||
char name[32];
|
||||
unsigned width, height;
|
||||
unsigned offsets[MIPLEVELS]; /* four mip maps stored */
|
||||
char animname[32]; /* next frame in animation chain */
|
||||
int flags;
|
||||
int contents;
|
||||
int value;
|
||||
char name[32];
|
||||
unsigned width, height;
|
||||
unsigned offsets[MIPLEVELS]; /* four mip maps stored */
|
||||
char animname[32]; /* next frame in animation chain */
|
||||
int flags;
|
||||
int contents;
|
||||
int value;
|
||||
} miptex_t;
|
||||
|
||||
/* .BSP file format */
|
||||
|
||||
#define IDBSPHEADER (('P'<<24)+('S'<<16)+('B'<<8)+'I') /* little-endian "IBSP" */
|
||||
#define BSPVERSION 38
|
||||
#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 */
|
||||
#define MAX_MAP_MODELS 1024
|
||||
#define MAX_MAP_BRUSHES 8192
|
||||
#define MAX_MAP_ENTITIES 2048
|
||||
#define MAX_MAP_ENTSTRING 0x40000
|
||||
#define MAX_MAP_TEXINFO 8192
|
||||
/* 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
|
||||
#define MAX_MAP_ENTSTRING 0x40000
|
||||
#define MAX_MAP_TEXINFO 8192
|
||||
|
||||
#define MAX_MAP_AREAS 256
|
||||
#define MAX_MAP_AREAPORTALS 1024
|
||||
#define MAX_MAP_PLANES 65536
|
||||
#define MAX_MAP_NODES 65536
|
||||
#define MAX_MAP_BRUSHSIDES 65536
|
||||
#define MAX_MAP_LEAFS 65536
|
||||
#define MAX_MAP_VERTS 65536
|
||||
#define MAX_MAP_FACES 65536
|
||||
#define MAX_MAP_LEAFFACES 65536
|
||||
#define MAX_MAP_LEAFBRUSHES 65536
|
||||
#define MAX_MAP_PORTALS 65536
|
||||
#define MAX_MAP_EDGES 128000
|
||||
#define MAX_MAP_SURFEDGES 256000
|
||||
#define MAX_MAP_LIGHTING 0x200000
|
||||
#define MAX_MAP_VISIBILITY 0x100000
|
||||
#define MAX_MAP_AREAS 256
|
||||
#define MAX_MAP_AREAPORTALS 1024
|
||||
#define MAX_MAP_PLANES 65536
|
||||
#define MAX_MAP_NODES 65536
|
||||
#define MAX_MAP_BRUSHSIDES 65536
|
||||
#define MAX_MAP_LEAFS 65536
|
||||
#define MAX_MAP_VERTS 65536
|
||||
#define MAX_MAP_FACES 65536
|
||||
#define MAX_MAP_LEAFFACES 65536
|
||||
#define MAX_MAP_LEAFBRUSHES 65536
|
||||
#define MAX_MAP_PORTALS 65536
|
||||
#define MAX_MAP_EDGES 128000
|
||||
#define MAX_MAP_SURFEDGES 256000
|
||||
#define MAX_MAP_LIGHTING 0x200000
|
||||
#define MAX_MAP_VISIBILITY 0x100000
|
||||
|
||||
/* key / value pair sizes */
|
||||
|
||||
#define MAX_KEY 32
|
||||
#define MAX_VALUE 1024
|
||||
#define MAX_KEY 32
|
||||
#define MAX_VALUE 1024
|
||||
|
||||
/* ================================================================== */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int fileofs, filelen;
|
||||
int fileofs, filelen;
|
||||
} lump_t;
|
||||
|
||||
#define LUMP_ENTITIES 0
|
||||
#define LUMP_PLANES 1
|
||||
#define LUMP_VERTEXES 2
|
||||
#define LUMP_VISIBILITY 3
|
||||
#define LUMP_NODES 4
|
||||
#define LUMP_TEXINFO 5
|
||||
#define LUMP_FACES 6
|
||||
#define LUMP_LIGHTING 7
|
||||
#define LUMP_LEAFS 8
|
||||
#define LUMP_LEAFFACES 9
|
||||
#define LUMP_LEAFBRUSHES 10
|
||||
#define LUMP_EDGES 11
|
||||
#define LUMP_SURFEDGES 12
|
||||
#define LUMP_MODELS 13
|
||||
#define LUMP_BRUSHES 14
|
||||
#define LUMP_BRUSHSIDES 15
|
||||
#define LUMP_POP 16
|
||||
#define LUMP_AREAS 17
|
||||
#define LUMP_AREAPORTALS 18
|
||||
#define HEADER_LUMPS 19
|
||||
#define LUMP_ENTITIES 0
|
||||
#define LUMP_PLANES 1
|
||||
#define LUMP_VERTEXES 2
|
||||
#define LUMP_VISIBILITY 3
|
||||
#define LUMP_NODES 4
|
||||
#define LUMP_TEXINFO 5
|
||||
#define LUMP_FACES 6
|
||||
#define LUMP_LIGHTING 7
|
||||
#define LUMP_LEAFS 8
|
||||
#define LUMP_LEAFFACES 9
|
||||
#define LUMP_LEAFBRUSHES 10
|
||||
#define LUMP_EDGES 11
|
||||
#define LUMP_SURFEDGES 12
|
||||
#define LUMP_MODELS 13
|
||||
#define LUMP_BRUSHES 14
|
||||
#define LUMP_BRUSHSIDES 15
|
||||
#define LUMP_POP 16
|
||||
#define LUMP_AREAS 17
|
||||
#define LUMP_AREAPORTALS 18
|
||||
#define HEADER_LUMPS 19
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int ident;
|
||||
int version;
|
||||
lump_t lumps[HEADER_LUMPS];
|
||||
int ident;
|
||||
int version;
|
||||
lump_t lumps[HEADER_LUMPS];
|
||||
} dheader_t;
|
||||
|
||||
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 */
|
||||
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 */
|
||||
} dmodel_t;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float point[3];
|
||||
float point[3];
|
||||
} dvertex_t;
|
||||
|
||||
|
||||
/* 0-2 are axial planes */
|
||||
#define PLANE_X 0
|
||||
#define PLANE_Y 1
|
||||
#define PLANE_Z 2
|
||||
#define PLANE_X 0
|
||||
#define PLANE_Y 1
|
||||
#define PLANE_Z 2
|
||||
|
||||
/* 3-5 are non-axial planes snapped to the nearest */
|
||||
#define PLANE_ANYX 3
|
||||
#define PLANE_ANYY 4
|
||||
#define PLANE_ANYZ 5
|
||||
#define PLANE_ANYX 3
|
||||
#define PLANE_ANYY 4
|
||||
#define PLANE_ANYZ 5
|
||||
|
||||
/* planes (x&~1) and (x&~1)+1 are always opposites */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float normal[3];
|
||||
float dist;
|
||||
int type; /* PLANE_X - PLANE_ANYZ */
|
||||
float normal[3];
|
||||
float dist;
|
||||
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 */
|
||||
#define CONTENTS_WINDOW 2 /* translucent, but not watery */
|
||||
#define CONTENTS_AUX 4
|
||||
#define CONTENTS_LAVA 8
|
||||
#define CONTENTS_SLIME 16
|
||||
#define CONTENTS_WATER 32
|
||||
#define CONTENTS_MIST 64
|
||||
#define LAST_VISIBLE_CONTENTS 64
|
||||
#define CONTENTS_SOLID 1 /* an eye is never valid in a solid */
|
||||
#define CONTENTS_WINDOW 2 /* translucent, but not watery */
|
||||
#define CONTENTS_AUX 4
|
||||
#define CONTENTS_LAVA 8
|
||||
#define CONTENTS_SLIME 16
|
||||
#define CONTENTS_WATER 32
|
||||
#define CONTENTS_MIST 64
|
||||
#define LAST_VISIBLE_CONTENTS 64
|
||||
|
||||
/* remaining contents are non-visible, and don't eat brushes */
|
||||
#define CONTENTS_AREAPORTAL 0x8000
|
||||
#define CONTENTS_AREAPORTAL 0x8000
|
||||
|
||||
#define CONTENTS_PLAYERCLIP 0x10000
|
||||
#define CONTENTS_MONSTERCLIP 0x20000
|
||||
#define CONTENTS_PLAYERCLIP 0x10000
|
||||
#define CONTENTS_MONSTERCLIP 0x20000
|
||||
|
||||
/* currents can be added to any other contents, and may be mixed */
|
||||
#define CONTENTS_CURRENT_0 0x40000
|
||||
#define CONTENTS_CURRENT_90 0x80000
|
||||
#define CONTENTS_CURRENT_180 0x100000
|
||||
#define CONTENTS_CURRENT_270 0x200000
|
||||
#define CONTENTS_CURRENT_UP 0x400000
|
||||
#define CONTENTS_CURRENT_DOWN 0x800000
|
||||
#define CONTENTS_CURRENT_0 0x40000
|
||||
#define CONTENTS_CURRENT_90 0x80000
|
||||
#define CONTENTS_CURRENT_180 0x100000
|
||||
#define CONTENTS_CURRENT_270 0x200000
|
||||
#define CONTENTS_CURRENT_UP 0x400000
|
||||
#define CONTENTS_CURRENT_DOWN 0x800000
|
||||
|
||||
#define CONTENTS_ORIGIN 0x1000000 /* removed before bsping an entity */
|
||||
#define CONTENTS_ORIGIN 0x1000000 /* removed before bsping an entity */
|
||||
|
||||
#define CONTENTS_MONSTER 0x2000000 /* should never be on a brush, only in game */
|
||||
#define CONTENTS_DEADMONSTER 0x4000000
|
||||
#define CONTENTS_DETAIL 0x8000000 /* brushes to be added after vis leafs */
|
||||
#define CONTENTS_TRANSLUCENT 0x10000000 /* auto set if any surface has trans */
|
||||
#define CONTENTS_LADDER 0x20000000
|
||||
#define CONTENTS_MONSTER 0x2000000 /* should never be on a brush, only in game */
|
||||
#define CONTENTS_DEADMONSTER 0x4000000
|
||||
#define CONTENTS_DETAIL 0x8000000 /* brushes to be added after vis leafs */
|
||||
#define CONTENTS_TRANSLUCENT 0x10000000 /* auto set if any surface has trans */
|
||||
#define CONTENTS_LADDER 0x20000000
|
||||
|
||||
#define SURF_LIGHT 0x1 /* value will hold the light strength */
|
||||
#define SURF_LIGHT 0x1 /* value will hold the light strength */
|
||||
|
||||
#define SURF_SLICK 0x2 /* effects game physics */
|
||||
#define SURF_SLICK 0x2 /* effects game physics */
|
||||
|
||||
#define SURF_SKY 0x4 /* don't draw, but add to skybox */
|
||||
#define SURF_WARP 0x8 /* turbulent water warp */
|
||||
#define SURF_TRANS33 0x10
|
||||
#define SURF_TRANS66 0x20
|
||||
#define SURF_FLOWING 0x40 /* scroll towards angle */
|
||||
#define SURF_NODRAW 0x80 /* don't bother referencing the texture */
|
||||
#define SURF_SKY 0x4 /* don't draw, but add to skybox */
|
||||
#define SURF_WARP 0x8 /* turbulent water warp */
|
||||
#define SURF_TRANS33 0x10
|
||||
#define SURF_TRANS66 0x20
|
||||
#define SURF_FLOWING 0x40 /* scroll towards angle */
|
||||
#define SURF_NODRAW 0x80 /* don't bother referencing the texture */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int planenum;
|
||||
int children[2]; /* negative numbers are -(leafs+1), not nodes */
|
||||
short mins[3]; /* for frustom culling */
|
||||
short maxs[3];
|
||||
unsigned short firstface;
|
||||
unsigned short numfaces; /* counting both sides */
|
||||
int planenum;
|
||||
int children[2]; /* negative numbers are -(leafs+1), not nodes */
|
||||
short mins[3]; /* for frustom culling */
|
||||
short maxs[3];
|
||||
unsigned short firstface;
|
||||
unsigned short numfaces; /* counting both sides */
|
||||
} dnode_t;
|
||||
|
||||
typedef struct texinfo_s
|
||||
{
|
||||
float vecs[2][4]; /* [s/t][xyz offset] */
|
||||
int flags; /* miptex flags + overrides */
|
||||
int value; /* light emission, etc */
|
||||
char texture[32]; /* texture name (textures*.wal) */
|
||||
int nexttexinfo; /* for animations, -1 = end of chain */
|
||||
float vecs[2][4]; /* [s/t][xyz offset] */
|
||||
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 */
|
||||
unsigned short v[2]; /* vertex numbers */
|
||||
} dedge_t;
|
||||
|
||||
#define MAXLIGHTMAPS 4
|
||||
#define MAXLIGHTMAPS 4
|
||||
typedef struct
|
||||
{
|
||||
unsigned short planenum;
|
||||
short side;
|
||||
unsigned short planenum;
|
||||
short side;
|
||||
|
||||
int firstedge; /* we must support > 64k edges */
|
||||
short numedges;
|
||||
short texinfo;
|
||||
int firstedge; /* we must support > 64k edges */
|
||||
short numedges;
|
||||
short texinfo;
|
||||
|
||||
/* lighting info */
|
||||
byte styles[MAXLIGHTMAPS];
|
||||
int lightofs; /* start of [numstyles*surfsize] samples */
|
||||
byte styles[MAXLIGHTMAPS];
|
||||
int lightofs; /* start of [numstyles*surfsize] samples */
|
||||
} dface_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int contents; /* OR of all brushes (not needed?) */
|
||||
int contents; /* OR of all brushes (not needed?) */
|
||||
|
||||
short cluster;
|
||||
short area;
|
||||
short cluster;
|
||||
short area;
|
||||
|
||||
short mins[3]; /* for frustum culling */
|
||||
short maxs[3];
|
||||
short mins[3]; /* for frustum culling */
|
||||
short maxs[3];
|
||||
|
||||
unsigned short firstleafface;
|
||||
unsigned short numleaffaces;
|
||||
unsigned short firstleafface;
|
||||
unsigned short numleaffaces;
|
||||
|
||||
unsigned short firstleafbrush;
|
||||
unsigned short numleafbrushes;
|
||||
unsigned short firstleafbrush;
|
||||
unsigned short numleafbrushes;
|
||||
} dleaf_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned short planenum; /* facing out of the leaf */
|
||||
short texinfo;
|
||||
unsigned short planenum; /* facing out of the leaf */
|
||||
short texinfo;
|
||||
} dbrushside_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int firstside;
|
||||
int numsides;
|
||||
int contents;
|
||||
int firstside;
|
||||
int numsides;
|
||||
int contents;
|
||||
} dbrush_t;
|
||||
|
||||
#define ANGLE_UP -1
|
||||
#define ANGLE_DOWN -2
|
||||
#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 */
|
||||
#define DVIS_PVS 0
|
||||
#define DVIS_PHS 1
|
||||
/* 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
|
||||
{
|
||||
int numclusters;
|
||||
int bitofs[8][2]; /* bitofs[numclusters][2] */
|
||||
int numclusters;
|
||||
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;
|
||||
int otherarea;
|
||||
int portalnum;
|
||||
int otherarea;
|
||||
} dareaportal_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int numareaportals;
|
||||
int firstareaportal;
|
||||
int numareaportals;
|
||||
int firstareaportal;
|
||||
} darea_t;
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -27,6 +27,6 @@
|
|||
#ifndef UNIX_GLOB_H
|
||||
#define UNIX_GLOB_H
|
||||
|
||||
int glob_match ( char *pattern, char *text );
|
||||
int glob_match(char *pattern, char *text);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -55,14 +55,12 @@ typedef enum {false, true} qboolean;
|
|||
#define MAX_QPATH 64 /* max length of a quake game pathname */
|
||||
|
||||
#ifdef _WIN32
|
||||
#define MAX_OSPATH 256 /* max length of a filesystem pathname (same as MAX_PATH) */
|
||||
#define MAX_OSPATH 256 /* max length of a filesystem pathname (same as MAX_PATH) */
|
||||
#else
|
||||
#define MAX_OSPATH 128 /* max length of a filesystem pathname */
|
||||
#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,10 +126,12 @@ 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] = \
|
||||
a[2] - b[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 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] = \
|
||||
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)
|
||||
#define VectorNegate(a, b) (b[0] = -a[0], b[1] = -a[1], b[2] = -a[2])
|
||||
|
@ -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);
|
||||
|
||||
/* ============================================= */
|
||||
|
||||
|
@ -201,7 +203,7 @@ void Com_sprintf(char *dest, int size, char *fmt, ...);
|
|||
|
||||
void Com_PageInMemory(byte *buffer, int size);
|
||||
|
||||
char *strlwr ( char *s );
|
||||
char *strlwr(char *s);
|
||||
|
||||
/* ============================================= */
|
||||
|
||||
|
@ -237,7 +239,7 @@ qboolean Info_Validate(char *s);
|
|||
/* ============================================= */
|
||||
|
||||
/* Random number generator */
|
||||
int randk(void);
|
||||
int randk(void);
|
||||
float frandk(void);
|
||||
float crandk(void);
|
||||
void randk_seed(void);
|
||||
|
@ -364,19 +366,23 @@ typedef struct cvar_s
|
|||
/* content masks */
|
||||
#define MASK_ALL (-1)
|
||||
#define MASK_SOLID (CONTENTS_SOLID | CONTENTS_WINDOW)
|
||||
#define MASK_PLAYERSOLID (CONTENTS_SOLID | CONTENTS_PLAYERCLIP | \
|
||||
CONTENTS_WINDOW | CONTENTS_MONSTER)
|
||||
#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 | \
|
||||
CONTENTS_WINDOW | CONTENTS_MONSTER)
|
||||
#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 | \
|
||||
CONTENTS_DEADMONSTER)
|
||||
#define MASK_CURRENT (CONTENTS_CURRENT_0 | CONTENTS_CURRENT_90 | \
|
||||
CONTENTS_CURRENT_180 | CONTENTS_CURRENT_270 | \
|
||||
CONTENTS_CURRENT_UP | \
|
||||
CONTENTS_CURRENT_DOWN)
|
||||
#define MASK_SHOT \
|
||||
(CONTENTS_SOLID | CONTENTS_MONSTER | CONTENTS_WINDOW | \
|
||||
CONTENTS_DEADMONSTER)
|
||||
#define MASK_CURRENT \
|
||||
(CONTENTS_CURRENT_0 | CONTENTS_CURRENT_90 | \
|
||||
CONTENTS_CURRENT_180 | CONTENTS_CURRENT_270 | \
|
||||
CONTENTS_CURRENT_UP | \
|
||||
CONTENTS_CURRENT_DOWN)
|
||||
|
||||
/* gi.BoxEdicts() can return a list of either solid or trigger entities */
|
||||
#define AREA_SOLID 1
|
||||
|
@ -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 */
|
||||
|
|
155
src/common/md4.c
155
src/common/md4.c
|
@ -8,23 +8,26 @@
|
|||
|
||||
#include <inttypes.h>
|
||||
|
||||
#define ROTATELEFT32(x, s) (((x)<<(s))|((x)>>(32-(s))))
|
||||
#define ROTATELEFT32(x, s) (((x) << (s)) | ((x) >> (32 - (s))))
|
||||
|
||||
#define F(X, Y, Z) (((X)&(Y)) | ((~X)&(Z)))
|
||||
#define G(X, Y, Z) (((X)&(Y)) | ((X)&(Z)) | ((Y)&(Z)))
|
||||
#define H(X, Y, Z) ((X) ^ (Y) ^ (Z))
|
||||
#define F(X, Y, Z) (((X)&(Y)) | ((~X) & (Z)))
|
||||
#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); \
|
||||
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); \
|
||||
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); \
|
||||
a = ROTATELEFT32(a, s); \
|
||||
}
|
||||
|
||||
static uint32_t X[16];
|
||||
|
@ -33,62 +36,63 @@ 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;
|
||||
CC = C;
|
||||
DD = D;
|
||||
|
||||
S(A, B, C, D, 0, 3);
|
||||
S(D, A, B, C, 1, 7);
|
||||
S(C, D, A, B, 2, 11);
|
||||
S(B, C, D, A, 3, 19);
|
||||
S(A, B, C, D, 4, 3);
|
||||
S(D, A, B, C, 5, 7);
|
||||
S(C, D, A, B, 6, 11);
|
||||
S(B, C, D, A, 7, 19);
|
||||
S(A, B, C, D, 8, 3);
|
||||
S(D, A, B, C, 9, 7);
|
||||
S(A, B, C, D, 0, 3);
|
||||
S(D, A, B, C, 1, 7);
|
||||
S(C, D, A, B, 2, 11);
|
||||
S(B, C, D, A, 3, 19);
|
||||
S(A, B, C, D, 4, 3);
|
||||
S(D, A, B, C, 5, 7);
|
||||
S(C, D, A, B, 6, 11);
|
||||
S(B, C, D, A, 7, 19);
|
||||
S(A, B, C, D, 8, 3);
|
||||
S(D, A, B, C, 9, 7);
|
||||
S(C, D, A, B, 10, 11);
|
||||
S(B, C, D, A, 11, 19);
|
||||
S(A, B, C, D, 12, 3);
|
||||
S(D, A, B, C, 13, 7);
|
||||
S(A, B, C, D, 12, 3);
|
||||
S(D, A, B, C, 13, 7);
|
||||
S(C, D, A, B, 14, 11);
|
||||
S(B, C, D, A, 15, 19);
|
||||
|
||||
T(A, B, C, D, 0, 3);
|
||||
T(D, A, B, C, 4, 5);
|
||||
T(C, D, A, B, 8, 9);
|
||||
T(A, B, C, D, 0, 3);
|
||||
T(D, A, B, C, 4, 5);
|
||||
T(C, D, A, B, 8, 9);
|
||||
T(B, C, D, A, 12, 13);
|
||||
T(A, B, C, D, 1, 3);
|
||||
T(D, A, B, C, 5, 5);
|
||||
T(C, D, A, B, 9, 9);
|
||||
T(A, B, C, D, 1, 3);
|
||||
T(D, A, B, C, 5, 5);
|
||||
T(C, D, A, B, 9, 9);
|
||||
T(B, C, D, A, 13, 13);
|
||||
T(A, B, C, D, 2, 3);
|
||||
T(D, A, B, C, 6, 5);
|
||||
T(C, D, A, B, 10, 9);
|
||||
T(A, B, C, D, 2, 3);
|
||||
T(D, A, B, C, 6, 5);
|
||||
T(C, D, A, B, 10, 9);
|
||||
T(B, C, D, A, 14, 13);
|
||||
T(A, B, C, D, 3, 3);
|
||||
T(D, A, B, C, 7, 5);
|
||||
T(C, D, A, B, 11, 9);
|
||||
T(A, B, C, D, 3, 3);
|
||||
T(D, A, B, C, 7, 5);
|
||||
T(C, D, A, B, 11, 9);
|
||||
T(B, C, D, A, 15, 13);
|
||||
|
||||
U(A, B, C, D, 0, 3);
|
||||
U(D, A, B, C, 8, 9);
|
||||
U(C, D, A, B, 4, 11);
|
||||
U(A, B, C, D, 0, 3);
|
||||
U(D, A, B, C, 8, 9);
|
||||
U(C, D, A, B, 4, 11);
|
||||
U(B, C, D, A, 12, 15);
|
||||
U(A, B, C, D, 2, 3);
|
||||
U(D, A, B, C, 10, 9);
|
||||
U(C, D, A, B, 6, 11);
|
||||
U(A, B, C, D, 2, 3);
|
||||
U(D, A, B, C, 10, 9);
|
||||
U(C, D, A, B, 6, 11);
|
||||
U(B, C, D, A, 14, 15);
|
||||
U(A, B, C, D, 1, 3);
|
||||
U(D, A, B, C, 9, 9);
|
||||
U(C, D, A, B, 5, 11);
|
||||
U(A, B, C, D, 1, 3);
|
||||
U(D, A, B, C, 9, 9);
|
||||
U(C, D, A, B, 5, 11);
|
||||
U(B, C, D, A, 13, 15);
|
||||
U(A, B, C, D, 3, 3);
|
||||
U(D, A, B, C, 11, 9);
|
||||
U(C, D, A, B, 7, 11);
|
||||
U(A, B, C, D, 3, 3);
|
||||
U(D, A, B, C, 11, 9);
|
||||
U(C, D, A, B, 7, 11);
|
||||
U(B, C, D, A, 15, 15);
|
||||
|
||||
A += AA;
|
||||
|
@ -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 */
|
||||
|
@ -115,8 +120,8 @@ static void PerformMD4(const unsigned char *buf, int length, unsigned char *dige
|
|||
{
|
||||
for (j = 0; j < 16; j++)
|
||||
{
|
||||
X[j] = ((ptr[0]<< 0)|(ptr[1]<< 8)|
|
||||
(ptr[2]<<16)|(ptr[3]<<24));
|
||||
X[j] = ((ptr[0] << 0) | (ptr[1] << 8) |
|
||||
(ptr[2] << 16) | (ptr[3] << 24));
|
||||
|
||||
ptr += 4;
|
||||
}
|
||||
|
@ -128,25 +133,27 @@ static void PerformMD4(const unsigned char *buf, int length, unsigned char *dige
|
|||
|
||||
for (j = 0; j < i; j++)
|
||||
{
|
||||
X[j] = ((ptr[0]<< 0)|(ptr[1]<< 8)|
|
||||
(ptr[2]<<16)|(ptr[3]<<24));
|
||||
X[j] = ((ptr[0] << 0) | (ptr[1] << 8) |
|
||||
(ptr[2] << 16) | (ptr[3] << 24));
|
||||
|
||||
ptr += 4;
|
||||
}
|
||||
|
||||
switch(rem % 4)
|
||||
switch (rem % 4)
|
||||
{
|
||||
case 0:
|
||||
X[j] = 0x80U;
|
||||
break;
|
||||
case 1:
|
||||
X[j] = ((ptr[0]<< 0)|((0x80U)<< 8));
|
||||
X[j] = ((ptr[0] << 0) | ((0x80U) << 8));
|
||||
break;
|
||||
case 2:
|
||||
X[j] = ((ptr[0]<< 0)|(ptr[1]<< 8)|((0x80U)<<16));
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -154,32 +161,36 @@ static void PerformMD4(const unsigned char *buf, int length, unsigned char *dige
|
|||
|
||||
if (j > 14)
|
||||
{
|
||||
for (; j < 16; j++)
|
||||
for ( ; j < 16; j++)
|
||||
{
|
||||
X[j] = 0;
|
||||
}
|
||||
|
||||
DoMD4();
|
||||
|
||||
j = 0;
|
||||
}
|
||||
|
||||
for (; j < 14; j++)
|
||||
for ( ; j < 14; j++)
|
||||
{
|
||||
X[j] = 0;
|
||||
}
|
||||
|
||||
X[14] = (length & 0x1FFFFFFF) << 3;
|
||||
X[14] = (length & 0x1FFFFFFF) << 3;
|
||||
X[15] = (length & ~0x1FFFFFFF) >> 29;
|
||||
|
||||
DoMD4();
|
||||
|
||||
digest[ 0] = (A & 0x000000FF) >> 0;
|
||||
digest[ 1] = (A & 0x0000FF00) >> 8;
|
||||
digest[ 2] = (A & 0x00FF0000) >> 16;
|
||||
digest[ 3] = (A & 0xFF000000) >> 24;
|
||||
digest[ 4] = (B & 0x000000FF) >> 0;
|
||||
digest[ 5] = (B & 0x0000FF00) >> 8;
|
||||
digest[ 6] = (B & 0x00FF0000) >> 16;
|
||||
digest[ 7] = (B & 0xFF000000) >> 24;
|
||||
digest[ 8] = (C & 0x000000FF) >> 0;
|
||||
digest[ 9] = (C & 0x0000FF00) >> 8;
|
||||
digest[0] = (A & 0x000000FF) >> 0;
|
||||
digest[1] = (A & 0x0000FF00) >> 8;
|
||||
digest[2] = (A & 0x00FF0000) >> 16;
|
||||
digest[3] = (A & 0xFF000000) >> 24;
|
||||
digest[4] = (B & 0x000000FF) >> 0;
|
||||
digest[5] = (B & 0x0000FF00) >> 8;
|
||||
digest[6] = (B & 0x00FF0000) >> 16;
|
||||
digest[7] = (B & 0xFF000000) >> 24;
|
||||
digest[8] = (C & 0x000000FF) >> 0;
|
||||
digest[9] = (C & 0x0000FF00) >> 8;
|
||||
digest[10] = (C & 0x00FF0000) >> 16;
|
||||
digest[11] = (C & 0xFF000000) >> 24;
|
||||
digest[12] = (D & 0x000000FF) >> 0;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -28,24 +28,23 @@
|
|||
#include "header/zone.h"
|
||||
#include <setjmp.h>
|
||||
|
||||
FILE *log_stats_file;
|
||||
cvar_t *host_speeds;
|
||||
cvar_t *log_stats;
|
||||
cvar_t *developer;
|
||||
cvar_t *modder;
|
||||
cvar_t *timescale;
|
||||
cvar_t *fixedtime;
|
||||
FILE *log_stats_file;
|
||||
cvar_t *host_speeds;
|
||||
cvar_t *log_stats;
|
||||
cvar_t *developer;
|
||||
cvar_t *modder;
|
||||
cvar_t *timescale;
|
||||
cvar_t *fixedtime;
|
||||
#ifndef DEDICATED_ONLY
|
||||
cvar_t *showtrace;
|
||||
cvar_t *showtrace;
|
||||
#endif
|
||||
cvar_t *dedicated;
|
||||
cvar_t *dedicated;
|
||||
|
||||
extern cvar_t *logfile_active;
|
||||
extern jmp_buf abortframe; /* an ERR_DROP occured, exit the entire frame */
|
||||
extern zhead_t z_chain;
|
||||
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,
|
||||
|
@ -113,44 +112,51 @@ static byte chktbl[1024] =
|
|||
};
|
||||
|
||||
/* host_speeds times */
|
||||
int time_before_game;
|
||||
int time_after_game;
|
||||
int time_before_ref;
|
||||
int time_after_ref;
|
||||
int time_before_game;
|
||||
int time_after_game;
|
||||
int time_before_ref;
|
||||
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;
|
||||
byte *p;
|
||||
byte chkb[60 + 4];
|
||||
unsigned short crc;
|
||||
byte r;
|
||||
int n;
|
||||
int x;
|
||||
byte *p;
|
||||
byte chkb[60 + 4];
|
||||
unsigned short crc;
|
||||
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);
|
||||
memcpy(chkb, base, length);
|
||||
|
||||
chkb[length] = p[0];
|
||||
chkb[length+1] = p[1];
|
||||
chkb[length+2] = p[2];
|
||||
chkb[length+3] = p[3];
|
||||
chkb[length + 1] = p[1];
|
||||
chkb[length + 2] = p[2];
|
||||
chkb[length + 3] = p[3];
|
||||
|
||||
length += 4;
|
||||
|
||||
crc = CRC_Block(chkb, length);
|
||||
|
||||
for (x=0, n=0; n<length; n++)
|
||||
for (x = 0, n = 0; n < length; n++)
|
||||
{
|
||||
x += chkb[n];
|
||||
}
|
||||
|
||||
r = (crc ^ x) & 0xff;
|
||||
|
||||
|
@ -158,219 +164,234 @@ byte COM_BlockSequenceCRCByte (byte *base, int length, int sequence)
|
|||
}
|
||||
|
||||
#ifndef DEDICATED_ONLY
|
||||
void Key_Init (void);
|
||||
void SCR_EndLoadingPlaque (void);
|
||||
void Key_Init(void);
|
||||
void SCR_EndLoadingPlaque(void);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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));
|
||||
Com_Error(ERR_FATAL, "%s", Cmd_Argv(1));
|
||||
}
|
||||
|
||||
void Qcommon_Init (int argc, char **argv)
|
||||
void
|
||||
Qcommon_Init(int argc, char **argv)
|
||||
{
|
||||
char *s;
|
||||
char *s;
|
||||
|
||||
if (setjmp (abortframe) )
|
||||
Sys_Error ("Error during initialization");
|
||||
if (setjmp(abortframe))
|
||||
{
|
||||
Sys_Error("Error during initialization");
|
||||
}
|
||||
|
||||
z_chain.next = z_chain.prev = &z_chain;
|
||||
|
||||
/* prepare enough of the subsystems to handle
|
||||
cvar and command buffer management */
|
||||
COM_InitArgv (argc, argv);
|
||||
COM_InitArgv(argc, argv);
|
||||
|
||||
Swap_Init ();
|
||||
Cbuf_Init ();
|
||||
Swap_Init();
|
||||
Cbuf_Init();
|
||||
|
||||
Cmd_Init ();
|
||||
Cvar_Init ();
|
||||
Cmd_Init();
|
||||
Cvar_Init();
|
||||
|
||||
#ifndef DEDICATED_ONLY
|
||||
Key_Init ();
|
||||
Key_Init();
|
||||
#endif
|
||||
|
||||
/* we need to add the early commands twice, because
|
||||
a basedir or cddir needs to be set before execing
|
||||
config files, but we want other parms to override
|
||||
the settings of the config files */
|
||||
Cbuf_AddEarlyCommands (false);
|
||||
Cbuf_Execute ();
|
||||
Cbuf_AddEarlyCommands(false);
|
||||
Cbuf_Execute();
|
||||
|
||||
FS_InitFilesystem ();
|
||||
FS_InitFilesystem();
|
||||
|
||||
Cbuf_AddText ("exec default.cfg\n");
|
||||
Cbuf_AddText ("exec yq2.cfg\n");
|
||||
Cbuf_AddText ("exec config.cfg\n");
|
||||
Cbuf_AddText("exec default.cfg\n");
|
||||
Cbuf_AddText("exec yq2.cfg\n");
|
||||
Cbuf_AddText("exec config.cfg\n");
|
||||
|
||||
Cbuf_AddEarlyCommands (true);
|
||||
Cbuf_Execute ();
|
||||
Cbuf_AddEarlyCommands(true);
|
||||
Cbuf_Execute();
|
||||
|
||||
/* init commands and vars */
|
||||
Cmd_AddCommand ("z_stats", Z_Stats_f);
|
||||
Cmd_AddCommand ("error", Com_Error_f);
|
||||
Cmd_AddCommand("z_stats", Z_Stats_f);
|
||||
Cmd_AddCommand("error", Com_Error_f);
|
||||
|
||||
host_speeds = Cvar_Get ("host_speeds", "0", 0);
|
||||
log_stats = Cvar_Get ("log_stats", "0", 0);
|
||||
developer = Cvar_Get ("developer", "0", 0);
|
||||
modder = Cvar_Get ("modder", "0", 0);
|
||||
timescale = Cvar_Get ("timescale", "1", 0);
|
||||
fixedtime = Cvar_Get ("fixedtime", "0", 0);
|
||||
logfile_active = Cvar_Get ("logfile", "1", CVAR_ARCHIVE);
|
||||
host_speeds = Cvar_Get("host_speeds", "0", 0);
|
||||
log_stats = Cvar_Get("log_stats", "0", 0);
|
||||
developer = Cvar_Get("developer", "0", 0);
|
||||
modder = Cvar_Get("modder", "0", 0);
|
||||
timescale = Cvar_Get("timescale", "1", 0);
|
||||
fixedtime = Cvar_Get("fixedtime", "0", 0);
|
||||
logfile_active = Cvar_Get("logfile", "1", CVAR_ARCHIVE);
|
||||
#ifndef DEDICATED_ONLY
|
||||
showtrace = Cvar_Get ("showtrace", "0", 0);
|
||||
showtrace = Cvar_Get("showtrace", "0", 0);
|
||||
#endif
|
||||
|
||||
#ifdef DEDICATED_ONLY
|
||||
dedicated = Cvar_Get ("dedicated", "1", CVAR_NOSET);
|
||||
dedicated = Cvar_Get("dedicated", "1", CVAR_NOSET);
|
||||
#else
|
||||
dedicated = Cvar_Get ("dedicated", "0", CVAR_NOSET);
|
||||
dedicated = Cvar_Get("dedicated", "0", CVAR_NOSET);
|
||||
#endif
|
||||
|
||||
s = va("%4.2f %s %s %s", VERSION, CPUSTRING, __DATE__, BUILDSTRING);
|
||||
Cvar_Get ("version", s, CVAR_SERVERINFO|CVAR_NOSET);
|
||||
Cvar_Get("version", s, CVAR_SERVERINFO | CVAR_NOSET);
|
||||
|
||||
if (dedicated->value)
|
||||
Cmd_AddCommand ("quit", Com_Quit);
|
||||
{
|
||||
Cmd_AddCommand("quit", Com_Quit);
|
||||
}
|
||||
|
||||
Sys_Init();
|
||||
NET_Init();
|
||||
Netchan_Init ();
|
||||
SV_Init ();
|
||||
Netchan_Init();
|
||||
SV_Init();
|
||||
#ifndef DEDICATED_ONLY
|
||||
CL_Init ();
|
||||
CL_Init();
|
||||
#endif
|
||||
|
||||
/* add + commands from command line */
|
||||
if (!Cbuf_AddLateCommands ())
|
||||
if (!Cbuf_AddLateCommands())
|
||||
{
|
||||
/* if the user didn't give any commands, run default action */
|
||||
if (!dedicated->value)
|
||||
Cbuf_AddText ("d1\n");
|
||||
|
||||
{
|
||||
Cbuf_AddText("d1\n");
|
||||
}
|
||||
else
|
||||
Cbuf_AddText ("dedicated_start\n");
|
||||
{
|
||||
Cbuf_AddText("dedicated_start\n");
|
||||
}
|
||||
|
||||
Cbuf_Execute ();
|
||||
Cbuf_Execute();
|
||||
}
|
||||
|
||||
#ifndef DEDICATED_ONLY
|
||||
|
||||
else
|
||||
{
|
||||
/* the user asked for something explicit
|
||||
so drop the loading plaque */
|
||||
SCR_EndLoadingPlaque ();
|
||||
SCR_EndLoadingPlaque();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Com_Printf ("==== Yamagi Quake II Initialized ====\n\n");
|
||||
Com_Printf ("*************************************\n\n");
|
||||
Com_Printf("==== Yamagi Quake II Initialized ====\n\n");
|
||||
Com_Printf("*************************************\n\n");
|
||||
}
|
||||
|
||||
void Qcommon_Frame (int msec)
|
||||
void
|
||||
Qcommon_Frame(int msec)
|
||||
{
|
||||
char *s;
|
||||
char *s;
|
||||
|
||||
#ifndef DEDICATED_ONLY
|
||||
int time_before = 0;
|
||||
int time_between = 0;
|
||||
int time_after;
|
||||
int time_before = 0;
|
||||
int time_between = 0;
|
||||
int time_after;
|
||||
#endif
|
||||
|
||||
if (setjmp (abortframe) )
|
||||
if (setjmp(abortframe))
|
||||
{
|
||||
return; /* an ERR_DROP was thrown */
|
||||
}
|
||||
|
||||
if ( log_stats->modified )
|
||||
if (log_stats->modified)
|
||||
{
|
||||
log_stats->modified = false;
|
||||
|
||||
if ( log_stats->value )
|
||||
if (log_stats->value)
|
||||
{
|
||||
if ( log_stats_file )
|
||||
if (log_stats_file)
|
||||
{
|
||||
fclose( log_stats_file );
|
||||
fclose(log_stats_file);
|
||||
log_stats_file = 0;
|
||||
}
|
||||
|
||||
log_stats_file = fopen( "stats.log", "w" );
|
||||
log_stats_file = fopen("stats.log", "w");
|
||||
|
||||
if ( log_stats_file )
|
||||
fprintf( log_stats_file, "entities,dlights,parts,frame time\n" );
|
||||
if (log_stats_file)
|
||||
{
|
||||
fprintf(log_stats_file, "entities,dlights,parts,frame time\n");
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if ( log_stats_file )
|
||||
if (log_stats_file)
|
||||
{
|
||||
fclose( log_stats_file );
|
||||
fclose(log_stats_file);
|
||||
log_stats_file = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
extern int c_pointcontents;
|
||||
extern int c_traces, c_brush_traces;
|
||||
extern int c_pointcontents;
|
||||
|
||||
Com_Printf ("%4i traces %4i points\n", c_traces, c_pointcontents);
|
||||
Com_Printf("%4i traces %4i points\n", c_traces, c_pointcontents);
|
||||
c_traces = 0;
|
||||
c_brush_traces = 0;
|
||||
c_pointcontents = 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
do
|
||||
{
|
||||
s = Sys_ConsoleInput ();
|
||||
s = Sys_ConsoleInput();
|
||||
|
||||
if (s)
|
||||
Cbuf_AddText (va("%s\n",s));
|
||||
{
|
||||
Cbuf_AddText(va("%s\n", s));
|
||||
}
|
||||
}
|
||||
while (s);
|
||||
|
||||
Cbuf_Execute ();
|
||||
Cbuf_Execute();
|
||||
|
||||
#ifndef DEDICATED_ONLY
|
||||
|
||||
if (host_speeds->value)
|
||||
time_before = Sys_Milliseconds ();
|
||||
|
||||
{
|
||||
time_before = Sys_Milliseconds();
|
||||
}
|
||||
#endif
|
||||
|
||||
SV_Frame (msec);
|
||||
SV_Frame(msec);
|
||||
|
||||
#ifndef DEDICATED_ONLY
|
||||
|
||||
if (host_speeds->value)
|
||||
time_between = Sys_Milliseconds ();
|
||||
{
|
||||
time_between = Sys_Milliseconds();
|
||||
}
|
||||
|
||||
CL_Frame (msec);
|
||||
CL_Frame(msec);
|
||||
|
||||
if (host_speeds->value)
|
||||
{
|
||||
int all, sv, gm, cl, rf;
|
||||
int all, sv, gm, cl, rf;
|
||||
|
||||
time_after = Sys_Milliseconds ();
|
||||
time_after = Sys_Milliseconds();
|
||||
all = time_after - time_before;
|
||||
sv = time_between - time_before;
|
||||
cl = time_after - time_between;
|
||||
|
@ -378,13 +399,14 @@ void Qcommon_Frame (int msec)
|
|||
rf = time_after_ref - time_before_ref;
|
||||
sv -= gm;
|
||||
cl -= rf;
|
||||
Com_Printf ("all:%3i sv:%3i gm:%3i cl:%3i rf:%3i\n",
|
||||
all, sv, gm, cl, rf);
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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,166 +191,213 @@ 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;
|
||||
byte *buf;
|
||||
|
||||
buf = SZ_GetSpace (sb, 1);
|
||||
buf = SZ_GetSpace(sb, 1);
|
||||
buf[0] = c;
|
||||
}
|
||||
|
||||
void MSG_WriteByte (sizebuf_t *sb, int c)
|
||||
void
|
||||
MSG_WriteByte(sizebuf_t *sb, int c)
|
||||
{
|
||||
byte *buf;
|
||||
byte *buf;
|
||||
|
||||
buf = SZ_GetSpace (sb, 1);
|
||||
buf = SZ_GetSpace(sb, 1);
|
||||
buf[0] = c;
|
||||
}
|
||||
|
||||
void MSG_WriteShort (sizebuf_t *sb, int c)
|
||||
void
|
||||
MSG_WriteShort(sizebuf_t *sb, int c)
|
||||
{
|
||||
byte *buf;
|
||||
byte *buf;
|
||||
|
||||
buf = SZ_GetSpace (sb, 2);
|
||||
buf[0] = c&0xff;
|
||||
buf[1] = c>>8;
|
||||
buf = SZ_GetSpace(sb, 2);
|
||||
buf[0] = c & 0xff;
|
||||
buf[1] = c >> 8;
|
||||
}
|
||||
|
||||
void MSG_WriteLong (sizebuf_t *sb, int c)
|
||||
void
|
||||
MSG_WriteLong(sizebuf_t *sb, int c)
|
||||
{
|
||||
byte *buf;
|
||||
byte *buf;
|
||||
|
||||
buf = SZ_GetSpace (sb, 4);
|
||||
buf[0] = c&0xff;
|
||||
buf[1] = (c>>8)&0xff;
|
||||
buf[2] = (c>>16)&0xff;
|
||||
buf[3] = c>>24;
|
||||
buf = SZ_GetSpace(sb, 4);
|
||||
buf[0] = c & 0xff;
|
||||
buf[1] = (c >> 8) & 0xff;
|
||||
buf[2] = (c >> 16) & 0xff;
|
||||
buf[3] = c >> 24;
|
||||
}
|
||||
|
||||
void MSG_WriteFloat (sizebuf_t *sb, float f)
|
||||
void
|
||||
MSG_WriteFloat(sizebuf_t *sb, float f)
|
||||
{
|
||||
union
|
||||
{
|
||||
float f;
|
||||
int l;
|
||||
float f;
|
||||
int l;
|
||||
} dat;
|
||||
|
||||
|
||||
dat.f = f;
|
||||
dat.l = LittleLong (dat.l);
|
||||
dat.l = LittleLong(dat.l);
|
||||
|
||||
SZ_Write (sb, &dat.l, 4);
|
||||
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);
|
||||
{
|
||||
SZ_Write(sb, "", 1);
|
||||
}
|
||||
|
||||
else
|
||||
SZ_Write (sb, s, (int)strlen(s)+1);
|
||||
{
|
||||
SZ_Write(sb, s, (int)strlen(s) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
void MSG_WriteCoord (sizebuf_t *sb, float f)
|
||||
void
|
||||
MSG_WriteCoord(sizebuf_t *sb, float f)
|
||||
{
|
||||
MSG_WriteShort (sb, (int)(f*8));
|
||||
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));
|
||||
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);
|
||||
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));
|
||||
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;
|
||||
int bits;
|
||||
|
||||
/* Movement messages */
|
||||
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);
|
||||
MSG_WriteByte(buf, bits);
|
||||
|
||||
if (bits & CM_ANGLE1)
|
||||
MSG_WriteShort (buf, cmd->angles[0]);
|
||||
{
|
||||
MSG_WriteShort(buf, cmd->angles[0]);
|
||||
}
|
||||
|
||||
if (bits & CM_ANGLE2)
|
||||
MSG_WriteShort (buf, cmd->angles[1]);
|
||||
{
|
||||
MSG_WriteShort(buf, cmd->angles[1]);
|
||||
}
|
||||
|
||||
if (bits & CM_ANGLE3)
|
||||
MSG_WriteShort (buf, cmd->angles[2]);
|
||||
{
|
||||
MSG_WriteShort(buf, cmd->angles[2]);
|
||||
}
|
||||
|
||||
if (bits & CM_FORWARD)
|
||||
MSG_WriteShort (buf, cmd->forwardmove);
|
||||
{
|
||||
MSG_WriteShort(buf, cmd->forwardmove);
|
||||
}
|
||||
|
||||
if (bits & CM_SIDE)
|
||||
MSG_WriteShort (buf, cmd->sidemove);
|
||||
{
|
||||
MSG_WriteShort(buf, cmd->sidemove);
|
||||
}
|
||||
|
||||
if (bits & CM_UP)
|
||||
MSG_WriteShort (buf, cmd->upmove);
|
||||
{
|
||||
MSG_WriteShort(buf, cmd->upmove);
|
||||
}
|
||||
|
||||
if (bits & CM_BUTTONS)
|
||||
MSG_WriteByte (buf, cmd->buttons);
|
||||
{
|
||||
MSG_WriteByte(buf, cmd->buttons);
|
||||
}
|
||||
|
||||
if (bits & CM_IMPULSE)
|
||||
MSG_WriteByte (buf, cmd->impulse);
|
||||
{
|
||||
MSG_WriteByte(buf, cmd->impulse);
|
||||
}
|
||||
|
||||
MSG_WriteByte (buf, cmd->msec);
|
||||
MSG_WriteByte (buf, cmd->lightlevel);
|
||||
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;
|
||||
int i, best;
|
||||
float d, bestd;
|
||||
|
||||
if (!dir)
|
||||
{
|
||||
MSG_WriteByte (sb, 0);
|
||||
MSG_WriteByte(sb, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
bestd = 0;
|
||||
best = 0;
|
||||
|
||||
for (i=0 ; i<NUMVERTEXNORMALS ; i++)
|
||||
for (i = 0; i < NUMVERTEXNORMALS; i++)
|
||||
{
|
||||
d = DotProduct (dir, bytedirs[i]);
|
||||
d = DotProduct(dir, bytedirs[i]);
|
||||
|
||||
if (d > bestd)
|
||||
{
|
||||
|
@ -360,244 +406,639 @@ void MSG_WriteDir (sizebuf_t *sb, vec3_t dir)
|
|||
}
|
||||
}
|
||||
|
||||
MSG_WriteByte (sb, best);
|
||||
MSG_WriteByte(sb, best);
|
||||
}
|
||||
|
||||
void MSG_ReadDir (sizebuf_t *sb, vec3_t dir)
|
||||
void
|
||||
MSG_ReadDir(sizebuf_t *sb, vec3_t dir)
|
||||
{
|
||||
int b;
|
||||
int b;
|
||||
|
||||
b = MSG_ReadByte (sb);
|
||||
b = MSG_ReadByte(sb);
|
||||
|
||||
if (b >= NUMVERTEXNORMALS)
|
||||
Com_Error (ERR_DROP, "MSF_ReadDir: out of range");
|
||||
{
|
||||
Com_Error(ERR_DROP, "MSF_ReadDir: out of range");
|
||||
}
|
||||
|
||||
VectorCopy (bytedirs[b], dir);
|
||||
VectorCopy(bytedirs[b], 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;
|
||||
int bits;
|
||||
|
||||
if (!to->number)
|
||||
Com_Error (ERR_FATAL, "Unset entity number");
|
||||
{
|
||||
Com_Error(ERR_FATAL, "Unset entity number");
|
||||
}
|
||||
|
||||
if (to->number >= MAX_EDICTS)
|
||||
Com_Error (ERR_FATAL, "Entity 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] )
|
||||
if (to->angles[0] != from->angles[0])
|
||||
{
|
||||
bits |= U_ANGLE1;
|
||||
}
|
||||
|
||||
if ( to->angles[1] != from->angles[1] )
|
||||
if (to->angles[1] != from->angles[1])
|
||||
{
|
||||
bits |= U_ANGLE2;
|
||||
}
|
||||
|
||||
if ( to->angles[2] != from->angles[2] )
|
||||
if (to->angles[2] != from->angles[2])
|
||||
{
|
||||
bits |= U_ANGLE3;
|
||||
}
|
||||
|
||||
if ( to->skinnum != from->skinnum )
|
||||
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);
|
||||
{
|
||||
bits |= (U_SKIN8 | U_SKIN16);
|
||||
}
|
||||
}
|
||||
|
||||
if ( to->frame != from->frame )
|
||||
if (to->frame != from->frame)
|
||||
{
|
||||
if (to->frame < 256)
|
||||
{
|
||||
bits |= U_FRAME8;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
bits |= U_FRAME16;
|
||||
}
|
||||
}
|
||||
|
||||
if ( to->effects != from->effects )
|
||||
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;
|
||||
{
|
||||
bits |= U_EFFECTS8 | U_EFFECTS16;
|
||||
}
|
||||
}
|
||||
|
||||
if ( to->renderfx != from->renderfx )
|
||||
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;
|
||||
{
|
||||
bits |= U_RENDERFX8 | U_RENDERFX16;
|
||||
}
|
||||
}
|
||||
|
||||
if ( to->solid != from->solid )
|
||||
if (to->solid != from->solid)
|
||||
{
|
||||
bits |= U_SOLID;
|
||||
}
|
||||
|
||||
/* event is not delta compressed, just 0 compressed */
|
||||
if ( to->event )
|
||||
if (to->event)
|
||||
{
|
||||
bits |= U_EVENT;
|
||||
}
|
||||
|
||||
if ( to->modelindex != from->modelindex )
|
||||
if (to->modelindex != from->modelindex)
|
||||
{
|
||||
bits |= U_MODEL;
|
||||
}
|
||||
|
||||
if ( to->modelindex2 != from->modelindex2 )
|
||||
if (to->modelindex2 != from->modelindex2)
|
||||
{
|
||||
bits |= U_MODEL2;
|
||||
}
|
||||
|
||||
if ( to->modelindex3 != from->modelindex3 )
|
||||
if (to->modelindex3 != from->modelindex3)
|
||||
{
|
||||
bits |= U_MODEL3;
|
||||
}
|
||||
|
||||
if ( to->modelindex4 != from->modelindex4 )
|
||||
if (to->modelindex4 != from->modelindex4)
|
||||
{
|
||||
bits |= U_MODEL4;
|
||||
}
|
||||
|
||||
if ( to->sound != from->sound )
|
||||
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 );
|
||||
MSG_WriteByte(msg, bits & 255);
|
||||
|
||||
if (bits & 0xff000000)
|
||||
{
|
||||
MSG_WriteByte (msg, (bits>>8)&255 );
|
||||
MSG_WriteByte (msg, (bits>>16)&255 );
|
||||
MSG_WriteByte (msg, (bits>>24)&255 );
|
||||
MSG_WriteByte(msg, (bits >> 8) & 255);
|
||||
MSG_WriteByte(msg, (bits >> 16) & 255);
|
||||
MSG_WriteByte(msg, (bits >> 24) & 255);
|
||||
}
|
||||
|
||||
else if (bits & 0x00ff0000)
|
||||
{
|
||||
MSG_WriteByte (msg, (bits>>8)&255 );
|
||||
MSG_WriteByte (msg, (bits>>16)&255 );
|
||||
MSG_WriteByte(msg, (bits >> 8) & 255);
|
||||
MSG_WriteByte(msg, (bits >> 16) & 255);
|
||||
}
|
||||
|
||||
else if (bits & 0x0000ff00)
|
||||
{
|
||||
MSG_WriteByte (msg, (bits>>8)&255 );
|
||||
MSG_WriteByte(msg, (bits >> 8) & 255);
|
||||
}
|
||||
|
||||
if (bits & U_NUMBER16)
|
||||
MSG_WriteShort (msg, to->number);
|
||||
{
|
||||
MSG_WriteShort(msg, to->number);
|
||||
}
|
||||
|
||||
else
|
||||
MSG_WriteByte (msg, to->number);
|
||||
{
|
||||
MSG_WriteByte(msg, to->number);
|
||||
}
|
||||
|
||||
if (bits & U_MODEL)
|
||||
MSG_WriteByte (msg, to->modelindex);
|
||||
{
|
||||
MSG_WriteByte(msg, to->modelindex);
|
||||
}
|
||||
|
||||
if (bits & U_MODEL2)
|
||||
MSG_WriteByte (msg, to->modelindex2);
|
||||
{
|
||||
MSG_WriteByte(msg, to->modelindex2);
|
||||
}
|
||||
|
||||
if (bits & U_MODEL3)
|
||||
MSG_WriteByte (msg, to->modelindex3);
|
||||
{
|
||||
MSG_WriteByte(msg, to->modelindex3);
|
||||
}
|
||||
|
||||
if (bits & U_MODEL4)
|
||||
MSG_WriteByte (msg, to->modelindex4);
|
||||
{
|
||||
MSG_WriteByte(msg, to->modelindex4);
|
||||
}
|
||||
|
||||
if (bits & U_FRAME8)
|
||||
MSG_WriteByte (msg, to->frame);
|
||||
{
|
||||
MSG_WriteByte(msg, to->frame);
|
||||
}
|
||||
|
||||
if (bits & U_FRAME16)
|
||||
MSG_WriteShort (msg, to->frame);
|
||||
{
|
||||
MSG_WriteShort(msg, to->frame);
|
||||
}
|
||||
|
||||
if ((bits & U_SKIN8) && (bits & U_SKIN16)) /*used for laser colors */
|
||||
MSG_WriteLong (msg, to->skinnum);
|
||||
{
|
||||
MSG_WriteLong(msg, to->skinnum);
|
||||
}
|
||||
|
||||
else if (bits & U_SKIN8)
|
||||
MSG_WriteByte (msg, to->skinnum);
|
||||
{
|
||||
MSG_WriteByte(msg, to->skinnum);
|
||||
}
|
||||
|
||||
else if (bits & U_SKIN16)
|
||||
MSG_WriteShort (msg, to->skinnum);
|
||||
{
|
||||
MSG_WriteShort(msg, to->skinnum);
|
||||
}
|
||||
|
||||
if ( (bits & (U_EFFECTS8|U_EFFECTS16)) == (U_EFFECTS8|U_EFFECTS16) )
|
||||
MSG_WriteLong (msg, to->effects);
|
||||
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);
|
||||
{
|
||||
MSG_WriteByte(msg, to->effects);
|
||||
}
|
||||
|
||||
else if (bits & U_EFFECTS16)
|
||||
MSG_WriteShort (msg, to->effects);
|
||||
{
|
||||
MSG_WriteShort(msg, to->effects);
|
||||
}
|
||||
|
||||
if ( (bits & (U_RENDERFX8|U_RENDERFX16)) == (U_RENDERFX8|U_RENDERFX16) )
|
||||
MSG_WriteLong (msg, to->renderfx);
|
||||
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);
|
||||
{
|
||||
MSG_WriteByte(msg, to->renderfx);
|
||||
}
|
||||
|
||||
else if (bits & U_RENDERFX16)
|
||||
MSG_WriteShort (msg, to->renderfx);
|
||||
{
|
||||
MSG_WriteShort(msg, to->renderfx);
|
||||
}
|
||||
|
||||
if (bits & U_ORIGIN1)
|
||||
MSG_WriteCoord (msg, to->origin[0]);
|
||||
{
|
||||
MSG_WriteCoord(msg, to->origin[0]);
|
||||
}
|
||||
|
||||
if (bits & U_ORIGIN2)
|
||||
MSG_WriteCoord (msg, to->origin[1]);
|
||||
{
|
||||
MSG_WriteCoord(msg, to->origin[1]);
|
||||
}
|
||||
|
||||
if (bits & U_ORIGIN3)
|
||||
MSG_WriteCoord (msg, to->origin[2]);
|
||||
{
|
||||
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)
|
||||
{
|
||||
MSG_WriteCoord (msg, to->old_origin[0]);
|
||||
MSG_WriteCoord (msg, to->old_origin[1]);
|
||||
MSG_WriteCoord (msg, to->old_origin[2]);
|
||||
MSG_WriteCoord(msg, to->old_origin[0]);
|
||||
MSG_WriteCoord(msg, to->old_origin[1]);
|
||||
MSG_WriteCoord(msg, to->old_origin[2]);
|
||||
}
|
||||
|
||||
if (bits & U_SOUND)
|
||||
MSG_WriteByte (msg, to->sound);
|
||||
{
|
||||
MSG_WriteByte(msg, to->sound);
|
||||
}
|
||||
|
||||
if (bits & U_EVENT)
|
||||
MSG_WriteByte (msg, to->event);
|
||||
{
|
||||
MSG_WriteByte(msg, to->event);
|
||||
}
|
||||
|
||||
if (bits & U_SOLID)
|
||||
MSG_WriteShort (msg, to->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);
|
||||
}
|
||||
}
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
*
|
||||
* =======================================================================
|
||||
*
|
||||
* The low level network code
|
||||
* The low level, platform independant network code
|
||||
*
|
||||
* =======================================================================
|
||||
*/
|
||||
|
@ -81,65 +81,69 @@
|
|||
* something in the unacknowledged reliable
|
||||
*/
|
||||
|
||||
cvar_t *showpackets;
|
||||
cvar_t *showdrop;
|
||||
cvar_t *qport;
|
||||
cvar_t *showpackets;
|
||||
cvar_t *showdrop;
|
||||
cvar_t *qport;
|
||||
|
||||
netadr_t net_from;
|
||||
sizebuf_t net_message;
|
||||
byte net_message_buffer[MAX_MSGLEN];
|
||||
netadr_t net_from;
|
||||
sizebuf_t net_message;
|
||||
byte net_message_buffer[MAX_MSGLEN];
|
||||
|
||||
void Netchan_Init (void)
|
||||
void
|
||||
Netchan_Init(void)
|
||||
{
|
||||
int port;
|
||||
int port;
|
||||
|
||||
/* pick a port value that should be nice and random */
|
||||
port = Sys_Milliseconds() & 0xffff;
|
||||
|
||||
showpackets = Cvar_Get ("showpackets", "0", 0);
|
||||
showdrop = Cvar_Get ("showdrop", "0", 0);
|
||||
qport = Cvar_Get ("qport", va("%i", port), CVAR_NOSET);
|
||||
showpackets = Cvar_Get("showpackets", "0", 0);
|
||||
showdrop = Cvar_Get("showdrop", "0", 0);
|
||||
qport = Cvar_Get("qport", va("%i", port), CVAR_NOSET);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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];
|
||||
sizebuf_t send;
|
||||
byte send_buf[MAX_MSGLEN];
|
||||
|
||||
/* write the packet header */
|
||||
SZ_Init (&send, send_buf, sizeof(send_buf));
|
||||
SZ_Init(&send, send_buf, sizeof(send_buf));
|
||||
|
||||
MSG_WriteLong (&send, -1); /* -1 sequence means out of band */
|
||||
SZ_Write (&send, data, length);
|
||||
MSG_WriteLong(&send, -1); /* -1 sequence means out of band */
|
||||
SZ_Write(&send, data, length);
|
||||
|
||||
/* send the datagram */
|
||||
NET_SendPacket (net_socket, send.cursize, send.data, adr);
|
||||
NET_SendPacket(net_socket, send.cursize, send.data, adr);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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];
|
||||
va_list argptr;
|
||||
static char string[MAX_MSGLEN - 4];
|
||||
|
||||
va_start (argptr, format);
|
||||
vsnprintf (string, MAX_MSGLEN - 4, format, argptr);
|
||||
va_end (argptr);
|
||||
va_start(argptr, format);
|
||||
vsnprintf(string, MAX_MSGLEN - 4, format, argptr);
|
||||
va_end(argptr);
|
||||
|
||||
Netchan_OutOfBand (net_socket, adr, strlen(string), (byte *)string);
|
||||
Netchan_OutOfBand(net_socket, adr, strlen(string), (byte *)string);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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));
|
||||
memset(chan, 0, sizeof(*chan));
|
||||
|
||||
chan->sock = sock;
|
||||
chan->remote_address = adr;
|
||||
|
@ -148,31 +152,37 @@ void Netchan_Setup (netsrc_t sock, netchan_t *chan, netadr_t adr, int qport)
|
|||
chan->incoming_sequence = 0;
|
||||
chan->outgoing_sequence = 1;
|
||||
|
||||
SZ_Init (&chan->message, chan->message_buf, sizeof(chan->message_buf));
|
||||
SZ_Init(&chan->message, chan->message_buf, sizeof(chan->message_buf));
|
||||
chan->message.allowoverflow = true;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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;
|
||||
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,79 +199,89 @@ 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];
|
||||
qboolean send_reliable;
|
||||
unsigned w1, w2;
|
||||
sizebuf_t send;
|
||||
byte send_buf[MAX_MSGLEN];
|
||||
qboolean send_reliable;
|
||||
unsigned w1, w2;
|
||||
|
||||
/* check for message overflow */
|
||||
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;
|
||||
}
|
||||
|
||||
send_reliable = Netchan_NeedReliable (chan);
|
||||
send_reliable = Netchan_NeedReliable(chan);
|
||||
|
||||
if (!chan->reliable_length && chan->message.cursize)
|
||||
{
|
||||
memcpy (chan->reliable_buf, chan->message_buf, chan->message.cursize);
|
||||
memcpy(chan->reliable_buf, chan->message_buf, chan->message.cursize);
|
||||
chan->reliable_length = chan->message.cursize;
|
||||
chan->message.cursize = 0;
|
||||
chan->reliable_sequence ^= 1;
|
||||
}
|
||||
|
||||
/* write the packet header */
|
||||
SZ_Init (&send, send_buf, sizeof(send_buf));
|
||||
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);
|
||||
w1 = (chan->outgoing_sequence & ~(1 << 31)) | (send_reliable << 31);
|
||||
w2 =
|
||||
(chan->incoming_sequence &
|
||||
~(1 << 31)) | (chan->incoming_reliable_sequence << 31);
|
||||
|
||||
chan->outgoing_sequence++;
|
||||
chan->last_sent = curtime;
|
||||
|
||||
MSG_WriteLong (&send, w1);
|
||||
MSG_WriteLong (&send, w2);
|
||||
MSG_WriteLong(&send, w1);
|
||||
MSG_WriteLong(&send, w2);
|
||||
|
||||
/* send the qport if we are a client */
|
||||
if (chan->sock == NS_CLIENT)
|
||||
MSG_WriteShort (&send, qport->value);
|
||||
{
|
||||
MSG_WriteShort(&send, qport->value);
|
||||
}
|
||||
|
||||
/* copy the reliable message to the packet first */
|
||||
if (send_reliable)
|
||||
{
|
||||
SZ_Write (&send, chan->reliable_buf, chan->reliable_length);
|
||||
SZ_Write(&send, chan->reliable_buf, chan->reliable_length);
|
||||
chan->last_reliable_sequence = chan->outgoing_sequence;
|
||||
}
|
||||
|
||||
/* add the unreliable part if space is available */
|
||||
if (send.maxsize - send.cursize >= length)
|
||||
SZ_Write (&send, data, length);
|
||||
{
|
||||
SZ_Write(&send, data, length);
|
||||
}
|
||||
else
|
||||
Com_Printf ("Netchan_Transmit: dumped unreliable\n");
|
||||
{
|
||||
Com_Printf("Netchan_Transmit: dumped unreliable\n");
|
||||
}
|
||||
|
||||
/* send the datagram */
|
||||
NET_SendPacket (chan->sock, send.cursize, send.data, chan->remote_address);
|
||||
NET_SendPacket(chan->sock, send.cursize, send.data, chan->remote_address);
|
||||
|
||||
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,71 +289,78 @@ 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;
|
||||
unsigned sequence, sequence_ack;
|
||||
unsigned reliable_ack, reliable_message;
|
||||
|
||||
/* get sequence numbers */
|
||||
MSG_BeginReading (msg);
|
||||
sequence = MSG_ReadLong (msg);
|
||||
sequence_ack = MSG_ReadLong (msg);
|
||||
MSG_BeginReading(msg);
|
||||
sequence = MSG_ReadLong(msg);
|
||||
sequence_ack = MSG_ReadLong(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;
|
||||
|
||||
sequence &= ~(1<<31);
|
||||
sequence_ack &= ~(1<<31);
|
||||
sequence &= ~(1 << 31);
|
||||
sequence_ack &= ~(1 << 31);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/* dropped packets don't keep the message from being used */
|
||||
chan->dropped = sequence - (chan->incoming_sequence+1);
|
||||
chan->dropped = sequence - (chan->incoming_sequence + 1);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -26,34 +26,42 @@
|
|||
|
||||
#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));
|
||||
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;
|
||||
void *data;
|
||||
|
||||
if (buf->cursize + length > buf->maxsize)
|
||||
{
|
||||
if (!buf->allowoverflow)
|
||||
Com_Error (ERR_FATAL, "SZ_GetSpace: overflow without allowoverflow set");
|
||||
{
|
||||
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);
|
||||
SZ_Clear(buf);
|
||||
buf->overflowed = true;
|
||||
Com_Printf ("SZ_GetSpace: overflow\n");
|
||||
Com_Printf("SZ_GetSpace: overflow\n");
|
||||
}
|
||||
|
||||
data = buf->data + buf->cursize;
|
||||
|
@ -62,26 +70,33 @@ 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);
|
||||
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;
|
||||
int len;
|
||||
|
||||
len = (int)strlen(data)+1;
|
||||
len = (int)strlen(data) + 1;
|
||||
|
||||
if (buf->cursize)
|
||||
{
|
||||
if (buf->data[buf->cursize-1])
|
||||
memcpy ((byte *)SZ_GetSpace(buf, len),data,len); /* no trailing 0 */
|
||||
|
||||
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 */
|
||||
{
|
||||
memcpy((byte *)SZ_GetSpace(buf, len - 1) - 1, data, len); /* write over trailing 0 */
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
memcpy ((byte *)SZ_GetSpace(buf, len),data,len);
|
||||
{
|
||||
memcpy((byte *)SZ_GetSpace(buf, len), data, len);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
*
|
||||
* =======================================================================
|
||||
*
|
||||
* Zone malloc. It's just a normal mallic with counter.
|
||||
* Zone malloc. It's just a normal malloc with tags.
|
||||
*
|
||||
* =======================================================================
|
||||
*/
|
||||
|
@ -29,20 +29,21 @@
|
|||
|
||||
#define Z_MAGIC 0x1d1d
|
||||
|
||||
zhead_t z_chain;
|
||||
int z_count, z_bytes;
|
||||
zhead_t z_chain;
|
||||
int z_count, z_bytes;
|
||||
|
||||
void Z_Free (void *ptr)
|
||||
void
|
||||
Z_Free(void *ptr)
|
||||
{
|
||||
zhead_t *z;
|
||||
zhead_t *z;
|
||||
|
||||
z = ((zhead_t *)ptr) - 1;
|
||||
|
||||
if (z->magic != Z_MAGIC)
|
||||
{
|
||||
printf( "free: %p failed\n", ptr );
|
||||
printf("free: %p failed\n", ptr);
|
||||
abort();
|
||||
Com_Error (ERR_FATAL, "Z_Free: bad magic");
|
||||
Com_Error(ERR_FATAL, "Z_Free: bad magic");
|
||||
}
|
||||
|
||||
z->prev->next = z->next;
|
||||
|
@ -50,38 +51,45 @@ void Z_Free (void *ptr)
|
|||
|
||||
z_count--;
|
||||
z_bytes -= z->size;
|
||||
free (z);
|
||||
free(z);
|
||||
}
|
||||
|
||||
void Z_Stats_f (void)
|
||||
void
|
||||
Z_Stats_f(void)
|
||||
{
|
||||
Com_Printf ("%i bytes in %i blocks\n", z_bytes, z_count);
|
||||
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;
|
||||
zhead_t *z, *next;
|
||||
|
||||
for (z=z_chain.next ; z != &z_chain ; z=next)
|
||||
for (z = z_chain.next; z != &z_chain; z = next)
|
||||
{
|
||||
next = z->next;
|
||||
|
||||
if (z->tag == tag)
|
||||
Z_Free ((void *)(z+1));
|
||||
{
|
||||
Z_Free((void *)(z + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void *Z_TagMalloc (int size, int tag)
|
||||
void *
|
||||
Z_TagMalloc(int size, int tag)
|
||||
{
|
||||
zhead_t *z;
|
||||
zhead_t *z;
|
||||
|
||||
size = size + sizeof(zhead_t);
|
||||
z = malloc(size);
|
||||
|
||||
if (!z)
|
||||
Com_Error (ERR_FATAL, "Z_Malloc: failed on allocation of %i bytes",size);
|
||||
{
|
||||
Com_Error(ERR_FATAL, "Z_Malloc: failed on allocation of %i bytes", size);
|
||||
}
|
||||
|
||||
memset (z, 0, size);
|
||||
memset(z, 0, size);
|
||||
z_count++;
|
||||
z_bytes += size;
|
||||
z->magic = Z_MAGIC;
|
||||
|
@ -93,10 +101,12 @@ void *Z_TagMalloc (int size, int tag)
|
|||
z_chain.next->prev = z;
|
||||
z_chain.next = z;
|
||||
|
||||
return (void *)(z+1);
|
||||
return (void *)(z + 1);
|
||||
}
|
||||
|
||||
void *Z_Malloc (int size)
|
||||
void *
|
||||
Z_Malloc(int size)
|
||||
{
|
||||
return Z_TagMalloc (size, 0);
|
||||
return Z_TagMalloc(size, 0);
|
||||
}
|
||||
|
||||
|
|
265
src/sdl/cd.c
265
src/sdl/cd.c
|
@ -30,9 +30,9 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "SDL/SDL.h"
|
||||
#include "SDL/SDL.h"
|
||||
#else
|
||||
#include "SDL.h"
|
||||
#include "SDL.h"
|
||||
#endif
|
||||
|
||||
#include "../client/header/client.h"
|
||||
|
@ -49,39 +49,39 @@ cvar_t *cd_volume;
|
|||
cvar_t *cd_nocd;
|
||||
cvar_t *cd_dev;
|
||||
|
||||
static void CD_f ();
|
||||
static void CD_f();
|
||||
|
||||
static void
|
||||
CDAudio_Eject ()
|
||||
CDAudio_Eject()
|
||||
{
|
||||
if ( !cd_id || !enabled )
|
||||
if (!cd_id || !enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( SDL_CDEject( cd_id ) )
|
||||
if (SDL_CDEject(cd_id))
|
||||
{
|
||||
Com_DPrintf( "Unable to eject CD-ROM tray.\n" );
|
||||
Com_DPrintf("Unable to eject CD-ROM tray.\n");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CDAudio_Play ( int track, qboolean looping )
|
||||
CDAudio_Play(int track, qboolean looping)
|
||||
{
|
||||
CDstatus cd_stat;
|
||||
|
||||
lastTrack = track + 1;
|
||||
|
||||
if ( !cd_id || !enabled )
|
||||
if (!cd_id || !enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
cd_stat = SDL_CDStatus( cd_id );
|
||||
cd_stat = SDL_CDStatus(cd_id);
|
||||
|
||||
if ( !cdValid )
|
||||
if (!cdValid)
|
||||
{
|
||||
if ( !CD_INDRIVE( cd_stat ) || ( !cd_id->numtracks ) )
|
||||
if (!CD_INDRIVE(cd_stat) || (!cd_id->numtracks))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -89,17 +89,17 @@ CDAudio_Play ( int track, qboolean looping )
|
|||
cdValid = true;
|
||||
}
|
||||
|
||||
if ( ( track < 1 ) || ( track >= cd_id->numtracks ) )
|
||||
if ((track < 1) || (track >= cd_id->numtracks))
|
||||
{
|
||||
Com_DPrintf( "CDAudio: Bad track number: %d\n", track );
|
||||
Com_DPrintf("CDAudio: Bad track number: %d\n", track);
|
||||
return;
|
||||
}
|
||||
|
||||
track--;
|
||||
|
||||
if ( cd_stat == CD_PLAYING )
|
||||
if (cd_stat == CD_PLAYING)
|
||||
{
|
||||
if ( cd_id->cur_track == track )
|
||||
if (cd_id->cur_track == track)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -107,10 +107,11 @@ CDAudio_Play ( int track, qboolean looping )
|
|||
CDAudio_Stop();
|
||||
}
|
||||
|
||||
if ( SDL_CDPlay( cd_id, cd_id->track [ track ].offset,
|
||||
cd_id->track [ track ].length ) )
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -118,35 +119,35 @@ CDAudio_Play ( int track, qboolean looping )
|
|||
}
|
||||
|
||||
void
|
||||
CDAudio_RandomPlay ( void )
|
||||
CDAudio_RandomPlay(void)
|
||||
{
|
||||
int track, i = 0, free_tracks = 0;
|
||||
float f;
|
||||
CDstatus cd_stat;
|
||||
byte *track_bools;
|
||||
|
||||
if ( !cd_id || !enabled )
|
||||
if (!cd_id || !enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
track_bools = (byte *) malloc( cd_id->numtracks * sizeof ( byte ) );
|
||||
track_bools = (byte *)malloc(cd_id->numtracks * sizeof(byte));
|
||||
|
||||
if ( track_bools == 0 )
|
||||
if (track_bools == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* create an array of available audio tracknumbers */
|
||||
for ( ; i < cd_id->numtracks; i++ )
|
||||
for ( ; i < cd_id->numtracks; i++)
|
||||
{
|
||||
track_bools [ i ] = cd_id->track [ i ].type == SDL_AUDIO_TRACK;
|
||||
free_tracks += track_bools [ i ];
|
||||
track_bools[i] = cd_id->track[i].type == SDL_AUDIO_TRACK;
|
||||
free_tracks += track_bools[i];
|
||||
}
|
||||
|
||||
if ( !free_tracks )
|
||||
if (!free_tracks)
|
||||
{
|
||||
Com_DPrintf( "CDAudio_RandomPlay: Unable to find and play a random audio track, insert an audio cd please" );
|
||||
Com_DPrintf("CDAudio_RandomPlay: Unable to find and play a random audio track, insert an audio cd please");
|
||||
goto free_end;
|
||||
}
|
||||
|
||||
|
@ -155,18 +156,18 @@ CDAudio_RandomPlay ( void )
|
|||
{
|
||||
do
|
||||
{
|
||||
f = ( (float) randk() ) / ( (float) RAND_MAX + 1.0 );
|
||||
track = (int) ( cd_id->numtracks * f );
|
||||
f = ((float)randk()) / ((float)RAND_MAX + 1.0);
|
||||
track = (int)(cd_id->numtracks * f);
|
||||
}
|
||||
while ( !track_bools [ track ] );
|
||||
while (!track_bools[track]);
|
||||
|
||||
lastTrack = track + 1;
|
||||
|
||||
cd_stat = SDL_CDStatus( cd_id );
|
||||
cd_stat = SDL_CDStatus(cd_id);
|
||||
|
||||
if ( !cdValid )
|
||||
if (!cdValid)
|
||||
{
|
||||
if ( !CD_INDRIVE( cd_stat ) || ( !cd_id->numtracks ) )
|
||||
if (!CD_INDRIVE(cd_stat) || (!cd_id->numtracks))
|
||||
{
|
||||
goto free_end;
|
||||
}
|
||||
|
@ -174,9 +175,9 @@ CDAudio_RandomPlay ( void )
|
|||
cdValid = true;
|
||||
}
|
||||
|
||||
if ( cd_stat == CD_PLAYING )
|
||||
if (cd_stat == CD_PLAYING)
|
||||
{
|
||||
if ( cd_id->cur_track == track + 1 )
|
||||
if (cd_id->cur_track == track + 1)
|
||||
{
|
||||
goto free_end;
|
||||
}
|
||||
|
@ -184,10 +185,10 @@ CDAudio_RandomPlay ( void )
|
|||
CDAudio_Stop();
|
||||
}
|
||||
|
||||
if ( SDL_CDPlay( cd_id, cd_id->track [ track ].offset,
|
||||
cd_id->track [ track ].length ) )
|
||||
if (SDL_CDPlay(cd_id, cd_id->track[track].offset,
|
||||
cd_id->track[track].length))
|
||||
{
|
||||
track_bools [ track ] = 0;
|
||||
track_bools[track] = 0;
|
||||
free_tracks--;
|
||||
}
|
||||
else
|
||||
|
@ -196,95 +197,95 @@ CDAudio_RandomPlay ( void )
|
|||
break;
|
||||
}
|
||||
}
|
||||
while ( free_tracks > 0 );
|
||||
while (free_tracks > 0);
|
||||
|
||||
free_end:
|
||||
free( (void *) track_bools );
|
||||
free((void *)track_bools);
|
||||
}
|
||||
|
||||
void
|
||||
CDAudio_Stop ()
|
||||
CDAudio_Stop()
|
||||
{
|
||||
int cdstate;
|
||||
|
||||
if ( !cd_id || !enabled )
|
||||
if (!cd_id || !enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
cdstate = SDL_CDStatus( cd_id );
|
||||
cdstate = SDL_CDStatus(cd_id);
|
||||
|
||||
if ( ( cdstate != CD_PLAYING ) && ( cdstate != CD_PAUSED ) )
|
||||
if ((cdstate != CD_PLAYING) && (cdstate != CD_PAUSED))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( SDL_CDStop( cd_id ) )
|
||||
if (SDL_CDStop(cd_id))
|
||||
{
|
||||
Com_DPrintf( "CDAudio_Stop: Failed to stop track.\n" );
|
||||
Com_DPrintf("CDAudio_Stop: Failed to stop track.\n");
|
||||
}
|
||||
|
||||
playLooping = 0;
|
||||
}
|
||||
|
||||
void
|
||||
CDAudio_Pause ()
|
||||
CDAudio_Pause()
|
||||
{
|
||||
if ( !cd_id || !enabled )
|
||||
if (!cd_id || !enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( SDL_CDStatus( cd_id ) != CD_PLAYING )
|
||||
if (SDL_CDStatus(cd_id) != CD_PLAYING)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( SDL_CDPause( cd_id ) )
|
||||
if (SDL_CDPause(cd_id))
|
||||
{
|
||||
Com_DPrintf( "CDAudio_Pause: Failed to pause track.\n" );
|
||||
Com_DPrintf("CDAudio_Pause: Failed to pause track.\n");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CDAudio_Resume ()
|
||||
CDAudio_Resume()
|
||||
{
|
||||
if ( !cd_id || !enabled )
|
||||
if (!cd_id || !enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( SDL_CDStatus( cd_id ) != CD_PAUSED )
|
||||
if (SDL_CDStatus(cd_id) != CD_PAUSED)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( SDL_CDResume( cd_id ) )
|
||||
if (SDL_CDResume(cd_id))
|
||||
{
|
||||
Com_DPrintf( "CDAudio_Resume: Failed to resume track.\n" );
|
||||
Com_DPrintf("CDAudio_Resume: Failed to resume track.\n");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CDAudio_Update ()
|
||||
CDAudio_Update()
|
||||
{
|
||||
static int cnt = 0;
|
||||
|
||||
if ( !cd_id || !enabled )
|
||||
if (!cd_id || !enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( cd_volume && ( cd_volume->value != cdvolume ) )
|
||||
if (cd_volume && (cd_volume->value != cdvolume))
|
||||
{
|
||||
if ( cdvolume )
|
||||
if (cdvolume)
|
||||
{
|
||||
Cvar_SetValue( "cd_volume", 0.0 );
|
||||
Cvar_SetValue("cd_volume", 0.0);
|
||||
CDAudio_Pause();
|
||||
}
|
||||
else
|
||||
{
|
||||
Cvar_SetValue( "cd_volume", 1.0 );
|
||||
Cvar_SetValue("cd_volume", 1.0);
|
||||
CDAudio_Resume();
|
||||
}
|
||||
|
||||
|
@ -293,150 +294,150 @@ CDAudio_Update ()
|
|||
}
|
||||
|
||||
/* this causes too much overhead to be executed every frame */
|
||||
if ( ++cnt == 16 )
|
||||
if (++cnt == 16)
|
||||
{
|
||||
cnt = 0;
|
||||
|
||||
if ( cd_nocd->value )
|
||||
if (cd_nocd->value)
|
||||
{
|
||||
CDAudio_Stop();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( playLooping &&
|
||||
( SDL_CDStatus( cd_id ) != CD_PLAYING ) &&
|
||||
( SDL_CDStatus( cd_id ) != CD_PAUSED ) )
|
||||
if (playLooping &&
|
||||
(SDL_CDStatus(cd_id) != CD_PLAYING) &&
|
||||
(SDL_CDStatus(cd_id) != CD_PAUSED))
|
||||
{
|
||||
CDAudio_Play( lastTrack, true );
|
||||
CDAudio_Play(lastTrack, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
CDAudio_Init ()
|
||||
CDAudio_Init()
|
||||
{
|
||||
cvar_t *cv;
|
||||
|
||||
if ( initialized )
|
||||
if (initialized)
|
||||
{
|
||||
return ( 0 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
cv = Cvar_Get( "nocdaudio", "0", CVAR_NOSET );
|
||||
cv = Cvar_Get("nocdaudio", "0", CVAR_NOSET);
|
||||
|
||||
if ( cv->value )
|
||||
if (cv->value)
|
||||
{
|
||||
return ( -1 );
|
||||
return -1;
|
||||
}
|
||||
|
||||
cd_nocd = Cvar_Get( "cd_nocd", "0", CVAR_ARCHIVE );
|
||||
cd_nocd = Cvar_Get("cd_nocd", "0", CVAR_ARCHIVE);
|
||||
|
||||
if ( cd_nocd->value )
|
||||
if (cd_nocd->value)
|
||||
{
|
||||
return ( -1 );
|
||||
return -1;
|
||||
}
|
||||
|
||||
cd_volume = Cvar_Get( "cd_volume", "1", CVAR_ARCHIVE );
|
||||
cd_volume = Cvar_Get("cd_volume", "1", CVAR_ARCHIVE);
|
||||
|
||||
if ( SDL_WasInit( SDL_INIT_EVERYTHING ) == 0 )
|
||||
if (SDL_WasInit(SDL_INIT_EVERYTHING) == 0)
|
||||
{
|
||||
if ( SDL_Init( SDL_INIT_CDROM ) < 0 )
|
||||
if (SDL_Init(SDL_INIT_CDROM) < 0)
|
||||
{
|
||||
Com_Printf( "Couldn't init SDL cdrom: %s\n", SDL_GetError() );
|
||||
return ( -1 );
|
||||
Com_Printf("Couldn't init SDL cdrom: %s\n", SDL_GetError());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if ( SDL_WasInit( SDL_INIT_CDROM ) == 0 )
|
||||
else if (SDL_WasInit(SDL_INIT_CDROM) == 0)
|
||||
{
|
||||
if ( SDL_InitSubSystem( SDL_INIT_CDROM ) < 0 )
|
||||
if (SDL_InitSubSystem(SDL_INIT_CDROM) < 0)
|
||||
{
|
||||
Com_Printf( "Couldn't init SDL cdrom: %s\n", SDL_GetError() );
|
||||
return ( -1 );
|
||||
Com_Printf("Couldn't init SDL cdrom: %s\n", SDL_GetError());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
cd_id = SDL_CDOpen( 0 );
|
||||
cd_id = SDL_CDOpen(0);
|
||||
|
||||
if ( !cd_id )
|
||||
if (!cd_id)
|
||||
{
|
||||
Com_Printf( "CDAudio_Init: Unable to open default CD-ROM drive: %s\n",
|
||||
SDL_GetError() );
|
||||
return ( -1 );
|
||||
Com_Printf("CDAudio_Init: Unable to open default CD-ROM drive: %s\n",
|
||||
SDL_GetError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
enabled = true;
|
||||
cdValid = true;
|
||||
|
||||
if ( !CD_INDRIVE( SDL_CDStatus( cd_id ) ) )
|
||||
if (!CD_INDRIVE(SDL_CDStatus(cd_id)))
|
||||
{
|
||||
Com_Printf( "CDAudio_Init: No CD in drive.\n" );
|
||||
Com_Printf("CDAudio_Init: No CD in drive.\n");
|
||||
cdValid = false;
|
||||
}
|
||||
|
||||
if ( !cd_id->numtracks )
|
||||
if (!cd_id->numtracks)
|
||||
{
|
||||
Com_Printf( "CDAudio_Init: CD contains no audio tracks.\n" );
|
||||
Com_Printf("CDAudio_Init: CD contains no audio tracks.\n");
|
||||
cdValid = false;
|
||||
}
|
||||
|
||||
Cmd_AddCommand( "cd", CD_f );
|
||||
Com_Printf( "CD Audio Initialized.\n" );
|
||||
return ( 0 );
|
||||
Cmd_AddCommand("cd", CD_f);
|
||||
Com_Printf("CD Audio Initialized.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
CDAudio_Shutdown ()
|
||||
CDAudio_Shutdown()
|
||||
{
|
||||
if ( !cd_id )
|
||||
if (!cd_id)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CDAudio_Stop();
|
||||
SDL_CDClose( cd_id );
|
||||
SDL_CDClose(cd_id);
|
||||
cd_id = NULL;
|
||||
|
||||
if ( SDL_WasInit( SDL_INIT_EVERYTHING ) == SDL_INIT_CDROM )
|
||||
if (SDL_WasInit(SDL_INIT_EVERYTHING) == SDL_INIT_CDROM)
|
||||
{
|
||||
SDL_Quit();
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_QuitSubSystem( SDL_INIT_CDROM );
|
||||
SDL_QuitSubSystem(SDL_INIT_CDROM);
|
||||
}
|
||||
|
||||
initialized = false;
|
||||
}
|
||||
|
||||
static void
|
||||
CD_f ()
|
||||
CD_f()
|
||||
{
|
||||
char *command;
|
||||
int cdstate;
|
||||
|
||||
if ( Cmd_Argc() < 2 )
|
||||
if (Cmd_Argc() < 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
command = Cmd_Argv( 1 );
|
||||
command = Cmd_Argv(1);
|
||||
|
||||
if ( !Q_strcasecmp( command, "on" ) )
|
||||
if (!Q_strcasecmp(command, "on"))
|
||||
{
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
if ( !Q_strcasecmp( command, "off" ) )
|
||||
if (!Q_strcasecmp(command, "off"))
|
||||
{
|
||||
if ( !cd_id )
|
||||
if (!cd_id)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
cdstate = SDL_CDStatus( cd_id );
|
||||
cdstate = SDL_CDStatus(cd_id);
|
||||
|
||||
if ( ( cdstate == CD_PLAYING ) || ( cdstate == CD_PAUSED ) )
|
||||
if ((cdstate == CD_PLAYING) || (cdstate == CD_PAUSED))
|
||||
{
|
||||
CDAudio_Stop();
|
||||
}
|
||||
|
@ -445,64 +446,64 @@ CD_f ()
|
|||
return;
|
||||
}
|
||||
|
||||
if ( !Q_strcasecmp( command, "play" ) )
|
||||
if (!Q_strcasecmp(command, "play"))
|
||||
{
|
||||
CDAudio_Play( (byte) (int)strtol( Cmd_Argv( 2 ), (char **)NULL, 10 ), false );
|
||||
CDAudio_Play((byte)(int)strtol(Cmd_Argv(2), (char **)NULL, 10), false);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !Q_strcasecmp( command, "loop" ) )
|
||||
if (!Q_strcasecmp(command, "loop"))
|
||||
{
|
||||
CDAudio_Play( (byte) (int)strtol( Cmd_Argv( 2 ), (char **)NULL, 10 ), true );
|
||||
CDAudio_Play((byte)(int)strtol(Cmd_Argv(2), (char **)NULL, 10), true);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !Q_strcasecmp( command, "stop" ) )
|
||||
if (!Q_strcasecmp(command, "stop"))
|
||||
{
|
||||
CDAudio_Stop();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !Q_strcasecmp( command, "pause" ) )
|
||||
if (!Q_strcasecmp(command, "pause"))
|
||||
{
|
||||
CDAudio_Pause();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !Q_strcasecmp( command, "resume" ) )
|
||||
if (!Q_strcasecmp(command, "resume"))
|
||||
{
|
||||
CDAudio_Resume();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !Q_strcasecmp( command, "eject" ) )
|
||||
if (!Q_strcasecmp(command, "eject"))
|
||||
{
|
||||
CDAudio_Eject();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !Q_strcasecmp( command, "info" ) )
|
||||
if (!Q_strcasecmp(command, "info"))
|
||||
{
|
||||
if ( !cd_id )
|
||||
if (!cd_id)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
cdstate = SDL_CDStatus( cd_id );
|
||||
Com_Printf( "%d tracks\n", cd_id->numtracks );
|
||||
cdstate = SDL_CDStatus(cd_id);
|
||||
Com_Printf("%d tracks\n", cd_id->numtracks);
|
||||
|
||||
if ( cdstate == CD_PLAYING )
|
||||
if (cdstate == CD_PLAYING)
|
||||
{
|
||||
Com_Printf( "Currently %s track %d\n",
|
||||
Com_Printf("Currently %s track %d\n",
|
||||
playLooping ? "looping" : "playing",
|
||||
cd_id->cur_track + 1 );
|
||||
cd_id->cur_track + 1);
|
||||
}
|
||||
else
|
||||
if ( cdstate == CD_PAUSED )
|
||||
if (cdstate == CD_PAUSED)
|
||||
{
|
||||
Com_Printf( "Paused %s track %d\n",
|
||||
Com_Printf("Paused %s track %d\n",
|
||||
playLooping ? "looping" : "playing",
|
||||
cd_id->cur_track + 1 );
|
||||
cd_id->cur_track + 1);
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -510,9 +511,9 @@ CD_f ()
|
|||
}
|
||||
|
||||
void
|
||||
CDAudio_Activate ( qboolean active )
|
||||
CDAudio_Activate(qboolean active)
|
||||
{
|
||||
if ( active )
|
||||
if (active)
|
||||
{
|
||||
CDAudio_Resume();
|
||||
}
|
||||
|
|
660
src/sdl/input.c
660
src/sdl/input.c
|
@ -39,31 +39,31 @@
|
|||
#define MOUSE_MAX 3000
|
||||
#define MOUSE_MIN 40
|
||||
|
||||
static int old_windowed_mouse;
|
||||
static cvar_t *windowed_mouse;
|
||||
static cvar_t *in_grab;
|
||||
static int mouse_x, mouse_y;
|
||||
static int old_mouse_x, old_mouse_y;
|
||||
static int mouse_buttonstate;
|
||||
static int mouse_oldbuttonstate;
|
||||
static int old_windowed_mouse;
|
||||
static cvar_t *windowed_mouse;
|
||||
static cvar_t *in_grab;
|
||||
static int mouse_x, mouse_y;
|
||||
static int old_mouse_x, old_mouse_y;
|
||||
static int mouse_buttonstate;
|
||||
static int mouse_oldbuttonstate;
|
||||
|
||||
struct
|
||||
{
|
||||
int key;
|
||||
int down;
|
||||
int key;
|
||||
int down;
|
||||
} keyq[128];
|
||||
|
||||
int keyq_head=0;
|
||||
int keyq_tail=0;
|
||||
int keyq_head = 0;
|
||||
int keyq_tail = 0;
|
||||
int mx;
|
||||
int my;
|
||||
|
||||
Key_Event_fp_t Key_Event_fp;
|
||||
|
||||
extern SDL_Surface *surface;
|
||||
static in_state_t *in_state;
|
||||
extern SDL_Surface *surface;
|
||||
static in_state_t *in_state;
|
||||
static unsigned char KeyStates[SDLK_LAST];
|
||||
static qboolean mlooking;
|
||||
static qboolean mlooking;
|
||||
|
||||
static cvar_t *sensitivity;
|
||||
static cvar_t *exponential_speedup;
|
||||
|
@ -84,103 +84,228 @@ static cvar_t *in_mouse;
|
|||
int
|
||||
IN_TranslateSDLtoQ2Key(unsigned int keysym)
|
||||
{
|
||||
int key = 0;
|
||||
int key = 0;
|
||||
|
||||
if( keysym >= SDLK_SPACE && keysym < SDLK_DELETE )
|
||||
{
|
||||
/* 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;
|
||||
if ((keysym >= SDLK_SPACE) && (keysym < SDLK_DELETE))
|
||||
{
|
||||
/* 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_LSHIFT:
|
||||
case SDLK_RSHIFT:
|
||||
key = K_SHIFT;
|
||||
break;
|
||||
case SDLK_LCTRL:
|
||||
case SDLK_RCTRL:
|
||||
key = K_CTRL;
|
||||
break;
|
||||
case SDLK_RMETA:
|
||||
case SDLK_LMETA:
|
||||
key = K_COMMAND;
|
||||
break;
|
||||
case SDLK_RALT:
|
||||
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_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;
|
||||
default:
|
||||
|
||||
case SDLK_LSHIFT:
|
||||
case SDLK_RSHIFT: key = K_SHIFT; break;
|
||||
if ((keysym >= SDLK_WORLD_0) && (keysym <= SDLK_WORLD_95))
|
||||
{
|
||||
key = (keysym - SDLK_WORLD_0) + K_WORLD_0;
|
||||
}
|
||||
|
||||
case SDLK_LCTRL:
|
||||
case SDLK_RCTRL: key = K_CTRL; break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
case SDLK_RMETA:
|
||||
case SDLK_LMETA: key = K_COMMAND; break;
|
||||
|
||||
case SDLK_RALT:
|
||||
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;
|
||||
|
||||
default:
|
||||
if( keysym >= SDLK_WORLD_0 && keysym <= SDLK_WORLD_95 )
|
||||
key = ( keysym - SDLK_WORLD_0 ) + K_WORLD_0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return key;
|
||||
return key;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -191,10 +316,11 @@ IN_GetEvent(SDL_Event *event)
|
|||
{
|
||||
unsigned int key;
|
||||
|
||||
switch(event->type)
|
||||
switch (event->type)
|
||||
{
|
||||
/* 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;
|
||||
|
||||
|
@ -229,14 +359,14 @@ IN_GetEvent(SDL_Event *event)
|
|||
|
||||
if (surface->flags & SDL_FULLSCREEN)
|
||||
{
|
||||
ri.Cvar_SetValue( "vid_fullscreen", 1 );
|
||||
ri.Cvar_SetValue("vid_fullscreen", 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ri.Cvar_SetValue( "vid_fullscreen", 0 );
|
||||
ri.Cvar_SetValue("vid_fullscreen", 0);
|
||||
}
|
||||
|
||||
fullscreen = ri.Cvar_Get( "vid_fullscreen", "0", 0 );
|
||||
fullscreen = ri.Cvar_Get("vid_fullscreen", "0", 0);
|
||||
fullscreen->modified = false;
|
||||
|
||||
break;
|
||||
|
@ -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,104 +411,105 @@ 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;
|
||||
int bstate;
|
||||
SDL_Event event;
|
||||
static int IN_Update_Flag;
|
||||
int bstate;
|
||||
|
||||
/* Protection against multiple calls */
|
||||
if (IN_Update_Flag == 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
/* Protection against multiple calls */
|
||||
if (IN_Update_Flag == 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IN_Update_Flag = 1;
|
||||
IN_Update_Flag = 1;
|
||||
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
IN_GetEvent(&event);
|
||||
}
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
IN_GetEvent(&event);
|
||||
}
|
||||
|
||||
/* Mouse button processing. Button 4
|
||||
and 5 are the mousewheel and thus
|
||||
not processed here. */
|
||||
/* Mouse button processing. Button 4
|
||||
and 5 are the mousewheel and thus
|
||||
not processed here. */
|
||||
if (!mx && !my)
|
||||
{
|
||||
SDL_GetRelativeMouseState(&mx, &my);
|
||||
}
|
||||
|
||||
if (!mx && !my)
|
||||
{
|
||||
SDL_GetRelativeMouseState(&mx, &my);
|
||||
}
|
||||
mouse_buttonstate = 0;
|
||||
bstate = SDL_GetMouseState(NULL, NULL);
|
||||
|
||||
mouse_buttonstate = 0;
|
||||
bstate = SDL_GetMouseState(NULL, NULL);
|
||||
if (SDL_BUTTON(1) & bstate)
|
||||
{
|
||||
mouse_buttonstate |= (1 << 0);
|
||||
}
|
||||
|
||||
if (SDL_BUTTON(1) & bstate)
|
||||
{
|
||||
mouse_buttonstate |= (1 << 0);
|
||||
}
|
||||
if (SDL_BUTTON(3) & bstate)
|
||||
{
|
||||
mouse_buttonstate |= (1 << 1);
|
||||
}
|
||||
|
||||
if (SDL_BUTTON(3) & bstate)
|
||||
{
|
||||
mouse_buttonstate |= (1 << 1);
|
||||
}
|
||||
if (SDL_BUTTON(2) & bstate)
|
||||
{
|
||||
mouse_buttonstate |= (1 << 2);
|
||||
}
|
||||
|
||||
if (SDL_BUTTON(2) & bstate)
|
||||
{
|
||||
mouse_buttonstate |= (1 << 2);
|
||||
}
|
||||
if (SDL_BUTTON(6) & bstate)
|
||||
{
|
||||
mouse_buttonstate |= (1 << 3);
|
||||
}
|
||||
|
||||
if (SDL_BUTTON(6) & bstate)
|
||||
{
|
||||
mouse_buttonstate |= (1 << 3);
|
||||
}
|
||||
if (SDL_BUTTON(7) & bstate)
|
||||
{
|
||||
mouse_buttonstate |= (1 << 4);
|
||||
}
|
||||
|
||||
if (SDL_BUTTON(7) & bstate)
|
||||
{
|
||||
mouse_buttonstate |= (1 << 4);
|
||||
}
|
||||
/* Grab and ungrab the mouse if the
|
||||
* console is opened */
|
||||
if (in_grab->value == 2)
|
||||
{
|
||||
if (old_windowed_mouse != windowed_mouse->value)
|
||||
{
|
||||
old_windowed_mouse = windowed_mouse->value;
|
||||
|
||||
/* Grab and ungrab the mouse if the
|
||||
console is opened */
|
||||
if (in_grab->value == 2)
|
||||
{
|
||||
if (old_windowed_mouse != windowed_mouse->value)
|
||||
{
|
||||
old_windowed_mouse = windowed_mouse->value;
|
||||
if (!windowed_mouse->value)
|
||||
{
|
||||
SDL_WM_GrabInput(SDL_GRAB_OFF);
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_WM_GrabInput(SDL_GRAB_ON);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (in_grab->value == 1)
|
||||
{
|
||||
SDL_WM_GrabInput(SDL_GRAB_ON);
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_WM_GrabInput(SDL_GRAB_OFF);
|
||||
}
|
||||
|
||||
if (!windowed_mouse->value)
|
||||
{
|
||||
SDL_WM_GrabInput(SDL_GRAB_OFF);
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_WM_GrabInput(SDL_GRAB_ON);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (in_grab->value == 1)
|
||||
{
|
||||
SDL_WM_GrabInput(SDL_GRAB_ON);
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_WM_GrabInput(SDL_GRAB_OFF);
|
||||
}
|
||||
/* Process the key events */
|
||||
while (keyq_head != keyq_tail)
|
||||
{
|
||||
in_state->Key_Event_fp(keyq[keyq_tail].key, keyq[keyq_tail].down);
|
||||
keyq_tail = (keyq_tail + 1) & 127;
|
||||
}
|
||||
|
||||
/* Process the key events */
|
||||
while (keyq_head != keyq_tail)
|
||||
{
|
||||
in_state->Key_Event_fp(keyq[keyq_tail].key, keyq[keyq_tail].down);
|
||||
keyq_tail = (keyq_tail + 1) & 127;
|
||||
}
|
||||
|
||||
IN_Update_Flag = 0;
|
||||
IN_Update_Flag = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Closes all inputs and clears
|
||||
* the input queue.
|
||||
*/
|
||||
void IN_Close(void)
|
||||
void
|
||||
IN_Close(void)
|
||||
{
|
||||
keyq_head = 0;
|
||||
keyq_tail = 0;
|
||||
|
@ -384,34 +520,37 @@ void IN_Close(void)
|
|||
/*
|
||||
* Gets the mouse state
|
||||
*/
|
||||
void IN_GetMouseState(int *x, int *y, int *state) {
|
||||
*x = mx;
|
||||
*y = my;
|
||||
*state = mouse_buttonstate;
|
||||
void
|
||||
IN_GetMouseState(int *x, int *y, int *state)
|
||||
{
|
||||
*x = mx;
|
||||
*y = my;
|
||||
*state = mouse_buttonstate;
|
||||
}
|
||||
|
||||
/*
|
||||
* Cleares the mouse state
|
||||
*/
|
||||
void IN_ClearMouseState()
|
||||
void
|
||||
IN_ClearMouseState()
|
||||
{
|
||||
mx = my = 0;
|
||||
mx = my = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Centers the view
|
||||
*/
|
||||
static void
|
||||
IN_ForceCenterView ( void )
|
||||
IN_ForceCenterView(void)
|
||||
{
|
||||
in_state->viewangles [ PITCH ] = 0;
|
||||
in_state->viewangles[PITCH] = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Look up
|
||||
*/
|
||||
static void
|
||||
IN_MLookDown ( void )
|
||||
IN_MLookDown(void)
|
||||
{
|
||||
mlooking = true;
|
||||
}
|
||||
|
@ -420,7 +559,7 @@ IN_MLookDown ( void )
|
|||
* Look down
|
||||
*/
|
||||
static void
|
||||
IN_MLookUp ( void )
|
||||
IN_MLookUp(void)
|
||||
{
|
||||
mlooking = false;
|
||||
in_state->IN_CenterView_fp();
|
||||
|
@ -440,47 +579,48 @@ IN_KeyboardInit(Key_Event_fp_t fp)
|
|||
* Initializes the backend
|
||||
*/
|
||||
void
|
||||
IN_BackendInit ( in_state_t *in_state_p )
|
||||
IN_BackendInit(in_state_t *in_state_p)
|
||||
{
|
||||
in_state = in_state_p;
|
||||
m_filter = ri.Cvar_Get( "m_filter", "0", CVAR_ARCHIVE );
|
||||
in_mouse = ri.Cvar_Get( "in_mouse", "0", CVAR_ARCHIVE );
|
||||
m_filter = ri.Cvar_Get("m_filter", "0", CVAR_ARCHIVE);
|
||||
in_mouse = ri.Cvar_Get("in_mouse", "0", CVAR_ARCHIVE);
|
||||
|
||||
freelook = ri.Cvar_Get( "freelook", "1", 0 );
|
||||
lookstrafe = ri.Cvar_Get( "lookstrafe", "0", 0 );
|
||||
sensitivity = ri.Cvar_Get( "sensitivity", "3", 0 );
|
||||
exponential_speedup = ri.Cvar_Get( "exponential_speedup", "0", CVAR_ARCHIVE );
|
||||
freelook = ri.Cvar_Get("freelook", "1", 0);
|
||||
lookstrafe = ri.Cvar_Get("lookstrafe", "0", 0);
|
||||
sensitivity = ri.Cvar_Get("sensitivity", "3", 0);
|
||||
exponential_speedup = ri.Cvar_Get("exponential_speedup", "0", CVAR_ARCHIVE);
|
||||
|
||||
m_pitch = ri.Cvar_Get( "m_pitch", "0.022", 0 );
|
||||
m_yaw = ri.Cvar_Get( "m_yaw", "0.022", 0 );
|
||||
m_forward = ri.Cvar_Get( "m_forward", "1", 0 );
|
||||
m_side = ri.Cvar_Get( "m_side", "0.8", 0 );
|
||||
m_pitch = ri.Cvar_Get("m_pitch", "0.022", 0);
|
||||
m_yaw = ri.Cvar_Get("m_yaw", "0.022", 0);
|
||||
m_forward = ri.Cvar_Get("m_forward", "1", 0);
|
||||
m_side = ri.Cvar_Get("m_side", "0.8", 0);
|
||||
|
||||
ri.Cmd_AddCommand( "+mlook", IN_MLookDown );
|
||||
ri.Cmd_AddCommand( "-mlook", IN_MLookUp );
|
||||
ri.Cmd_AddCommand( "force_centerview", IN_ForceCenterView );
|
||||
ri.Cmd_AddCommand("+mlook", IN_MLookDown);
|
||||
ri.Cmd_AddCommand("-mlook", IN_MLookUp);
|
||||
ri.Cmd_AddCommand("force_centerview", IN_ForceCenterView);
|
||||
|
||||
mouse_x = mouse_y = 0.0;
|
||||
|
||||
/* SDL stuff */
|
||||
SDL_EnableUNICODE( 0 );
|
||||
SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL );
|
||||
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);
|
||||
in_grab = ri.Cvar_Get ("in_grab", "2", 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" );
|
||||
Com_Printf("Input initialized.\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* Shuts the backend down
|
||||
*/
|
||||
void
|
||||
IN_BackendShutdown ( void )
|
||||
IN_BackendShutdown(void)
|
||||
{
|
||||
ri.Cmd_RemoveCommand( "+mlook" );
|
||||
ri.Cmd_RemoveCommand( "-mlook" );
|
||||
ri.Cmd_RemoveCommand( "force_centerview" );
|
||||
ri.Cmd_RemoveCommand("+mlook");
|
||||
ri.Cmd_RemoveCommand("-mlook");
|
||||
ri.Cmd_RemoveCommand("force_centerview");
|
||||
Com_Printf("Input shut down.\n");
|
||||
}
|
||||
|
||||
|
@ -488,43 +628,43 @@ IN_BackendShutdown ( void )
|
|||
* Mouse button handling
|
||||
*/
|
||||
void
|
||||
IN_BackendMouseButtons ( void )
|
||||
IN_BackendMouseButtons(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
IN_GetMouseState( &mouse_x, &mouse_y, &mouse_buttonstate );
|
||||
IN_GetMouseState(&mouse_x, &mouse_y, &mouse_buttonstate);
|
||||
|
||||
for ( i = 0; i < 3; i++ )
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
if ( ( mouse_buttonstate & ( 1 << i ) ) && !( mouse_oldbuttonstate & ( 1 << i ) ) )
|
||||
if ((mouse_buttonstate & (1 << i)) && !(mouse_oldbuttonstate & (1 << i)))
|
||||
{
|
||||
in_state->Key_Event_fp( K_MOUSE1 + i, true );
|
||||
in_state->Key_Event_fp(K_MOUSE1 + i, true);
|
||||
}
|
||||
|
||||
if ( !( mouse_buttonstate & ( 1 << i ) ) && ( mouse_oldbuttonstate & ( 1 << i ) ) )
|
||||
if (!(mouse_buttonstate & (1 << i)) && (mouse_oldbuttonstate & (1 << i)))
|
||||
{
|
||||
in_state->Key_Event_fp( K_MOUSE1 + i, false );
|
||||
in_state->Key_Event_fp(K_MOUSE1 + i, false);
|
||||
}
|
||||
}
|
||||
|
||||
if ( ( mouse_buttonstate & ( 1 << 3 ) ) && !( mouse_oldbuttonstate & ( 1 << 3 ) ) )
|
||||
if ((mouse_buttonstate & (1 << 3)) && !(mouse_oldbuttonstate & (1 << 3)))
|
||||
{
|
||||
in_state->Key_Event_fp( K_MOUSE4, true );
|
||||
in_state->Key_Event_fp(K_MOUSE4, true);
|
||||
}
|
||||
|
||||
if ( !( mouse_buttonstate & ( 1 << 3 ) ) && ( mouse_oldbuttonstate & ( 1 << 3 ) ) )
|
||||
if (!(mouse_buttonstate & (1 << 3)) && (mouse_oldbuttonstate & (1 << 3)))
|
||||
{
|
||||
in_state->Key_Event_fp( K_MOUSE4, false );
|
||||
in_state->Key_Event_fp(K_MOUSE4, false);
|
||||
}
|
||||
|
||||
if ( ( mouse_buttonstate & ( 1 << 4 ) ) && !( mouse_oldbuttonstate & ( 1 << 4 ) ) )
|
||||
if ((mouse_buttonstate & (1 << 4)) && !(mouse_oldbuttonstate & (1 << 4)))
|
||||
{
|
||||
in_state->Key_Event_fp( K_MOUSE5, true );
|
||||
in_state->Key_Event_fp(K_MOUSE5, true);
|
||||
}
|
||||
|
||||
if ( !( mouse_buttonstate & ( 1 << 4 ) ) && ( mouse_oldbuttonstate & ( 1 << 4 ) ) )
|
||||
if (!(mouse_buttonstate & (1 << 4)) && (mouse_oldbuttonstate & (1 << 4)))
|
||||
{
|
||||
in_state->Key_Event_fp( K_MOUSE5, false );
|
||||
in_state->Key_Event_fp(K_MOUSE5, false);
|
||||
}
|
||||
|
||||
mouse_oldbuttonstate = mouse_buttonstate;
|
||||
|
@ -534,54 +674,55 @@ IN_BackendMouseButtons ( void )
|
|||
* Move handling
|
||||
*/
|
||||
void
|
||||
IN_BackendMove ( usercmd_t *cmd )
|
||||
IN_BackendMove(usercmd_t *cmd)
|
||||
{
|
||||
IN_GetMouseState( &mouse_x, &mouse_y, &mouse_buttonstate );
|
||||
IN_GetMouseState(&mouse_x, &mouse_y, &mouse_buttonstate);
|
||||
|
||||
if ( m_filter->value )
|
||||
if (m_filter->value)
|
||||
{
|
||||
if ( ( mouse_x > 1 ) || ( mouse_x < -1) )
|
||||
if ((mouse_x > 1) || (mouse_x < -1))
|
||||
{
|
||||
mouse_x = ( mouse_x + old_mouse_x ) * 0.5;
|
||||
mouse_x = (mouse_x + old_mouse_x) * 0.5;
|
||||
}
|
||||
if ( ( mouse_y > 1 ) || ( mouse_y < -1) )
|
||||
|
||||
if ((mouse_y > 1) || (mouse_y < -1))
|
||||
{
|
||||
mouse_y = ( mouse_y + old_mouse_y ) * 0.5;
|
||||
mouse_y = (mouse_y + old_mouse_y) * 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
old_mouse_x = mouse_x;
|
||||
old_mouse_y = mouse_y;
|
||||
|
||||
if ( mouse_x || mouse_y )
|
||||
if (mouse_x || mouse_y)
|
||||
{
|
||||
if ( !exponential_speedup->value )
|
||||
if (!exponential_speedup->value)
|
||||
{
|
||||
mouse_x *= sensitivity->value;
|
||||
mouse_y *= sensitivity->value;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( ( mouse_x > MOUSE_MIN ) || ( mouse_y > MOUSE_MIN ) ||
|
||||
( mouse_x < -MOUSE_MIN ) || ( mouse_y < -MOUSE_MIN ) )
|
||||
if ((mouse_x > MOUSE_MIN) || (mouse_y > MOUSE_MIN) ||
|
||||
(mouse_x < -MOUSE_MIN) || (mouse_y < -MOUSE_MIN))
|
||||
{
|
||||
mouse_x = ( mouse_x * mouse_x * mouse_x ) / 4;
|
||||
mouse_y = ( mouse_y * mouse_y * mouse_y ) / 4;
|
||||
mouse_x = (mouse_x * mouse_x * mouse_x) / 4;
|
||||
mouse_y = (mouse_y * mouse_y * mouse_y) / 4;
|
||||
|
||||
if ( mouse_x > MOUSE_MAX )
|
||||
if (mouse_x > MOUSE_MAX)
|
||||
{
|
||||
mouse_x = MOUSE_MAX;
|
||||
}
|
||||
else if ( mouse_x < -MOUSE_MAX )
|
||||
else if (mouse_x < -MOUSE_MAX)
|
||||
{
|
||||
mouse_x = -MOUSE_MAX;
|
||||
}
|
||||
|
||||
if ( mouse_y > MOUSE_MAX )
|
||||
if (mouse_y > MOUSE_MAX)
|
||||
{
|
||||
mouse_y = MOUSE_MAX;
|
||||
}
|
||||
else if ( mouse_y < -MOUSE_MAX )
|
||||
else if (mouse_y < -MOUSE_MAX)
|
||||
{
|
||||
mouse_y = -MOUSE_MAX;
|
||||
}
|
||||
|
@ -589,20 +730,20 @@ IN_BackendMove ( usercmd_t *cmd )
|
|||
}
|
||||
|
||||
/* add mouse X/Y movement to cmd */
|
||||
if ( ( *in_state->in_strafe_state & 1 ) ||
|
||||
( lookstrafe->value && mlooking ) )
|
||||
if ((*in_state->in_strafe_state & 1) ||
|
||||
(lookstrafe->value && mlooking))
|
||||
{
|
||||
cmd->sidemove += m_side->value * mouse_x;
|
||||
}
|
||||
else
|
||||
{
|
||||
in_state->viewangles [ YAW ] -= m_yaw->value * mouse_x;
|
||||
in_state->viewangles[YAW] -= m_yaw->value * mouse_x;
|
||||
}
|
||||
|
||||
if ( ( mlooking || freelook->value ) &&
|
||||
!( *in_state->in_strafe_state & 1 ) )
|
||||
if ((mlooking || freelook->value) &&
|
||||
!(*in_state->in_strafe_state & 1))
|
||||
{
|
||||
in_state->viewangles [ PITCH ] += m_pitch->value * mouse_y;
|
||||
in_state->viewangles[PITCH] += m_pitch->value * mouse_y;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -612,3 +753,4 @@ IN_BackendMove ( usercmd_t *cmd )
|
|||
IN_ClearMouseState();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,15 +41,15 @@
|
|||
|
||||
/* X.org stuff */
|
||||
#ifdef X11GAMMA
|
||||
#include <X11/Xos.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/extensions/xf86vmode.h>
|
||||
#include <X11/Xos.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/extensions/xf86vmode.h>
|
||||
#endif
|
||||
|
||||
SDL_Surface *surface;
|
||||
glwstate_t glw_state;
|
||||
qboolean have_stencil = false;
|
||||
SDL_Surface *surface;
|
||||
glwstate_t glw_state;
|
||||
qboolean have_stencil = false;
|
||||
|
||||
char *displayname = NULL;
|
||||
int screen = -1;
|
||||
|
@ -62,19 +62,22 @@ XF86VidModeGamma x11_oldgamma;
|
|||
/*
|
||||
* Initialzes the SDL OpenGL context
|
||||
*/
|
||||
int GLimp_Init(void)
|
||||
int
|
||||
GLimp_Init(void)
|
||||
{
|
||||
if (!SDL_WasInit(SDL_INIT_VIDEO))
|
||||
{
|
||||
char driverName[ 64 ];
|
||||
{
|
||||
char driverName[64];
|
||||
|
||||
if (SDL_Init(SDL_INIT_VIDEO) == -1)
|
||||
{
|
||||
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 );
|
||||
if (SDL_Init(SDL_INIT_VIDEO) == -1)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -83,15 +86,18 @@ int GLimp_Init(void)
|
|||
/*
|
||||
* Sets the window icon
|
||||
*/
|
||||
static void SetSDLIcon()
|
||||
static void
|
||||
SetSDLIcon()
|
||||
{
|
||||
SDL_Surface *icon;
|
||||
SDL_Color color;
|
||||
Uint8 *ptr;
|
||||
int i;
|
||||
int mask;
|
||||
SDL_Color color;
|
||||
Uint8 *ptr;
|
||||
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++;
|
||||
}
|
||||
|
@ -136,7 +143,7 @@ UpdateHardwareGamma(void)
|
|||
float gamma;
|
||||
XF86VidModeGamma x11_gamma;
|
||||
|
||||
gamma =vid_gamma->value;
|
||||
gamma = vid_gamma->value;
|
||||
|
||||
x11_gamma.red = gamma;
|
||||
x11_gamma.green = gamma;
|
||||
|
@ -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;
|
||||
|
@ -195,7 +204,7 @@ static qboolean GLimp_InitGraphics( qboolean fullscreen )
|
|||
}
|
||||
|
||||
/* Create the window */
|
||||
ri.Vid_NewWindow (vid.width, vid.height);
|
||||
ri.Vid_NewWindow(vid.width, vid.height);
|
||||
|
||||
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
|
||||
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
|
||||
|
@ -217,15 +226,17 @@ 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)
|
||||
if (counter == 1)
|
||||
{
|
||||
Sys_Error(PRINT_ALL, "Failed to revert to gl_mode 4. Exiting...\n");
|
||||
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 */
|
||||
|
@ -256,7 +267,7 @@ static qboolean GLimp_InitGraphics( qboolean fullscreen )
|
|||
|
||||
/* Initialize hardware gamma */
|
||||
#ifdef X11GAMMA
|
||||
if ( ( dpy = XOpenDisplay( displayname ) ) == NULL )
|
||||
if ((dpy = XOpenDisplay(displayname)) == NULL)
|
||||
{
|
||||
ri.Con_Printf(PRINT_ALL, "Unable to open display.\n");
|
||||
}
|
||||
|
@ -270,7 +281,7 @@ static qboolean GLimp_InitGraphics( qboolean fullscreen )
|
|||
gl_state.hwgamma = true;
|
||||
vid_gamma->modified = true;
|
||||
|
||||
XF86VidModeGetGamma(dpy, screen, &x11_oldgamma);
|
||||
XF86VidModeGetGamma(dpy, screen, &x11_oldgamma);
|
||||
|
||||
ri.Con_Printf(PRINT_ALL, "Using hardware gamma via X11.\n");
|
||||
}
|
||||
|
@ -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,21 +313,22 @@ 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 );
|
||||
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" );
|
||||
ri.Con_Printf(PRINT_ALL, " invalid mode\n");
|
||||
return rserr_invalid_mode;
|
||||
}
|
||||
|
||||
ri.Con_Printf( PRINT_ALL, " %d %d\n", *pwidth, *pheight);
|
||||
ri.Con_Printf(PRINT_ALL, " %d %d\n", *pwidth, *pheight);
|
||||
|
||||
if ( !GLimp_InitGraphics( fullscreen ) )
|
||||
if (!GLimp_InitGraphics(fullscreen))
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -272,3 +272,4 @@ SNDDMA_BeginPainting(void)
|
|||
{
|
||||
SDL_LockAudio();
|
||||
}
|
||||
|
||||
|
|
|
@ -29,13 +29,13 @@
|
|||
#ifdef USE_OPENAL
|
||||
|
||||
#ifndef _QAL_API_H_
|
||||
#define _QAL_API_H_
|
||||
#define _QAL_API_H_
|
||||
|
||||
#include <AL/al.h>
|
||||
#include <AL/efx.h>
|
||||
#include <AL/al.h>
|
||||
#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;
|
||||
|
|
|
@ -28,13 +28,13 @@
|
|||
#ifndef UNIX_UNIX_H
|
||||
#define UNIX_UNIX_H
|
||||
|
||||
typedef void ( *Key_Event_fp_t )( int key, qboolean down );
|
||||
extern void ( *IN_Update_fp )( void );
|
||||
typedef void (*Key_Event_fp_t)(int key, qboolean down);
|
||||
extern void (*IN_Update_fp)(void);
|
||||
|
||||
typedef struct in_state
|
||||
{
|
||||
/* Pointers to functions back in client, set by vid_so */
|
||||
void ( *IN_CenterView_fp )( void );
|
||||
void (*IN_CenterView_fp)(void);
|
||||
Key_Event_fp_t Key_Event_fp;
|
||||
vec_t *viewangles;
|
||||
int *in_strafe_state;
|
||||
|
|
|
@ -24,9 +24,8 @@
|
|||
* =======================================================================
|
||||
*/
|
||||
|
||||
|
||||
/* For mremap() - must be before sys/mman.h include! */
|
||||
#if defined( __linux__ ) && ! defined( _GNU_SOURCE )
|
||||
#if defined(__linux__) && !defined(_GNU_SOURCE)
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
|
@ -36,107 +35,106 @@
|
|||
|
||||
#include "../common/header/common.h"
|
||||
|
||||
#if defined( __FreeBSD__ )
|
||||
#if defined(__FreeBSD__)
|
||||
#include <machine/param.h>
|
||||
#define MAP_ANONYMOUS MAP_ANON
|
||||
#endif
|
||||
|
||||
|
||||
byte *membase;
|
||||
int maxhunksize;
|
||||
int curhunksize;
|
||||
|
||||
void *
|
||||
Hunk_Begin ( int maxsize )
|
||||
Hunk_Begin(int maxsize)
|
||||
{
|
||||
/* reserve a huge chunk of memory, but don't commit any yet */
|
||||
maxhunksize = maxsize + sizeof ( int );
|
||||
maxhunksize = maxsize + sizeof(int);
|
||||
curhunksize = 0;
|
||||
|
||||
membase = mmap( 0, maxhunksize, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0 );
|
||||
membase = mmap(0, maxhunksize, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
|
||||
if ( ( membase == NULL ) || ( membase == (byte *) -1 ) )
|
||||
if ((membase == NULL) || (membase == (byte *)-1))
|
||||
{
|
||||
Sys_Error( "unable to virtual allocate %d bytes", maxsize );
|
||||
Sys_Error("unable to virtual allocate %d bytes", maxsize);
|
||||
}
|
||||
|
||||
*( (int *) membase ) = curhunksize;
|
||||
*((int *)membase) = curhunksize;
|
||||
|
||||
return ( membase + sizeof ( int ) );
|
||||
return membase + sizeof(int);
|
||||
}
|
||||
|
||||
void *
|
||||
Hunk_Alloc ( int size )
|
||||
Hunk_Alloc(int size)
|
||||
{
|
||||
byte *buf;
|
||||
|
||||
/* round to cacheline */
|
||||
size = ( size + 31 ) & ~31;
|
||||
size = (size + 31) & ~31;
|
||||
|
||||
if ( curhunksize + size > maxhunksize )
|
||||
if (curhunksize + size > maxhunksize)
|
||||
{
|
||||
Sys_Error( "Hunk_Alloc overflow" );
|
||||
Sys_Error("Hunk_Alloc overflow");
|
||||
}
|
||||
|
||||
buf = membase + sizeof ( int ) + curhunksize;
|
||||
buf = membase + sizeof(int) + curhunksize;
|
||||
curhunksize += size;
|
||||
return ( buf );
|
||||
return buf;
|
||||
}
|
||||
|
||||
int
|
||||
Hunk_End ( void )
|
||||
Hunk_End(void)
|
||||
{
|
||||
byte *n = NULL;
|
||||
|
||||
#if defined( __FreeBSD__ )
|
||||
#if defined(__FreeBSD__)
|
||||
size_t old_size = maxhunksize;
|
||||
size_t new_size = curhunksize + sizeof ( int );
|
||||
size_t new_size = curhunksize + sizeof(int);
|
||||
void *unmap_base;
|
||||
size_t unmap_len;
|
||||
|
||||
new_size = round_page( new_size );
|
||||
old_size = round_page( old_size );
|
||||
new_size = round_page(new_size);
|
||||
old_size = round_page(old_size);
|
||||
|
||||
if ( new_size > old_size )
|
||||
if (new_size > old_size)
|
||||
{
|
||||
n = 0; /* error */
|
||||
}
|
||||
else if ( new_size < old_size )
|
||||
else if (new_size < old_size)
|
||||
{
|
||||
unmap_base = (caddr_t) ( membase + new_size );
|
||||
unmap_base = (caddr_t)(membase + new_size);
|
||||
unmap_len = old_size - new_size;
|
||||
n = munmap( unmap_base, unmap_len ) + membase;
|
||||
n = munmap(unmap_base, unmap_len) + membase;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if defined( __linux__ )
|
||||
n = (byte *)mremap( membase, maxhunksize, curhunksize + sizeof ( int ), 0 );
|
||||
#if defined(__linux__)
|
||||
n = (byte *)mremap(membase, maxhunksize, curhunksize + sizeof(int), 0);
|
||||
#endif
|
||||
|
||||
if ( n != membase )
|
||||
if (n != membase)
|
||||
{
|
||||
Sys_Error( "Hunk_End: Could not remap virtual block (%d)", errno );
|
||||
Sys_Error("Hunk_End: Could not remap virtual block (%d)", errno);
|
||||
}
|
||||
|
||||
*( (int *) membase ) = curhunksize + sizeof ( int );
|
||||
*((int *)membase) = curhunksize + sizeof(int);
|
||||
|
||||
return ( curhunksize );
|
||||
return curhunksize;
|
||||
}
|
||||
|
||||
void
|
||||
Hunk_Free ( void *base )
|
||||
Hunk_Free(void *base)
|
||||
{
|
||||
byte *m;
|
||||
|
||||
if ( base )
|
||||
if (base)
|
||||
{
|
||||
m = ( (byte *) base ) - sizeof ( int );
|
||||
m = ((byte *)base) - sizeof(int);
|
||||
|
||||
if ( munmap( m, *( (int *) m ) ) )
|
||||
if (munmap(m, *((int *)m)))
|
||||
{
|
||||
Sys_Error( "Hunk_Free: munmap failed (%d)", errno );
|
||||
Sys_Error("Hunk_Free: munmap failed (%d)", errno);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,11 +35,11 @@
|
|||
#include "header/unix.h"
|
||||
|
||||
int
|
||||
main ( int argc, char **argv )
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int time, oldtime, newtime;
|
||||
|
||||
/* register signal handler */
|
||||
/* register signal handler */
|
||||
registerHandler();
|
||||
|
||||
/* Prevent running Quake II as root. Only very mad
|
||||
|
@ -59,7 +59,7 @@ main ( int argc, char **argv )
|
|||
{
|
||||
printf("The effective UID is not the real UID! Your binary is probably marked\n");
|
||||
printf("'setuid'. That is not good idea, please fix it :) If you really know\n");
|
||||
printf("what you're doin edit src/unix/main.c and remove this check. Don't\n");
|
||||
printf("what you're doin edit src/unix/main.c and remove this check. Don't\n");
|
||||
printf("complain if Quake II eats your dog afterwards!\n");
|
||||
|
||||
return 1;
|
||||
|
@ -68,8 +68,8 @@ main ( int argc, char **argv )
|
|||
/* enforce C locale */
|
||||
setenv("LC_ALL", "C", 1);
|
||||
|
||||
printf( "\nYamagi Quake II v%4.2f\n", VERSION);
|
||||
printf( "=====================\n\n");
|
||||
printf("\nYamagi Quake II v%4.2f\n", VERSION);
|
||||
printf("=====================\n\n");
|
||||
|
||||
#ifndef DEDICATED_ONLY
|
||||
printf("Client build options:\n");
|
||||
|
@ -95,14 +95,14 @@ main ( int argc, char **argv )
|
|||
#endif
|
||||
#endif
|
||||
|
||||
printf("Platform: %s\n", BUILDSTRING);
|
||||
printf("Platform: %s\n", BUILDSTRING);
|
||||
printf("Architecture: %s\n", CPUSTRING);
|
||||
|
||||
|
||||
/* Seed PRNG */
|
||||
randk_seed();
|
||||
|
||||
/* Initialze the game */
|
||||
Qcommon_Init( argc, argv );
|
||||
Qcommon_Init(argc, argv);
|
||||
|
||||
/* Do not delay reads on stdin*/
|
||||
fcntl(fileno(stdin), F_SETFL, fcntl(fileno(stdin), F_GETFL, NULL) | FNDELAY);
|
||||
|
@ -110,7 +110,7 @@ main ( int argc, char **argv )
|
|||
oldtime = Sys_Milliseconds();
|
||||
|
||||
/* The legendary Quake II mainloop */
|
||||
while ( 1 )
|
||||
while (1)
|
||||
{
|
||||
/* find time spent rendering last frame */
|
||||
do
|
||||
|
@ -118,11 +118,12 @@ main ( int argc, char **argv )
|
|||
newtime = Sys_Milliseconds();
|
||||
time = newtime - oldtime;
|
||||
}
|
||||
while ( time < 1 );
|
||||
while (time < 1);
|
||||
|
||||
Qcommon_Frame( time );
|
||||
Qcommon_Frame(time);
|
||||
oldtime = newtime;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,33 +40,33 @@
|
|||
|
||||
netadr_t net_local_adr;
|
||||
|
||||
#define LOOPBACK 0x7f000001
|
||||
#define MAX_LOOPBACK 4
|
||||
#define QUAKE2MCAST "ff12::666"
|
||||
#define LOOPBACK 0x7f000001
|
||||
#define MAX_LOOPBACK 4
|
||||
#define QUAKE2MCAST "ff12::666"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
byte data [ MAX_MSGLEN ];
|
||||
byte data[MAX_MSGLEN];
|
||||
int datalen;
|
||||
} loopmsg_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
loopmsg_t msgs [ MAX_LOOPBACK ];
|
||||
loopmsg_t msgs[MAX_LOOPBACK];
|
||||
int get, send;
|
||||
} loopback_t;
|
||||
|
||||
loopback_t loopbacks [ 2 ];
|
||||
int ip_sockets [ 2 ];
|
||||
loopback_t loopbacks[2];
|
||||
int ip_sockets[2];
|
||||
int ip6_sockets[2];
|
||||
int ipx_sockets [ 2 ];
|
||||
int ipx_sockets[2];
|
||||
char *multicast_interface = NULL;
|
||||
|
||||
int NET_Socket(char *net_interface, int port, netsrc_t type, int family);
|
||||
char *NET_ErrorString ( void );
|
||||
char *NET_ErrorString(void);
|
||||
|
||||
void
|
||||
NetadrToSockadr ( netadr_t *a, struct sockaddr_storage *s )
|
||||
NetadrToSockadr(netadr_t *a, struct sockaddr_storage *s)
|
||||
{
|
||||
struct sockaddr_in6 *s6;
|
||||
|
||||
|
@ -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__
|
||||
|
@ -115,8 +117,8 @@ NetadrToSockadr ( netadr_t *a, struct sockaddr_storage *s )
|
|||
#endif
|
||||
s->ss_family = AF_INET;
|
||||
memcpy(&((struct sockaddr_in *)s)->sin_addr,
|
||||
&((struct in6_addr *)a->ip)->s6_addr[12],
|
||||
sizeof(struct in_addr));
|
||||
&((struct in6_addr *)a->ip)->s6_addr[12],
|
||||
sizeof(struct in_addr));
|
||||
((struct sockaddr_in *)s)->sin_port = a->port;
|
||||
}
|
||||
else
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -145,9 +147,9 @@ NetadrToSockadr ( netadr_t *a, struct sockaddr_storage *s )
|
|||
}
|
||||
|
||||
void
|
||||
SockadrToNetadr ( struct sockaddr_storage *s, netadr_t *a )
|
||||
SockadrToNetadr(struct sockaddr_storage *s, netadr_t *a)
|
||||
{
|
||||
struct sockaddr_in6 *s6;
|
||||
struct sockaddr_in6 *s6;
|
||||
|
||||
if (s->ss_family == AF_INET)
|
||||
{
|
||||
|
@ -181,12 +183,12 @@ SockadrToNetadr ( struct sockaddr_storage *s, netadr_t *a )
|
|||
}
|
||||
|
||||
void
|
||||
NET_Init ( )
|
||||
NET_Init()
|
||||
{
|
||||
}
|
||||
|
||||
qboolean
|
||||
NET_CompareAdr ( netadr_t a, netadr_t b )
|
||||
NET_CompareAdr(netadr_t a, netadr_t b)
|
||||
{
|
||||
if (a.type != b.type)
|
||||
{
|
||||
|
@ -222,7 +224,7 @@ NET_CompareAdr ( netadr_t a, netadr_t b )
|
|||
* Compares without the port
|
||||
*/
|
||||
qboolean
|
||||
NET_CompareBaseAdr ( netadr_t a, netadr_t b )
|
||||
NET_CompareBaseAdr(netadr_t a, netadr_t b)
|
||||
{
|
||||
if (a.type != b.type)
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -349,7 +354,7 @@ NET_BaseAdrToString(netadr_t a)
|
|||
}
|
||||
|
||||
char *
|
||||
NET_AdrToString ( netadr_t a )
|
||||
NET_AdrToString(netadr_t a)
|
||||
{
|
||||
static char s[64];
|
||||
const char *base;
|
||||
|
@ -361,7 +366,7 @@ NET_AdrToString ( netadr_t a )
|
|||
}
|
||||
|
||||
qboolean
|
||||
NET_StringToSockaddr ( char *s, struct sockaddr_storage *sadr )
|
||||
NET_StringToSockaddr(char *s, struct sockaddr_storage *sadr)
|
||||
{
|
||||
char copy[128];
|
||||
char *addrs, *space;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -434,7 +440,7 @@ NET_StringToSockaddr ( char *s, struct sockaddr_storage *sadr )
|
|||
}
|
||||
|
||||
qboolean
|
||||
NET_StringToAdr ( char *s, netadr_t *a )
|
||||
NET_StringToAdr(char *s, netadr_t *a)
|
||||
{
|
||||
struct sockaddr_storage sadr;
|
||||
|
||||
|
@ -457,55 +463,55 @@ NET_StringToAdr ( char *s, netadr_t *a )
|
|||
}
|
||||
|
||||
qboolean
|
||||
NET_IsLocalAddress ( netadr_t adr )
|
||||
NET_IsLocalAddress(netadr_t adr)
|
||||
{
|
||||
return ( NET_CompareAdr( adr, net_local_adr ) );
|
||||
return NET_CompareAdr(adr, net_local_adr);
|
||||
}
|
||||
|
||||
qboolean
|
||||
NET_GetLoopPacket ( netsrc_t sock, netadr_t *net_from, sizebuf_t *net_message )
|
||||
NET_GetLoopPacket(netsrc_t sock, netadr_t *net_from, sizebuf_t *net_message)
|
||||
{
|
||||
int i;
|
||||
loopback_t *loop;
|
||||
loopback_t *loop;
|
||||
|
||||
loop = &loopbacks [ sock ];
|
||||
loop = &loopbacks[sock];
|
||||
|
||||
if ( loop->send - loop->get > MAX_LOOPBACK )
|
||||
if (loop->send - loop->get > MAX_LOOPBACK)
|
||||
{
|
||||
loop->get = loop->send - MAX_LOOPBACK;
|
||||
}
|
||||
|
||||
if ( loop->get >= loop->send )
|
||||
if (loop->get >= loop->send)
|
||||
{
|
||||
return ( false );
|
||||
return false;
|
||||
}
|
||||
|
||||
i = loop->get & ( MAX_LOOPBACK - 1 );
|
||||
i = loop->get & (MAX_LOOPBACK - 1);
|
||||
loop->get++;
|
||||
|
||||
memcpy( net_message->data, loop->msgs [ i ].data, loop->msgs [ i ].datalen );
|
||||
net_message->cursize = loop->msgs [ i ].datalen;
|
||||
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
|
||||
NET_SendLoopPacket ( netsrc_t sock, int length, void *data, netadr_t to )
|
||||
NET_SendLoopPacket(netsrc_t sock, int length, void *data, netadr_t to)
|
||||
{
|
||||
int i;
|
||||
loopback_t *loop;
|
||||
loopback_t *loop;
|
||||
|
||||
loop = &loopbacks [ sock ^ 1 ];
|
||||
loop = &loopbacks[sock ^ 1];
|
||||
|
||||
i = loop->send & ( MAX_LOOPBACK - 1 );
|
||||
i = loop->send & (MAX_LOOPBACK - 1);
|
||||
loop->send++;
|
||||
|
||||
memcpy( loop->msgs [ i ].data, data, length );
|
||||
loop->msgs [ i ].datalen = length;
|
||||
memcpy(loop->msgs[i].data, data, length);
|
||||
loop->msgs[i].datalen = length;
|
||||
}
|
||||
|
||||
qboolean
|
||||
NET_GetPacket ( netsrc_t sock, netadr_t *net_from, sizebuf_t *net_message )
|
||||
NET_GetPacket(netsrc_t sock, netadr_t *net_from, sizebuf_t *net_message)
|
||||
{
|
||||
int ret;
|
||||
struct sockaddr_storage from;
|
||||
|
@ -573,7 +579,7 @@ 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 )
|
||||
NET_SendPacket(netsrc_t sock, int length, void *data, netadr_t to)
|
||||
{
|
||||
int ret;
|
||||
struct sockaddr_storage addr;
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -717,7 +731,7 @@ NET_SendPacket ( netsrc_t sock, int length, void *data, netadr_t to )
|
|||
}
|
||||
|
||||
void
|
||||
NET_OpenIP ( void )
|
||||
NET_OpenIP(void)
|
||||
{
|
||||
cvar_t *port, *ip;
|
||||
|
||||
|
@ -753,7 +767,7 @@ NET_OpenIP ( void )
|
|||
* A single player game will only use the loopback code
|
||||
*/
|
||||
void
|
||||
NET_Config ( qboolean multiplayer )
|
||||
NET_Config(qboolean multiplayer)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
@ -791,7 +805,7 @@ NET_Config ( qboolean multiplayer )
|
|||
/* =================================================================== */
|
||||
|
||||
int
|
||||
NET_Socket ( char *net_interface, int port, netsrc_t type, int family )
|
||||
NET_Socket(char *net_interface, int port, netsrc_t type, int family)
|
||||
{
|
||||
char Buf[BUFSIZ], *Host, *Service;
|
||||
int newsocket, Error;
|
||||
|
@ -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,11 +877,12 @@ 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());
|
||||
return 0;
|
||||
NET_ErrorString());
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (bind(newsocket, ai->ai_addr, ai->ai_addrlen) < 0)
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -937,32 +964,33 @@ NET_Socket ( char *net_interface, int port, netsrc_t type, int family )
|
|||
}
|
||||
|
||||
void
|
||||
NET_Shutdown ( void )
|
||||
NET_Shutdown(void)
|
||||
{
|
||||
NET_Config( false ); /* close sockets */
|
||||
NET_Config(false); /* close sockets */
|
||||
}
|
||||
|
||||
char *
|
||||
NET_ErrorString ( void )
|
||||
NET_ErrorString(void)
|
||||
{
|
||||
int code;
|
||||
|
||||
code = errno;
|
||||
return ( strerror( code ) );
|
||||
return strerror(code);
|
||||
}
|
||||
|
||||
/*
|
||||
* sleeps msec or until net socket is ready
|
||||
*/
|
||||
void
|
||||
NET_Sleep ( int msec )
|
||||
NET_Sleep(int msec)
|
||||
{
|
||||
struct timeval timeout;
|
||||
fd_set fdset;
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
6360
src/unix/qgl.c
6360
src/unix/qgl.c
File diff suppressed because it is too large
Load diff
|
@ -53,180 +53,206 @@ unsigned sys_frame_time;
|
|||
int curtime;
|
||||
static void *game_library;
|
||||
|
||||
static char findbase [ MAX_OSPATH ];
|
||||
static char findpath [ MAX_OSPATH ];
|
||||
static char findpattern [ MAX_OSPATH ];
|
||||
static DIR *fdir;
|
||||
static char findbase[MAX_OSPATH];
|
||||
static char findpath[MAX_OSPATH];
|
||||
static char findpattern[MAX_OSPATH];
|
||||
static DIR *fdir;
|
||||
|
||||
qboolean stdin_active = true;
|
||||
extern FILE *logfile;
|
||||
|
||||
static qboolean
|
||||
CompareAttributes ( char *path, char *name, unsigned musthave, unsigned canthave )
|
||||
CompareAttributes(char *path, char *name, unsigned musthave, unsigned canthave)
|
||||
{
|
||||
struct stat st;
|
||||
char fn [ MAX_OSPATH ];
|
||||
char fn[MAX_OSPATH];
|
||||
|
||||
/* . and .. never match */
|
||||
if ( ( strcmp( name, "." ) == 0 ) || ( strcmp( name, ".." ) == 0 ) )
|
||||
if ((strcmp(name, ".") == 0) || (strcmp(name, "..") == 0))
|
||||
{
|
||||
return ( false );
|
||||
return false;
|
||||
}
|
||||
|
||||
return ( true );
|
||||
return true;
|
||||
|
||||
if ( stat( fn, &st ) == -1 )
|
||||
if (stat(fn, &st) == -1)
|
||||
{
|
||||
return ( false ); /* shouldn't happen */
|
||||
return false; /* shouldn't happen */
|
||||
}
|
||||
|
||||
if ( ( st.st_mode & S_IFDIR ) && ( canthave & SFF_SUBDIR ) )
|
||||
if ((st.st_mode & S_IFDIR) && (canthave & SFF_SUBDIR))
|
||||
{
|
||||
return ( false );
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ( musthave & SFF_SUBDIR ) && !( st.st_mode & S_IFDIR ) )
|
||||
if ((musthave & SFF_SUBDIR) && !(st.st_mode & S_IFDIR))
|
||||
{
|
||||
return ( false );
|
||||
return false;
|
||||
}
|
||||
|
||||
return ( true );
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
Sys_Init ( void )
|
||||
Sys_Init(void)
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
Sys_Milliseconds ( void )
|
||||
Sys_Milliseconds(void)
|
||||
{
|
||||
struct timeval tp;
|
||||
struct timezone tzp;
|
||||
static int secbase;
|
||||
|
||||
gettimeofday( &tp, &tzp );
|
||||
gettimeofday(&tp, &tzp);
|
||||
|
||||
if ( !secbase )
|
||||
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;
|
||||
curtime = (tp.tv_sec - secbase) * 1000 + tp.tv_usec / 1000;
|
||||
|
||||
return ( curtime );
|
||||
return curtime;
|
||||
}
|
||||
|
||||
void
|
||||
Sys_Mkdir ( char *path )
|
||||
Sys_Mkdir(char *path)
|
||||
{
|
||||
mkdir( path, 0755 );
|
||||
mkdir(path, 0755);
|
||||
}
|
||||
|
||||
char *
|
||||
Sys_GetCurrentDirectory ( void )
|
||||
Sys_GetCurrentDirectory(void)
|
||||
{
|
||||
static char dir [ MAX_OSPATH ];
|
||||
static char dir[MAX_OSPATH];
|
||||
|
||||
if ( !getcwd( dir, sizeof ( dir ) ) )
|
||||
if (!getcwd(dir, sizeof(dir)))
|
||||
{
|
||||
Sys_Error( "Couldn't get current working directory" );
|
||||
Sys_Error("Couldn't get current working directory");
|
||||
}
|
||||
|
||||
return ( dir );
|
||||
return dir;
|
||||
}
|
||||
|
||||
char *
|
||||
Sys_FindFirst ( char *path, unsigned musthave, unsigned canhave )
|
||||
Sys_FindFirst(char *path, unsigned musthave, unsigned canhave)
|
||||
{
|
||||
struct dirent *d;
|
||||
char *p;
|
||||
|
||||
if ( fdir )
|
||||
if (fdir)
|
||||
{
|
||||
Sys_Error( "Sys_BeginFind without close" );
|
||||
Sys_Error("Sys_BeginFind without close");
|
||||
}
|
||||
|
||||
strcpy( findbase, path );
|
||||
strcpy(findbase, path);
|
||||
|
||||
if ( ( p = strrchr( findbase, '/' ) ) != NULL )
|
||||
if ((p = strrchr(findbase, '/')) != NULL)
|
||||
{
|
||||
*p = 0;
|
||||
strcpy( findpattern, p + 1 );
|
||||
strcpy(findpattern, p + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy( findpattern, "*" );
|
||||
strcpy(findpattern, "*");
|
||||
}
|
||||
|
||||
if ( strcmp( findpattern, "*.*" ) == 0 )
|
||||
if (strcmp(findpattern, "*.*") == 0)
|
||||
{
|
||||
strcpy( findpattern, "*" );
|
||||
strcpy(findpattern, "*");
|
||||
}
|
||||
|
||||
if ( ( fdir = opendir( findbase ) ) == NULL )
|
||||
if ((fdir = opendir(findbase)) == NULL)
|
||||
{
|
||||
return ( NULL );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while ( ( d = readdir( fdir ) ) != NULL )
|
||||
while ((d = readdir(fdir)) != NULL)
|
||||
{
|
||||
if ( !*findpattern || glob_match( findpattern, d->d_name ) )
|
||||
if (!*findpattern || glob_match(findpattern, d->d_name))
|
||||
{
|
||||
if ( CompareAttributes( findbase, d->d_name, musthave, canhave ) )
|
||||
if (CompareAttributes(findbase, d->d_name, musthave, canhave))
|
||||
{
|
||||
sprintf( findpath, "%s/%s", findbase, d->d_name );
|
||||
return ( findpath );
|
||||
sprintf(findpath, "%s/%s", findbase, d->d_name);
|
||||
return findpath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ( NULL );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *
|
||||
Sys_FindNext ( unsigned musthave, unsigned canhave )
|
||||
Sys_FindNext(unsigned musthave, unsigned canhave)
|
||||
{
|
||||
struct dirent *d;
|
||||
|
||||
if ( fdir == NULL )
|
||||
if (fdir == NULL)
|
||||
{
|
||||
return ( NULL );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while ( ( d = readdir( fdir ) ) != NULL )
|
||||
while ((d = readdir(fdir)) != NULL)
|
||||
{
|
||||
if ( !*findpattern || glob_match( findpattern, d->d_name ) )
|
||||
if (!*findpattern || glob_match(findpattern, d->d_name))
|
||||
{
|
||||
if ( CompareAttributes( findbase, d->d_name, musthave, canhave ) )
|
||||
if (CompareAttributes(findbase, d->d_name, musthave, canhave))
|
||||
{
|
||||
sprintf( findpath, "%s/%s", findbase, d->d_name );
|
||||
return ( findpath );
|
||||
sprintf(findpath, "%s/%s", findbase, d->d_name);
|
||||
return findpath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ( NULL );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
Sys_FindClose ( void )
|
||||
Sys_FindClose(void)
|
||||
{
|
||||
if ( fdir != NULL )
|
||||
if (fdir != NULL)
|
||||
{
|
||||
closedir( fdir );
|
||||
closedir(fdir);
|
||||
}
|
||||
|
||||
fdir = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
Sys_ConsoleOutput ( char *string )
|
||||
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)
|
||||
{
|
||||
|
@ -234,116 +260,116 @@ Sys_Quit(void)
|
|||
CL_Shutdown();
|
||||
#endif
|
||||
|
||||
if (logfile)
|
||||
if (logfile)
|
||||
{
|
||||
fclose (logfile);
|
||||
fclose(logfile);
|
||||
logfile = NULL;
|
||||
}
|
||||
|
||||
Qcommon_Shutdown();
|
||||
fcntl( 0, F_SETFL, fcntl( 0, F_GETFL, 0 ) & ~FNDELAY );
|
||||
fcntl(0, F_SETFL, fcntl(0, F_GETFL, 0) & ~FNDELAY);
|
||||
|
||||
printf("------------------------------------\n");
|
||||
|
||||
exit( 0 );
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void
|
||||
Sys_Error ( char *error, ... )
|
||||
Sys_Error(char *error, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
char string [ 1024 ];
|
||||
char string[1024];
|
||||
|
||||
/* change stdin to non blocking */
|
||||
fcntl( 0, F_SETFL, fcntl( 0, F_GETFL, 0 ) & ~FNDELAY );
|
||||
fcntl(0, F_SETFL, fcntl(0, F_GETFL, 0) & ~FNDELAY);
|
||||
|
||||
#ifndef DEDICATED_ONLY
|
||||
CL_Shutdown();
|
||||
#endif
|
||||
Qcommon_Shutdown();
|
||||
|
||||
va_start( argptr, error );
|
||||
vsnprintf( string, 1024, error, argptr );
|
||||
va_end( argptr );
|
||||
fprintf( stderr, "Error: %s\n", string );
|
||||
va_start(argptr, error);
|
||||
vsnprintf(string, 1024, error, argptr);
|
||||
va_end(argptr);
|
||||
fprintf(stderr, "Error: %s\n", string);
|
||||
|
||||
exit( 1 );
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* returns -1 if not present
|
||||
*/
|
||||
int
|
||||
Sys_FileTime ( char *path )
|
||||
Sys_FileTime(char *path)
|
||||
{
|
||||
struct stat buf;
|
||||
|
||||
if ( stat( path, &buf ) == -1 )
|
||||
if (stat(path, &buf) == -1)
|
||||
{
|
||||
return ( -1 );
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ( buf.st_mtime );
|
||||
return buf.st_mtime;
|
||||
}
|
||||
|
||||
void
|
||||
floating_point_exception_handler ( int whatever )
|
||||
floating_point_exception_handler(int whatever)
|
||||
{
|
||||
signal( SIGFPE, floating_point_exception_handler );
|
||||
signal(SIGFPE, floating_point_exception_handler);
|
||||
}
|
||||
|
||||
char *
|
||||
Sys_ConsoleInput ( void )
|
||||
Sys_ConsoleInput(void)
|
||||
{
|
||||
static char text [ 256 ];
|
||||
static char text[256];
|
||||
int len;
|
||||
fd_set fdset;
|
||||
struct timeval timeout;
|
||||
|
||||
if ( !dedicated || !dedicated->value )
|
||||
if (!dedicated || !dedicated->value)
|
||||
{
|
||||
return ( NULL );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ( !stdin_active )
|
||||
if (!stdin_active)
|
||||
{
|
||||
return ( NULL );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
FD_ZERO( &fdset );
|
||||
FD_SET( 0, &fdset ); /* stdin */
|
||||
FD_ZERO(&fdset);
|
||||
FD_SET(0, &fdset); /* stdin */
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = 0;
|
||||
|
||||
if ( ( select( 1, &fdset, NULL, NULL, &timeout ) == -1 ) || !FD_ISSET( 0, &fdset ) )
|
||||
if ((select(1, &fdset, NULL, NULL, &timeout) == -1) || !FD_ISSET(0, &fdset))
|
||||
{
|
||||
return ( NULL );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
len = read( 0, text, sizeof ( text ) );
|
||||
len = read(0, text, sizeof(text));
|
||||
|
||||
if ( len == 0 ) /* eof! */
|
||||
if (len == 0) /* eof! */
|
||||
{
|
||||
stdin_active = false;
|
||||
return ( NULL );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ( len < 1 )
|
||||
if (len < 1)
|
||||
{
|
||||
return ( NULL );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
text [ len - 1 ] = 0; /* rip off the /n and terminate */
|
||||
text[len - 1] = 0; /* rip off the /n and terminate */
|
||||
|
||||
return ( text );
|
||||
return text;
|
||||
}
|
||||
|
||||
void
|
||||
Sys_UnloadGame ( void )
|
||||
Sys_UnloadGame(void)
|
||||
{
|
||||
if ( game_library )
|
||||
if (game_library)
|
||||
{
|
||||
dlclose( game_library );
|
||||
dlclose(game_library);
|
||||
}
|
||||
|
||||
game_library = NULL;
|
||||
|
@ -353,65 +379,65 @@ Sys_UnloadGame ( void )
|
|||
* Loads the game dll
|
||||
*/
|
||||
void *
|
||||
Sys_GetGameAPI ( void *parms )
|
||||
Sys_GetGameAPI(void *parms)
|
||||
{
|
||||
void *( *GetGameAPI )(void *);
|
||||
void *(*GetGameAPI)(void *);
|
||||
|
||||
FILE *fp;
|
||||
char name [ MAX_OSPATH ];
|
||||
char *path;
|
||||
char *str_p;
|
||||
FILE *fp;
|
||||
char name[MAX_OSPATH];
|
||||
char *path;
|
||||
char *str_p;
|
||||
const char *gamename = "game.so";
|
||||
|
||||
setreuid( getuid(), getuid() );
|
||||
setegid( getgid() );
|
||||
setreuid(getuid(), getuid());
|
||||
setegid(getgid());
|
||||
|
||||
if ( game_library )
|
||||
if (game_library)
|
||||
{
|
||||
Com_Error( ERR_FATAL, "Sys_GetGameAPI without Sys_UnloadingGame" );
|
||||
Com_Error(ERR_FATAL, "Sys_GetGameAPI without Sys_UnloadingGame");
|
||||
}
|
||||
|
||||
Com_Printf( "LoadLibrary(\"%s\")\n", gamename );
|
||||
Com_Printf("LoadLibrary(\"%s\")\n", gamename);
|
||||
|
||||
/* now run through the search paths */
|
||||
path = NULL;
|
||||
|
||||
while ( 1 )
|
||||
while (1)
|
||||
{
|
||||
path = FS_NextPath( path );
|
||||
path = FS_NextPath(path);
|
||||
|
||||
if ( !path )
|
||||
if (!path)
|
||||
{
|
||||
return ( NULL ); /* couldn't find one anywhere */
|
||||
return NULL; /* couldn't find one anywhere */
|
||||
}
|
||||
|
||||
snprintf( name, MAX_OSPATH, "%s/%s", path, gamename );
|
||||
snprintf(name, MAX_OSPATH, "%s/%s", path, gamename);
|
||||
|
||||
/* skip it if it just doesn't exist */
|
||||
fp = fopen( name, "rb" );
|
||||
fp = fopen(name, "rb");
|
||||
|
||||
if ( fp == NULL )
|
||||
if (fp == NULL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
fclose( fp );
|
||||
fclose(fp);
|
||||
|
||||
game_library = dlopen( name, RTLD_NOW );
|
||||
game_library = dlopen(name, RTLD_NOW);
|
||||
|
||||
if ( game_library )
|
||||
if (game_library)
|
||||
{
|
||||
Com_MDPrintf( "LoadLibrary (%s)\n", name );
|
||||
Com_MDPrintf("LoadLibrary (%s)\n", name);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
Com_Printf( "LoadLibrary (%s):", name );
|
||||
Com_Printf("LoadLibrary (%s):", name);
|
||||
|
||||
path = (char *) dlerror();
|
||||
str_p = strchr( path, ':' ); /* skip the path (already shown) */
|
||||
path = (char *)dlerror();
|
||||
str_p = strchr(path, ':'); /* skip the path (already shown) */
|
||||
|
||||
if ( str_p == NULL )
|
||||
if (str_p == NULL)
|
||||
{
|
||||
str_p = path;
|
||||
}
|
||||
|
@ -420,33 +446,31 @@ Sys_GetGameAPI ( void *parms )
|
|||
str_p++;
|
||||
}
|
||||
|
||||
Com_Printf( "%s\n", str_p );
|
||||
Com_Printf("%s\n", str_p);
|
||||
|
||||
return ( NULL );
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
GetGameAPI = (void *) dlsym( game_library, "GetGameAPI" );
|
||||
GetGameAPI = (void *)dlsym(game_library, "GetGameAPI");
|
||||
|
||||
if ( !GetGameAPI )
|
||||
if (!GetGameAPI)
|
||||
{
|
||||
Sys_UnloadGame();
|
||||
return ( NULL );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ( GetGameAPI( parms ) );
|
||||
return GetGameAPI(parms);
|
||||
}
|
||||
|
||||
void
|
||||
Sys_SendKeyEvents ( void )
|
||||
Sys_SendKeyEvents(void)
|
||||
{
|
||||
#ifndef DEDICATED_ONLY
|
||||
|
||||
if ( IN_Update_fp )
|
||||
if (IN_Update_fp)
|
||||
{
|
||||
IN_Update_fp();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* grab frame time */
|
||||
|
|
285
src/unix/vid.c
285
src/unix/vid.c
|
@ -45,69 +45,70 @@
|
|||
refexport_t re;
|
||||
|
||||
/* Console variables that we need to access from this module */
|
||||
cvar_t *vid_gamma;
|
||||
cvar_t *vid_ref; /* Name of Refresh DLL loaded */
|
||||
cvar_t *vid_xpos; /* X coordinate of window position */
|
||||
cvar_t *vid_ypos; /* Y coordinate of window position */
|
||||
cvar_t *vid_fullscreen;
|
||||
cvar_t *vid_gamma;
|
||||
cvar_t *vid_ref; /* Name of Refresh DLL loaded */
|
||||
cvar_t *vid_xpos; /* X coordinate of window position */
|
||||
cvar_t *vid_ypos; /* Y coordinate of window position */
|
||||
cvar_t *vid_fullscreen;
|
||||
|
||||
/* Global variables used internally by this module */
|
||||
viddef_t viddef; /* global video state; used by other modules */
|
||||
void *reflib_library; /* Handle to refresh DLL */
|
||||
void *reflib_library; /* Handle to refresh DLL */
|
||||
qboolean reflib_active = 0;
|
||||
|
||||
#define VID_NUM_MODES ( sizeof ( vid_modes ) / sizeof ( vid_modes [ 0 ] ) )
|
||||
#define VID_NUM_MODES (sizeof(vid_modes) / sizeof(vid_modes[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 );
|
||||
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);
|
||||
|
||||
in_state_t in_state;
|
||||
|
||||
void ( *IN_BackendInit_fp )( in_state_t *in_state_p );
|
||||
void ( *IN_BackendShutdown_fp )( void );
|
||||
void ( *IN_BackendMouseButtons_fp )( void );
|
||||
void ( *IN_BackendMove_fp )( usercmd_t *cmd );
|
||||
void (*IN_BackendInit_fp)(in_state_t *in_state_p);
|
||||
void (*IN_BackendShutdown_fp)(void);
|
||||
void (*IN_BackendMouseButtons_fp)(void);
|
||||
void (*IN_BackendMove_fp)(usercmd_t *cmd);
|
||||
|
||||
extern void VID_MenuShutdown ( void );
|
||||
extern void VID_MenuShutdown(void);
|
||||
|
||||
/* DLL GLUE */
|
||||
|
||||
#define MAXPRINTMSG 4096
|
||||
|
||||
void
|
||||
VID_Printf ( int print_level, char *fmt, ... )
|
||||
VID_Printf(int print_level, char *fmt, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
char msg [ MAXPRINTMSG ];
|
||||
char msg[MAXPRINTMSG];
|
||||
|
||||
va_start( argptr, fmt );
|
||||
vsnprintf( msg, MAXPRINTMSG, fmt, argptr );
|
||||
va_end( argptr );
|
||||
va_start(argptr, fmt);
|
||||
vsnprintf(msg, MAXPRINTMSG, fmt, argptr);
|
||||
va_end(argptr);
|
||||
|
||||
if ( print_level == PRINT_ALL )
|
||||
if (print_level == PRINT_ALL)
|
||||
{
|
||||
Com_Printf( "%s", msg );
|
||||
Com_Printf("%s", msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
Com_DPrintf( "%s", msg );
|
||||
Com_DPrintf("%s", msg);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
VID_Error ( int err_level, char *fmt, ... )
|
||||
VID_Error(int err_level, char *fmt, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
char msg [ MAXPRINTMSG ];
|
||||
char msg[MAXPRINTMSG];
|
||||
|
||||
va_start( argptr, fmt );
|
||||
vsnprintf( msg, MAXPRINTMSG, fmt, argptr );
|
||||
va_end( argptr );
|
||||
va_start(argptr, fmt);
|
||||
vsnprintf(msg, MAXPRINTMSG, fmt, argptr);
|
||||
va_end(argptr);
|
||||
|
||||
Com_Error( err_level, "%s", msg );
|
||||
Com_Error(err_level, "%s", msg);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -116,7 +117,7 @@ VID_Error ( int err_level, char *fmt, ... )
|
|||
* cause the entire video mode and refresh DLL to be reset on the next frame.
|
||||
*/
|
||||
void
|
||||
VID_Restart_f ( void )
|
||||
VID_Restart_f(void)
|
||||
{
|
||||
vid_ref->modified = true;
|
||||
}
|
||||
|
@ -130,68 +131,68 @@ typedef struct vidmode_s
|
|||
|
||||
/* This must be the same as in menu.c! */
|
||||
vidmode_t vid_modes[] = {
|
||||
{ "Mode 0: 320x240", 320, 240, 0 },
|
||||
{ "Mode 1: 400x300", 400, 300, 1 },
|
||||
{ "Mode 2: 512x384", 512, 384, 2 },
|
||||
{ "Mode 3: 640x400", 640, 400, 3 },
|
||||
{ "Mode 4: 640x480", 640, 480, 4 },
|
||||
{ "Mode 5: 800x500", 800, 500, 5 },
|
||||
{ "Mode 6: 800x600", 800, 600, 6 },
|
||||
{ "Mode 7: 960x720", 960, 720, 7 },
|
||||
{ "Mode 8: 1024x480", 1024, 480, 8 },
|
||||
{ "Mode 9: 1024x640", 1024, 640, 9 },
|
||||
{ "Mode 10: 1024x768", 1024, 768, 10 },
|
||||
{ "Mode 11: 1152x768", 1152, 768, 11 },
|
||||
{ "Mode 12: 1152x864", 1152, 864, 12 },
|
||||
{ "Mode 13: 1280x800", 1280, 800, 13 },
|
||||
{ "Mode 14: 1280x854", 1280, 854, 14 },
|
||||
{ "Mode 15: 1280x960", 1280, 860, 15 },
|
||||
{ "Mode 16: 1280x1024", 1280, 1024, 16 },
|
||||
{ "Mode 17: 1440x900", 1440, 900, 17 },
|
||||
{ "Mode 18: 1600x1200", 1600, 1200, 18 },
|
||||
{ "Mode 19: 1680x1050", 1680, 1050, 19 },
|
||||
{ "Mode 20: 1920x1080", 1920, 1080, 20 },
|
||||
{ "Mode 21: 1920x1200", 1920, 1200, 21 },
|
||||
{ "Mode 22: 2048x1536", 2048, 1536, 22 },
|
||||
{"Mode 0: 320x240", 320, 240, 0},
|
||||
{"Mode 1: 400x300", 400, 300, 1},
|
||||
{"Mode 2: 512x384", 512, 384, 2},
|
||||
{"Mode 3: 640x400", 640, 400, 3},
|
||||
{"Mode 4: 640x480", 640, 480, 4},
|
||||
{"Mode 5: 800x500", 800, 500, 5},
|
||||
{"Mode 6: 800x600", 800, 600, 6},
|
||||
{"Mode 7: 960x720", 960, 720, 7},
|
||||
{"Mode 8: 1024x480", 1024, 480, 8},
|
||||
{"Mode 9: 1024x640", 1024, 640, 9},
|
||||
{"Mode 10: 1024x768", 1024, 768, 10},
|
||||
{"Mode 11: 1152x768", 1152, 768, 11},
|
||||
{"Mode 12: 1152x864", 1152, 864, 12},
|
||||
{"Mode 13: 1280x800", 1280, 800, 13},
|
||||
{"Mode 14: 1280x854", 1280, 854, 14},
|
||||
{"Mode 15: 1280x960", 1280, 860, 15},
|
||||
{"Mode 16: 1280x1024", 1280, 1024, 16},
|
||||
{"Mode 17: 1440x900", 1440, 900, 17},
|
||||
{"Mode 18: 1600x1200", 1600, 1200, 18},
|
||||
{"Mode 19: 1680x1050", 1680, 1050, 19},
|
||||
{"Mode 20: 1920x1080", 1920, 1080, 20},
|
||||
{"Mode 21: 1920x1200", 1920, 1200, 21},
|
||||
{"Mode 22: 2048x1536", 2048, 1536, 22},
|
||||
};
|
||||
|
||||
qboolean
|
||||
VID_GetModeInfo ( int *width, int *height, int mode )
|
||||
VID_GetModeInfo(int *width, int *height, int mode)
|
||||
{
|
||||
if ( ( mode < 0 ) || ( mode >= VID_NUM_MODES ) )
|
||||
if ((mode < 0) || (mode >= VID_NUM_MODES))
|
||||
{
|
||||
return ( false );
|
||||
return false;
|
||||
}
|
||||
|
||||
*width = vid_modes [ mode ].width;
|
||||
*height = vid_modes [ mode ].height;
|
||||
*width = vid_modes[mode].width;
|
||||
*height = vid_modes[mode].height;
|
||||
|
||||
return ( true );
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
VID_NewWindow ( int width, int height )
|
||||
VID_NewWindow(int width, int height)
|
||||
{
|
||||
viddef.width = width;
|
||||
viddef.width = width;
|
||||
viddef.height = height;
|
||||
}
|
||||
|
||||
void
|
||||
VID_FreeReflib ( void )
|
||||
VID_FreeReflib(void)
|
||||
{
|
||||
if ( reflib_library )
|
||||
if (reflib_library)
|
||||
{
|
||||
if ( IN_Close_fp )
|
||||
if (IN_Close_fp)
|
||||
{
|
||||
IN_Close_fp();
|
||||
}
|
||||
|
||||
if ( IN_BackendShutdown_fp )
|
||||
if (IN_BackendShutdown_fp)
|
||||
{
|
||||
IN_BackendShutdown_fp();
|
||||
}
|
||||
|
||||
dlclose( reflib_library );
|
||||
dlclose(reflib_library);
|
||||
}
|
||||
|
||||
IN_KeyboardInit_fp = NULL;
|
||||
|
@ -202,28 +203,28 @@ VID_FreeReflib ( void )
|
|||
IN_BackendMouseButtons_fp = NULL;
|
||||
IN_BackendMove_fp = NULL;
|
||||
|
||||
memset( &re, 0, sizeof ( re ) );
|
||||
memset(&re, 0, sizeof(re));
|
||||
reflib_library = NULL;
|
||||
reflib_active = false;
|
||||
reflib_active = false;
|
||||
}
|
||||
|
||||
qboolean
|
||||
VID_LoadRefresh ( char *name )
|
||||
VID_LoadRefresh(char *name)
|
||||
{
|
||||
refimport_t ri;
|
||||
R_GetRefAPI_t R_GetRefAPI;
|
||||
char fn [ MAX_OSPATH ];
|
||||
char *path;
|
||||
char fn[MAX_OSPATH];
|
||||
char *path;
|
||||
struct stat st;
|
||||
|
||||
if ( reflib_active )
|
||||
if (reflib_active)
|
||||
{
|
||||
if ( IN_Close_fp )
|
||||
if (IN_Close_fp)
|
||||
{
|
||||
IN_Close_fp();
|
||||
}
|
||||
|
||||
if ( IN_BackendShutdown_fp )
|
||||
if (IN_BackendShutdown_fp)
|
||||
{
|
||||
IN_BackendShutdown_fp();
|
||||
}
|
||||
|
@ -234,24 +235,24 @@ VID_LoadRefresh ( char *name )
|
|||
VID_FreeReflib();
|
||||
}
|
||||
|
||||
Com_Printf( "----- refresher initialization -----\n");
|
||||
Com_Printf("----- refresher initialization -----\n");
|
||||
|
||||
path = Cvar_Get( "basedir", ".", CVAR_NOSET )->string;
|
||||
snprintf( fn, MAX_OSPATH, "%s/%s", path, name );
|
||||
path = Cvar_Get("basedir", ".", CVAR_NOSET)->string;
|
||||
snprintf(fn, MAX_OSPATH, "%s/%s", path, name);
|
||||
|
||||
if ( stat( fn, &st ) == -1 )
|
||||
if (stat(fn, &st) == -1)
|
||||
{
|
||||
Com_Printf( "LoadLibrary(\"%s\") failed: %s\n", name, strerror( errno ) );
|
||||
return ( false );
|
||||
Com_Printf("LoadLibrary(\"%s\") failed: %s\n", name, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ( reflib_library = dlopen( fn, RTLD_LAZY ) ) == 0 )
|
||||
if ((reflib_library = dlopen(fn, RTLD_LAZY)) == 0)
|
||||
{
|
||||
Com_Printf( "LoadLibrary(\"%s\") failed: %s\n", name, dlerror() );
|
||||
return ( false );
|
||||
Com_Printf("LoadLibrary(\"%s\") failed: %s\n", name, dlerror());
|
||||
return false;
|
||||
}
|
||||
|
||||
Com_Printf( "LoadLibrary(\"%s\")\n", fn );
|
||||
Com_Printf("LoadLibrary(\"%s\")\n", fn);
|
||||
|
||||
ri.Cmd_AddCommand = Cmd_AddCommand;
|
||||
ri.Cmd_RemoveCommand = Cmd_RemoveCommand;
|
||||
|
@ -271,17 +272,17 @@ VID_LoadRefresh ( char *name )
|
|||
ri.Vid_MenuInit = VID_MenuInit;
|
||||
ri.Vid_NewWindow = VID_NewWindow;
|
||||
|
||||
if ( ( R_GetRefAPI = (void *) dlsym( reflib_library, "R_GetRefAPI" ) ) == 0 )
|
||||
if ((R_GetRefAPI = (void *)dlsym(reflib_library, "R_GetRefAPI")) == 0)
|
||||
{
|
||||
Com_Error( ERR_FATAL, "dlsym failed on %s", name );
|
||||
Com_Error(ERR_FATAL, "dlsym failed on %s", name);
|
||||
}
|
||||
|
||||
re = R_GetRefAPI( ri );
|
||||
re = R_GetRefAPI(ri);
|
||||
|
||||
if ( re.api_version != API_VERSION )
|
||||
if (re.api_version != API_VERSION)
|
||||
{
|
||||
VID_FreeReflib();
|
||||
Com_Error( ERR_FATAL, "%s has incompatible api_version", name );
|
||||
Com_Error(ERR_FATAL, "%s has incompatible api_version", name);
|
||||
}
|
||||
|
||||
/* Init IN (Mouse) */
|
||||
|
@ -291,40 +292,40 @@ VID_LoadRefresh ( char *name )
|
|||
in_state.in_strafe_state = &in_strafe.state;
|
||||
in_state.in_speed_state = &in_speed.state;
|
||||
|
||||
if ( ( ( IN_BackendInit_fp = dlsym( reflib_library, "IN_BackendInit" ) ) == NULL ) ||
|
||||
( ( IN_BackendShutdown_fp = dlsym( reflib_library, "IN_BackendShutdown" ) ) == NULL ) ||
|
||||
( ( IN_BackendMouseButtons_fp = dlsym( reflib_library, "IN_BackendMouseButtons" ) ) == NULL ) ||
|
||||
( ( IN_BackendMove_fp = dlsym( reflib_library, "IN_BackendMove" ) ) == NULL ) )
|
||||
if (((IN_BackendInit_fp = dlsym(reflib_library, "IN_BackendInit")) == NULL) ||
|
||||
((IN_BackendShutdown_fp = dlsym(reflib_library, "IN_BackendShutdown")) == NULL) ||
|
||||
((IN_BackendMouseButtons_fp = dlsym(reflib_library, "IN_BackendMouseButtons")) == NULL) ||
|
||||
((IN_BackendMove_fp = dlsym(reflib_library, "IN_BackendMove")) == NULL))
|
||||
{
|
||||
Com_Error( ERR_FATAL, "No input backend init functions in REF.\n" );
|
||||
Com_Error(ERR_FATAL, "No input backend init functions in REF.\n");
|
||||
}
|
||||
|
||||
if ( IN_BackendInit_fp )
|
||||
if (IN_BackendInit_fp)
|
||||
{
|
||||
IN_BackendInit_fp( &in_state );
|
||||
IN_BackendInit_fp(&in_state);
|
||||
}
|
||||
|
||||
if ( re.Init( 0, 0 ) == -1 )
|
||||
if (re.Init(0, 0) == -1)
|
||||
{
|
||||
re.Shutdown();
|
||||
VID_FreeReflib();
|
||||
return ( false );
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Init IN */
|
||||
if ( ( ( IN_KeyboardInit_fp = dlsym( reflib_library, "IN_KeyboardInit" ) ) == NULL ) ||
|
||||
( ( IN_Update_fp = dlsym( reflib_library, "IN_Update" ) ) == NULL ) ||
|
||||
( ( IN_Close_fp = dlsym( reflib_library, "IN_Close" ) ) == NULL ) )
|
||||
if (((IN_KeyboardInit_fp = dlsym(reflib_library, "IN_KeyboardInit")) == NULL) ||
|
||||
((IN_Update_fp = dlsym(reflib_library, "IN_Update")) == NULL) ||
|
||||
((IN_Close_fp = dlsym(reflib_library, "IN_Close")) == NULL))
|
||||
{
|
||||
Com_Error( ERR_FATAL, "No keyboard input functions in REF.\n" );
|
||||
Com_Error(ERR_FATAL, "No keyboard input functions in REF.\n");
|
||||
}
|
||||
|
||||
IN_KeyboardInit_fp( Do_Key_Event );
|
||||
IN_KeyboardInit_fp(Do_Key_Event);
|
||||
Key_ClearStates();
|
||||
|
||||
Com_Printf( "------------------------------------\n\n" );
|
||||
Com_Printf("------------------------------------\n\n");
|
||||
reflib_active = true;
|
||||
return ( true );
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -334,16 +335,16 @@ VID_LoadRefresh ( char *name )
|
|||
* and/or video mode to match.
|
||||
*/
|
||||
void
|
||||
VID_CheckChanges ( void )
|
||||
VID_CheckChanges(void)
|
||||
{
|
||||
char name [ 100 ];
|
||||
char name[100];
|
||||
|
||||
if ( vid_ref->modified )
|
||||
if (vid_ref->modified)
|
||||
{
|
||||
S_StopAllSounds();
|
||||
}
|
||||
|
||||
while ( vid_ref->modified )
|
||||
while (vid_ref->modified)
|
||||
{
|
||||
/* refresh has changed */
|
||||
vid_ref->modified = false;
|
||||
|
@ -351,47 +352,46 @@ VID_CheckChanges ( void )
|
|||
cl.refresh_prepped = false;
|
||||
cls.disable_screen = true;
|
||||
|
||||
sprintf( name, "ref_%s.so", vid_ref->string );
|
||||
sprintf(name, "ref_%s.so", vid_ref->string);
|
||||
|
||||
if ( !VID_LoadRefresh( name ) )
|
||||
if (!VID_LoadRefresh(name))
|
||||
{
|
||||
Cvar_Set( "vid_ref", "gl" );
|
||||
Cvar_Set("vid_ref", "gl");
|
||||
}
|
||||
|
||||
cls.disable_screen = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
VID_Init ( void )
|
||||
VID_Init(void)
|
||||
{
|
||||
/* Create the video variables so we know how to start the graphics drivers */
|
||||
vid_ref = Cvar_Get( "vid_ref", "gl", CVAR_ARCHIVE );
|
||||
vid_ref = Cvar_Get("vid_ref", "gl", CVAR_ARCHIVE);
|
||||
|
||||
vid_xpos = Cvar_Get( "vid_xpos", "3", CVAR_ARCHIVE );
|
||||
vid_ypos = Cvar_Get( "vid_ypos", "22", CVAR_ARCHIVE );
|
||||
vid_fullscreen = Cvar_Get( "vid_fullscreen", "0", CVAR_ARCHIVE );
|
||||
vid_gamma = Cvar_Get( "vid_gamma", "1", CVAR_ARCHIVE );
|
||||
vid_xpos = Cvar_Get("vid_xpos", "3", CVAR_ARCHIVE);
|
||||
vid_ypos = Cvar_Get("vid_ypos", "22", CVAR_ARCHIVE);
|
||||
vid_fullscreen = Cvar_Get("vid_fullscreen", "0", CVAR_ARCHIVE);
|
||||
vid_gamma = Cvar_Get("vid_gamma", "1", CVAR_ARCHIVE);
|
||||
|
||||
/* Add some console commands that we want to handle */
|
||||
Cmd_AddCommand( "vid_restart", VID_Restart_f );
|
||||
Cmd_AddCommand("vid_restart", VID_Restart_f);
|
||||
|
||||
/* Start the graphics mode and load refresh DLL */
|
||||
VID_CheckChanges();
|
||||
}
|
||||
|
||||
void
|
||||
VID_Shutdown ( void )
|
||||
VID_Shutdown(void)
|
||||
{
|
||||
if ( reflib_active )
|
||||
if (reflib_active)
|
||||
{
|
||||
if ( IN_Close_fp )
|
||||
if (IN_Close_fp)
|
||||
{
|
||||
IN_Close_fp();
|
||||
}
|
||||
|
||||
if ( IN_BackendShutdown_fp )
|
||||
if (IN_BackendShutdown_fp)
|
||||
{
|
||||
IN_BackendShutdown_fp();
|
||||
}
|
||||
|
@ -411,55 +411,56 @@ VID_Shutdown ( void )
|
|||
* ever have their names changed.
|
||||
*/
|
||||
qboolean
|
||||
VID_CheckRefExists ( const char *ref )
|
||||
VID_CheckRefExists(const char *ref)
|
||||
{
|
||||
char fn [ MAX_OSPATH ];
|
||||
char *path;
|
||||
char fn[MAX_OSPATH];
|
||||
char *path;
|
||||
struct stat st;
|
||||
|
||||
path = Cvar_Get( "basedir", ".", CVAR_NOSET )->string;
|
||||
snprintf( fn, MAX_OSPATH, "%s/ref_%s.so", path, ref );
|
||||
path = Cvar_Get("basedir", ".", CVAR_NOSET)->string;
|
||||
snprintf(fn, MAX_OSPATH, "%s/ref_%s.so", path, ref);
|
||||
|
||||
if ( stat( fn, &st ) == 0 )
|
||||
if (stat(fn, &st) == 0)
|
||||
{
|
||||
return ( true );
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ( false );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* INPUT */
|
||||
void
|
||||
IN_Shutdown ( void )
|
||||
IN_Shutdown(void)
|
||||
{
|
||||
if ( IN_BackendShutdown_fp )
|
||||
if (IN_BackendShutdown_fp)
|
||||
{
|
||||
IN_BackendShutdown_fp();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
IN_Commands ( void )
|
||||
IN_Commands(void)
|
||||
{
|
||||
if ( IN_BackendMouseButtons_fp )
|
||||
if (IN_BackendMouseButtons_fp)
|
||||
{
|
||||
IN_BackendMouseButtons_fp();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
IN_Move ( usercmd_t *cmd )
|
||||
IN_Move(usercmd_t *cmd)
|
||||
{
|
||||
if ( IN_BackendMove_fp )
|
||||
if (IN_BackendMove_fp)
|
||||
{
|
||||
IN_BackendMove_fp( cmd );
|
||||
IN_BackendMove_fp(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Do_Key_Event ( int key, qboolean down )
|
||||
Do_Key_Event(int key, qboolean down)
|
||||
{
|
||||
Key_Event( key, down, Sys_Milliseconds() );
|
||||
Key_Event(key, down, Sys_Milliseconds());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue