diff --git a/src/common/crc.c b/src/common/crc.c index 27572a14..09800a4a 100644 --- a/src/common/crc.c +++ b/src/common/crc.c @@ -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; } + diff --git a/src/common/cvar.c b/src/common/cvar.c index 874ce843..cef412b8 100644 --- a/src/common/cvar.c +++ b/src/common/cvar.c @@ -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 [u / s]\n"); + Com_Printf("usage: set [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); } + diff --git a/src/common/filesystem.c b/src/common/filesystem.c index b791ae58..60467a5f 100644 --- a/src/common/filesystem.c +++ b/src/common/filesystem.c @@ -29,14 +29,14 @@ #include "../common/header/glob.h" #ifdef ZIP -#include "unzip/unzip.h" + #include "unzip/unzip.h" #endif -#define MAX_HANDLES 512 -#define MAX_READ 0x10000 -#define MAX_WRITE 0x10000 -#define MAX_FIND_FILES 0x04000 -#define MAX_PAKS 100 +#define MAX_HANDLES 512 +#define MAX_READ 0x10000 +#define MAX_WRITE 0x10000 +#define MAX_FIND_FILES 0x04000 +#define MAX_PAKS 100 #ifdef SYSTEMWIDE #ifndef SYSTEMDIR @@ -46,38 +46,38 @@ typedef struct { - char name[MAX_QPATH]; - fsMode_t mode; - FILE *file; /* Only one will be used. */ + char name[MAX_QPATH]; + fsMode_t mode; + FILE *file; /* Only one will be used. */ #ifdef ZIP - unzFile *zip; /* (file or zip) */ + unzFile *zip; /* (file or zip) */ #endif } fsHandle_t; typedef struct fsLink_s { - char *from; - char *to; - int length; + char *from; + char *to; + int length; struct fsLink_s *next; } fsLink_t; typedef struct { - char name[MAX_QPATH]; - int size; - int offset; /* Ignored in PK3 files. */ + char name[MAX_QPATH]; + int size; + int offset; /* Ignored in PK3 files. */ } fsPackFile_t; typedef struct { - char name[MAX_OSPATH]; - int numFiles; - FILE *pak; + char name[MAX_OSPATH]; + int numFiles; + FILE *pak; #ifdef ZIP - unzFile *pk3; + unzFile *pk3; #endif - fsPackFile_t *files; + fsPackFile_t *files; } fsPack_t; typedef struct fsSearchPath_s @@ -97,18 +97,17 @@ typedef enum typedef struct { - char *suffix; - fsPackFormat_t format; + char *suffix; + fsPackFormat_t format; } fsPackTypes_t; -fsHandle_t fs_handles[MAX_HANDLES]; -fsLink_t *fs_links; +fsHandle_t fs_handles[MAX_HANDLES]; +fsLink_t *fs_links; fsSearchPath_t *fs_searchPaths; fsSearchPath_t *fs_baseSearchPaths; /* Pack formats / suffixes. */ -fsPackTypes_t fs_packtypes[] = -{ +fsPackTypes_t fs_packtypes[] = { {"pak", PAK}, #ifdef ZIP {"pk2", PK3}, @@ -117,27 +116,27 @@ fsPackTypes_t fs_packtypes[] = #endif }; -char fs_gamedir[MAX_OSPATH]; -static char fs_currentGame[MAX_QPATH]; +char fs_gamedir[MAX_OSPATH]; +static char fs_currentGame[MAX_QPATH]; -static char fs_fileInPath[MAX_OSPATH]; -static qboolean fs_fileInPack; +static char fs_fileInPath[MAX_OSPATH]; +static qboolean fs_fileInPack; /* Set by FS_FOpenFile. */ -int file_from_pak = 0; +int file_from_pak = 0; #ifdef ZIP -int file_from_pk3 = 0; -char file_from_pk3_name[MAX_QPATH]; +int file_from_pk3 = 0; +char file_from_pk3_name[MAX_QPATH]; #endif -cvar_t *fs_homepath; -cvar_t *fs_basedir; -cvar_t *fs_cddir; -cvar_t *fs_gamedirvar; -cvar_t *fs_debug; +cvar_t *fs_homepath; +cvar_t *fs_basedir; +cvar_t *fs_cddir; +cvar_t *fs_gamedirvar; +cvar_t *fs_debug; -fsHandle_t *FS_GetFileByHandle(fileHandle_t f); -char *Sys_GetCurrentDirectory(void); +fsHandle_t *FS_GetFileByHandle(fileHandle_t f); +char *Sys_GetCurrentDirectory(void); /* * All of Quake's data access is through a hierchal file system, but the @@ -176,30 +175,30 @@ Com_FilePath(const char *path, char *dst, int dstSize) memcpy(dst, path, pos - path); dst[pos - path] = '\0'; } - else { Com_Printf("Com_FilePath: not enough space.\n"); return; } } - else + { strncpy(dst, path, dstSize); + } } int -FS_FileLength(FILE * f) +FS_FileLength(FILE *f) { - int pos; /* Current position. */ - int end; /* End of file. */ + int pos; /* Current position. */ + int end; /* End of file. */ pos = ftell(f); fseek(f, 0, SEEK_END); end = ftell(f); fseek(f, pos, SEEK_SET); - return (end); + return end; } /* @@ -208,8 +207,8 @@ FS_FileLength(FILE * f) void FS_CreatePath(char *path) { - char *cur; /* Current '/'. */ - char *old; /* Old '/'. */ + char *cur; /* Current '/'. */ + char *old; /* Old '/'. */ FS_DPrintf("FS_CreatePath(%s)\n", path); @@ -232,17 +231,19 @@ FS_CreatePath(char *path) old = cur; cur = strchr(old + 1, '/'); - } + } } void -FS_DPrintf(const char *format,...) +FS_DPrintf(const char *format, ...) { - char msg[1024]; - va_list argPtr; + char msg[1024]; + va_list argPtr; if (fs_debug->value != 1) + { return; + } va_start(argPtr, format); vsnprintf(msg, sizeof(msg), format, argPtr); @@ -254,59 +255,63 @@ FS_DPrintf(const char *format,...) char * FS_Gamedir(void) { - return (fs_gamedir); + return fs_gamedir; } /* * Returns a FILE * for a fileHandle_t. */ -FILE * +FILE * FS_FileForHandle(fileHandle_t f) { - fsHandle_t *handle; + fsHandle_t *handle; handle = FS_GetFileByHandle(f); #ifdef ZIP if (handle->zip != NULL) + { Com_Error(ERR_DROP, "FS_FileForHandle: can't get FILE on zip file"); + } #endif if (handle->file == NULL) + { Com_Error(ERR_DROP, "FS_FileForHandle: NULL"); + } - return (handle->file); + return handle->file; } /* * Finds a free fileHandle_t. */ fsHandle_t * -FS_HandleForFile(const char *path, fileHandle_t * f) +FS_HandleForFile(const char *path, fileHandle_t *f) { - int i; - fsHandle_t *handle; + int i; + fsHandle_t *handle; handle = fs_handles; for (i = 0; i < MAX_HANDLES; i++, handle++) { - if (handle->file == NULL + if ((handle->file == NULL) #ifdef ZIP - && handle->zip == NULL + && (handle->zip == NULL) #endif - ) + ) { strncpy(handle->name, path, sizeof(handle->name)); *f = i + 1; - return (handle); + return handle; } } /* Failed. */ Com_Error(ERR_DROP, "FS_HandleForFile: none free"); - return (NULL); + return NULL; } /* @@ -315,24 +320,26 @@ FS_HandleForFile(const char *path, fileHandle_t * f) fsHandle_t * FS_GetFileByHandle(fileHandle_t f) { - if (f < 0 || f > MAX_HANDLES) + if ((f < 0) || (f > MAX_HANDLES)) { Com_Error(ERR_DROP, "FS_GetFileByHandle: out of range"); } if (f == 0) + { f++; + } - return (&fs_handles[f - 1]); + return &fs_handles[f - 1]; } /* * Returns file size or -1 on error. */ int -FS_FOpenFileAppend(fsHandle_t * handle) +FS_FOpenFileAppend(fsHandle_t *handle) { - char path[MAX_OSPATH]; + char path[MAX_OSPATH]; FS_CreatePath(handle->name); @@ -343,24 +350,28 @@ FS_FOpenFileAppend(fsHandle_t * handle) if (handle->file) { if (fs_debug->value) + { Com_Printf("FS_FOpenFileAppend: '%s'.\n", path); + } - return (FS_FileLength(handle->file)); + return FS_FileLength(handle->file); } if (fs_debug->value) + { Com_Printf("FS_FOpenFileAppend: couldn't open '%s'.\n", path); + } - return (-1); + return -1; } /* * Always returns 0 or -1 on error. */ int -FS_FOpenFileWrite(fsHandle_t * handle) +FS_FOpenFileWrite(fsHandle_t *handle) { - char path[MAX_OSPATH]; + char path[MAX_OSPATH]; FS_CreatePath(handle->name); @@ -369,15 +380,19 @@ FS_FOpenFileWrite(fsHandle_t * handle) if ((handle->file = fopen(path, "w")) == NULL) { if (fs_debug->value) + { Com_Printf("FS_FOpenFileWrite: '%s'.\n", path); + } - return (0); + return 0; } if (fs_debug->value) + { Com_Printf("FS_FOpenFileWrite: couldn't open '%s'.\n", path); + } - return (-1); + return -1; } /* @@ -385,12 +400,12 @@ FS_FOpenFileWrite(fsHandle_t * handle) * files inside pack files (both PAK and PK3). */ int -FS_FOpenFileRead(fsHandle_t * handle) +FS_FOpenFileRead(fsHandle_t *handle) { - char path[MAX_OSPATH]; - int i; + char path[MAX_OSPATH]; + int i; fsSearchPath_t *search; - fsPack_t *pack; + fsPack_t *pack; file_from_pak = 0; #ifdef ZIP @@ -410,12 +425,15 @@ FS_FOpenFileRead(fsHandle_t * handle) if (Q_stricmp(pack->files[i].name, handle->name) == 0) { /* Found it! */ - Com_FilePath(pack->name, fs_fileInPath, sizeof(fs_fileInPath)); + Com_FilePath(pack->name, fs_fileInPath, + sizeof(fs_fileInPath)); fs_fileInPack = true; if (fs_debug->value) + { Com_Printf("FS_FOpenFileRead: '%s' (found in '%s').\n", - handle->name, pack->name); + handle->name, pack->name); + } if (pack->pak) { @@ -426,24 +444,27 @@ FS_FOpenFileRead(fsHandle_t * handle) if (handle->file) { fseek(handle->file, pack->files[i].offset, SEEK_SET); - return (pack->files[i].size); + return pack->files[i].size; } } - #ifdef ZIP else if (pack->pk3) { /* PK3 */ file_from_pk3 = 1; - strncpy(file_from_pk3_name, strrchr(pack->name, '/') + 1, sizeof(file_from_pk3_name)); + strncpy(file_from_pk3_name, strrchr(pack->name, + '/') + 1, sizeof(file_from_pk3_name)); handle->zip = unzOpen(pack->name); if (handle->zip) { - if (unzLocateFile(handle->zip, handle->name, 2) == UNZ_OK) + if (unzLocateFile(handle->zip, handle->name, + 2) == UNZ_OK) { if (unzOpenCurrentFile(handle->zip) == UNZ_OK) - return (pack->files[i].size); + { + return pack->files[i].size; + } } unzClose(handle->zip); @@ -455,7 +476,6 @@ FS_FOpenFileRead(fsHandle_t * handle) } } } - else { /* Search in a directory tree. */ @@ -470,7 +490,9 @@ FS_FOpenFileRead(fsHandle_t * handle) } if (!handle->file) + { continue; + } if (handle->file) { @@ -479,8 +501,10 @@ FS_FOpenFileRead(fsHandle_t * handle) fs_fileInPack = false; if (fs_debug->value) + { Com_Printf("FS_FOpenFileRead: '%s' (found in '%s').\n", - handle->name, search->path); + handle->name, search->path); + } return FS_FileLength(handle->file); } @@ -492,9 +516,11 @@ FS_FOpenFileRead(fsHandle_t * handle) fs_fileInPack = false; if (fs_debug->value) + { Com_Printf("FS_FOpenFileRead: couldn't find '%s'.\n", handle->name); + } - return (-1); + return -1; } /* @@ -503,13 +529,14 @@ FS_FOpenFileRead(fsHandle_t * handle) void FS_FCloseFile(fileHandle_t f) { - fsHandle_t *handle; + fsHandle_t *handle; handle = FS_GetFileByHandle(f); if (handle->file) + { fclose(handle->file); - + } #ifdef ZIP else if (handle->zip) { @@ -529,13 +556,17 @@ Developer_searchpath(int who) for (search = fs_searchPaths; search; search = search->next) { if (strstr(search->path, "xatrix")) - return (1); + { + return 1; + } if (strstr(search->path, "rogue")) - return (2); + { + return 2; + } } - return (0); + return 0; } qboolean @@ -546,10 +577,12 @@ modType(char *name) for (search = fs_searchPaths; search; search = search->next) { if (strstr(search->path, name)) + { return true; + } } - return (0); + return 0; } /* @@ -557,10 +590,10 @@ modType(char *name) * for streaming data out of either a pak file or a seperate file. */ int -FS_FOpenFile(const char *name, fileHandle_t * f, fsMode_t mode) +FS_FOpenFile(const char *name, fileHandle_t *f, fsMode_t mode) { - int size = 0; - fsHandle_t *handle; + int size = 0; + fsHandle_t *handle; handle = FS_HandleForFile(name, f); @@ -584,13 +617,15 @@ FS_FOpenFile(const char *name, fileHandle_t * f, fsMode_t mode) } if (size != -1) - return (size); + { + return size; + } /* Couldn't open, so free the handle. */ memset(handle, 0, sizeof(*handle)); *f = 0; - return (-1); + return -1; } /* @@ -599,30 +634,34 @@ FS_FOpenFile(const char *name, fileHandle_t * f, fsMode_t mode) int FS_Read(void *buffer, int size, fileHandle_t f) { - qboolean tried = false; /* Tried to read from a CD. */ - byte *buf; /* Buffer. */ - int r; /* Number of bytes read. */ - int remaining;/* Remaining bytes. */ - fsHandle_t *handle; /* File handle. */ + qboolean tried = false; /* Tried to read from a CD. */ + byte *buf; /* Buffer. */ + int r; /* Number of bytes read. */ + int remaining; /* Remaining bytes. */ + fsHandle_t *handle; /* File handle. */ handle = FS_GetFileByHandle(f); /* Read. */ remaining = size; - buf = (byte *) buffer; + buf = (byte *)buffer; while (remaining) { if (handle->file) + { r = fread(buf, 1, remaining, handle->file); - + } #ifdef ZIP else if (handle->zip) + { r = unzReadCurrentFile(handle->zip, buf, remaining); + } #endif - else - return (0); + { + return 0; + } if (r == 0) { @@ -631,23 +670,26 @@ FS_Read(void *buffer, int size, fileHandle_t f) /* Might tried to read from a CD. */ tried = true; } - else { /* Already tried once. */ - Com_Error(ERR_FATAL, va("FS_Read: 0 bytes read from '%s'", handle->name)); - return (size - remaining); + Com_Error(ERR_FATAL, + va("FS_Read: 0 bytes read from '%s'", handle->name)); + return size - remaining; } } - else if (r == -1) - Com_Error(ERR_FATAL, "FS_Read: -1 bytes read from '%s'", handle->name); + { + Com_Error(ERR_FATAL, + "FS_Read: -1 bytes read from '%s'", + handle->name); + } remaining -= r; buf += r; } - return (size); + return size; } /* @@ -657,18 +699,18 @@ FS_Read(void *buffer, int size, fileHandle_t f) int FS_FRead(void *buffer, int size, int count, fileHandle_t f) { - qboolean tried = false; /* Tried to read from a CD. */ - byte *buf; /* Buffer. */ - int loops; /* Loop indicator. */ - int r; /* Number of bytes read. */ - int remaining; /* Remaining bytes. */ - fsHandle_t *handle; /* File handle. */ + qboolean tried = false; /* Tried to read from a CD. */ + byte *buf; /* Buffer. */ + int loops; /* Loop indicator. */ + int r; /* Number of bytes read. */ + int remaining; /* Remaining bytes. */ + fsHandle_t *handle; /* File handle. */ handle = FS_GetFileByHandle(f); /* Read. */ loops = count; - buf = (byte *) buffer; + buf = (byte *)buffer; while (loops) { @@ -678,15 +720,19 @@ FS_FRead(void *buffer, int size, int count, fileHandle_t f) while (remaining) { if (handle->file) + { r = fread(buf, 1, remaining, handle->file); - + } #ifdef ZIP else if (handle->zip) + { r = unzReadCurrentFile(handle->zip, buf, remaining); + } #endif - else - return (0); + { + return 0; + } if (r == 0) { @@ -695,16 +741,18 @@ FS_FRead(void *buffer, int size, int count, fileHandle_t f) /* Might tried to read from a CD. */ tried = true; } - else { /* Already tried once. */ - return (size - remaining); + return size - remaining; } } - else if (r == -1) - Com_Error(ERR_FATAL, "FS_FRead: -1 bytes read from '%s'", handle->name); + { + Com_Error(ERR_FATAL, + "FS_FRead: -1 bytes read from '%s'", + handle->name); + } remaining -= r; buf += r; @@ -713,7 +761,7 @@ FS_FRead(void *buffer, int size, int count, fileHandle_t f) loops--; } - return (size); + return size; } /* @@ -722,60 +770,71 @@ FS_FRead(void *buffer, int size, int count, fileHandle_t f) int FS_Write(const void *buffer, int size, fileHandle_t f) { - - byte *buf; /* Buffer. */ - int remaining; /* Remaining bytes. */ - int w = 0; /* Numbre of bytes written. */ - fsHandle_t *handle; /* File handle. */ + byte *buf; /* Buffer. */ + int remaining; /* Remaining bytes. */ + int w = 0; /* Numbre of bytes written. */ + fsHandle_t *handle; /* File handle. */ handle = FS_GetFileByHandle(f); /* Write. */ remaining = size; - buf = (byte *) buffer; + buf = (byte *)buffer; while (remaining) { if (handle->file) + { w = fwrite(buf, 1, remaining, handle->file); - + } #ifdef ZIP else if (handle->zip) - Com_Error(ERR_FATAL, "FS_Write: can't write to zip file '%s'", handle->name); + { + Com_Error(ERR_FATAL, + "FS_Write: can't write to zip file '%s'", + handle->name); + } #endif - else - return (0); + { + return 0; + } if (w == 0) { Com_Printf("FS_Write: 0 bytes written to '%s'.\n", handle->name); return size - remaining; } - else if (w == -1) - Com_Error(ERR_FATAL, "FS_Write: -1 bytes written to '%s'", handle->name); + { + Com_Error(ERR_FATAL, + "FS_Write: -1 bytes written to '%s'", + handle->name); + } remaining -= w; buf += w; } - return (size); + return size; } int FS_FTell(fileHandle_t f) { - fsHandle_t *handle; + fsHandle_t *handle; handle = FS_GetFileByHandle(f); if (handle->file) + { return ftell(handle->file); - + } #ifdef ZIP else if (handle->zip) + { return unztell(handle->zip); + } #endif return 0; @@ -787,24 +846,28 @@ FS_FTell(fileHandle_t f) char ** FS_ListPak(char *find, int *num) { - char **list = 0; /* File list. */ - int nfiles = 0; /* Number of files. */ - int nfound = 0; /* Number of files found. */ - int i; /* Loop counter. */ - fsPack_t *pak; /* Pak file. */ - fsSearchPath_t *search; /* Search path. */ + char **list = 0; /* File list. */ + int nfiles = 0; /* Number of files. */ + int nfound = 0; /* Number of files found. */ + int i; /* Loop counter. */ + fsPack_t *pak; /* Pak file. */ + fsSearchPath_t *search; /* Search path. */ /* Check pak files. */ for (search = fs_searchPaths; search != NULL; search = search->next) { if (search->pack == NULL) + { continue; + } pak = search->pack; /* Find and build list. */ for (i = 0; i < pak->numFiles; i++) + { nfiles++; + } } list = calloc(nfiles, sizeof(char *)); @@ -812,7 +875,9 @@ FS_ListPak(char *find, int *num) for (search = fs_searchPaths; search != NULL; search = search->next) { if (search->pack == NULL) + { continue; + } pak = search->pack; @@ -830,20 +895,20 @@ FS_ListPak(char *find, int *num) *num = nfound; list = realloc(list, sizeof(char *) * nfound); - return (list); + return list; } void FS_Seek(fileHandle_t f, int offset, fsOrigin_t origin) { #ifdef ZIP - byte dummy[0x8000]; /* Dummy buffer to skip bytes. */ - int len; /* Length of byte chunk to skip. */ - int r; /* Number of bytes read. */ - int remaining = 0; /* Remaining bytes to skip. */ - unz_file_info info; /* ZIP information. */ + byte dummy[0x8000]; /* Dummy buffer to skip bytes. */ + int len; /* Length of byte chunk to skip. */ + int r; /* Number of bytes read. */ + int remaining = 0; /* Remaining bytes to skip. */ + unz_file_info info; /* ZIP information. */ #endif - fsHandle_t *handle; /* File handle. */ + fsHandle_t *handle; /* File handle. */ handle = FS_GetFileByHandle(f); @@ -865,7 +930,6 @@ FS_Seek(fileHandle_t f, int offset, fsOrigin_t origin) break; } } - #ifdef ZIP else if (handle->zip) { @@ -878,7 +942,14 @@ FS_Seek(fileHandle_t f, int offset, fsOrigin_t origin) remaining = offset + unztell(handle->zip); break; case FS_SEEK_END: - unzGetCurrentFileInfo(handle->zip, &info, NULL, 0, NULL, 0, NULL, 0); + unzGetCurrentFileInfo(handle->zip, + &info, + NULL, + 0, + NULL, + 0, + NULL, + 0); remaining = offset + info.uncompressed_size; break; default: @@ -896,12 +967,16 @@ FS_Seek(fileHandle_t f, int offset, fsOrigin_t origin) len = remaining; if (len > sizeof(dummy)) + { len = sizeof(dummy); + } r = unzReadCurrentFile(handle->zip, dummy, len); if (r <= 0) + { break; + } remaining -= r; } @@ -915,35 +990,38 @@ FS_Seek(fileHandle_t f, int offset, fsOrigin_t origin) int FS_Tell(fileHandle_t f) { - fsHandle_t *handle; + fsHandle_t *handle; handle = FS_GetFileByHandle(f); if (handle->file) - return (ftell(handle->file)); - + { + return ftell(handle->file); + } #ifdef ZIP else if (handle->zip) - return (unztell(handle->zip)); + { + return unztell(handle->zip); + } #endif - return (-1); + return -1; } qboolean FS_FileExists(char *path) { - fileHandle_t f; + fileHandle_t f; FS_FOpenFile(path, &f, FS_READ); if (f != 0) { FS_FCloseFile(f); - return (true); + return true; } - return (false); + return false; } void @@ -952,7 +1030,10 @@ FS_RenameFile(const char *oldPath, const char *newPath) FS_DPrintf("FS_RenameFile(%s, %s)\n", oldPath, newPath); if (rename(oldPath, newPath)) - FS_DPrintf("FS_RenameFile: failed to rename '%s' to '%s'.\n", oldPath, newPath); + { + FS_DPrintf("FS_RenameFile: failed to rename '%s' to '%s'.\n", + oldPath, newPath); + } } void @@ -961,7 +1042,9 @@ FS_DeleteFile(const char *path) FS_DPrintf("FS_DeleteFile(%s)\n", path); if (remove(path)) + { FS_DPrintf("FS_DeleteFile: failed to delete '%s'.\n", path); + } } /* @@ -971,9 +1054,9 @@ FS_DeleteFile(const char *path) int FS_LoadFile(char *path, void **buffer) { - byte *buf; /* Buffer. */ - int size; /* File size. */ - fileHandle_t f; /* File handle. */ + byte *buf; /* Buffer. */ + int size; /* File size. */ + fileHandle_t f; /* File handle. */ buf = NULL; size = FS_FOpenFile(path, &f, FS_READ); @@ -981,15 +1064,17 @@ FS_LoadFile(char *path, void **buffer) if (size <= 0) { if (buffer) + { *buffer = NULL; + } - return (size); + return size; } if (buffer == NULL) { FS_FCloseFile(f); - return (size); + return size; } buf = Z_Malloc(size); @@ -998,7 +1083,7 @@ FS_LoadFile(char *path, void **buffer) FS_Read(buf, size, f); FS_FCloseFile(f); - return (size); + return size; } void @@ -1022,18 +1107,20 @@ FS_FreeFile(void *buffer) fsPack_t * FS_LoadPAK(const char *packPath) { - int i; /* Loop counter. */ - int numFiles; /* Number of files in PAK. */ - FILE *handle; /* File handle. */ - fsPackFile_t *files; /* List of files in PAK. */ - fsPack_t *pack; /* PAK file. */ - dpackheader_t header; /* PAK file header. */ - dpackfile_t info[MAX_FILES_IN_PACK]; /* PAK info. */ + int i; /* Loop counter. */ + int numFiles; /* Number of files in PAK. */ + FILE *handle; /* File handle. */ + fsPackFile_t *files; /* List of files in PAK. */ + fsPack_t *pack; /* PAK file. */ + dpackheader_t header; /* PAK file header. */ + dpackfile_t info[MAX_FILES_IN_PACK]; /* PAK info. */ handle = fopen(packPath, "rb"); if (handle == NULL) - return (NULL); + { + return NULL; + } fread(&header, 1, sizeof(dpackheader_t), handle); @@ -1048,10 +1135,11 @@ FS_LoadPAK(const char *packPath) numFiles = header.dirlen / sizeof(dpackfile_t); - if (numFiles > MAX_FILES_IN_PACK || numFiles == 0) + if ((numFiles > MAX_FILES_IN_PACK) || (numFiles == 0)) { fclose(handle); - Com_Error(ERR_FATAL, "FS_LoadPAK: '%s' has %i files", packPath, numFiles); + Com_Error(ERR_FATAL, "FS_LoadPAK: '%s' has %i files", + packPath, numFiles); } files = Z_Malloc(numFiles * sizeof(fsPackFile_t)); @@ -1078,7 +1166,7 @@ FS_LoadPAK(const char *packPath) Com_Printf("Added packfile '%s' (%i files).\n", pack, numFiles); - return (pack); + return pack; } #ifdef ZIP @@ -1091,22 +1179,24 @@ FS_LoadPAK(const char *packPath) fsPack_t * FS_LoadPK3(const char *packPath) { - char fileName[MAX_QPATH]; /* File name. */ - int i = 0; /* Loop counter. */ - int numFiles; /* Number of files in PK3. */ - int status; /* Error indicator. */ - fsPackFile_t *files; /* List of files in PK3. */ - fsPack_t *pack; /* PK3 file. */ - unzFile *handle; /* Zip file handle. */ - unz_file_info info; /* Zip file info. */ - unz_global_info global; /* Zip file global info. */ + char fileName[MAX_QPATH]; /* File name. */ + int i = 0; /* Loop counter. */ + int numFiles; /* Number of files in PK3. */ + int status; /* Error indicator. */ + fsPackFile_t *files; /* List of files in PK3. */ + fsPack_t *pack; /* PK3 file. */ + unzFile *handle; /* Zip file handle. */ + unz_file_info info; /* Zip file info. */ + unz_global_info global; /* Zip file global info. */ handle = unzOpen(packPath); if (handle == NULL) + { return NULL; + } - if (unzGetGlobalInfo(handle, &global)!=UNZ_OK) + if (unzGetGlobalInfo(handle, &global) != UNZ_OK) { unzClose(handle); Com_Error(ERR_FATAL, "FS_LoadPK3: '%s' is not a pack file", packPath); @@ -1114,10 +1204,11 @@ FS_LoadPK3(const char *packPath) numFiles = global.number_entry; - if (numFiles > MAX_FILES_IN_PACK || numFiles == 0) + if ((numFiles > MAX_FILES_IN_PACK) || (numFiles == 0)) { unzClose(handle); - Com_Error(ERR_FATAL, "FS_LoadPK3: '%s' has %i files", packPath, numFiles); + Com_Error(ERR_FATAL, "FS_LoadPK3: '%s' has %i files", + packPath, numFiles); } files = Z_Malloc(numFiles * sizeof(fsPackFile_t)); @@ -1128,7 +1219,8 @@ FS_LoadPK3(const char *packPath) while (status == UNZ_OK) { fileName[0] = '\0'; - unzGetCurrentFileInfo(handle, &info, fileName, MAX_QPATH, NULL, 0, NULL, 0); + unzGetCurrentFileInfo(handle, &info, fileName, MAX_QPATH, + NULL, 0, NULL, 0); strncpy(files[i].name, fileName, sizeof(files[i].name)); files[i].offset = -1; /* Not used in ZIP files */ files[i].size = info.uncompressed_size; @@ -1145,7 +1237,7 @@ FS_LoadPK3(const char *packPath) Com_Printf("Added packfile '%s' (%i files).\n", pack, numFiles); - return (pack); + return pack; } #endif @@ -1158,12 +1250,12 @@ FS_LoadPK3(const char *packPath) void FS_AddGameDirectory(const char *dir) { - char **list; /* File list. */ - char path[MAX_OSPATH]; /* Path to PAK / PK3. */ - int i, j; /* Loop counters. */ - int nfiles; /* Number of files in list. */ - fsSearchPath_t *search; /* Search path. */ - fsPack_t *pack; /* PAK / PK3 file. */ + char **list; /* File list. */ + char path[MAX_OSPATH]; /* Path to PAK / PK3. */ + int i, j; /* Loop counters. */ + int nfiles; /* Number of files in list. */ + fsSearchPath_t *search; /* Search path. */ + fsPack_t *pack; /* PAK / PK3 file. */ pack = NULL; @@ -1181,9 +1273,11 @@ FS_AddGameDirectory(const char *dir) /* Add numbered pack files in sequence. */ for (i = 0; i < sizeof(fs_packtypes) / sizeof(fs_packtypes[0]); i++) + { for (j = 0; j < MAX_PAKS; j++) { - Com_sprintf(path, sizeof(path), "%s/pak%d.%s", dir, j, fs_packtypes[i].suffix); + Com_sprintf(path, sizeof(path), "%s/pak%d.%s", + dir, j, fs_packtypes[i].suffix); switch (fs_packtypes[i].format) { @@ -1198,13 +1292,16 @@ FS_AddGameDirectory(const char *dir) } if (pack == NULL) + { continue; + } search = Z_Malloc(sizeof(fsSearchPath_t)); search->pack = pack; search->next = fs_searchPaths; fs_searchPaths = search; } + } /* Add not numbered pack files. */ for (i = 0; i < sizeof(fs_packtypes) / sizeof(fs_packtypes[0]); i++) @@ -1212,15 +1309,20 @@ FS_AddGameDirectory(const char *dir) Com_sprintf(path, sizeof(path), "%s/*.%s", dir, fs_packtypes[i].suffix); if ((list = FS_ListFiles(path, &nfiles, 0, SFF_SUBDIR)) == NULL) + { continue; + } - Com_sprintf(path, sizeof(path), "%s/pak*.%s", dir, fs_packtypes[i].suffix); + Com_sprintf(path, sizeof(path), "%s/pak*.%s", + dir, fs_packtypes[i].suffix); for (j = 0; j < nfiles - 1; j++) { /* Skip numbered packs. */ if (glob_match(path, list[j])) + { continue; + } switch (fs_packtypes[i].format) { @@ -1235,7 +1337,9 @@ FS_AddGameDirectory(const char *dir) } if (pack == NULL) + { continue; + } search = Z_Malloc(sizeof(fsSearchPath_t)); search->pack = pack; @@ -1255,7 +1359,7 @@ FS_AddHomeAsGameDirectory(char *dir) { char gdir[MAX_OSPATH]; int len; - + #ifdef _WIN32 char *cur; char *old; @@ -1268,7 +1372,7 @@ FS_AddHomeAsGameDirectory(char *dir) cur = old = profile; - /* Replace backslashes by slashes */ + /* Replace backslashes with slashes */ if (strstr(cur, "\\") != NULL) { while (cur != NULL) @@ -1276,19 +1380,18 @@ FS_AddHomeAsGameDirectory(char *dir) if ((cur - old) > 1) { *cur = '/'; - } old = cur; - cur = strchr(old + 1, '\\'); + cur = strchr(old + 1, '\\'); } } - len = snprintf(gdir, sizeof(gdir), "%s%s%s/", profile, - "/Documents/YamagiQ2/", dir); + len = snprintf(gdir, sizeof(gdir), "%s%s%s/", profile, + "/Documents/YamagiQ2/", dir); #else char *homedir = getenv("HOME"); - + if (!homedir) { return; @@ -1297,36 +1400,36 @@ FS_AddHomeAsGameDirectory(char *dir) len = snprintf(gdir, sizeof(gdir), "%s/.yq2/%s/", homedir, dir); #endif - FS_CreatePath(gdir); - if ((len > 0) && (len < sizeof(gdir)) && (gdir[len-1] == '/')) - gdir[len-1] = 0; + if ((len > 0) && (len < sizeof(gdir)) && (gdir[len - 1] == '/')) + { + gdir[len - 1] = 0; + } - strncpy(fs_gamedir,gdir,sizeof(fs_gamedir)-1); - fs_gamedir[sizeof(fs_gamedir)-1] = 0; + strncpy(fs_gamedir, gdir, sizeof(fs_gamedir) - 1); + fs_gamedir[sizeof(fs_gamedir) - 1] = 0; - FS_AddGameDirectory (gdir); + FS_AddGameDirectory(gdir); } #ifdef SYSTEMWIDE - -void FS_AddSystemwideGameDirectory(char *dir) +void +FS_AddSystemwideGameDirectory(char *dir) { - char gdir[MAX_OSPATH]; - char *datadir = SYSTEMDIR; + char gdir[MAX_OSPATH]; + char *datadir = SYSTEMDIR; int len = snprintf(gdir, sizeof(gdir), "%s/%s/", datadir, dir); - printf("Using %s to fetch paks\n", gdir); + printf("Using %s to fetch paks\n", gdir); - if ((len > 0) && (len < sizeof(gdir)) && (gdir[len-1] == '/')) + if ((len > 0) && (len < sizeof(gdir)) && (gdir[len - 1] == '/')) { - gdir[len-1] = 0; + gdir[len - 1] = 0; } - FS_AddGameDirectory (gdir); + FS_AddGameDirectory(gdir); } - #endif /* @@ -1335,36 +1438,42 @@ void FS_AddSystemwideGameDirectory(char *dir) char * FS_NextPath(char *prevPath) { - char *prev; - fsSearchPath_t *search; + char *prev; + fsSearchPath_t *search; if (prevPath == NULL) - return (fs_gamedir); + { + return fs_gamedir; + } prev = fs_gamedir; for (search = fs_searchPaths; search; search = search->next) { if (search->pack != NULL) + { continue; + } if (prevPath == prev) - return (search->path); + { + return search->path; + } prev = search->path; } - return (NULL); + return NULL; } void FS_Path_f(void) { - int i; - int totalFiles = 0; - fsSearchPath_t *search; - fsHandle_t *handle; - fsLink_t *link; + int i; + int totalFiles = 0; + fsSearchPath_t *search; + fsHandle_t *handle; + fsLink_t *link; Com_Printf("Current search path:\n"); @@ -1372,26 +1481,34 @@ FS_Path_f(void) { if (search->pack != NULL) { - Com_Printf("%s (%i files)\n", search->pack->name, search->pack->numFiles); + Com_Printf("%s (%i files)\n", search->pack->name, + search->pack->numFiles); totalFiles += search->pack->numFiles; } - else + { Com_Printf("%s\n", search->path); + } } Com_Printf("\n"); for (i = 0, handle = fs_handles; i < MAX_HANDLES; i++, handle++) - if (handle->file != NULL + { + if ((handle->file != NULL) #ifdef ZIP - || handle->zip != NULL + || (handle->zip != NULL) #endif - ) + ) + { Com_Printf("Handle %i: '%s'.\n", i + 1, handle->name); + } + } for (i = 0, link = fs_links; link; i++, link = link->next) + { Com_Printf("Link %i: '%s' -> '%s'.\n", i, link->from, link->to); + } Com_Printf("----------------------\n"); #ifdef ZIP @@ -1404,14 +1521,14 @@ FS_Path_f(void) void FS_Startup(void) { - int i; + int i; fsSearchPath_t *next; - fsPack_t *pack; + fsPack_t *pack; if (strstr(fs_gamedirvar->string, "..") || - strstr(fs_gamedirvar->string, ".") || - strstr(fs_gamedirvar->string, "/") || - fs_gamedirvar->string[0] == '\0') + strstr(fs_gamedirvar->string, ".") || + strstr(fs_gamedirvar->string, "/") || + (fs_gamedirvar->string[0] == '\0')) { Com_Printf("Invalid game directory.\n"); Cvar_ForceSet("fs_game", BASEDIRNAME); @@ -1428,11 +1545,15 @@ FS_Startup(void) pack = fs_searchPaths->pack; if (pack->pak != NULL) + { fclose(pack->pak); + } #ifdef ZIP if (pack->pk3 != NULL) + { unzClose(pack->pk3); + } #endif Z_Free(pack->files); @@ -1446,21 +1567,29 @@ FS_Startup(void) /* Close open files for game dir. */ for (i = 0; i < MAX_HANDLES; i++) + { if (strstr(fs_handles[i].name, fs_currentGame) && - (fs_handles[i].file != NULL + ((fs_handles[i].file != NULL) #ifdef ZIP - || fs_handles[i].zip != NULL + || (fs_handles[i].zip != NULL) #endif - )) + )) + { FS_FCloseFile(i); + } + } /* Don't add baseq2 again. */ if (Q_stricmp(fs_gamedirvar->string, BASEDIRNAME) == 0) + { strncpy(fs_gamedir, fs_basedir->string, sizeof(fs_gamedir)); - + } else + { /* Add the directories. */ - FS_AddGameDirectory(va("%s/%s", fs_homepath->string, fs_gamedirvar->string)); + FS_AddGameDirectory(va("%s/%s", fs_homepath->string, + fs_gamedirvar->string)); + } } strncpy(fs_currentGame, fs_gamedirvar->string, sizeof(fs_currentGame)); @@ -1471,19 +1600,26 @@ FS_Startup(void) void FS_ExecAutoexec(void) { - char *dir; - char name[MAX_QPATH]; + char *dir; + char name[MAX_QPATH]; dir = (char *)Cvar_VariableString("gamedir"); if (dir[0] != '\0') - Com_sprintf(name, sizeof(name), "%s/%s/autoexec.cfg", fs_basedir->string, dir); - + { + Com_sprintf(name, sizeof(name), "%s/%s/autoexec.cfg", + fs_basedir->string, dir); + } else - Com_sprintf(name, sizeof(name), "%s/%s/autoexec.cfg", fs_basedir->string, BASEDIRNAME); + { + Com_sprintf(name, sizeof(name), "%s/%s/autoexec.cfg", + fs_basedir->string, BASEDIRNAME); + } if (Sys_FindFirst(name, 0, SFF_SUBDIR | SFF_HIDDEN | SFF_SYSTEM) != NULL) + { Cbuf_AddText("exec autoexec.cfg\n"); + } Sys_FindClose(); } @@ -1494,7 +1630,7 @@ FS_ExecAutoexec(void) void FS_SetGamedir(char *dir) { - int i; + int i; fsSearchPath_t *next; if (strstr(dir, "..") || strstr(dir, "/")) @@ -1509,11 +1645,15 @@ FS_SetGamedir(char *dir) if (fs_searchPaths->pack) { if (fs_searchPaths->pack->pak) + { fclose(fs_searchPaths->pack->pak); + } #ifdef ZIP if (fs_searchPaths->pack->pk3) + { unzClose(fs_searchPaths->pack->pk3); + } #endif Z_Free(fs_searchPaths->pack->files); @@ -1527,32 +1667,40 @@ FS_SetGamedir(char *dir) /* Close open files for game dir. */ for (i = 0; i < MAX_HANDLES; i++) + { if (strstr(fs_handles[i].name, dir) && - (fs_handles[i].file != NULL + ((fs_handles[i].file != NULL) #ifdef ZIP - || fs_handles[i].zip != NULL + || (fs_handles[i].zip != NULL) #endif - )) + )) + { FS_FCloseFile(i); + } + } /* Flush all data, so it will be forced to reload. */ - if (dedicated != NULL && dedicated->value != 1) + if ((dedicated != NULL) && (dedicated->value != 1)) + { Cbuf_AddText("vid_restart\nsnd_restart\n"); + } - Com_sprintf(fs_gamedir, sizeof(fs_gamedir), "%s/%s", fs_basedir->string, dir); + Com_sprintf(fs_gamedir, sizeof(fs_gamedir), "%s/%s", + fs_basedir->string, dir); - if (strcmp(dir, BASEDIRNAME) == 0 || (*dir == 0)) + if ((strcmp(dir, BASEDIRNAME) == 0) || (*dir == 0)) { Cvar_FullSet("gamedir", "", CVAR_SERVERINFO | CVAR_NOSET); Cvar_FullSet("game", "", CVAR_LATCH | CVAR_SERVERINFO); } - else { Cvar_FullSet("gamedir", dir, CVAR_SERVERINFO | CVAR_NOSET); if (fs_cddir->string[0] == '\0') + { FS_AddGameDirectory(va("%s/%s", fs_cddir->string, dir)); + } #ifdef SYSTEMWIDE FS_AddSystemwideGameDirectory(dir); @@ -1569,7 +1717,7 @@ FS_SetGamedir(char *dir) void FS_Link_f(void) { - fsLink_t *l, **prev; + fsLink_t *l, **prev; if (Cmd_Argc() != 3) { @@ -1615,11 +1763,12 @@ FS_Link_f(void) * Create a list of files that match a criteria. */ char ** -FS_ListFiles(char *findname, int *numfiles, unsigned musthave, unsigned canthave) +FS_ListFiles(char *findname, int *numfiles, + unsigned musthave, unsigned canthave) { - char **list; /* List of files. */ - char *s; /* Next file in list. */ - int nfiles; /* Number of files in list. */ + char **list; /* List of files. */ + char *s; /* Next file in list. */ + int nfiles; /* Number of files in list. */ /* Initialize variables. */ list = NULL; @@ -1631,7 +1780,9 @@ FS_ListFiles(char *findname, int *numfiles, unsigned musthave, unsigned canthave while (s != NULL) { if (s[strlen(s) - 1] != '.') + { nfiles++; + } s = Sys_FindNext(musthave, canthave); } @@ -1640,7 +1791,9 @@ FS_ListFiles(char *findname, int *numfiles, unsigned musthave, unsigned canthave /* Check if there are matches. */ if (nfiles == 0) - return (NULL); + { + return NULL; + } nfiles++; /* Add space for a guard. */ *numfiles = nfiles; @@ -1665,7 +1818,7 @@ FS_ListFiles(char *findname, int *numfiles, unsigned musthave, unsigned canthave Sys_FindClose(); - return (list); + return list; } /* @@ -1675,46 +1828,59 @@ FS_ListFiles(char *findname, int *numfiles, unsigned musthave, unsigned canthave * SFF_SUBDIR it changes). */ qboolean -ComparePackFiles(const char *findname, const char *name, - unsigned musthave, unsigned canthave, char *output, int size) +ComparePackFiles(const char *findname, const char *name, unsigned musthave, + unsigned canthave, char *output, int size) { - qboolean retval; - char *ptr; - char buffer[MAX_OSPATH]; + qboolean retval; + char *ptr; + char buffer[MAX_OSPATH]; strncpy(buffer, name, sizeof(buffer)); - if ((canthave & SFF_SUBDIR) && name[strlen(name)-1] == '/') - return (false); + if ((canthave & SFF_SUBDIR) && (name[strlen(name) - 1] == '/')) + { + return false; + } if (musthave & SFF_SUBDIR) { if ((ptr = strrchr(buffer, '/')) != NULL) + { *ptr = '\0'; - + } else - return (false); + { + return false; + } } if ((musthave & SFF_HIDDEN) || (canthave & SFF_HIDDEN)) { if ((ptr = strrchr(buffer, '/')) == NULL) + { ptr = buffer; + } - if (((musthave & SFF_HIDDEN) && ptr[1] != '.') || - ((canthave & SFF_HIDDEN) && ptr[1] == '.')) - return (false); + if (((musthave & SFF_HIDDEN) && (ptr[1] != '.')) || + ((canthave & SFF_HIDDEN) && (ptr[1] == '.'))) + { + return false; + } } if (canthave & SFF_RDONLY) - return (false); + { + return false; + } retval = glob_match((char *)findname, buffer); - if (retval && output != NULL) + if (retval && (output != NULL)) + { strncpy(output, buffer, size); + } - return (retval); + return retval; } /* @@ -1723,15 +1889,16 @@ ComparePackFiles(const char *findname, const char *name, * including .pak and .pk3 files. */ char ** -FS_ListFiles2(char *findname, int *numfiles, unsigned musthave, unsigned canthave) +FS_ListFiles2(char *findname, int *numfiles, + unsigned musthave, unsigned canthave) { - fsSearchPath_t *search; /* Search path. */ - int i, j; /* Loop counters. */ - int nfiles; /* Number of files found. */ - int tmpnfiles; /* Temp number of files. */ - char **tmplist; /* Temporary list of files. */ - char **list; /* List of files found. */ - char path[MAX_OSPATH]; /* Temporary path. */ + fsSearchPath_t *search; /* Search path. */ + int i, j; /* Loop counters. */ + int nfiles; /* Number of files found. */ + int tmpnfiles; /* Temp number of files. */ + char **tmplist; /* Temporary list of files. */ + char **list; /* List of files found. */ + char path[MAX_OSPATH]; /* Temporary path. */ nfiles = 0; list = malloc(sizeof(char *)); @@ -1741,38 +1908,45 @@ FS_ListFiles2(char *findname, int *numfiles, unsigned musthave, unsigned canthav if (search->pack != NULL) { if (canthave & SFF_INPACK) + { continue; + } for (i = 0, j = 0; i < search->pack->numFiles; i++) - if (ComparePackFiles(findname, - search->pack->files[i].name, - musthave, canthave, NULL, 0)) + { + if (ComparePackFiles(findname, search->pack->files[i].name, + musthave, canthave, NULL, 0)) + { j++; + } + } if (j == 0) + { continue; + } nfiles += j; list = realloc(list, nfiles * sizeof(char *)); - for (i = 0, j = nfiles - j; - i < search->pack->numFiles; - i++) - if (ComparePackFiles(findname, - search->pack->files[i].name, - musthave, canthave, path, sizeof(path))) + for (i = 0, j = nfiles - j; i < search->pack->numFiles; i++) + { + if (ComparePackFiles(findname, search->pack->files[i].name, + musthave, canthave, path, sizeof(path))) + { list[j++] = strdup(path); + } + } } - else if (search->path != NULL) { if (musthave & SFF_INPACK) + { continue; + } - Com_sprintf(path, sizeof(path), "%s/%s", - search->path, findname); - tmplist = FS_ListFiles(path, &tmpnfiles, musthave, - canthave); + Com_sprintf(path, sizeof(path), "%s/%s", search->path, findname); + tmplist = FS_ListFiles(path, &tmpnfiles, musthave, canthave); if (tmplist != NULL) { @@ -1780,11 +1954,10 @@ FS_ListFiles2(char *findname, int *numfiles, unsigned musthave, unsigned canthav nfiles += tmpnfiles; list = realloc(list, nfiles * sizeof(char *)); - for (i = 0, j = nfiles - tmpnfiles; - i < tmpnfiles; - i++, j++) - list[j] = strdup(tmplist[i] + - strlen(search->path) + 1); + for (i = 0, j = nfiles - tmpnfiles; i < tmpnfiles; i++, j++) + { + list[j] = strdup(tmplist[i] + strlen(search->path) + 1); + } FS_FreeList(tmplist, tmpnfiles + 1); } @@ -1797,16 +1970,20 @@ FS_ListFiles2(char *findname, int *numfiles, unsigned musthave, unsigned canthav for (i = 0; i < nfiles; i++) { if (list[i] == NULL) + { continue; + } for (j = i + 1; j < nfiles; j++) - if (list[j] != NULL && - strcmp(list[i], list[j]) == 0) + { + if ((list[j] != NULL) && + (strcmp(list[i], list[j]) == 0)) { free(list[j]); list[j] = NULL; tmpnfiles++; } + } } if (tmpnfiles > 0) @@ -1815,8 +1992,12 @@ FS_ListFiles2(char *findname, int *numfiles, unsigned musthave, unsigned canthav tmplist = malloc(nfiles * sizeof(char *)); for (i = 0, j = 0; i < nfiles + tmpnfiles; i++) + { if (list[i] != NULL) + { tmplist[j++] = list[i]; + } + } free(list); list = tmplist; @@ -1838,7 +2019,7 @@ FS_ListFiles2(char *findname, int *numfiles, unsigned musthave, unsigned canthav *numfiles = nfiles; - return (list); + return list; } /* @@ -1847,10 +2028,12 @@ FS_ListFiles2(char *findname, int *numfiles, unsigned musthave, unsigned canthav void FS_FreeList(char **list, int nfiles) { - int i; + int i; for (i = 0; i < nfiles - 1; i++) + { free(list[i]); + } free(list); } @@ -1861,16 +2044,18 @@ FS_FreeList(char **list, int nfiles) void FS_Dir_f(void) { - char **dirnames; /* File list. */ - char findname[1024]; /* File search path and pattern. */ - char *path = NULL; /* Search path. */ - char wildcard[1024] = "*.*"; /* File pattern. */ - int i; /* Loop counter. */ - int ndirs; /* Number of files in list. */ + char **dirnames; /* File list. */ + char findname[1024]; /* File search path and pattern. */ + char *path = NULL; /* Search path. */ + char wildcard[1024] = "*.*"; /* File pattern. */ + int i; /* Loop counter. */ + int ndirs; /* Number of files in list. */ /* Check for pattern in arguments. */ if (Cmd_Argc() != 1) + { strncpy(wildcard, Cmd_Argv(1), sizeof(wildcard)); + } /* Scan search paths and list files. */ while ((path = FS_NextPath(path)) != NULL) @@ -1884,10 +2069,13 @@ FS_Dir_f(void) for (i = 0; i < ndirs - 1; i++) { if (strrchr(dirnames[i], '/')) + { Com_Printf("%s\n", strrchr(dirnames[i], '/') + 1); - + } else + { Com_Printf("%s\n", dirnames[i]); + } } FS_FreeList(dirnames, ndirs); @@ -1905,19 +2093,17 @@ FS_InitFilesystem(void) Cmd_AddCommand("link", FS_Link_f); Cmd_AddCommand("dir", FS_Dir_f); - /* - * basedir Allows the game to run from outside the data tree. - */ + /* basedir Allows the game to run from outside the data tree. */ fs_basedir = Cvar_Get("basedir", ".", CVAR_NOSET); - /* - * cddir Logically concatenates the cddir after the basedir to - * allow the game to run from outside the data tree. - */ + /* cddir Logically concatenates the cddir after the basedir to + allow the game to run from outside the data tree. */ fs_cddir = Cvar_Get("cddir", "", CVAR_NOSET); if (fs_cddir->string[0] != '\0') + { FS_AddGameDirectory(va("%s/" BASEDIRNAME, fs_cddir->string)); + } /* Debug flag. */ fs_debug = Cvar_Get("fs_debug", "0", 0); @@ -1942,7 +2128,9 @@ FS_InitFilesystem(void) /* Check for game override. */ if (fs_gamedirvar->string[0] != '\0') + { FS_SetGamedir(fs_gamedirvar->string); + } /* Create directory if it does not exist. */ FS_CreatePath(fs_gamedir); @@ -1953,10 +2141,10 @@ FS_InitFilesystem(void) void FS_Shutdown(void) { - int i; - fsHandle_t *handle; - fsSearchPath_t *next; - fsPack_t *pack; + int i; + fsHandle_t *handle; + fsSearchPath_t *next; + fsPack_t *pack; /* Unregister commands. */ Cmd_RemoveCommand("dir"); @@ -1967,7 +2155,9 @@ FS_Shutdown(void) for (i = 0, handle = fs_handles; i < MAX_HANDLES; i++, handle++) { if (handle->file != NULL) + { fclose(handle->file); + } #ifdef ZIP if (handle->zip != NULL) @@ -1986,11 +2176,15 @@ FS_Shutdown(void) pack = fs_searchPaths->pack; if (pack->pak != NULL) + { fclose(pack->pak); + } #ifdef ZIP if (pack->pk3 != NULL) + { unzClose(pack->pk3); + } #endif Z_Free(pack->files); @@ -2002,3 +2196,4 @@ FS_Shutdown(void) fs_searchPaths = next; } } + diff --git a/src/common/glob.c b/src/common/glob.c index d37fcdc8..3e917fe2 100644 --- a/src/common/glob.c +++ b/src/common/glob.c @@ -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'; } + diff --git a/src/common/md4.c b/src/common/md4.c index a0dd8ad5..86f358c3 100644 --- a/src/common/md4.c +++ b/src/common/md4.c @@ -8,23 +8,26 @@ #include -#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; } + diff --git a/src/common/misc.c b/src/common/misc.c index c0681ba2..918699fe 100644 --- a/src/common/misc.c +++ b/src/common/misc.c @@ -28,24 +28,23 @@ #include "header/zone.h" #include -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; nvalue) - 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) { } + diff --git a/src/common/netchan.c b/src/common/netchan.c index 86828c7d..3b457d84 100644 --- a/src/common/netchan.c +++ b/src/common/netchan.c @@ -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; } + diff --git a/src/common/pmove.c b/src/common/pmove.c index eeeb5f60..6a67ee8a 100644 --- a/src/common/pmove.c +++ b/src/common/pmove.c @@ -32,65 +32,64 @@ void AL_Underwater(); void AL_Overwater(); #endif -#define STEPSIZE 18 +#define STEPSIZE 18 /* all of the locals will be zeroed before each - pmove, just to make damn sure we don't have - any differences when running on client or server */ + * pmove, just to make damn sure we don't have + * any differences when running on client or server */ typedef struct { - vec3_t origin; /* full float precision */ - vec3_t velocity; /* full float precision */ + vec3_t origin; /* full float precision */ + vec3_t velocity; /* full float precision */ - vec3_t forward, right, up; - float frametime; + vec3_t forward, right, up; + float frametime; + csurface_t *groundsurface; + cplane_t groundplane; + int groundcontents; - csurface_t *groundsurface; - cplane_t groundplane; - int groundcontents; - - vec3_t previous_origin; - qboolean ladder; + vec3_t previous_origin; + qboolean ladder; } pml_t; -pmove_t *pm; -pml_t pml; +pmove_t *pm; +pml_t pml; /* movement parameters */ -float pm_stopspeed = 100; -float pm_maxspeed = 300; -float pm_duckspeed = 100; -float pm_accelerate = 10; -float pm_airaccelerate = 0; -float pm_wateraccelerate = 10; -float pm_friction = 6; -float pm_waterfriction = 1; -float pm_waterspeed = 400; +float pm_stopspeed = 100; +float pm_maxspeed = 300; +float pm_duckspeed = 100; +float pm_accelerate = 10; +float pm_airaccelerate = 0; +float pm_wateraccelerate = 10; +float pm_friction = 6; +float pm_waterfriction = 1; +float pm_waterspeed = 400; -/* - * Slide off of the impacting object - * returns the blocked flags (1 = floor, 2 = step / wall) - */ +#define STOP_EPSILON 0.1 /* Slide off of the impacting object returns the blocked flags (1 = floor, 2 = step / wall) */ +#define MIN_STEP_NORMAL 0.7 /* can't step up onto very steep slopes */ +#define MAX_CLIP_PLANES 5 -#define STOP_EPSILON 0.1 - -void PM_ClipVelocity (vec3_t in, vec3_t normal, vec3_t out, float overbounce) +void +PM_ClipVelocity(vec3_t in, vec3_t normal, vec3_t out, float overbounce) { - float backoff; - float change; - int i; + float backoff; + float change; + int i; - backoff = DotProduct (in, normal) * overbounce; + backoff = DotProduct(in, normal) * overbounce; - for (i=0 ; i<3 ; i++) + for (i = 0; i < 3; i++) { - change = normal[i]*backoff; + change = normal[i] * backoff; out[i] = in[i] - change; - if (out[i] > -STOP_EPSILON && out[i] < STOP_EPSILON) + if ((out[i] > -STOP_EPSILON) && (out[i] < STOP_EPSILON)) + { out[i] = 0; + } } } @@ -101,34 +100,35 @@ void PM_ClipVelocity (vec3_t in, vec3_t normal, vec3_t out, float overbounce) * Returns a new origin, velocity, and contact entity * Does not modify any world state? */ -#define MIN_STEP_NORMAL 0.7 /* can't step up onto very steep slopes */ -#define MAX_CLIP_PLANES 5 -void PM_StepSlideMove_ (void) +void +PM_StepSlideMove_(void) { - int bumpcount, numbumps; - vec3_t dir; - float d; - int numplanes; - vec3_t planes[MAX_CLIP_PLANES]; - vec3_t primal_velocity; - int i, j; - trace_t trace; - vec3_t end; - float time_left; + int bumpcount, numbumps; + vec3_t dir; + float d; + int numplanes; + vec3_t planes[MAX_CLIP_PLANES]; + vec3_t primal_velocity; + int i, j; + trace_t trace; + vec3_t end; + float time_left; numbumps = 4; - VectorCopy (pml.velocity, primal_velocity); + VectorCopy(pml.velocity, primal_velocity); numplanes = 0; time_left = pml.frametime; - for (bumpcount=0 ; bumpcounttrace (pml.origin, pm->mins, pm->maxs, end); + trace = pm->trace(pml.origin, pm->mins, pm->maxs, end); if (trace.allsolid) { @@ -140,15 +140,17 @@ void PM_StepSlideMove_ (void) if (trace.fraction > 0) { /* actually covered some distance */ - VectorCopy (trace.endpos, pml.origin); + VectorCopy(trace.endpos, pml.origin); numplanes = 0; } if (trace.fraction == 1) + { break; /* moved the entire distance */ + } /* save entity for contact */ - if (pm->numtouch < MAXTOUCH && trace.ent) + if ((pm->numtouch < MAXTOUCH) && trace.ent) { pm->touchents[pm->numtouch] = trace.ent; pm->numtouch++; @@ -160,27 +162,33 @@ void PM_StepSlideMove_ (void) if (numplanes >= MAX_CLIP_PLANES) { /* this shouldn't really happen */ - VectorCopy (vec3_origin, pml.velocity); + VectorCopy(vec3_origin, pml.velocity); break; } - VectorCopy (trace.plane.normal, planes[numplanes]); + VectorCopy(trace.plane.normal, planes[numplanes]); numplanes++; /* modify original_velocity so it parallels all of the clip planes */ - for (i=0 ; is.pm_time) { - VectorCopy (primal_velocity, pml.velocity); + VectorCopy(primal_velocity, pml.velocity); } } -void PM_StepSlideMove (void) +void +PM_StepSlideMove(void) { - vec3_t start_o, start_v; - vec3_t down_o, down_v; - trace_t trace; - float down_dist, up_dist; - vec3_t up, down; + vec3_t start_o, start_v; + vec3_t down_o, down_v; + trace_t trace; + float down_dist, up_dist; + vec3_t up, down; - VectorCopy (pml.origin, start_o); - VectorCopy (pml.velocity, start_v); + VectorCopy(pml.origin, start_o); + VectorCopy(pml.velocity, start_v); - PM_StepSlideMove_ (); + PM_StepSlideMove_(); - VectorCopy (pml.origin, down_o); - VectorCopy (pml.velocity, down_v); + VectorCopy(pml.origin, down_o); + VectorCopy(pml.velocity, down_v); - VectorCopy (start_o, up); + VectorCopy(start_o, up); up[2] += STEPSIZE; - trace = pm->trace (up, pm->mins, pm->maxs, up); + trace = pm->trace(up, pm->mins, pm->maxs, up); if (trace.allsolid) + { return; /* can't step up */ + } /* try sliding above */ - VectorCopy (up, pml.origin); - VectorCopy (start_v, pml.velocity); + VectorCopy(up, pml.origin); + VectorCopy(start_v, pml.velocity); - PM_StepSlideMove_ (); + PM_StepSlideMove_(); /* push down the final amount */ - VectorCopy (pml.origin, down); + VectorCopy(pml.origin, down); down[2] -= STEPSIZE; - trace = pm->trace (pml.origin, pm->mins, pm->maxs, down); + trace = pm->trace(pml.origin, pm->mins, pm->maxs, down); if (!trace.allsolid) { - VectorCopy (trace.endpos, pml.origin); + VectorCopy(trace.endpos, pml.origin); } VectorCopy(pml.origin, up); /* decide which one went farther */ - down_dist = (down_o[0] - start_o[0])*(down_o[0] - start_o[0]) - + (down_o[1] - start_o[1])*(down_o[1] - start_o[1]); - up_dist = (up[0] - start_o[0])*(up[0] - start_o[0]) - + (up[1] - start_o[1])*(up[1] - start_o[1]); + down_dist = (down_o[0] - start_o[0]) * (down_o[0] - start_o[0]) + + (down_o[1] - start_o[1]) * (down_o[1] - start_o[1]); + up_dist = (up[0] - start_o[0]) * (up[0] - start_o[0]) + + (up[1] - start_o[1]) * (up[1] - start_o[1]); - if (down_dist > up_dist || trace.plane.normal[2] < MIN_STEP_NORMAL) + if ((down_dist > up_dist) || (trace.plane.normal[2] < MIN_STEP_NORMAL)) { - VectorCopy (down_o, pml.origin); - VectorCopy (down_v, pml.velocity); + VectorCopy(down_o, pml.origin); + VectorCopy(down_v, pml.velocity); return; } @@ -277,16 +288,17 @@ void PM_StepSlideMove (void) /* * Handles both ground friction and water friction */ -void PM_Friction (void) +void +PM_Friction(void) { - float *vel; - float speed, newspeed, control; - float friction; - float drop; + float *vel; + float speed, newspeed, control; + float friction; + float drop; vel = pml.velocity; - speed = (float)sqrt(vel[0]*vel[0] +vel[1]*vel[1] + vel[2]*vel[2]); + speed = (float)sqrt(vel[0] * vel[0] + vel[1] * vel[1] + vel[2] * vel[2]); if (speed < 1) { @@ -298,16 +310,19 @@ void PM_Friction (void) drop = 0; /* apply ground friction */ - if ((pm->groundentity && pml.groundsurface && !(pml.groundsurface->flags & SURF_SLICK) ) || (pml.ladder) ) + if ((pm->groundentity && pml.groundsurface && + !(pml.groundsurface->flags & SURF_SLICK)) || (pml.ladder)) { friction = pm_friction; control = speed < pm_stopspeed ? pm_stopspeed : speed; - drop += control*friction*pml.frametime; + drop += control * friction * pml.frametime; } /* apply water friction */ if (pm->waterlevel && !pml.ladder) - drop += speed*pm_waterfriction*pm->waterlevel*pml.frametime; + { + drop += speed * pm_waterfriction * pm->waterlevel * pml.frametime; + } /* scale the velocity */ newspeed = speed - drop; @@ -327,199 +342,264 @@ void PM_Friction (void) /* * Handles user intended acceleration */ -void PM_Accelerate (vec3_t wishdir, float wishspeed, float accel) +void +PM_Accelerate(vec3_t wishdir, float wishspeed, float accel) { - int i; - float addspeed, accelspeed, currentspeed; + int i; + float addspeed, accelspeed, currentspeed; - currentspeed = DotProduct (pml.velocity, wishdir); + currentspeed = DotProduct(pml.velocity, wishdir); addspeed = wishspeed - currentspeed; if (addspeed <= 0) + { return; + } - accelspeed = accel*pml.frametime*wishspeed; + accelspeed = accel * pml.frametime * wishspeed; if (accelspeed > addspeed) + { accelspeed = addspeed; + } - for (i=0 ; i<3 ; i++) - pml.velocity[i] += accelspeed*wishdir[i]; + for (i = 0; i < 3; i++) + { + pml.velocity[i] += accelspeed * wishdir[i]; + } } -void PM_AirAccelerate (vec3_t wishdir, float wishspeed, float accel) +void +PM_AirAccelerate(vec3_t wishdir, float wishspeed, float accel) { - int i; - float addspeed, accelspeed, currentspeed, wishspd = wishspeed; + int i; + float addspeed, accelspeed, currentspeed, wishspd = wishspeed; if (wishspd > 30) + { wishspd = 30; + } - currentspeed = DotProduct (pml.velocity, wishdir); + currentspeed = DotProduct(pml.velocity, wishdir); addspeed = wishspd - currentspeed; if (addspeed <= 0) + { return; + } accelspeed = accel * wishspeed * pml.frametime; if (accelspeed > addspeed) + { accelspeed = addspeed; + } - for (i=0 ; i<3 ; i++) - pml.velocity[i] += accelspeed*wishdir[i]; + for (i = 0; i < 3; i++) + { + pml.velocity[i] += accelspeed * wishdir[i]; + } } -void PM_AddCurrents (vec3_t wishvel) +void +PM_AddCurrents(vec3_t wishvel) { - vec3_t v; - float s; + vec3_t v; + float s; /* account for ladders */ - if (pml.ladder && fabs(pml.velocity[2]) <= 200) + if (pml.ladder && (fabs(pml.velocity[2]) <= 200)) { if ((pm->viewangles[PITCH] <= -15) && (pm->cmd.forwardmove > 0)) + { wishvel[2] = 200; - + } else if ((pm->viewangles[PITCH] >= 15) && (pm->cmd.forwardmove > 0)) + { wishvel[2] = -200; - + } else if (pm->cmd.upmove > 0) + { wishvel[2] = 200; - + } else if (pm->cmd.upmove < 0) + { wishvel[2] = -200; - + } else + { wishvel[2] = 0; + } /* limit horizontal speed when on a ladder */ if (wishvel[0] < -25) + { wishvel[0] = -25; - + } else if (wishvel[0] > 25) + { wishvel[0] = 25; + } if (wishvel[1] < -25) + { wishvel[1] = -25; - + } else if (wishvel[1] > 25) + { wishvel[1] = 25; + } } /* add water currents */ if (pm->watertype & MASK_CURRENT) { - VectorClear (v); + VectorClear(v); if (pm->watertype & CONTENTS_CURRENT_0) + { v[0] += 1; + } if (pm->watertype & CONTENTS_CURRENT_90) + { v[1] += 1; + } if (pm->watertype & CONTENTS_CURRENT_180) + { v[0] -= 1; + } if (pm->watertype & CONTENTS_CURRENT_270) + { v[1] -= 1; + } if (pm->watertype & CONTENTS_CURRENT_UP) + { v[2] += 1; + } if (pm->watertype & CONTENTS_CURRENT_DOWN) + { v[2] -= 1; + } s = pm_waterspeed; if ((pm->waterlevel == 1) && (pm->groundentity)) + { s /= 2; + } - VectorMA (wishvel, s, v, wishvel); + VectorMA(wishvel, s, v, wishvel); } /* add conveyor belt velocities */ if (pm->groundentity) { - VectorClear (v); + VectorClear(v); if (pml.groundcontents & CONTENTS_CURRENT_0) + { v[0] += 1; + } if (pml.groundcontents & CONTENTS_CURRENT_90) + { v[1] += 1; + } if (pml.groundcontents & CONTENTS_CURRENT_180) + { v[0] -= 1; + } if (pml.groundcontents & CONTENTS_CURRENT_270) + { v[1] -= 1; + } if (pml.groundcontents & CONTENTS_CURRENT_UP) + { v[2] += 1; + } if (pml.groundcontents & CONTENTS_CURRENT_DOWN) + { v[2] -= 1; + } - VectorMA (wishvel, 100, v, wishvel); + VectorMA(wishvel, 100, v, wishvel); } } -void PM_WaterMove (void) +void +PM_WaterMove(void) { - int i; - vec3_t wishvel; - float wishspeed; - vec3_t wishdir; + int i; + vec3_t wishvel; + float wishspeed; + vec3_t wishdir; /* user intentions */ - for (i=0 ; i<3 ; i++) - wishvel[i] = pml.forward[i]*pm->cmd.forwardmove + pml.right[i]*pm->cmd.sidemove; + for (i = 0; i < 3; i++) + { + wishvel[i] = pml.forward[i] * pm->cmd.forwardmove + + pml.right[i] * pm->cmd.sidemove; + } if (!pm->cmd.forwardmove && !pm->cmd.sidemove && !pm->cmd.upmove) + { wishvel[2] -= 60; /* drift towards bottom */ - + } else + { wishvel[2] += pm->cmd.upmove; + } - PM_AddCurrents (wishvel); + PM_AddCurrents(wishvel); - VectorCopy (wishvel, wishdir); + VectorCopy(wishvel, wishdir); wishspeed = VectorNormalize(wishdir); if (wishspeed > pm_maxspeed) { - VectorScale (wishvel, pm_maxspeed/wishspeed, wishvel); + VectorScale(wishvel, pm_maxspeed / wishspeed, wishvel); wishspeed = pm_maxspeed; } wishspeed *= 0.5; - PM_Accelerate (wishdir, wishspeed, pm_wateraccelerate); + PM_Accelerate(wishdir, wishspeed, pm_wateraccelerate); - PM_StepSlideMove (); + PM_StepSlideMove(); } -void PM_AirMove (void) +void +PM_AirMove(void) { - int i; - vec3_t wishvel; - float fmove, smove; - vec3_t wishdir; - float wishspeed; - float maxspeed; + int i; + vec3_t wishvel; + float fmove, smove; + vec3_t wishdir; + float wishspeed; + float maxspeed; fmove = pm->cmd.forwardmove; smove = pm->cmd.sidemove; - for (i=0 ; i<2 ; i++) - wishvel[i] = pml.forward[i]*fmove + pml.right[i]*smove; + for (i = 0; i < 2; i++) + { + wishvel[i] = pml.forward[i] * fmove + pml.right[i] * smove; + } wishvel[2] = 0; - PM_AddCurrents (wishvel); + PM_AddCurrents(wishvel); - VectorCopy (wishvel, wishdir); + VectorCopy(wishvel, wishdir); wishspeed = VectorNormalize(wishdir); /* clamp to server defined max speed */ @@ -527,13 +607,13 @@ void PM_AirMove (void) if (wishspeed > maxspeed) { - VectorScale (wishvel, maxspeed/wishspeed, wishvel); + VectorScale(wishvel, maxspeed / wishspeed, wishvel); wishspeed = maxspeed; } - if ( pml.ladder ) + if (pml.ladder) { - PM_Accelerate (wishdir, wishspeed, pm_accelerate); + PM_Accelerate(wishdir, wishspeed, pm_accelerate); if (!wishvel[2]) { @@ -542,61 +622,71 @@ void PM_AirMove (void) pml.velocity[2] -= pm->s.gravity * pml.frametime; if (pml.velocity[2] < 0) - pml.velocity[2] = 0; + { + pml.velocity[2] = 0; + } } - else { pml.velocity[2] += pm->s.gravity * pml.frametime; if (pml.velocity[2] > 0) - pml.velocity[2] = 0; + { + pml.velocity[2] = 0; + } } } - PM_StepSlideMove (); + PM_StepSlideMove(); } - - else if ( pm->groundentity ) + else if (pm->groundentity) { /* walking on ground */ pml.velocity[2] = 0; - PM_Accelerate (wishdir, wishspeed, pm_accelerate); + PM_Accelerate(wishdir, wishspeed, pm_accelerate); - if(pm->s.gravity > 0) + if (pm->s.gravity > 0) + { pml.velocity[2] = 0; - + } else + { pml.velocity[2] -= pm->s.gravity * pml.frametime; + } if (!pml.velocity[0] && !pml.velocity[1]) + { return; + } - PM_StepSlideMove (); + PM_StepSlideMove(); } - else { /* not on ground, so little effect on velocity */ if (pm_airaccelerate) - PM_AirAccelerate (wishdir, wishspeed, pm_accelerate); - + { + PM_AirAccelerate(wishdir, wishspeed, pm_accelerate); + } else - PM_Accelerate (wishdir, wishspeed, 1); + { + PM_Accelerate(wishdir, wishspeed, 1); + } /* add gravity */ pml.velocity[2] -= pm->s.gravity * pml.frametime; - PM_StepSlideMove (); + PM_StepSlideMove(); } } -void PM_CatagorizePosition (void) +void +PM_CatagorizePosition(void) { - vec3_t point; - int cont; - trace_t trace; - float sample1; - float sample2; + vec3_t point; + int cont; + trace_t trace; + float sample1; + float sample2; /* if the player hull point one unit down is solid, the player is on ground */ @@ -611,20 +701,18 @@ void PM_CatagorizePosition (void) pm->s.pm_flags &= ~PMF_ON_GROUND; pm->groundentity = NULL; } - else { - trace = pm->trace (pml.origin, pm->mins, pm->maxs, point); + trace = pm->trace(pml.origin, pm->mins, pm->maxs, point); pml.groundplane = trace.plane; pml.groundsurface = trace.surface; pml.groundcontents = trace.contents; - if (!trace.ent || (trace.plane.normal[2] < 0.7 && !trace.startsolid) ) + if (!trace.ent || ((trace.plane.normal[2] < 0.7) && !trace.startsolid)) { pm->groundentity = NULL; pm->s.pm_flags &= ~PMF_ON_GROUND; } - else { pm->groundentity = trace.ent; @@ -632,11 +720,12 @@ void PM_CatagorizePosition (void) /* hitting solid ground will end a waterjump */ if (pm->s.pm_flags & PMF_TIME_WATERJUMP) { - pm->s.pm_flags &= ~(PMF_TIME_WATERJUMP | PMF_TIME_LAND | PMF_TIME_TELEPORT); + pm->s.pm_flags &= + ~(PMF_TIME_WATERJUMP | PMF_TIME_LAND | PMF_TIME_TELEPORT); pm->s.pm_time = 0; } - if (! (pm->s.pm_flags & PMF_ON_GROUND) ) + if (!(pm->s.pm_flags & PMF_ON_GROUND)) { /* just hit the ground */ pm->s.pm_flags |= PMF_ON_GROUND; @@ -648,15 +737,18 @@ void PM_CatagorizePosition (void) /* don't allow another jump for a little while */ if (pml.velocity[2] < -400) + { pm->s.pm_time = 25; - + } else + { pm->s.pm_time = 18; + } } } } - if (pm->numtouch < MAXTOUCH && trace.ent) + if ((pm->numtouch < MAXTOUCH) && trace.ent) { pm->touchents[pm->numtouch] = trace.ent; pm->numtouch++; @@ -671,29 +763,31 @@ void PM_CatagorizePosition (void) sample1 = sample2 / 2; point[2] = pml.origin[2] + pm->mins[2] + 1; - cont = pm->pointcontents (point); + cont = pm->pointcontents(point); if (cont & MASK_WATER) { pm->watertype = cont; pm->waterlevel = 1; point[2] = pml.origin[2] + pm->mins[2] + sample1; - cont = pm->pointcontents (point); + cont = pm->pointcontents(point); if (cont & MASK_WATER) { pm->waterlevel = 2; point[2] = pml.origin[2] + pm->mins[2] + sample2; - cont = pm->pointcontents (point); + cont = pm->pointcontents(point); if (cont & MASK_WATER) + { pm->waterlevel = 3; + } } } - } -void PM_CheckJump (void) +void +PM_CheckJump(void) { if (pm->s.pm_flags & PMF_TIME_LAND) { @@ -710,10 +804,14 @@ void PM_CheckJump (void) /* must wait for jump to be released */ if (pm->s.pm_flags & PMF_JUMP_HELD) + { return; + } if (pm->s.pm_type == PM_DEAD) + { return; + } if (pm->waterlevel >= 2) { @@ -721,22 +819,30 @@ void PM_CheckJump (void) pm->groundentity = NULL; if (pml.velocity[2] <= -300) + { return; + } if (pm->watertype == CONTENTS_WATER) + { pml.velocity[2] = 100; - + } else if (pm->watertype == CONTENTS_SLIME) + { pml.velocity[2] = 80; - + } else + { pml.velocity[2] = 50; + } return; } if (pm->groundentity == NULL) - return; /* in air, so no effect */ + { + return; /* in air, so no effect */ + } pm->s.pm_flags |= PMF_JUMP_HELD; @@ -744,18 +850,23 @@ void PM_CheckJump (void) pml.velocity[2] += 270; if (pml.velocity[2] < 270) + { pml.velocity[2] = 270; + } } -void PM_CheckSpecialMovement (void) +void +PM_CheckSpecialMovement(void) { - vec3_t spot; - int cont; - vec3_t flatforward; - trace_t trace; + vec3_t spot; + int cont; + vec3_t flatforward; + trace_t trace; if (pm->s.pm_time) + { return; + } pml.ladder = false; @@ -763,99 +874,111 @@ void PM_CheckSpecialMovement (void) flatforward[0] = pml.forward[0]; flatforward[1] = pml.forward[1]; flatforward[2] = 0; - VectorNormalize (flatforward); + VectorNormalize(flatforward); - VectorMA (pml.origin, 1, flatforward, spot); - trace = pm->trace (pml.origin, pm->mins, pm->maxs, spot); + VectorMA(pml.origin, 1, flatforward, spot); + trace = pm->trace(pml.origin, pm->mins, pm->maxs, spot); if ((trace.fraction < 1) && (trace.contents & CONTENTS_LADDER)) + { pml.ladder = true; + } /* check for water jump */ if (pm->waterlevel != 2) + { return; + } - VectorMA (pml.origin, 30, flatforward, spot); + VectorMA(pml.origin, 30, flatforward, spot); spot[2] += 4; - cont = pm->pointcontents (spot); + cont = pm->pointcontents(spot); if (!(cont & CONTENTS_SOLID)) + { return; + } spot[2] += 16; - cont = pm->pointcontents (spot); + cont = pm->pointcontents(spot); if (cont) + { return; + } /* jump out of water */ - VectorScale (flatforward, 50, pml.velocity); + VectorScale(flatforward, 50, pml.velocity); pml.velocity[2] = 350; pm->s.pm_flags |= PMF_TIME_WATERJUMP; pm->s.pm_time = 255; } -void PM_FlyMove (qboolean doclip) +void +PM_FlyMove(qboolean doclip) { - float speed, drop, friction, control, newspeed; - float currentspeed, addspeed, accelspeed; - int i; - vec3_t wishvel; - float fmove, smove; - vec3_t wishdir; - float wishspeed; - vec3_t end; - trace_t trace; + float speed, drop, friction, control, newspeed; + float currentspeed, addspeed, accelspeed; + int i; + vec3_t wishvel; + float fmove, smove; + vec3_t wishdir; + float wishspeed; + vec3_t end; + trace_t trace; pm->viewheight = 22; /* friction */ - speed = VectorLength (pml.velocity); + speed = VectorLength(pml.velocity); if (speed < 1) { - VectorCopy (vec3_origin, pml.velocity); + VectorCopy(vec3_origin, pml.velocity); } - else { drop = 0; - friction = pm_friction*1.5f; /* extra friction */ + friction = pm_friction * 1.5f; /* extra friction */ control = speed < pm_stopspeed ? pm_stopspeed : speed; - drop += control*friction*pml.frametime; + drop += control * friction * pml.frametime; /* scale the velocity */ newspeed = speed - drop; if (newspeed < 0) + { newspeed = 0; + } newspeed /= speed; - VectorScale (pml.velocity, newspeed, pml.velocity); + VectorScale(pml.velocity, newspeed, pml.velocity); } /* accelerate */ fmove = pm->cmd.forwardmove; smove = pm->cmd.sidemove; - VectorNormalize (pml.forward); - VectorNormalize (pml.right); + VectorNormalize(pml.forward); + VectorNormalize(pml.right); - for (i=0 ; i<3 ; i++) - wishvel[i] = pml.forward[i]*fmove + pml.right[i]*smove; + for (i = 0; i < 3; i++) + { + wishvel[i] = pml.forward[i] * fmove + pml.right[i] * smove; + } wishvel[2] += pm->cmd.upmove; - VectorCopy (wishvel, wishdir); + VectorCopy(wishvel, wishdir); wishspeed = VectorNormalize(wishdir); /* clamp to server defined max speed */ if (wishspeed > pm_maxspeed) { - VectorScale (wishvel, pm_maxspeed/wishspeed, wishvel); + VectorScale(wishvel, pm_maxspeed / wishspeed, wishvel); wishspeed = pm_maxspeed; } @@ -863,39 +986,47 @@ void PM_FlyMove (qboolean doclip) addspeed = wishspeed - currentspeed; if (addspeed <= 0) + { return; + } - accelspeed = pm_accelerate*pml.frametime*wishspeed; + accelspeed = pm_accelerate * pml.frametime * wishspeed; if (accelspeed > addspeed) + { accelspeed = addspeed; + } - for (i=0 ; i<3 ; i++) - pml.velocity[i] += accelspeed*wishdir[i]; + for (i = 0; i < 3; i++) + { + pml.velocity[i] += accelspeed * wishdir[i]; + } if (doclip) { - for (i=0 ; i<3 ; i++) + for (i = 0; i < 3; i++) + { end[i] = pml.origin[i] + pml.frametime * pml.velocity[i]; + } - trace = pm->trace (pml.origin, pm->mins, pm->maxs, end); + trace = pm->trace(pml.origin, pm->mins, pm->maxs, end); - VectorCopy (trace.endpos, pml.origin); + VectorCopy(trace.endpos, pml.origin); } - else { /* move */ - VectorMA (pml.origin, pml.frametime, pml.velocity, pml.origin); + VectorMA(pml.origin, pml.frametime, pml.velocity, pml.origin); } } /* * Sets mins, maxs, and pm->viewheight */ -void PM_CheckDuck (void) +void +PM_CheckDuck(void) { - trace_t trace; + trace_t trace; pm->mins[0] = -16; pm->mins[1] = -16; @@ -917,13 +1048,11 @@ void PM_CheckDuck (void) { pm->s.pm_flags |= PMF_DUCKED; } - - else if (pm->cmd.upmove < 0 && (pm->s.pm_flags & PMF_ON_GROUND) ) + else if ((pm->cmd.upmove < 0) && (pm->s.pm_flags & PMF_ON_GROUND)) { /* duck */ pm->s.pm_flags |= PMF_DUCKED; } - else { /* stand up if possible */ @@ -931,10 +1060,12 @@ void PM_CheckDuck (void) { /* try to stand up */ pm->maxs[2] = 32; - trace = pm->trace (pml.origin, pm->mins, pm->maxs, pml.origin); + trace = pm->trace(pml.origin, pm->mins, pm->maxs, pml.origin); if (!trace.allsolid) + { pm->s.pm_flags &= ~PMF_DUCKED; + } } } @@ -943,7 +1074,6 @@ void PM_CheckDuck (void) pm->maxs[2] = 4; pm->viewheight = -2; } - else { pm->maxs[2] = 32; @@ -951,42 +1081,49 @@ void PM_CheckDuck (void) } } -void PM_DeadMove (void) +void +PM_DeadMove(void) { - float forward; + float forward; if (!pm->groundentity) + { return; + } /* extra friction */ - forward = VectorLength (pml.velocity); + forward = VectorLength(pml.velocity); forward -= 20; if (forward <= 0) { - VectorClear (pml.velocity); + VectorClear(pml.velocity); } - else { - VectorNormalize (pml.velocity); - VectorScale (pml.velocity, forward, pml.velocity); + VectorNormalize(pml.velocity); + VectorScale(pml.velocity, forward, pml.velocity); } } -qboolean PM_GoodPosition (void) +qboolean +PM_GoodPosition(void) { - trace_t trace; - vec3_t origin, end; - int i; + trace_t trace; + vec3_t origin, end; + int i; if (pm->s.pm_type == PM_SPECTATOR) + { return true; + } - for (i=0 ; i<3 ; i++) - origin[i] = end[i] = pm->s.origin[i]*0.125f; + for (i = 0; i < 3; i++) + { + origin[i] = end[i] = pm->s.origin[i] * 0.125f; + } - trace = pm->trace (origin, pm->mins, pm->maxs, end); + trace = pm->trace(origin, pm->mins, pm->maxs, end); return !trace.allsolid; } @@ -995,123 +1132,143 @@ qboolean PM_GoodPosition (void) * On exit, the origin will have a value that is pre-quantized to the 0.125 * precision of the network channel and in a valid position. */ -void PM_SnapPosition (void) +void +PM_SnapPosition(void) { - int sign[3]; - int i, j, bits; - short base[3]; + int sign[3]; + int i, j, bits; + short base[3]; /* try all single bits first */ - static int jitterbits[8] = {0,4,1,2,3,5,6,7}; + static int jitterbits[8] = {0, 4, 1, 2, 3, 5, 6, 7}; /* snap velocity to eigths */ - for (i=0 ; i<3 ; i++) - pm->s.velocity[i] = (int)(pml.velocity[i]*8); - - for (i=0 ; i<3 ; i++) + for (i = 0; i < 3; i++) { - if (pml.origin[i] >= 0) - sign[i] = 1; - - else - sign[i] = -1; - - pm->s.origin[i] = (int)(pml.origin[i]*8); - - if (pm->s.origin[i]*0.125f == pml.origin[i]) - sign[i] = 0; + pm->s.velocity[i] = (int)(pml.velocity[i] * 8); } - VectorCopy (pm->s.origin, base); + for (i = 0; i < 3; i++) + { + if (pml.origin[i] >= 0) + { + sign[i] = 1; + } + else + { + sign[i] = -1; + } + + pm->s.origin[i] = (int)(pml.origin[i] * 8); + + if (pm->s.origin[i] * 0.125f == pml.origin[i]) + { + sign[i] = 0; + } + } + + VectorCopy(pm->s.origin, base); /* try all combinations */ - for (j=0 ; j<8 ; j++) + for (j = 0; j < 8; j++) { bits = jitterbits[j]; - VectorCopy (base, pm->s.origin); + VectorCopy(base, pm->s.origin); - for (i=0 ; i<3 ; i++) - if (bits & (1<s.origin[i] += sign[i]; + } + } - if (PM_GoodPosition ()) + if (PM_GoodPosition()) + { return; + } } /* go back to the last position */ - VectorCopy (pml.previous_origin, pm->s.origin); + VectorCopy(pml.previous_origin, pm->s.origin); } -void PM_InitialSnapPosition(void) +void +PM_InitialSnapPosition(void) { - int x, y, z; - short base[3]; - static int offset[3] = { 0, -1, 1 }; + int x, y, z; + short base[3]; + static int offset[3] = {0, -1, 1}; - VectorCopy (pm->s.origin, base); + VectorCopy(pm->s.origin, base); - for ( z = 0; z < 3; z++ ) + for (z = 0; z < 3; z++) { - pm->s.origin[2] = base[2] + offset[ z ]; + pm->s.origin[2] = base[2] + offset[z]; - for ( y = 0; y < 3; y++ ) + for (y = 0; y < 3; y++) { - pm->s.origin[1] = base[1] + offset[ y ]; + pm->s.origin[1] = base[1] + offset[y]; - for ( x = 0; x < 3; x++ ) + for (x = 0; x < 3; x++) { - pm->s.origin[0] = base[0] + offset[ x ]; + pm->s.origin[0] = base[0] + offset[x]; - if (PM_GoodPosition ()) + if (PM_GoodPosition()) { - pml.origin[0] = pm->s.origin[0]*0.125f; - pml.origin[1] = pm->s.origin[1]*0.125f; - pml.origin[2] = pm->s.origin[2]*0.125f; - VectorCopy (pm->s.origin, pml.previous_origin); + pml.origin[0] = pm->s.origin[0] * 0.125f; + pml.origin[1] = pm->s.origin[1] * 0.125f; + pml.origin[2] = pm->s.origin[2] * 0.125f; + VectorCopy(pm->s.origin, pml.previous_origin); return; } } } } - Com_DPrintf ("Bad InitialSnapPosition\n"); + Com_DPrintf("Bad InitialSnapPosition\n"); } -void PM_ClampAngles (void) +void +PM_ClampAngles(void) { - short temp; - int i; + short temp; + int i; if (pm->s.pm_flags & PMF_TIME_TELEPORT) { - pm->viewangles[YAW] = SHORT2ANGLE(pm->cmd.angles[YAW] + pm->s.delta_angles[YAW]); + pm->viewangles[YAW] = SHORT2ANGLE( + pm->cmd.angles[YAW] + pm->s.delta_angles[YAW]); pm->viewangles[PITCH] = 0; pm->viewangles[ROLL] = 0; } - else { /* circularly clamp the angles with deltas */ - for (i=0 ; i<3 ; i++) + for (i = 0; i < 3; i++) { temp = pm->cmd.angles[i] + pm->s.delta_angles[i]; pm->viewangles[i] = SHORT2ANGLE(temp); } /* don't let the player look up or down more than 90 degrees */ - if (pm->viewangles[PITCH] > 89 && pm->viewangles[PITCH] < 180) + if ((pm->viewangles[PITCH] > 89) && (pm->viewangles[PITCH] < 180)) + { pm->viewangles[PITCH] = 89; - - else if (pm->viewangles[PITCH] < 271 && pm->viewangles[PITCH] >= 180) + } + else if ((pm->viewangles[PITCH] < 271) && (pm->viewangles[PITCH] >= 180)) + { pm->viewangles[PITCH] = 271; + } } - AngleVectors (pm->viewangles, pml.forward, pml.right, pml.up); + AngleVectors(pm->viewangles, pml.forward, pml.right, pml.up); } /* * Can be called by either the server or the client */ -void Pmove (pmove_t *pmove) +void +Pmove(pmove_t *pmove) { #if !defined(DEDICATED_ONLY) && defined(USE_OPENAL) static int underwater; @@ -1121,35 +1278,35 @@ void Pmove (pmove_t *pmove) /* clear results */ pm->numtouch = 0; - VectorClear (pm->viewangles); + VectorClear(pm->viewangles); pm->viewheight = 0; pm->groundentity = 0; pm->watertype = 0; pm->waterlevel = 0; /* clear all pmove local vars */ - memset (&pml, 0, sizeof(pml)); + memset(&pml, 0, sizeof(pml)); /* convert origin and velocity to float values */ - pml.origin[0] = pm->s.origin[0]*0.125f; - pml.origin[1] = pm->s.origin[1]*0.125f; - pml.origin[2] = pm->s.origin[2]*0.125f; + pml.origin[0] = pm->s.origin[0] * 0.125f; + pml.origin[1] = pm->s.origin[1] * 0.125f; + pml.origin[2] = pm->s.origin[2] * 0.125f; - pml.velocity[0] = pm->s.velocity[0]*0.125f; - pml.velocity[1] = pm->s.velocity[1]*0.125f; - pml.velocity[2] = pm->s.velocity[2]*0.125f; + pml.velocity[0] = pm->s.velocity[0] * 0.125f; + pml.velocity[1] = pm->s.velocity[1] * 0.125f; + pml.velocity[2] = pm->s.velocity[2] * 0.125f; /* save old org in case we get stuck */ - VectorCopy (pm->s.origin, pml.previous_origin); + VectorCopy(pm->s.origin, pml.previous_origin); pml.frametime = pm->cmd.msec * 0.001f; - PM_ClampAngles (); + PM_ClampAngles(); if (pm->s.pm_type == PM_SPECTATOR) { - PM_FlyMove (false); - PM_SnapPosition (); + PM_FlyMove(false); + PM_SnapPosition(); return; } @@ -1161,40 +1318,50 @@ void Pmove (pmove_t *pmove) } if (pm->s.pm_type == PM_FREEZE) - return; /* no movement at all */ + { + return; /* no movement at all */ + } /* set mins, maxs, and viewheight */ - PM_CheckDuck (); + PM_CheckDuck(); if (pm->snapinitial) - PM_InitialSnapPosition (); + { + PM_InitialSnapPosition(); + } /* set groundentity, watertype, and waterlevel */ - PM_CatagorizePosition (); + PM_CatagorizePosition(); if (pm->s.pm_type == PM_DEAD) - PM_DeadMove (); + { + PM_DeadMove(); + } - PM_CheckSpecialMovement (); + PM_CheckSpecialMovement(); /* drop timing counter */ if (pm->s.pm_time) { - int msec; + int msec; msec = pm->cmd.msec >> 3; if (!msec) - msec = 1; - - if ( msec >= pm->s.pm_time) { - pm->s.pm_flags &= ~(PMF_TIME_WATERJUMP | PMF_TIME_LAND | PMF_TIME_TELEPORT); - pm->s.pm_time = 0; + msec = 1; } + if (msec >= pm->s.pm_time) + { + pm->s.pm_flags &= + ~(PMF_TIME_WATERJUMP | PMF_TIME_LAND | PMF_TIME_TELEPORT); + pm->s.pm_time = 0; + } else + { pm->s.pm_time -= msec; + } } if (pm->s.pm_flags & PMF_TIME_TELEPORT) @@ -1213,36 +1380,39 @@ void Pmove (pmove_t *pmove) pm->s.pm_time = 0; } - PM_StepSlideMove (); + PM_StepSlideMove(); } else { - PM_CheckJump (); + PM_CheckJump(); - PM_Friction (); + PM_Friction(); if (pm->waterlevel >= 2) - PM_WaterMove (); - + { + PM_WaterMove(); + } else { - vec3_t angles; + vec3_t angles; VectorCopy(pm->viewangles, angles); if (angles[PITCH] > 180) + { angles[PITCH] = angles[PITCH] - 360; + } angles[PITCH] /= 3; - AngleVectors (angles, pml.forward, pml.right, pml.up); + AngleVectors(angles, pml.forward, pml.right, pml.up); - PM_AirMove (); + PM_AirMove(); } } /* set groundentity, watertype, and waterlevel for final spot */ - PM_CatagorizePosition (); + PM_CatagorizePosition(); #if !defined(DEDICATED_ONLY) && defined(USE_OPENAL) if ((pm->waterlevel == 3) && !underwater) @@ -1251,12 +1421,13 @@ void Pmove (pmove_t *pmove) AL_Underwater(); } - if ((pm->waterlevel < 3 && underwater)) + if (((pm->waterlevel < 3) && underwater)) { underwater = 0; AL_Overwater(); } #endif - PM_SnapPosition (); + PM_SnapPosition(); } + diff --git a/src/common/szone.c b/src/common/szone.c index 6b94d632..190bd815 100644 --- a/src/common/szone.c +++ b/src/common/szone.c @@ -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); + } } + diff --git a/src/common/zone.c b/src/common/zone.c index 24bec289..275ef07b 100644 --- a/src/common/zone.c +++ b/src/common/zone.c @@ -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); } +