mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-29 20:20:43 +00:00
various cleanups including TODOs and FIXMEs and rewrite va to use a dynamic
buffer.
This commit is contained in:
parent
4af4c69289
commit
630aa80dc4
6 changed files with 38 additions and 53 deletions
|
@ -315,7 +315,7 @@ C_Print (const char *fmt, va_list args)
|
||||||
if (!buffer)
|
if (!buffer)
|
||||||
Sys_Error ("console: could not allocate %d bytes\n",
|
Sys_Error ("console: could not allocate %d bytes\n",
|
||||||
buffer_size);
|
buffer_size);
|
||||||
size = vsnprintf (buffer, buffer_size, fmt, args);
|
size = vsnprintf (buffer, buffer_size, fmt, args) + 1;
|
||||||
//printf ("size = %d\n", size);
|
//printf ("size = %d\n", size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -118,9 +118,8 @@ Cbuf_AddText (const char *text)
|
||||||
/*
|
/*
|
||||||
Cbuf_InsertText
|
Cbuf_InsertText
|
||||||
|
|
||||||
Adds command text immediately after the current command
|
Adds command text to the beginning of the buffer.
|
||||||
Adds a \n to the text
|
Adds a \n to the text
|
||||||
TODO: Can we just read the buffer in the reverse order?
|
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
Cbuf_InsertText (const char *text)
|
Cbuf_InsertText (const char *text)
|
||||||
|
@ -308,19 +307,19 @@ Cmd_Exec_f (void)
|
||||||
Sys_Printf ("exec <filename> : execute a script file\n");
|
Sys_Printf ("exec <filename> : execute a script file\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// FIXME: is this safe freeing the hunk here?
|
|
||||||
mark = Hunk_LowMark ();
|
mark = Hunk_LowMark ();
|
||||||
f = (char *) COM_LoadHunkFile (Cmd_Argv (1));
|
f = (char *) COM_LoadHunkFile (Cmd_Argv (1));
|
||||||
if (!f) {
|
if (!f) {
|
||||||
Sys_Printf ("couldn't exec %s\n", Cmd_Argv (1));
|
Sys_Printf ("couldn't exec %s\n", Cmd_Argv (1));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Cbuf_InsertText (f);
|
||||||
|
Hunk_FreeToLowMark (mark);
|
||||||
|
|
||||||
if (!Cvar_Command () && (cmd_warncmd->int_val
|
if (!Cvar_Command () && (cmd_warncmd->int_val
|
||||||
|| (developer && developer->int_val)))
|
|| (developer && developer->int_val)))
|
||||||
Sys_Printf ("execing %s\n", Cmd_Argv (1));
|
Sys_Printf ("execing %s\n", Cmd_Argv (1));
|
||||||
|
|
||||||
Cbuf_InsertText (f);
|
|
||||||
Hunk_FreeToLowMark (mark);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -829,7 +828,6 @@ Cmd_ExpandVariables (const char *data, char *dest)
|
||||||
Cmd_ExecuteString
|
Cmd_ExecuteString
|
||||||
|
|
||||||
A complete command line has been parsed, so try to execute it
|
A complete command line has been parsed, so try to execute it
|
||||||
FIXME: lookupnoadd the token to speed search?
|
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
Cmd_ExecuteString (const char *text, cmd_source_t src)
|
Cmd_ExecuteString (const char *text, cmd_source_t src)
|
||||||
|
|
|
@ -67,7 +67,6 @@ struct hashtab_s {
|
||||||
unsigned long
|
unsigned long
|
||||||
Hash_String (const char *str)
|
Hash_String (const char *str)
|
||||||
{
|
{
|
||||||
//FIXME not 64 bit clean
|
|
||||||
#if 0
|
#if 0
|
||||||
unsigned long h = 0;
|
unsigned long h = 0;
|
||||||
while (*str) {
|
while (*str) {
|
||||||
|
@ -81,9 +80,8 @@ Hash_String (const char *str)
|
||||||
// shamelessly stolen from Daniel Phillips <phillips@innominate.de>
|
// shamelessly stolen from Daniel Phillips <phillips@innominate.de>
|
||||||
// from his post to lkml
|
// from his post to lkml
|
||||||
unsigned long hash0 = 0x12a3fe2d, hash1 = 0x37abe8f9;
|
unsigned long hash0 = 0x12a3fe2d, hash1 = 0x37abe8f9;
|
||||||
while (*str)
|
while (*str) {
|
||||||
{
|
unsigned long hash = hash1 + (hash0 ^ ((unsigned char)*str++ * 71523));
|
||||||
unsigned long hash = hash1 + (hash0 ^ (*str++ * 71523));
|
|
||||||
if (hash < 0) hash -= 0x7fffffff;
|
if (hash < 0) hash -= 0x7fffffff;
|
||||||
hash1 = hash0;
|
hash1 = hash0;
|
||||||
hash0 = hash;
|
hash0 = hash;
|
||||||
|
|
|
@ -62,13 +62,9 @@ ProjectPointOnPlane (vec3_t dst, const vec3_t p, const vec3_t normal)
|
||||||
|
|
||||||
d = DotProduct (normal, p) * inv_denom;
|
d = DotProduct (normal, p) * inv_denom;
|
||||||
|
|
||||||
n[0] = normal[0] * inv_denom;
|
VectorScale (normal, inv_denom * d, n);
|
||||||
n[1] = normal[1] * inv_denom;
|
|
||||||
n[2] = normal[2] * inv_denom;
|
|
||||||
|
|
||||||
dst[0] = p[0] - d * n[0];
|
VectorSubtract (p, n, dst);
|
||||||
dst[1] = p[1] - d * n[1];
|
|
||||||
dst[2] = p[2] - d * n[2];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// assumes "src" is normalized
|
// assumes "src" is normalized
|
||||||
|
@ -86,7 +82,7 @@ PerpendicularVector (vec3_t dst, const vec3_t src)
|
||||||
minelem = fabs (src[i]);
|
minelem = fabs (src[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tempvec[0] = tempvec[1] = tempvec[2] = 0.0F;
|
VectorZero (tempvec);
|
||||||
tempvec[pos] = 1.0F;
|
tempvec[pos] = 1.0F;
|
||||||
|
|
||||||
/* project the point onto the plane defined by src */
|
/* project the point onto the plane defined by src */
|
||||||
|
@ -109,10 +105,8 @@ VectorVectors(const vec3_t forward, vec3_t right, vec3_t up)
|
||||||
right[1] = -forward[0];
|
right[1] = -forward[0];
|
||||||
right[2] = forward[1];
|
right[2] = forward[1];
|
||||||
|
|
||||||
d = DotProduct(forward, right);
|
d = -DotProduct(forward, right);
|
||||||
right[0] -= d * forward[0];
|
VectorMA (right, d, forward, right);
|
||||||
right[1] -= d * forward[1];
|
|
||||||
right[2] -= d * forward[2];
|
|
||||||
VectorNormalize (right);
|
VectorNormalize (right);
|
||||||
CrossProduct(right, forward, up);
|
CrossProduct(right, forward, up);
|
||||||
}
|
}
|
||||||
|
@ -129,9 +123,7 @@ RotatePointAroundVector (vec3_t dst, const vec3_t dir, const vec3_t point,
|
||||||
int i;
|
int i;
|
||||||
vec3_t vr, vup, vf;
|
vec3_t vr, vup, vf;
|
||||||
|
|
||||||
vf[0] = dir[0];
|
VectorCopy (dir, vf);
|
||||||
vf[1] = dir[1];
|
|
||||||
vf[2] = dir[2];
|
|
||||||
|
|
||||||
PerpendicularVector (vr, dir);
|
PerpendicularVector (vr, dir);
|
||||||
CrossProduct (vr, vf, vup);
|
CrossProduct (vr, vf, vup);
|
||||||
|
@ -169,8 +161,7 @@ RotatePointAroundVector (vec3_t dst, const vec3_t dir, const vec3_t point,
|
||||||
R_ConcatRotations (tmpmat, im, rot);
|
R_ConcatRotations (tmpmat, im, rot);
|
||||||
|
|
||||||
for (i = 0; i < 3; i++) {
|
for (i = 0; i < 3; i++) {
|
||||||
dst[i] = rot[i][0] * point[0] + rot[i][1] * point[1] + rot[i][2] *
|
dst[i] = DotProduct (rot[i], point);
|
||||||
point[2];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,12 +172,6 @@ RotatePointAroundVector (vec3_t dst, const vec3_t dir, const vec3_t point,
|
||||||
float
|
float
|
||||||
anglemod (float a)
|
anglemod (float a)
|
||||||
{
|
{
|
||||||
#if 0
|
|
||||||
if (a >= 0)
|
|
||||||
a -= 360 * (int) (a / 360);
|
|
||||||
else
|
|
||||||
a += 360 * (1 + (int) (-a / 360));
|
|
||||||
#endif
|
|
||||||
a = (360.0 / 65536) * ((int) (a * (65536 / 360.0)) & 65535);
|
a = (360.0 / 65536) * ((int) (a * (65536 / 360.0)) & 65535);
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
@ -196,7 +181,7 @@ anglemod (float a)
|
||||||
|
|
||||||
Split out like this for ASM to call.
|
Split out like this for ASM to call.
|
||||||
*/
|
*/
|
||||||
void
|
void __attribute__ ((noreturn))
|
||||||
BOPS_Error (void)
|
BOPS_Error (void)
|
||||||
{
|
{
|
||||||
Sys_Error ("BoxOnPlaneSide: Bad signbits");
|
Sys_Error ("BoxOnPlaneSide: Bad signbits");
|
||||||
|
@ -280,9 +265,7 @@ BoxOnPlaneSide (const vec3_t emins, const vec3_t emaxs, mplane_t *p)
|
||||||
p->normal[2] * emaxs[2];
|
p->normal[2] * emaxs[2];
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dist1 = dist2 = 0; // shut up compiler
|
|
||||||
BOPS_Error ();
|
BOPS_Error ();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -582,7 +565,6 @@ GreatestCommonDivisor (int i1, int i2)
|
||||||
Invert24To16
|
Invert24To16
|
||||||
|
|
||||||
Inverts an 8.24 value to a 16.16 value
|
Inverts an 8.24 value to a 16.16 value
|
||||||
TODO: move to nonintel.c
|
|
||||||
*/
|
*/
|
||||||
fixed16_t
|
fixed16_t
|
||||||
Invert24To16 (fixed16_t val)
|
Invert24To16 (fixed16_t val)
|
||||||
|
|
|
@ -798,14 +798,6 @@ COM_AddDirectory (const char *dir)
|
||||||
COM_LoadGameDirectory (dir);
|
COM_LoadGameDirectory (dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
COM_AddGameDirectory
|
|
||||||
|
|
||||||
FIXME: this is a wrapper for COM_AddDirectory (which used to be
|
|
||||||
this function) to have it load share and base paths. Whenver
|
|
||||||
someone goes through to clean up the fs code, this function should
|
|
||||||
merge with COM_AddGameDirectory.
|
|
||||||
*/
|
|
||||||
void
|
void
|
||||||
COM_AddGameDirectory (const char *dir)
|
COM_AddGameDirectory (const char *dir)
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,6 +35,7 @@ static const char rcsid[] =
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "QF/qtypes.h"
|
#include "QF/qtypes.h"
|
||||||
|
#include "QF/sys.h"
|
||||||
#include "QF/va.h"
|
#include "QF/va.h"
|
||||||
|
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
|
@ -45,17 +46,31 @@ static const char rcsid[] =
|
||||||
|
|
||||||
does a varargs printf into a temp buffer, so I don't need to have
|
does a varargs printf into a temp buffer, so I don't need to have
|
||||||
varargs versions of all text functions.
|
varargs versions of all text functions.
|
||||||
FIXME: make this buffer size safe someday
|
|
||||||
*/
|
*/
|
||||||
char *
|
char *
|
||||||
va (const char *format, ...)
|
va (const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list argptr;
|
va_list args;
|
||||||
static char string[1024];
|
static char *string;
|
||||||
|
int size;
|
||||||
|
static int string_size;
|
||||||
|
|
||||||
va_start (argptr, format);
|
va_start (args, fmt);
|
||||||
vsnprintf (string, sizeof (string), format, argptr);
|
size = vsnprintf (string, string_size, fmt, args) + 1; // +1 for nul
|
||||||
va_end (argptr);
|
//printf ("size = %d\n", size);
|
||||||
|
while (size <= 0 || size > string_size) {
|
||||||
|
if (size > 0)
|
||||||
|
string_size = (size + 1023) & ~1023; // 1k multiples
|
||||||
|
else
|
||||||
|
string_size += 1024;
|
||||||
|
string = realloc (string, string_size);
|
||||||
|
if (!string)
|
||||||
|
Sys_Error ("console: could not allocate %d bytes\n",
|
||||||
|
string_size);
|
||||||
|
size = vsnprintf (string, string_size, fmt, args) + 1;
|
||||||
|
//printf ("size = %d\n", size);
|
||||||
|
}
|
||||||
|
va_end (args);
|
||||||
|
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue