Compare commits
7 Commits
586d1cef9b
...
49b23bd290
Author | SHA1 | Date |
---|---|---|
an | 49b23bd290 | |
an | 7c1801a236 | |
an | c382af789c | |
an | 96b1ebca95 | |
an | c5a4c2424a | |
an | 3b85dd08f9 | |
an | 677eecdd5a |
|
@ -72,7 +72,8 @@ set(srcs
|
|||
source/input.h
|
||||
source/keys.c
|
||||
source/keys.h
|
||||
source/lodepng.h
|
||||
source/lib/lodepng.h
|
||||
source/lib/stb_image_write.h
|
||||
source/mathlib.c
|
||||
source/mathlib.h
|
||||
source/menu.c
|
||||
|
@ -88,10 +89,13 @@ set(srcs
|
|||
source/net_sys.h
|
||||
source/platform.h
|
||||
source/pr_cmds.c
|
||||
source/pr_comp.h
|
||||
source/pr_defs.h
|
||||
source/pr_edict.c
|
||||
source/pr_edict.h
|
||||
source/pr_exec.c
|
||||
source/pr_global.h
|
||||
source/pr_load.c
|
||||
source/pr_ops.h
|
||||
source/pr_string.c
|
||||
source/progs.h
|
||||
source/protocol.h
|
||||
|
@ -114,25 +118,14 @@ set(srcs
|
|||
source/snd_codeci.h
|
||||
source/snd_dma.c
|
||||
source/snd_flac.c
|
||||
source/snd_flac.h
|
||||
source/snd_mem.c
|
||||
source/snd_mikmod.c
|
||||
source/snd_mikmod.h
|
||||
source/snd_mix.c
|
||||
source/snd_mp3.c
|
||||
source/snd_mp3.h
|
||||
source/snd_mpg123.c
|
||||
source/snd_opus.c
|
||||
source/snd_opus.h
|
||||
source/snd_umx.c
|
||||
source/snd_umx.h
|
||||
source/snd_vorbis.c
|
||||
source/snd_vorbis.h
|
||||
source/spritegn.h
|
||||
source/stb_image_write.h
|
||||
source/strl_fn.h
|
||||
source/strlcat.c
|
||||
source/strlcpy.c
|
||||
source/strl_fn.c
|
||||
source/sv_main.c
|
||||
source/sv_move.c
|
||||
source/sv_phys.c
|
||||
|
|
|
@ -29,13 +29,13 @@
|
|||
|
||||
#define MUSIC_DIRNAME "music"
|
||||
|
||||
bool bgmloop;
|
||||
bool bgm_loop;
|
||||
cvar_t bgm_extmusic = {"bgm_extmusic", "1", CVAR_ARCHIVE};
|
||||
|
||||
static bool no_extmusic = false;
|
||||
static float old_volume = -1.0f;
|
||||
|
||||
typedef enum _bgm_player
|
||||
typedef enum
|
||||
{
|
||||
BGM_NONE = -1,
|
||||
BGM_MIDIDRV = 1,
|
||||
|
@ -104,15 +104,15 @@ static void BGM_Loop_f(void)
|
|||
{
|
||||
if(q_strcasecmp(Cmd_Argv(1), "0") == 0 ||
|
||||
q_strcasecmp(Cmd_Argv(1), "off") == 0)
|
||||
bgmloop = false;
|
||||
bgm_loop = false;
|
||||
else if(q_strcasecmp(Cmd_Argv(1), "1") == 0 ||
|
||||
q_strcasecmp(Cmd_Argv(1), "on") == 0)
|
||||
bgmloop = true;
|
||||
bgm_loop = true;
|
||||
else if(q_strcasecmp(Cmd_Argv(1), "toggle") == 0)
|
||||
bgmloop = !bgmloop;
|
||||
bgm_loop = !bgm_loop;
|
||||
}
|
||||
|
||||
if(bgmloop)
|
||||
if(bgm_loop)
|
||||
Con_Printf("Music will be looped\n");
|
||||
else
|
||||
Con_Printf("Music will not be looped\n");
|
||||
|
@ -138,7 +138,7 @@ bool BGM_Init(void)
|
|||
if(COM_CheckParm("-noextmusic") != 0)
|
||||
no_extmusic = true;
|
||||
|
||||
bgmloop = true;
|
||||
bgm_loop = true;
|
||||
|
||||
for(i = 0; wanted_handlers[i].type != CODECTYPE_NONE; i++)
|
||||
{
|
||||
|
@ -278,7 +278,7 @@ void BGM_Play(const char *filename)
|
|||
Con_Printf("Couldn't handle music file %s\n", filename);
|
||||
}
|
||||
|
||||
void BGM_PlayCDtrack(byte track, bool looping)
|
||||
void BGM_PlayCDTrack(byte track, bool looping)
|
||||
{
|
||||
/* instead of searching by the order of music_handlers, do so by
|
||||
* the order of searchpath priority: the file from the searchpath
|
||||
|
@ -309,20 +309,20 @@ void BGM_PlayCDtrack(byte track, bool looping)
|
|||
while(handler)
|
||||
{
|
||||
if(! handler->is_available)
|
||||
goto _next;
|
||||
goto next;
|
||||
if(! CDRIPTYPE(handler->type))
|
||||
goto _next;
|
||||
goto next;
|
||||
q_snprintf(tmp, sizeof(tmp), "%s/track%02" PRIi32 ".%s",
|
||||
MUSIC_DIRNAME, (int32_t)track, handler->ext);
|
||||
if(! COM_FileExists(tmp, &path_id))
|
||||
goto _next;
|
||||
goto next;
|
||||
if(path_id > prev_id)
|
||||
{
|
||||
prev_id = path_id;
|
||||
type = handler->type;
|
||||
ext = handler->ext;
|
||||
}
|
||||
_next:
|
||||
next:
|
||||
handler = handler->next;
|
||||
}
|
||||
if(ext == NULL)
|
||||
|
@ -425,7 +425,7 @@ static void BGM_UpdateStream(void)
|
|||
}
|
||||
else if(res == 0) /* EOF */
|
||||
{
|
||||
if(bgmloop)
|
||||
if(bgm_loop)
|
||||
{
|
||||
if(did_rewind)
|
||||
{
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#ifndef spingle__bgmusic_h
|
||||
#define spingle__bgmusic_h
|
||||
|
||||
extern bool bgmloop;
|
||||
extern bool bgm_loop;
|
||||
extern cvar_t bgm_extmusic;
|
||||
|
||||
bool BGM_Init(void);
|
||||
|
@ -37,6 +37,6 @@ void BGM_Update(void);
|
|||
void BGM_Pause(void);
|
||||
void BGM_Resume(void);
|
||||
|
||||
void BGM_PlayCDtrack(byte track, bool looping);
|
||||
void BGM_PlayCDTrack(byte track, bool looping);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -264,7 +264,7 @@ void IN_JumpUp(void)
|
|||
|
||||
void IN_Impulse(void)
|
||||
{
|
||||
in_impulse = Q_atoi(Cmd_Argv(1));
|
||||
in_impulse = atoi(Cmd_Argv(1));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -404,7 +404,7 @@ void CL_BaseMove(usercmd_t *cmd)
|
|||
|
||||
CL_AdjustAngles();
|
||||
|
||||
Q_memset(cmd, 0, sizeof(*cmd));
|
||||
memset(cmd, 0, sizeof(*cmd));
|
||||
|
||||
if(in_strafe.state & 1)
|
||||
{
|
||||
|
|
|
@ -1056,7 +1056,7 @@ void CL_ParseServerMessage(void)
|
|||
if(i >= MAX_LIGHTSTYLES)
|
||||
Sys_Error("svc_lightstyle > MAX_LIGHTSTYLES");
|
||||
q_strlcpy(cl_lightstyle[i].map, MSG_ReadString(), MAX_STYLESTRING);
|
||||
cl_lightstyle[i].length = Q_strlen(cl_lightstyle[i].map);
|
||||
cl_lightstyle[i].length = strlen(cl_lightstyle[i].map);
|
||||
//johnfitz -- save extra info
|
||||
if(cl_lightstyle[i].length)
|
||||
{
|
||||
|
@ -1173,9 +1173,9 @@ void CL_ParseServerMessage(void)
|
|||
cl.cdtrack = MSG_ReadByte();
|
||||
cl.looptrack = MSG_ReadByte();
|
||||
if((cls.demoplayback || cls.demorecording) && (cls.forcetrack != -1))
|
||||
BGM_PlayCDtrack((byte)cls.forcetrack, true);
|
||||
BGM_PlayCDTrack((byte)cls.forcetrack, true);
|
||||
else
|
||||
BGM_PlayCDtrack((byte)cl.cdtrack, true);
|
||||
BGM_PlayCDTrack((byte)cl.cdtrack, true);
|
||||
break;
|
||||
|
||||
case svc_intermission:
|
||||
|
|
|
@ -38,7 +38,7 @@ typedef struct
|
|||
char name[MAX_SCOREBOARDNAME];
|
||||
float entertime;
|
||||
int32_t frags;
|
||||
int32_t colors; // two 4 bit fields
|
||||
int32_t colors; // 2x4 bit
|
||||
byte translations[VID_GRADES * 256];
|
||||
} scoreboard_t;
|
||||
|
||||
|
|
30
source/cmd.c
30
source/cmd.c
|
@ -74,7 +74,7 @@ Cbuf_Init
|
|||
*/
|
||||
void Cbuf_Init(void)
|
||||
{
|
||||
SZ_Alloc(&cmd_text, 1 << 18); // space for commands and script files. spike -- was 8192, but modern configs can be _HUGE_, at least if they contain lots of comments/docs for things.
|
||||
SZ_Alloc(&cmd_text, 1 << 18); // space for commands and script files. spike -- was 8192, but modern configs can be *HUGE*, at least if they contain lots of comments/docs for things.
|
||||
}
|
||||
|
||||
|
||||
|
@ -87,9 +87,9 @@ Adds command text at the end of the buffer
|
|||
*/
|
||||
void Cbuf_AddText(const char *text)
|
||||
{
|
||||
int32_t l;
|
||||
int32_t l;
|
||||
|
||||
l = Q_strlen(text);
|
||||
l = strlen(text);
|
||||
|
||||
if(cmd_text.cursize + l >= cmd_text.maxsize)
|
||||
{
|
||||
|
@ -97,7 +97,7 @@ void Cbuf_AddText(const char *text)
|
|||
return;
|
||||
}
|
||||
|
||||
SZ_Write(&cmd_text, text, Q_strlen(text));
|
||||
SZ_Write(&cmd_text, text, strlen(text));
|
||||
}
|
||||
|
||||
|
||||
|
@ -120,7 +120,7 @@ void Cbuf_InsertText(const char *text)
|
|||
if(templen)
|
||||
{
|
||||
temp = (char *) Z_Malloc(templen);
|
||||
Q_memcpy(temp, cmd_text.data, templen);
|
||||
memcpy(temp, cmd_text.data, templen);
|
||||
SZ_Clear(&cmd_text);
|
||||
}
|
||||
else
|
||||
|
@ -468,12 +468,12 @@ void Cmd_List_f(void)
|
|||
{
|
||||
cmd_function_t *cmd;
|
||||
const char *partial;
|
||||
int32_t len, count;
|
||||
size_t len, count;
|
||||
|
||||
if(Cmd_Argc() > 1)
|
||||
{
|
||||
partial = Cmd_Argv(1);
|
||||
len = Q_strlen(partial);
|
||||
len = strlen(partial);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -484,7 +484,7 @@ void Cmd_List_f(void)
|
|||
count = 0;
|
||||
for(cmd = cmd_functions ; cmd ; cmd = cmd->next)
|
||||
{
|
||||
if(partial && Q_strncmp(partial, cmd->name, len))
|
||||
if(partial && strncmp(partial, cmd->name, len))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -492,7 +492,7 @@ void Cmd_List_f(void)
|
|||
count++;
|
||||
}
|
||||
|
||||
Con_SafePrintf("%" PRIi32 " commands", count);
|
||||
Con_SafePrintf("%zu commands", count);
|
||||
if(partial)
|
||||
{
|
||||
Con_SafePrintf(" beginning with \"%s\"", partial);
|
||||
|
@ -502,7 +502,7 @@ void Cmd_List_f(void)
|
|||
|
||||
static char *Cmd_TintSubstring(const char *in, const char *substr, char *out, size_t outsize)
|
||||
{
|
||||
int32_t l;
|
||||
size_t l;
|
||||
char *m;
|
||||
q_strlcpy(out, in, outsize);
|
||||
while((m = q_strcasestr(out, substr)))
|
||||
|
@ -686,7 +686,7 @@ void Cmd_AddCommand(const char *cmd_name, xcommand_t function)
|
|||
// fail if the command already exists
|
||||
for(cmd = cmd_functions ; cmd ; cmd = cmd->next)
|
||||
{
|
||||
if(!Q_strcmp(cmd_name, cmd->name))
|
||||
if(!strcmp(cmd_name, cmd->name))
|
||||
{
|
||||
Con_Printf("Cmd_AddCommand: %s already defined\n", cmd_name);
|
||||
return;
|
||||
|
@ -729,7 +729,7 @@ bool Cmd_Exists(const char *cmd_name)
|
|||
|
||||
for(cmd = cmd_functions ; cmd ; cmd = cmd->next)
|
||||
{
|
||||
if(!Q_strcmp(cmd_name, cmd->name))
|
||||
if(!strcmp(cmd_name, cmd->name))
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -746,16 +746,16 @@ Cmd_CompleteCommand
|
|||
const char *Cmd_CompleteCommand(const char *partial)
|
||||
{
|
||||
cmd_function_t *cmd;
|
||||
int32_t len;
|
||||
size_t len;
|
||||
|
||||
len = Q_strlen(partial);
|
||||
len = strlen(partial);
|
||||
|
||||
if(!len)
|
||||
return NULL;
|
||||
|
||||
// check functions
|
||||
for(cmd = cmd_functions ; cmd ; cmd = cmd->next)
|
||||
if(!Q_strncmp(partial, cmd->name, len))
|
||||
if(!strncmp(partial, cmd->name, len))
|
||||
return cmd->name;
|
||||
|
||||
return NULL;
|
||||
|
|
280
source/common.c
280
source/common.c
|
@ -252,262 +252,6 @@ int32_t q_snprintf(char *str, size_t size, const char *format, ...)
|
|||
return ret;
|
||||
}
|
||||
|
||||
void Q_memset(void *dest, int32_t fill, size_t count)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if((((size_t)dest | count) & 3) == 0)
|
||||
{
|
||||
count >>= 2;
|
||||
fill = fill | (fill << 8) | (fill << 16) | (fill << 24);
|
||||
for(i = 0; i < count; i++)
|
||||
((int32_t *)dest)[i] = fill;
|
||||
}
|
||||
else
|
||||
for(i = 0; i < count; i++)
|
||||
((byte *)dest)[i] = fill;
|
||||
}
|
||||
|
||||
void Q_memcpy(void *dest, const void *src, size_t count)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if((((size_t)dest | (size_t)src | count) & 3) == 0)
|
||||
{
|
||||
count >>= 2;
|
||||
for(i = 0; i < count; i++)
|
||||
((int32_t *)dest)[i] = ((int32_t *)src)[i];
|
||||
}
|
||||
else
|
||||
for(i = 0; i < count; i++)
|
||||
((byte *)dest)[i] = ((byte *)src)[i];
|
||||
}
|
||||
|
||||
int32_t Q_memcmp(const void *m1, const void *m2, size_t count)
|
||||
{
|
||||
while(count)
|
||||
{
|
||||
count--;
|
||||
if(((byte *)m1)[count] != ((byte *)m2)[count])
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Q_strcpy(char *dest, const char *src)
|
||||
{
|
||||
while(*src)
|
||||
{
|
||||
*dest++ = *src++;
|
||||
}
|
||||
*dest++ = 0;
|
||||
}
|
||||
|
||||
void Q_strncpy(char *dest, const char *src, int32_t count)
|
||||
{
|
||||
while(*src && count--)
|
||||
{
|
||||
*dest++ = *src++;
|
||||
}
|
||||
if(count)
|
||||
*dest++ = 0;
|
||||
}
|
||||
|
||||
int32_t Q_strlen(const char *str)
|
||||
{
|
||||
int32_t count;
|
||||
|
||||
count = 0;
|
||||
while(str[count])
|
||||
count++;
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
char *Q_strrchr(const char *s, char c)
|
||||
{
|
||||
int32_t len = Q_strlen(s);
|
||||
s += len;
|
||||
while(len--)
|
||||
{
|
||||
if(*--s == c)
|
||||
return (char *)s;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void Q_strcat(char *dest, const char *src)
|
||||
{
|
||||
dest += Q_strlen(dest);
|
||||
Q_strcpy(dest, src);
|
||||
}
|
||||
|
||||
int32_t Q_strcmp(const char *s1, const char *s2)
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
if(*s1 != *s2)
|
||||
return -1; // strings not equal
|
||||
if(!*s1)
|
||||
return 0; // strings are equal
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t Q_strncmp(const char *s1, const char *s2, int32_t count)
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
if(!count--)
|
||||
return 0;
|
||||
if(*s1 != *s2)
|
||||
return -1; // strings not equal
|
||||
if(!*s1)
|
||||
return 0; // strings are equal
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t Q_atoi(const char *str)
|
||||
{
|
||||
int32_t val;
|
||||
int32_t sign;
|
||||
int32_t c;
|
||||
|
||||
if(*str == '-')
|
||||
{
|
||||
sign = -1;
|
||||
str++;
|
||||
}
|
||||
else
|
||||
sign = 1;
|
||||
|
||||
val = 0;
|
||||
|
||||
//
|
||||
// check for hex
|
||||
//
|
||||
if(str[0] == '0' && (str[1] == 'x' || str[1] == 'X'))
|
||||
{
|
||||
str += 2;
|
||||
while(1)
|
||||
{
|
||||
c = *str++;
|
||||
if(c >= '0' && c <= '9')
|
||||
val = (val << 4) + c - '0';
|
||||
else if(c >= 'a' && c <= 'f')
|
||||
val = (val << 4) + c - 'a' + 10;
|
||||
else if(c >= 'A' && c <= 'F')
|
||||
val = (val << 4) + c - 'A' + 10;
|
||||
else
|
||||
return val * sign;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// check for character
|
||||
//
|
||||
if(str[0] == '\'')
|
||||
{
|
||||
return sign * str[1];
|
||||
}
|
||||
|
||||
//
|
||||
// assume decimal
|
||||
//
|
||||
while(1)
|
||||
{
|
||||
c = *str++;
|
||||
if(c < '0' || c > '9')
|
||||
return val * sign;
|
||||
val = val * 10 + c - '0';
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
float Q_atof(const char *str)
|
||||
{
|
||||
double val;
|
||||
int32_t sign;
|
||||
int32_t c;
|
||||
int32_t decimal, total;
|
||||
|
||||
if(*str == '-')
|
||||
{
|
||||
sign = -1;
|
||||
str++;
|
||||
}
|
||||
else
|
||||
sign = 1;
|
||||
|
||||
val = 0;
|
||||
|
||||
//
|
||||
// check for hex
|
||||
//
|
||||
if(str[0] == '0' && (str[1] == 'x' || str[1] == 'X'))
|
||||
{
|
||||
str += 2;
|
||||
while(1)
|
||||
{
|
||||
c = *str++;
|
||||
if(c >= '0' && c <= '9')
|
||||
val = (val * 16) + c - '0';
|
||||
else if(c >= 'a' && c <= 'f')
|
||||
val = (val * 16) + c - 'a' + 10;
|
||||
else if(c >= 'A' && c <= 'F')
|
||||
val = (val * 16) + c - 'A' + 10;
|
||||
else
|
||||
return val * sign;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// check for character
|
||||
//
|
||||
if(str[0] == '\'')
|
||||
{
|
||||
return sign * str[1];
|
||||
}
|
||||
|
||||
//
|
||||
// assume decimal
|
||||
//
|
||||
decimal = -1;
|
||||
total = 0;
|
||||
while(1)
|
||||
{
|
||||
c = *str++;
|
||||
if(c == '.')
|
||||
{
|
||||
decimal = total;
|
||||
continue;
|
||||
}
|
||||
if(c < '0' || c > '9')
|
||||
break;
|
||||
val = val * 10 + c - '0';
|
||||
total++;
|
||||
}
|
||||
|
||||
if(decimal == -1)
|
||||
return val * sign;
|
||||
while(total > decimal)
|
||||
{
|
||||
val /= 10;
|
||||
total--;
|
||||
}
|
||||
|
||||
return val * sign;
|
||||
}
|
||||
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
|
@ -591,7 +335,7 @@ void MSG_WriteString(sizebuf_t *sb, const char *s)
|
|||
if(!s)
|
||||
SZ_Write(sb, "", 1);
|
||||
else
|
||||
SZ_Write(sb, s, Q_strlen(s) + 1);
|
||||
SZ_Write(sb, s, strlen(s) + 1);
|
||||
}
|
||||
|
||||
//johnfitz -- original behavior, 13.3 fixed point coords, max range +-4096
|
||||
|
@ -858,22 +602,22 @@ void *SZ_GetSpace(sizebuf_t *buf, int32_t length)
|
|||
|
||||
void SZ_Write(sizebuf_t *buf, const void *data, int32_t length)
|
||||
{
|
||||
Q_memcpy(SZ_GetSpace(buf, length), data, length);
|
||||
memcpy(SZ_GetSpace(buf, length), data, length);
|
||||
}
|
||||
|
||||
void SZ_Print(sizebuf_t *buf, const char *data)
|
||||
{
|
||||
int32_t len = Q_strlen(data) + 1;
|
||||
int32_t len = strlen(data) + 1;
|
||||
|
||||
if(buf->data[buf->cursize - 1])
|
||||
{
|
||||
/* no trailing 0 */
|
||||
Q_memcpy((byte *)SZ_GetSpace(buf, len), data, len);
|
||||
memcpy((byte *)SZ_GetSpace(buf, len), data, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* write over trailing 0 */
|
||||
Q_memcpy((byte *)SZ_GetSpace(buf, len - 1) - 1, data, len);
|
||||
memcpy((byte *)SZ_GetSpace(buf, len - 1) - 1, data, len);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1121,7 +865,7 @@ int32_t COM_CheckParm(const char *parm)
|
|||
{
|
||||
if(!com_argv[i])
|
||||
continue; // NEXTSTEP sometimes clears appkit vars.
|
||||
if(!Q_strcmp(parm, com_argv[i]))
|
||||
if(!strcmp(parm, com_argv[i]))
|
||||
return i;
|
||||
}
|
||||
|
||||
|
@ -1163,7 +907,7 @@ void COM_InitArgv(int32_t argc, char **argv)
|
|||
for(com_argc = 0; (com_argc < MAX_NUM_ARGVS) && (com_argc < argc); com_argc++)
|
||||
{
|
||||
largv[com_argc] = argv[com_argc];
|
||||
if(!Q_strcmp("-safe", argv[com_argc]))
|
||||
if(!strcmp("-safe", argv[com_argc]))
|
||||
safemode = 1;
|
||||
}
|
||||
|
||||
|
@ -1767,7 +1511,7 @@ static void COM_AddGameDirectory(const char *base, const char *dir)
|
|||
path_id = com_searchpaths->path_id << 1;
|
||||
else path_id = 1U;
|
||||
|
||||
_add_path:
|
||||
addpath:
|
||||
// add the directory to the search path
|
||||
search = (searchpath_t *) Z_Malloc(sizeof(searchpath_t));
|
||||
search->path_id = path_id;
|
||||
|
@ -1796,7 +1540,7 @@ _add_path:
|
|||
been_here = true;
|
||||
q_strlcpy(com_gamedir, va("%s/%s", host_parms->userdir, dir), sizeof(com_gamedir));
|
||||
Sys_mkdir(com_gamedir);
|
||||
goto _add_path;
|
||||
goto addpath;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1841,16 +1585,16 @@ static void COM_Game_f(void)
|
|||
// rely on QuakeSpasm extension treating '-game missionpack'
|
||||
// as '-missionpack', otherwise would be a mess
|
||||
if(!q_strcasecmp(p, &p2[1]))
|
||||
goto _same;
|
||||
goto same;
|
||||
Con_Printf("reloading game \"%s\" with \"%s\" support\n", p, &p2[1]);
|
||||
}
|
||||
else if(!*p2 && com_searchpaths->path_id > 2)
|
||||
Con_Printf("reloading game \"%s\" without mission pack support\n", p);
|
||||
else goto _same;
|
||||
else goto same;
|
||||
}
|
||||
else
|
||||
{
|
||||
_same:
|
||||
same:
|
||||
Con_Printf("\"game\" is already \"%s\"\n", COM_SkipPath(com_gamedir));
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -165,36 +165,24 @@ float MSG_ReadAngle16(uint32_t flags); //johnfitz
|
|||
|
||||
//============================================================================
|
||||
|
||||
void Q_memset(void *dest, int32_t fill, size_t count);
|
||||
void Q_memcpy(void *dest, const void *src, size_t count);
|
||||
int32_t Q_memcmp(const void *m1, const void *m2, size_t count);
|
||||
void Q_strcpy(char *dest, const char *src);
|
||||
void Q_strncpy(char *dest, const char *src, int32_t count);
|
||||
int32_t Q_strlen(const char *str);
|
||||
char *Q_strrchr(const char *s, char c);
|
||||
void Q_strcat(char *dest, const char *src);
|
||||
int32_t Q_strcmp(const char *s1, const char *s2);
|
||||
int32_t Q_strncmp(const char *s1, const char *s2, int32_t count);
|
||||
int32_t Q_atoi(const char *str);
|
||||
float Q_atof(const char *str);
|
||||
|
||||
|
||||
#include "strl_fn.h"
|
||||
/* use our own copies of strlcpy and strlcat taken from OpenBSD */
|
||||
size_t q_strlcpy(char *dst, const char *src, size_t size);
|
||||
size_t q_strlcat(char *dst, const char *src, size_t size);
|
||||
|
||||
/* locale-insensitive strcasecmp replacement functions: */
|
||||
extern int32_t q_strcasecmp(const char * s1, const char * s2);
|
||||
extern int32_t q_strncasecmp(const char *s1, const char *s2, size_t n);
|
||||
int32_t q_strcasecmp(const char * s1, const char * s2);
|
||||
int32_t q_strncasecmp(const char *s1, const char *s2, size_t n);
|
||||
|
||||
/* locale-insensitive case-insensitive alternative to strstr */
|
||||
extern char *q_strcasestr(const char *haystack, const char *needle);
|
||||
char *q_strcasestr(const char *haystack, const char *needle);
|
||||
|
||||
/* locale-insensitive strlwr/upr replacement functions: */
|
||||
extern char *q_strlwr(char *str);
|
||||
extern char *q_strupr(char *str);
|
||||
char *q_strlwr(char *str);
|
||||
char *q_strupr(char *str);
|
||||
|
||||
/* snprintf, vsnprintf : always use our versions. */
|
||||
extern int32_t q_snprintf(char *str, size_t size, const char *format, ...) FUNC_PRINTF(3, 4);
|
||||
extern int32_t q_vsnprintf(char *str, size_t size, const char *format, va_list args) FUNC_PRINTF(3, 0);
|
||||
int32_t q_snprintf(char *str, size_t size, const char *format, ...) FUNC_PRINTF(3, 4);
|
||||
int32_t q_vsnprintf(char *str, size_t size, const char *format, va_list args) FUNC_PRINTF(3, 0);
|
||||
|
||||
//============================================================================
|
||||
|
||||
|
@ -318,7 +306,7 @@ const char *COM_ParseStringNewline(const char *buffer);
|
|||
* Allocating and filling in the fshandle_t structure is the users'
|
||||
* responsibility when the file is initially opened. */
|
||||
|
||||
typedef struct _fshandle_t
|
||||
typedef struct
|
||||
{
|
||||
FILE *file;
|
||||
bool pak; /* is the file read from a pak */
|
||||
|
|
|
@ -140,7 +140,7 @@ Con_Clear_f
|
|||
static void Con_Clear_f(void)
|
||||
{
|
||||
if(con_text)
|
||||
Q_memset(con_text, ' ', con_buffersize); //johnfitz -- con_buffersize replaces CON_TEXTSIZE
|
||||
memset(con_text, ' ', con_buffersize); //johnfitz -- con_buffersize replaces CON_TEXTSIZE
|
||||
con_backscroll = 0; //johnfitz -- if console is empty, being scrolled up is confusing
|
||||
}
|
||||
|
||||
|
@ -276,8 +276,8 @@ void Con_CheckResize(void)
|
|||
mark = Hunk_LowMark(); //johnfitz
|
||||
tbuf = Hunk_AllocName(con_buffersize, __func__); //johnfitz
|
||||
|
||||
Q_memcpy(tbuf, con_text, con_buffersize); //johnfitz -- con_buffersize replaces CON_TEXTSIZE
|
||||
Q_memset(con_text, ' ', con_buffersize); //johnfitz -- con_buffersize replaces CON_TEXTSIZE
|
||||
memcpy(tbuf, con_text, con_buffersize); //johnfitz -- con_buffersize replaces CON_TEXTSIZE
|
||||
memset(con_text, ' ', con_buffersize); //johnfitz -- con_buffersize replaces CON_TEXTSIZE
|
||||
|
||||
for(i = 0; i < numlines; i++)
|
||||
{
|
||||
|
@ -309,13 +309,13 @@ void Con_Init(void)
|
|||
//johnfitz -- user settable console buffer size
|
||||
i = COM_CheckParm("-consize");
|
||||
if(i && i < com_argc - 1)
|
||||
con_buffersize = q_max(CON_MINSIZE, Q_atoi(com_argv[i + 1]) * 1024);
|
||||
con_buffersize = q_max(CON_MINSIZE, atoi(com_argv[i + 1]) * 1024);
|
||||
else
|
||||
con_buffersize = CON_TEXTSIZE;
|
||||
//johnfitz
|
||||
|
||||
con_text = (char *)Hunk_AllocName(con_buffersize, "con_text"); //johnfitz -- con_buffersize replaces CON_TEXTSIZE
|
||||
Q_memset(con_text, ' ', con_buffersize); //johnfitz -- con_buffersize replaces CON_TEXTSIZE
|
||||
memset(con_text, ' ', con_buffersize); //johnfitz -- con_buffersize replaces CON_TEXTSIZE
|
||||
con_linewidth = -1;
|
||||
|
||||
//johnfitz -- no need to run Con_CheckResize here
|
||||
|
@ -355,7 +355,7 @@ static void Con_Linefeed(void)
|
|||
|
||||
con_x = 0;
|
||||
con_current++;
|
||||
Q_memset(&con_text[(con_current % con_totallines)*con_linewidth], ' ', con_linewidth);
|
||||
memset(&con_text[(con_current % con_totallines)*con_linewidth], ' ', con_linewidth);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -642,7 +642,7 @@ void Con_CenterPrintf(int32_t linewidth, const char *fmt, ...)
|
|||
char line[MAXPRINTMSG]; //one line from the message
|
||||
char spaces[21]; //buffer for spaces
|
||||
char *src, *dst;
|
||||
int32_t len, s;
|
||||
int32_t len, s;
|
||||
|
||||
va_start(argptr, fmt);
|
||||
q_vsnprintf(msg, sizeof(msg), fmt, argptr);
|
||||
|
@ -836,7 +836,7 @@ const char *FindCompletion(const char *partial, filelist_item_t *filelist, int32
|
|||
static char matched[32];
|
||||
char *i_matched, *i_name;
|
||||
filelist_item_t *file;
|
||||
int32_t init, match, plen;
|
||||
size_t init, match, plen;
|
||||
|
||||
memset(matched, 0, sizeof(matched));
|
||||
plen = strlen(partial);
|
||||
|
@ -890,10 +890,10 @@ BuildTabList -- johnfitz
|
|||
*/
|
||||
void BuildTabList(const char *partial)
|
||||
{
|
||||
cmdalias_t *alias;
|
||||
cvar_t *cvar;
|
||||
cmd_function_t *cmd;
|
||||
int32_t len;
|
||||
cmdalias_t *alias;
|
||||
cvar_t *cvar;
|
||||
cmd_function_t *cmd;
|
||||
size_t len;
|
||||
|
||||
tablist = NULL;
|
||||
len = strlen(partial);
|
||||
|
@ -903,15 +903,15 @@ void BuildTabList(const char *partial)
|
|||
|
||||
cvar = Cvar_FindVarAfter("", CVAR_NONE);
|
||||
for(; cvar ; cvar = cvar->next)
|
||||
if(!Q_strncmp(partial, cvar->name, len))
|
||||
if(!strncmp(partial, cvar->name, len))
|
||||
AddToTabList(cvar->name, "cvar");
|
||||
|
||||
for(cmd = cmd_functions ; cmd ; cmd = cmd->next)
|
||||
if(!Q_strncmp(partial, cmd->name, len))
|
||||
if(!strncmp(partial, cmd->name, len))
|
||||
AddToTabList(cmd->name, "command");
|
||||
|
||||
for(alias = cmd_alias ; alias ; alias = alias->next)
|
||||
if(!Q_strncmp(partial, alias->name, len))
|
||||
if(!strncmp(partial, alias->name, len))
|
||||
AddToTabList(alias->name, "alias");
|
||||
}
|
||||
|
||||
|
@ -963,7 +963,7 @@ void Con_TabComplete(void)
|
|||
q_strlcpy(partial, matched_map, MAXCMDLINE);
|
||||
*c = '\0';
|
||||
q_strlcat(key_lines[edit_line], partial, MAXCMDLINE);
|
||||
key_linepos = c - key_lines[edit_line] + Q_strlen(matched_map); //set new cursor position
|
||||
key_linepos = c - key_lines[edit_line] + strlen(matched_map); //set new cursor position
|
||||
if(key_linepos >= MAXCMDLINE)
|
||||
key_linepos = MAXCMDLINE - 1;
|
||||
// if only one match, append a space
|
||||
|
@ -1027,7 +1027,7 @@ void Con_TabComplete(void)
|
|||
match = keydown[K_SHIFT] ? t->prev->name : t->name;
|
||||
do
|
||||
{
|
||||
if(!Q_strcmp(t->name, partial))
|
||||
if(!strcmp(t->name, partial))
|
||||
{
|
||||
match = keydown[K_SHIFT] ? t->prev->name : t->next->name;
|
||||
break;
|
||||
|
@ -1043,7 +1043,7 @@ void Con_TabComplete(void)
|
|||
q_strlcat(partial, key_lines[edit_line] + key_linepos, MAXCMDLINE); //then add chars after cursor
|
||||
*c = '\0'; //now copy all of this into edit line
|
||||
q_strlcat(key_lines[edit_line], partial, MAXCMDLINE);
|
||||
key_linepos = c - key_lines[edit_line] + Q_strlen(match); //set new cursor position
|
||||
key_linepos = c - key_lines[edit_line] + strlen(match); //set new cursor position
|
||||
if(key_linepos >= MAXCMDLINE)
|
||||
key_linepos = MAXCMDLINE - 1;
|
||||
|
||||
|
|
|
@ -43,12 +43,12 @@ void Cvar_List_f(void)
|
|||
{
|
||||
cvar_t *cvar;
|
||||
const char *partial;
|
||||
int32_t len, count;
|
||||
size_t len, count;
|
||||
|
||||
if(Cmd_Argc() > 1)
|
||||
{
|
||||
partial = Cmd_Argv(1);
|
||||
len = Q_strlen(partial);
|
||||
len = strlen(partial);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -59,7 +59,7 @@ void Cvar_List_f(void)
|
|||
count = 0;
|
||||
for(cvar = cvar_vars ; cvar ; cvar = cvar->next)
|
||||
{
|
||||
if(partial && Q_strncmp(partial, cvar->name, len))
|
||||
if(partial && strncmp(partial, cvar->name, len))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ void Cvar_List_f(void)
|
|||
count++;
|
||||
}
|
||||
|
||||
Con_SafePrintf("%" PRIi32 " cvars", count);
|
||||
Con_SafePrintf("%zu cvars", count);
|
||||
if(partial)
|
||||
{
|
||||
Con_SafePrintf(" beginning with \"%s\"", partial);
|
||||
|
@ -96,7 +96,7 @@ void Cvar_Inc_f(void)
|
|||
Cvar_SetValue(Cmd_Argv(1), Cvar_VariableValue(Cmd_Argv(1)) + 1);
|
||||
break;
|
||||
case 3:
|
||||
Cvar_SetValue(Cmd_Argv(1), Cvar_VariableValue(Cmd_Argv(1)) + Q_atof(Cmd_Argv(2)));
|
||||
Cvar_SetValue(Cmd_Argv(1), Cvar_VariableValue(Cmd_Argv(1)) + atof(Cmd_Argv(2)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -146,14 +146,14 @@ void Cvar_Cycle_f(void)
|
|||
//zero is assumed to be a string, even though it could actually be zero. The worst case
|
||||
//is that the first time you call this command, it won't match on zero when it should, but after that,
|
||||
//it will be comparing strings that all had the same source (the user) so it will work.
|
||||
if(Q_atof(Cmd_Argv(i)) == 0)
|
||||
if(atof(Cmd_Argv(i)) == 0)
|
||||
{
|
||||
if(!strcmp(Cmd_Argv(i), Cvar_VariableString(Cmd_Argv(1))))
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(Q_atof(Cmd_Argv(i)) == Cvar_VariableValue(Cmd_Argv(1)))
|
||||
if(atof(Cmd_Argv(i)) == Cvar_VariableValue(Cmd_Argv(1)))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -251,7 +251,7 @@ cvar_t *Cvar_FindVar(const char *var_name)
|
|||
|
||||
for(var = cvar_vars ; var ; var = var->next)
|
||||
{
|
||||
if(!Q_strcmp(var_name, var->name))
|
||||
if(!strcmp(var_name, var->name))
|
||||
return var;
|
||||
}
|
||||
|
||||
|
@ -323,7 +323,7 @@ float Cvar_VariableValue(const char *var_name)
|
|||
var = Cvar_FindVar(var_name);
|
||||
if(!var)
|
||||
return 0;
|
||||
return Q_atof(var->string);
|
||||
return atof(var->string);
|
||||
}
|
||||
|
||||
|
||||
|
@ -350,17 +350,17 @@ Cvar_CompleteVariable
|
|||
*/
|
||||
const char *Cvar_CompleteVariable(const char *partial)
|
||||
{
|
||||
cvar_t *cvar;
|
||||
int32_t len;
|
||||
cvar_t *cvar;
|
||||
size_t len;
|
||||
|
||||
len = Q_strlen(partial);
|
||||
len = strlen(partial);
|
||||
if(!len)
|
||||
return NULL;
|
||||
|
||||
// check functions
|
||||
for(cvar = cvar_vars ; cvar ; cvar = cvar->next)
|
||||
{
|
||||
if(!Q_strncmp(partial, cvar->name, len))
|
||||
if(!strncmp(partial, cvar->name, len))
|
||||
return cvar->name;
|
||||
}
|
||||
|
||||
|
@ -394,14 +394,14 @@ void Cvar_SetQuick(cvar_t *var, const char *value)
|
|||
var->string = Z_Strdup(value);
|
||||
else
|
||||
{
|
||||
int32_t len;
|
||||
size_t len;
|
||||
|
||||
if(!strcmp(var->string, value))
|
||||
return; // no change
|
||||
|
||||
var->flags |= CVAR_CHANGED;
|
||||
len = Q_strlen(value);
|
||||
if(len != Q_strlen(var->string))
|
||||
len = strlen(value);
|
||||
if(len != strlen(var->string))
|
||||
{
|
||||
Z_Free(var->string);
|
||||
var->string = (char *) Z_Malloc(len + 1);
|
||||
|
@ -409,7 +409,7 @@ void Cvar_SetQuick(cvar_t *var, const char *value)
|
|||
memcpy((char *)var->string, value, len + 1);
|
||||
}
|
||||
|
||||
var->value = Q_atof(var->string);
|
||||
var->value = atof(var->string);
|
||||
|
||||
//johnfitz -- save initial value for "reset" command
|
||||
if(!var->default_string)
|
||||
|
|
|
@ -28,7 +28,7 @@ cvar_t variables are used to hold scalar or string variables that can
|
|||
be changed or displayed at the console or prog code as well as accessed
|
||||
directly in C code.
|
||||
|
||||
it is sufficient to initialize a cvar_t with just the first two fields,
|
||||
it is sufficient to initialize a cvar_t with just the first two members,
|
||||
or you can add a ,true flag for variables that you want saved to the
|
||||
configuration file when the game is quit:
|
||||
|
||||
|
|
|
@ -498,7 +498,7 @@ void Mod_LoadTextures(lump_t *l)
|
|||
//johnfitz -- lots of changes
|
||||
if(!isDedicated) //no texture uploading for dedicated server
|
||||
{
|
||||
if(!q_strncasecmp(tx->name, "sky", 3)) //sky texture //also note -- was Q_strncmp, changed to match qbsp
|
||||
if(!q_strncasecmp(tx->name, "sky", 3)) //sky texture //also note -- was strncmp, changed to match qbsp
|
||||
Sky_LoadTexture(tx);
|
||||
else if(tx->name[0] == '*') //warping texture
|
||||
{
|
||||
|
@ -797,7 +797,7 @@ void Mod_LoadEntities(lump_t *l)
|
|||
uint32_t path_id;
|
||||
|
||||
if(! external_ents.value)
|
||||
goto _load_embedded;
|
||||
goto loadembedded;
|
||||
|
||||
q_strlcpy(entfilename, loadmodel->name, sizeof(entfilename));
|
||||
COM_StripExtension(entfilename, entfilename, sizeof(entfilename));
|
||||
|
@ -822,7 +822,7 @@ void Mod_LoadEntities(lump_t *l)
|
|||
}
|
||||
}
|
||||
|
||||
_load_embedded:
|
||||
loadembedded:
|
||||
if(!l->filelen)
|
||||
{
|
||||
loadmodel->entities = NULL;
|
||||
|
@ -1218,7 +1218,7 @@ void Mod_LoadFaces(lump_t *l, bool bsp2)
|
|||
out->samples = loadmodel->lightdata + (lofs * 3); //johnfitz -- lit support via lordhavoc (was "+ i")
|
||||
|
||||
//johnfitz -- this section rewritten
|
||||
if(!q_strncasecmp(out->texinfo->texture->name, "sky", 3)) // sky surface //also note -- was Q_strncmp, changed to match qbsp
|
||||
if(!q_strncasecmp(out->texinfo->texture->name, "sky", 3)) // sky surface //also note -- was strncmp, changed to match qbsp
|
||||
{
|
||||
out->flags |= (SURF_DRAWSKY | SURF_DRAWTILED);
|
||||
Mod_PolyForUnlitSurface(out); //no more subdivision
|
||||
|
|
|
@ -53,7 +53,6 @@ BRUSH MODELS
|
|||
//
|
||||
// in memory representation
|
||||
//
|
||||
// !!! if this is changed, it must be changed in asm_draw.h too !!!
|
||||
typedef struct
|
||||
{
|
||||
vec3_t position;
|
||||
|
@ -65,7 +64,6 @@ typedef struct
|
|||
|
||||
|
||||
// plane_t structure
|
||||
// !!! if this is changed, it must be changed in asm_i386.h too !!!
|
||||
typedef struct mplane_s
|
||||
{
|
||||
vec3_t normal;
|
||||
|
@ -114,7 +112,6 @@ typedef struct texture_s
|
|||
#define SURF_DRAWTELE 0x1000
|
||||
#define SURF_DRAWWATER 0x2000
|
||||
|
||||
// !!! if this is changed, it must be changed in asm_draw.h too !!!
|
||||
typedef struct
|
||||
{
|
||||
uint32_t v[2];
|
||||
|
@ -224,7 +221,6 @@ typedef struct mclipnode_s
|
|||
} mclipnode_t;
|
||||
//johnfitz
|
||||
|
||||
// !!! if this is changed, it must be changed in asm_i386.h too !!!
|
||||
typedef struct
|
||||
{
|
||||
mclipnode_t *clipnodes; //johnfitz -- was dclipnode_t
|
||||
|
@ -332,7 +328,6 @@ typedef struct
|
|||
maliasgroupframedesc_t frames[1];
|
||||
} maliasgroup_t;
|
||||
|
||||
// !!! if this is changed, it must be changed in asm_draw.h too !!!
|
||||
typedef struct mtriangle_s
|
||||
{
|
||||
int32_t facesfront;
|
||||
|
|
|
@ -34,7 +34,7 @@ mnode_t *r_pefragtopnode;
|
|||
ENTITY FRAGMENT FUNCTIONS
|
||||
|
||||
ericw -- GLQuake only uses efrags for static entities, and they're never
|
||||
removed, so I trimmed out unused functionality and fields in efrag_t.
|
||||
removed, so I trimmed out unused functionality and stuff in efrag_t.
|
||||
|
||||
Now, efrags are just a linked list for each leaf of the static
|
||||
entities that touch that leaf. The efrags are hunk-allocated so there is no
|
||||
|
|
|
@ -782,7 +782,7 @@ void SCR_ScreenShot_f(void)
|
|||
int32_t i, quality;
|
||||
bool ok;
|
||||
|
||||
Q_strncpy(ext, "png", sizeof(ext));
|
||||
strncpy(ext, "png", sizeof(ext));
|
||||
|
||||
if(Cmd_Argc() >= 2)
|
||||
{
|
||||
|
@ -791,7 +791,7 @@ void SCR_ScreenShot_f(void)
|
|||
if(!q_strcasecmp("png", requested_ext)
|
||||
|| !q_strcasecmp("tga", requested_ext)
|
||||
|| !q_strcasecmp("jpg", requested_ext))
|
||||
Q_strncpy(ext, requested_ext, sizeof(ext));
|
||||
strncpy(ext, requested_ext, sizeof(ext));
|
||||
else
|
||||
{
|
||||
SCR_ScreenShot_Usage();
|
||||
|
@ -802,7 +802,7 @@ void SCR_ScreenShot_f(void)
|
|||
// read quality as the 3rd param (only used for JPG)
|
||||
quality = 90;
|
||||
if(Cmd_Argc() >= 3)
|
||||
quality = Q_atoi(Cmd_Argv(2));
|
||||
quality = atoi(Cmd_Argv(2));
|
||||
if(quality < 1 || quality > 100)
|
||||
{
|
||||
SCR_ScreenShot_Usage();
|
||||
|
|
|
@ -134,7 +134,7 @@ static void TexMgr_TextureMode_f(cvar_t *var)
|
|||
|
||||
for(i = 0; i < NUM_GLMODES; i++)
|
||||
{
|
||||
if(!Q_strcmp(glmodes[i].name, gl_texturemode.string))
|
||||
if(!strcmp(glmodes[i].name, gl_texturemode.string))
|
||||
{
|
||||
if(glmode_idx != i)
|
||||
{
|
||||
|
|
|
@ -60,10 +60,10 @@ typedef enum
|
|||
// !!! if this is changed, it must be changed in d_ifacea.h too !!!
|
||||
typedef struct particle_s
|
||||
{
|
||||
// driver-usable fields
|
||||
// driver-usable
|
||||
vec3_t org;
|
||||
float color;
|
||||
// drivers never touch the following fields
|
||||
// drivers never touch the following
|
||||
struct particle_s *next;
|
||||
vec3_t vel;
|
||||
float ramp;
|
||||
|
|
|
@ -191,7 +191,7 @@ void Host_FindMaxClients(void)
|
|||
cls.state = ca_dedicated;
|
||||
if(i != (com_argc - 1))
|
||||
{
|
||||
svs.maxclients = Q_atoi(com_argv[i + 1]);
|
||||
svs.maxclients = atoi(com_argv[i + 1]);
|
||||
}
|
||||
else
|
||||
svs.maxclients = 8;
|
||||
|
@ -205,7 +205,7 @@ void Host_FindMaxClients(void)
|
|||
if(cls.state == ca_dedicated)
|
||||
Sys_Error("Only one of -dedicated or -listen can be specified");
|
||||
if(i != (com_argc - 1))
|
||||
svs.maxclients = Q_atoi(com_argv[i + 1]);
|
||||
svs.maxclients = atoi(com_argv[i + 1]);
|
||||
else
|
||||
svs.maxclients = 8;
|
||||
}
|
||||
|
@ -420,10 +420,10 @@ void SV_DropClient(bool crash)
|
|||
{
|
||||
// call the prog function for removing a client
|
||||
// this will set the body to a dead frame, among other things
|
||||
saveSelf = G_INT(GBL_self);
|
||||
G_INT(GBL_self) = EDICT_TO_PROG(host_client->edict);
|
||||
saveSelf = G_PEDICT(GBL_self);
|
||||
G_PEDICT(GBL_self) = EDICT_TO_PROG(host_client->edict);
|
||||
PR_ExecuteProgram(G_FUNC(GBL_ClientDisconnect));
|
||||
G_INT(GBL_self) = saveSelf;
|
||||
G_PEDICT(GBL_self) = saveSelf;
|
||||
}
|
||||
|
||||
Sys_Printf("Client %s removed\n", host_client->name);
|
||||
|
@ -666,7 +666,7 @@ Host_Frame
|
|||
Runs all active servers
|
||||
==================
|
||||
*/
|
||||
void _Host_Frame(float time)
|
||||
static void Host_FrameT(float time)
|
||||
{
|
||||
static double time1 = 0;
|
||||
static double time2 = 0;
|
||||
|
@ -771,12 +771,12 @@ void Host_Frame(float time)
|
|||
|
||||
if(!serverprofile.value)
|
||||
{
|
||||
_Host_Frame(time);
|
||||
Host_FrameT(time);
|
||||
return;
|
||||
}
|
||||
|
||||
time1 = Sys_DoubleTime();
|
||||
_Host_Frame(time);
|
||||
Host_FrameT(time);
|
||||
time2 = Sys_DoubleTime();
|
||||
|
||||
timetotal += time2 - time1;
|
||||
|
|
|
@ -67,7 +67,7 @@ void FileList_Add(const char *name, filelist_item_t **list)
|
|||
// ignore duplicate
|
||||
for(item = *list; item; item = item->next)
|
||||
{
|
||||
if(!Q_strcmp(name, item->name))
|
||||
if(!strcmp(name, item->name))
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -504,7 +504,7 @@ void Host_God_f(void)
|
|||
SV_ClientPrintf("godmode ON\n");
|
||||
break;
|
||||
case 2:
|
||||
if(Q_atof(Cmd_Argv(1)))
|
||||
if(atof(Cmd_Argv(1)))
|
||||
{
|
||||
ED_FLOAT(sv_player, ED_flags) = (int32_t)ED_FLOAT(sv_player, ED_flags) | FL_GODMODE;
|
||||
SV_ClientPrintf("godmode ON\n");
|
||||
|
@ -549,7 +549,7 @@ void Host_Notarget_f(void)
|
|||
SV_ClientPrintf("notarget ON\n");
|
||||
break;
|
||||
case 2:
|
||||
if(Q_atof(Cmd_Argv(1)))
|
||||
if(atof(Cmd_Argv(1)))
|
||||
{
|
||||
ED_FLOAT(sv_player, ED_flags) = (int32_t)ED_FLOAT(sv_player, ED_flags) | FL_NOTARGET;
|
||||
SV_ClientPrintf("notarget ON\n");
|
||||
|
@ -603,7 +603,7 @@ void Host_Noclip_f(void)
|
|||
}
|
||||
break;
|
||||
case 2:
|
||||
if(Q_atof(Cmd_Argv(1)))
|
||||
if(atof(Cmd_Argv(1)))
|
||||
{
|
||||
noclip_anglehack = true;
|
||||
ED_FLOAT(sv_player, ED_movetype) = MOVETYPE_NOCLIP;
|
||||
|
@ -718,7 +718,7 @@ void Host_Fly_f(void)
|
|||
}
|
||||
break;
|
||||
case 2:
|
||||
if(Q_atof(Cmd_Argv(1)))
|
||||
if(atof(Cmd_Argv(1)))
|
||||
{
|
||||
ED_FLOAT(sv_player, ED_movetype) = MOVETYPE_FLY;
|
||||
SV_ClientPrintf("flymode ON\n");
|
||||
|
@ -1297,7 +1297,7 @@ void Host_Name_f(void)
|
|||
|
||||
if(cmd_source == src_command)
|
||||
{
|
||||
if(Q_strcmp(cl_name.string, newName) == 0)
|
||||
if(strcmp(cl_name.string, newName) == 0)
|
||||
return;
|
||||
Cvar_Set("_cl_name", newName);
|
||||
if(cls.state == ca_connected)
|
||||
|
@ -1307,10 +1307,10 @@ void Host_Name_f(void)
|
|||
|
||||
if(host_client->name[0] && strcmp(host_client->name, "unconnected"))
|
||||
{
|
||||
if(Q_strcmp(host_client->name, newName) != 0)
|
||||
if(strcmp(host_client->name, newName) != 0)
|
||||
Con_Printf("%s renamed to %s\n", host_client->name, newName);
|
||||
}
|
||||
Q_strcpy(host_client->name, newName);
|
||||
strcpy(host_client->name, newName);
|
||||
ED_RSTRING(host_client->edict, ED_netname) = PR_SetEngineString(host_client->name);
|
||||
|
||||
// send notification to all clients
|
||||
|
@ -1546,7 +1546,7 @@ void Host_Kill_f(void)
|
|||
}
|
||||
|
||||
G_FLOAT(GBL_time) = sv.time;
|
||||
G_INT(GBL_self) = EDICT_TO_PROG(sv_player);
|
||||
G_PEDICT(GBL_self) = EDICT_TO_PROG(sv_player);
|
||||
PR_ExecuteProgram(G_FUNC(GBL_ClientKill));
|
||||
}
|
||||
|
||||
|
@ -1579,11 +1579,11 @@ void Host_Pause_f(void)
|
|||
|
||||
if(sv.paused)
|
||||
{
|
||||
SV_BroadcastPrintf("%s paused the game\n", PR_GetString(ED_RSTRING(sv_player, ED_netname)));
|
||||
SV_BroadcastPrintf("%s paused the game\n", ED_STRING(sv_player, ED_netname));
|
||||
}
|
||||
else
|
||||
{
|
||||
SV_BroadcastPrintf("%s unpaused the game\n", PR_GetString(ED_RSTRING(sv_player, ED_netname)));
|
||||
SV_BroadcastPrintf("%s unpaused the game\n", ED_STRING(sv_player, ED_netname));
|
||||
}
|
||||
|
||||
// send notification to all clients
|
||||
|
@ -1665,7 +1665,7 @@ void Host_Spawn_f(void)
|
|||
(&G_FLOAT(GBL_parm1))[i] = host_client->spawn_parms[i];
|
||||
// call the spawn function
|
||||
G_FLOAT(GBL_time) = sv.time;
|
||||
G_INT(GBL_self) = EDICT_TO_PROG(sv_player);
|
||||
G_PEDICT(GBL_self) = EDICT_TO_PROG(sv_player);
|
||||
PR_ExecuteProgram(G_FUNC(GBL_ClientConnect));
|
||||
|
||||
if((Sys_DoubleTime() - NET_QSocketGetTime(host_client->netconnection)) <= sv.time)
|
||||
|
@ -1788,9 +1788,9 @@ void Host_Kick_f(void)
|
|||
|
||||
save = host_client;
|
||||
|
||||
if(Cmd_Argc() > 2 && Q_strcmp(Cmd_Argv(1), "#") == 0)
|
||||
if(Cmd_Argc() > 2 && strcmp(Cmd_Argv(1), "#") == 0)
|
||||
{
|
||||
i = Q_atof(Cmd_Argv(2)) - 1;
|
||||
i = atof(Cmd_Argv(2)) - 1;
|
||||
if(i < 0 || i >= svs.maxclients)
|
||||
return;
|
||||
if(!svs.clients[i].active)
|
||||
|
@ -1918,7 +1918,7 @@ void Host_Give_f(void)
|
|||
{
|
||||
val = GetEdictFieldValue(sv_player, "ammo_shells1");
|
||||
if(val)
|
||||
val->_float = v;
|
||||
val->flt = v;
|
||||
}
|
||||
ED_FLOAT(sv_player, ED_ammo_shells) = v;
|
||||
break;
|
||||
|
@ -1929,7 +1929,7 @@ void Host_Give_f(void)
|
|||
val = GetEdictFieldValue(sv_player, "ammo_nails1");
|
||||
if(val)
|
||||
{
|
||||
val->_float = v;
|
||||
val->flt = v;
|
||||
if(ED_FLOAT(sv_player, ED_weapon) <= IT_LIGHTNING)
|
||||
ED_FLOAT(sv_player, ED_ammo_nails) = v;
|
||||
}
|
||||
|
@ -1946,7 +1946,7 @@ void Host_Give_f(void)
|
|||
val = GetEdictFieldValue(sv_player, "ammo_lava_nails");
|
||||
if(val)
|
||||
{
|
||||
val->_float = v;
|
||||
val->flt = v;
|
||||
if(ED_FLOAT(sv_player, ED_weapon) > IT_LIGHTNING)
|
||||
ED_FLOAT(sv_player, ED_ammo_nails) = v;
|
||||
}
|
||||
|
@ -1959,7 +1959,7 @@ void Host_Give_f(void)
|
|||
val = GetEdictFieldValue(sv_player, "ammo_rockets1");
|
||||
if(val)
|
||||
{
|
||||
val->_float = v;
|
||||
val->flt = v;
|
||||
if(ED_FLOAT(sv_player, ED_weapon) <= IT_LIGHTNING)
|
||||
ED_FLOAT(sv_player, ED_ammo_rockets) = v;
|
||||
}
|
||||
|
@ -1976,7 +1976,7 @@ void Host_Give_f(void)
|
|||
val = GetEdictFieldValue(sv_player, "ammo_multi_rockets");
|
||||
if(val)
|
||||
{
|
||||
val->_float = v;
|
||||
val->flt = v;
|
||||
if(ED_FLOAT(sv_player, ED_weapon) > IT_LIGHTNING)
|
||||
ED_FLOAT(sv_player, ED_ammo_rockets) = v;
|
||||
}
|
||||
|
@ -1993,7 +1993,7 @@ void Host_Give_f(void)
|
|||
val = GetEdictFieldValue(sv_player, "ammo_cells1");
|
||||
if(val)
|
||||
{
|
||||
val->_float = v;
|
||||
val->flt = v;
|
||||
if(ED_FLOAT(sv_player, ED_weapon) <= IT_LIGHTNING)
|
||||
ED_FLOAT(sv_player, ED_ammo_cells) = v;
|
||||
}
|
||||
|
@ -2010,7 +2010,7 @@ void Host_Give_f(void)
|
|||
val = GetEdictFieldValue(sv_player, "ammo_plasma");
|
||||
if(val)
|
||||
{
|
||||
val->_float = v;
|
||||
val->flt = v;
|
||||
if(ED_FLOAT(sv_player, ED_weapon) > IT_LIGHTNING)
|
||||
ED_FLOAT(sv_player, ED_ammo_cells) = v;
|
||||
}
|
||||
|
@ -2092,7 +2092,7 @@ edict_t *FindViewthing(void)
|
|||
for(i = 0 ; i < sv.num_edicts ; i++)
|
||||
{
|
||||
e = EDICT_NUM(i);
|
||||
if(!strcmp(PR_GetString(ED_RSTRING(e, ED_classname)), "viewthing"))
|
||||
if(!strcmp(ED_STRING(e, ED_classname), "viewthing"))
|
||||
return e;
|
||||
}
|
||||
Con_Printf("No viewthing on map\n");
|
||||
|
|
|
@ -25,14 +25,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#define STB_IMAGE_WRITE_STATIC
|
||||
#include "stb_image_write.h"
|
||||
#include "lib/stb_image_write.h"
|
||||
|
||||
#define LODEPNG_NO_COMPILE_DECODER
|
||||
#define LODEPNG_NO_COMPILE_CPP
|
||||
#define LODEPNG_NO_COMPILE_ANCILLARY_CHUNKS
|
||||
#define LODEPNG_NO_COMPILE_ERROR_TEXT
|
||||
#include "lodepng.h"
|
||||
#include "lodepng.c"
|
||||
#include "lib/lodepng.h"
|
||||
#include "lib/lodepng.c"
|
||||
|
||||
static char loadfilename[MAX_OSPATH]; //file scope so that error messages can use it
|
||||
|
||||
|
@ -147,7 +147,7 @@ bool Image_WriteTGA(const char *name, byte *data, int32_t width, int32_t height,
|
|||
if(handle == -1)
|
||||
return false;
|
||||
|
||||
Q_memset(header, 0, TARGAHEADERSIZE);
|
||||
memset(header, 0, TARGAHEADERSIZE);
|
||||
header[2] = 2; // uncompressed type
|
||||
header[12] = width & 255;
|
||||
header[13] = width >> 8;
|
||||
|
@ -303,7 +303,7 @@ byte *Image_LoadTGA(FILE *fin, int32_t *width, int32_t *height)
|
|||
if(row > 0)
|
||||
row--;
|
||||
else
|
||||
goto breakOut;
|
||||
goto breakout;
|
||||
//johnfitz -- fix for upside-down targas
|
||||
realrow = upside_down ? row : rows - 1 - row;
|
||||
pixbuf = targa_rgba + realrow * columns * 4;
|
||||
|
@ -346,7 +346,7 @@ byte *Image_LoadTGA(FILE *fin, int32_t *width, int32_t *height)
|
|||
if(row > 0)
|
||||
row--;
|
||||
else
|
||||
goto breakOut;
|
||||
goto breakout;
|
||||
//johnfitz -- fix for upside-down targas
|
||||
realrow = upside_down ? row : rows - 1 - row;
|
||||
pixbuf = targa_rgba + realrow * columns * 4;
|
||||
|
@ -355,7 +355,7 @@ byte *Image_LoadTGA(FILE *fin, int32_t *width, int32_t *height)
|
|||
}
|
||||
}
|
||||
}
|
||||
breakOut:
|
||||
breakout:
|
||||
;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -371,7 +371,7 @@ void Key_Console(int32_t key)
|
|||
|
||||
case K_UPARROW:
|
||||
if(history_line == edit_line)
|
||||
Q_strcpy(current, workline);
|
||||
strcpy(current, workline);
|
||||
|
||||
history_line_last = history_line;
|
||||
do
|
||||
|
@ -387,8 +387,8 @@ void Key_Console(int32_t key)
|
|||
}
|
||||
|
||||
key_tabpartial[0] = 0;
|
||||
Q_strcpy(workline, key_lines[history_line]);
|
||||
key_linepos = Q_strlen(workline);
|
||||
strcpy(workline, key_lines[history_line]);
|
||||
key_linepos = strlen(workline);
|
||||
return;
|
||||
|
||||
case K_DOWNARROW:
|
||||
|
@ -404,9 +404,9 @@ void Key_Console(int32_t key)
|
|||
while(history_line != edit_line && !key_lines[history_line][1]);
|
||||
|
||||
if(history_line == edit_line)
|
||||
Q_strcpy(workline, current);
|
||||
else Q_strcpy(workline, key_lines[history_line]);
|
||||
key_linepos = Q_strlen(workline);
|
||||
strcpy(workline, current);
|
||||
else strcpy(workline, key_lines[history_line]);
|
||||
key_linepos = strlen(workline);
|
||||
return;
|
||||
|
||||
case K_INS:
|
||||
|
|
113
source/mathlib.c
113
source/mathlib.c
|
@ -164,20 +164,6 @@ int32_t BoxOnPlaneSide(vec3_t emins, vec3_t emaxs, mplane_t *p)
|
|||
return sides;
|
||||
}
|
||||
|
||||
//johnfitz -- the opposite of AngleVectors. this takes forward and generates pitch yaw roll
|
||||
//TODO: take right and up vectors to properly set yaw and roll
|
||||
void VectorAngles(const vec3_t forward, vec3_t angles)
|
||||
{
|
||||
vec3_t temp;
|
||||
|
||||
temp[0] = forward[0];
|
||||
temp[1] = forward[1];
|
||||
temp[2] = 0;
|
||||
angles[PITCH] = -atan2(forward[2], VectorLength(temp)) / PI_DIV_180;
|
||||
angles[YAW] = atan2(forward[1], forward[0]) / PI_DIV_180;
|
||||
angles[ROLL] = 0;
|
||||
}
|
||||
|
||||
void AngleVectors(vec3_t angles, vec3_t forward, vec3_t right, vec3_t up)
|
||||
{
|
||||
float angle;
|
||||
|
@ -204,105 +190,6 @@ void AngleVectors(vec3_t angles, vec3_t forward, vec3_t right, vec3_t up)
|
|||
up[2] = cr * cp;
|
||||
}
|
||||
|
||||
int32_t VectorCompare(vec3_t v1, vec3_t v2)
|
||||
{
|
||||
int32_t i;
|
||||
|
||||
for(i = 0 ; i < 3 ; i++)
|
||||
if(v1[i] != v2[i])
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void VectorMA(vec3_t veca, float scale, vec3_t vecb, vec3_t vecc)
|
||||
{
|
||||
vecc[0] = veca[0] + scale * vecb[0];
|
||||
vecc[1] = veca[1] + scale * vecb[1];
|
||||
vecc[2] = veca[2] + scale * vecb[2];
|
||||
}
|
||||
|
||||
|
||||
vec_t _DotProduct(vec3_t v1, vec3_t v2)
|
||||
{
|
||||
return v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2];
|
||||
}
|
||||
|
||||
void _VectorSubtract(vec3_t veca, vec3_t vecb, vec3_t out)
|
||||
{
|
||||
out[0] = veca[0] - vecb[0];
|
||||
out[1] = veca[1] - vecb[1];
|
||||
out[2] = veca[2] - vecb[2];
|
||||
}
|
||||
|
||||
void _VectorAdd(vec3_t veca, vec3_t vecb, vec3_t out)
|
||||
{
|
||||
out[0] = veca[0] + vecb[0];
|
||||
out[1] = veca[1] + vecb[1];
|
||||
out[2] = veca[2] + vecb[2];
|
||||
}
|
||||
|
||||
void _VectorCopy(vec3_t in, vec3_t out)
|
||||
{
|
||||
out[0] = in[0];
|
||||
out[1] = in[1];
|
||||
out[2] = in[2];
|
||||
}
|
||||
|
||||
void CrossProduct(vec3_t v1, vec3_t v2, vec3_t cross)
|
||||
{
|
||||
cross[0] = v1[1] * v2[2] - v1[2] * v2[1];
|
||||
cross[1] = v1[2] * v2[0] - v1[0] * v2[2];
|
||||
cross[2] = v1[0] * v2[1] - v1[1] * v2[0];
|
||||
}
|
||||
|
||||
vec_t VectorLength(vec3_t v)
|
||||
{
|
||||
return sqrt(DotProduct(v, v));
|
||||
}
|
||||
|
||||
float VectorNormalize(vec3_t v)
|
||||
{
|
||||
float length, ilength;
|
||||
|
||||
length = sqrt(DotProduct(v, v));
|
||||
|
||||
if(length)
|
||||
{
|
||||
ilength = 1 / length;
|
||||
v[0] *= ilength;
|
||||
v[1] *= ilength;
|
||||
v[2] *= ilength;
|
||||
}
|
||||
|
||||
return length;
|
||||
|
||||
}
|
||||
|
||||
void VectorInverse(vec3_t v)
|
||||
{
|
||||
v[0] = -v[0];
|
||||
v[1] = -v[1];
|
||||
v[2] = -v[2];
|
||||
}
|
||||
|
||||
void VectorScale(vec3_t in, vec_t scale, vec3_t out)
|
||||
{
|
||||
out[0] = in[0] * scale;
|
||||
out[1] = in[1] * scale;
|
||||
out[2] = in[2] * scale;
|
||||
}
|
||||
|
||||
|
||||
int32_t Q_log2(int32_t val)
|
||||
{
|
||||
int32_t answer = 0;
|
||||
while(val >>= 1)
|
||||
answer++;
|
||||
return answer;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
================
|
||||
R_ConcatRotations
|
||||
|
|
164
source/mathlib.h
164
source/mathlib.h
|
@ -24,57 +24,157 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#ifndef spingle__mathlib_h
|
||||
#define spingle__mathlib_h
|
||||
|
||||
// mathlib.h
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#define PI 3.14159265358979323846
|
||||
#define PI_DIV_180 (PI / 180.0) //johnfitz
|
||||
|
||||
#define Q_rint(x) _Generic((x), float: Q_rintf, double: Q_rintd)(x)
|
||||
|
||||
struct mplane_s;
|
||||
|
||||
extern vec3_t vec3_origin;
|
||||
|
||||
#define Q_rint(x) ((x) > 0 ? (int32_t)((x) + 0.5) : (int32_t)((x) - 0.5))
|
||||
void TurnVector(vec3_t out, const vec3_t forward, const vec3_t side, float angle); //johnfitz
|
||||
|
||||
#define DotProduct(x,y) (x[0]*y[0]+x[1]*y[1]+x[2]*y[2])
|
||||
#define DoublePrecisionDotProduct(x,y) ((double)x[0]*y[0]+(double)x[1]*y[1]+(double)x[2]*y[2])
|
||||
#define VectorSubtract(a,b,c) {c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];}
|
||||
#define VectorAdd(a,b,c) {c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];}
|
||||
#define VectorCopy(a,b) {b[0]=a[0];b[1]=a[1];b[2]=a[2];}
|
||||
static inline int32_t Q_rintf(float x)
|
||||
{
|
||||
return x > 0 ? (int32_t)(x + 0.5) : (int32_t)(x - 0.5);
|
||||
}
|
||||
|
||||
static inline int32_t Q_rintd(double x)
|
||||
{
|
||||
return x > 0 ? (int32_t)(x + 0.5) : (int32_t)(x - 0.5);
|
||||
}
|
||||
|
||||
static inline vec_t DotProduct(vec3_t const v1, vec3_t const v2)
|
||||
{
|
||||
return v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2];
|
||||
}
|
||||
|
||||
static inline vec_t DoublePrecisionDotProduct(vec3_t const v1, vec3_t const v2)
|
||||
{
|
||||
return (double)v1[0] * v2[0] + (double)v1[1] * v2[1] + (double)v1[2] * v2[2];
|
||||
}
|
||||
static inline void VectorSubtract(vec3_t const veca, vec3_t const vecb, vec3_t out)
|
||||
{
|
||||
out[0] = veca[0] - vecb[0];
|
||||
out[1] = veca[1] - vecb[1];
|
||||
out[2] = veca[2] - vecb[2];
|
||||
}
|
||||
|
||||
static inline void VectorAdd(vec3_t const veca, vec3_t const vecb, vec3_t out)
|
||||
{
|
||||
out[0] = veca[0] + vecb[0];
|
||||
out[1] = veca[1] + vecb[1];
|
||||
out[2] = veca[2] + vecb[2];
|
||||
}
|
||||
|
||||
static inline void VectorCopy(vec3_t const in, vec3_t out)
|
||||
{
|
||||
out[0] = in[0];
|
||||
out[1] = in[1];
|
||||
out[2] = in[2];
|
||||
}
|
||||
|
||||
static inline void VectorInverse(vec3_t v)
|
||||
{
|
||||
v[0] = -v[0];
|
||||
v[1] = -v[1];
|
||||
v[2] = -v[2];
|
||||
}
|
||||
|
||||
static inline void VectorScale(vec3_t const in, vec_t scale, vec3_t out)
|
||||
{
|
||||
out[0] = in[0] * scale;
|
||||
out[1] = in[1] * scale;
|
||||
out[2] = in[2] * scale;
|
||||
}
|
||||
|
||||
//johnfitz -- courtesy of lordhavoc
|
||||
// QS: To avoid strict aliasing violations, use a float/int32_t union instead of type punning.
|
||||
// [agw] NO YOU FOOL THAT'S UNDEFINED BEHAVIOUR
|
||||
#define VectorNormalizeFast(_v) \
|
||||
{ \
|
||||
union { float f; uint32_t i; } _y, _number; \
|
||||
_number.f = DotProduct(_v, _v); \
|
||||
if(_number.f != 0.0) \
|
||||
{ \
|
||||
_y.i = 0x5f3759df - (_number.i >> 1); \
|
||||
_y.f = _y.f * (1.5f - (_number.f * 0.5f * _y.f * _y.f)); \
|
||||
VectorScale(_v, _y.f, _v); \
|
||||
} \
|
||||
static inline void VectorNormalizeFast(vec3_t v)
|
||||
{
|
||||
union { float f; uint32_t i; } y, number;
|
||||
number.f = DotProduct(v, v);
|
||||
if(number.f != 0.0)
|
||||
{
|
||||
y.i = 0x5f3759df - (number.i >> 1);
|
||||
y.f = y.f * (1.5f - (number.f * 0.5f * y.f * y.f));
|
||||
VectorScale(v, y.f, v);
|
||||
}
|
||||
}
|
||||
|
||||
void TurnVector(vec3_t out, const vec3_t forward, const vec3_t side, float angle); //johnfitz
|
||||
void VectorAngles(const vec3_t forward, vec3_t angles); //johnfitz
|
||||
static inline int32_t VectorCompare(vec3_t v1, vec3_t v2)
|
||||
{
|
||||
int32_t i;
|
||||
|
||||
void VectorMA(vec3_t veca, float scale, vec3_t vecb, vec3_t vecc);
|
||||
for(i = 0 ; i < 3 ; i++)
|
||||
if(v1[i] != v2[i])
|
||||
return 0;
|
||||
|
||||
vec_t _DotProduct(vec3_t v1, vec3_t v2);
|
||||
void _VectorSubtract(vec3_t veca, vec3_t vecb, vec3_t out);
|
||||
void _VectorAdd(vec3_t veca, vec3_t vecb, vec3_t out);
|
||||
void _VectorCopy(vec3_t in, vec3_t out);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int32_t VectorCompare(vec3_t v1, vec3_t v2);
|
||||
vec_t VectorLength(vec3_t v);
|
||||
void CrossProduct(vec3_t v1, vec3_t v2, vec3_t cross);
|
||||
float VectorNormalize(vec3_t v); // returns vector length
|
||||
void VectorInverse(vec3_t v);
|
||||
void VectorScale(vec3_t in, vec_t scale, vec3_t out);
|
||||
int32_t Q_log2(int32_t val);
|
||||
static inline void VectorMA(vec3_t veca, float scale, vec3_t vecb, vec3_t vecc)
|
||||
{
|
||||
vecc[0] = veca[0] + scale * vecb[0];
|
||||
vecc[1] = veca[1] + scale * vecb[1];
|
||||
vecc[2] = veca[2] + scale * vecb[2];
|
||||
}
|
||||
|
||||
static inline void CrossProduct(vec3_t v1, vec3_t v2, vec3_t cross)
|
||||
{
|
||||
cross[0] = v1[1] * v2[2] - v1[2] * v2[1];
|
||||
cross[1] = v1[2] * v2[0] - v1[0] * v2[2];
|
||||
cross[2] = v1[0] * v2[1] - v1[1] * v2[0];
|
||||
}
|
||||
|
||||
static inline vec_t VectorLength(vec3_t v)
|
||||
{
|
||||
return sqrt(DotProduct(v, v));
|
||||
}
|
||||
|
||||
static inline float VectorNormalize(vec3_t v)
|
||||
{
|
||||
float length, ilength;
|
||||
|
||||
length = sqrt(DotProduct(v, v));
|
||||
|
||||
if(length)
|
||||
{
|
||||
ilength = 1 / length;
|
||||
v[0] *= ilength;
|
||||
v[1] *= ilength;
|
||||
v[2] *= ilength;
|
||||
}
|
||||
|
||||
return length;
|
||||
|
||||
}
|
||||
|
||||
static inline int32_t Q_log2(int32_t val)
|
||||
{
|
||||
int32_t answer = 0;
|
||||
while(val >>= 1)
|
||||
answer++;
|
||||
return answer;
|
||||
}
|
||||
|
||||
//johnfitz -- the opposite of AngleVectors. this takes forward and generates pitch yaw roll
|
||||
//TODO: take right and up vectors to properly set yaw and roll
|
||||
static inline void VectorAngles(const vec3_t forward, vec3_t angles)
|
||||
{
|
||||
vec3_t temp;
|
||||
|
||||
temp[0] = forward[0];
|
||||
temp[1] = forward[1];
|
||||
temp[2] = 0;
|
||||
angles[PITCH] = -atan2(forward[2], VectorLength(temp)) / PI_DIV_180;
|
||||
angles[YAW] = atan2(forward[1], forward[0]) / PI_DIV_180;
|
||||
angles[ROLL] = 0;
|
||||
}
|
||||
|
||||
void R_ConcatRotations(float in1[3][3], float in2[3][3], float out[3][3]);
|
||||
void R_ConcatTransforms(float in1[3][4], float in2[3][4], float out[3][4]);
|
||||
|
|
|
@ -694,8 +694,8 @@ void M_Menu_Setup_f(void)
|
|||
key_dest = key_menu;
|
||||
m_state = m_setup;
|
||||
m_entersound = true;
|
||||
Q_strcpy(setup_myname, cl_name.string);
|
||||
Q_strcpy(setup_hostname, hostname.string);
|
||||
strcpy(setup_myname, cl_name.string);
|
||||
strcpy(setup_hostname, hostname.string);
|
||||
setup_top = setup_oldtop = ((int32_t)cl_color.value) >> 4;
|
||||
setup_bottom = setup_oldbottom = ((int32_t)cl_color.value) & 15;
|
||||
}
|
||||
|
@ -791,9 +791,9 @@ forward:
|
|||
goto forward;
|
||||
|
||||
// setup_cursor == 4 (OK)
|
||||
if(Q_strcmp(cl_name.string, setup_myname) != 0)
|
||||
if(strcmp(cl_name.string, setup_myname) != 0)
|
||||
Cbuf_AddText(va("name \"%s\"\n", setup_myname));
|
||||
if(Q_strcmp(hostname.string, setup_hostname) != 0)
|
||||
if(strcmp(hostname.string, setup_hostname) != 0)
|
||||
Cvar_Set("hostname", setup_hostname);
|
||||
if(setup_top != setup_oldtop || setup_bottom != setup_oldbottom)
|
||||
Cbuf_AddText(va("color %" PRIi32 " %" PRIi32 "\n", setup_top, setup_bottom));
|
||||
|
@ -1871,7 +1871,7 @@ void M_LanConfig_Key(int32_t key)
|
|||
lanConfig_cursor = 0;
|
||||
}
|
||||
|
||||
l = Q_atoi(lanConfig_portname);
|
||||
l = atoi(lanConfig_portname);
|
||||
if(l > 65535)
|
||||
l = lanConfig_port;
|
||||
else
|
||||
|
|
|
@ -246,9 +246,9 @@ extern int32_t hostCacheCount;
|
|||
extern hostcache_t hostcache[HOSTCACHESIZE];
|
||||
|
||||
|
||||
typedef struct _PollProcedure
|
||||
typedef struct PollProcedure_s
|
||||
{
|
||||
struct _PollProcedure *next;
|
||||
struct PollProcedure_s *next;
|
||||
double nextTime;
|
||||
void (*procedure)(void *arg);
|
||||
void *arg;
|
||||
|
|
|
@ -99,8 +99,8 @@ static void NET_Ban_f(void)
|
|||
case 1:
|
||||
if(banAddr.s_addr != INADDR_ANY)
|
||||
{
|
||||
Q_strcpy(addrStr, inet_ntoa(banAddr));
|
||||
Q_strcpy(maskStr, inet_ntoa(banMask));
|
||||
strcpy(addrStr, inet_ntoa(banAddr));
|
||||
strcpy(maskStr, inet_ntoa(banMask));
|
||||
print_fn("Banning %s [%s]\n", addrStr, maskStr);
|
||||
}
|
||||
else
|
||||
|
@ -145,7 +145,7 @@ int32_t Datagram_SendMessage(qsocket_t *sock, sizebuf_t *data)
|
|||
Sys_Error("SendMessage: called with canSend == false\n");
|
||||
#endif
|
||||
|
||||
Q_memcpy(sock->sendMessage, data->data, data->cursize);
|
||||
memcpy(sock->sendMessage, data->data, data->cursize);
|
||||
sock->sendMessageLength = data->cursize;
|
||||
|
||||
if(data->cursize <= MAX_DATAGRAM)
|
||||
|
@ -162,7 +162,7 @@ int32_t Datagram_SendMessage(qsocket_t *sock, sizebuf_t *data)
|
|||
|
||||
packetBuffer.length = BigLong(packetLen | (NETFLAG_DATA | eom));
|
||||
packetBuffer.sequence = BigLong(sock->sendSequence++);
|
||||
Q_memcpy(packetBuffer.data, sock->sendMessage, dataLen);
|
||||
memcpy(packetBuffer.data, sock->sendMessage, dataLen);
|
||||
|
||||
sock->canSend = false;
|
||||
|
||||
|
@ -195,7 +195,7 @@ static int32_t SendMessageNext(qsocket_t *sock)
|
|||
|
||||
packetBuffer.length = BigLong(packetLen | (NETFLAG_DATA | eom));
|
||||
packetBuffer.sequence = BigLong(sock->sendSequence++);
|
||||
Q_memcpy(packetBuffer.data, sock->sendMessage, dataLen);
|
||||
memcpy(packetBuffer.data, sock->sendMessage, dataLen);
|
||||
|
||||
sock->sendNext = false;
|
||||
|
||||
|
@ -228,7 +228,7 @@ static int32_t ReSendMessage(qsocket_t *sock)
|
|||
|
||||
packetBuffer.length = BigLong(packetLen | (NETFLAG_DATA | eom));
|
||||
packetBuffer.sequence = BigLong(sock->sendSequence - 1);
|
||||
Q_memcpy(packetBuffer.data, sock->sendMessage, dataLen);
|
||||
memcpy(packetBuffer.data, sock->sendMessage, dataLen);
|
||||
|
||||
sock->sendNext = false;
|
||||
|
||||
|
@ -273,7 +273,7 @@ int32_t Datagram_SendUnreliableMessage(qsocket_t *sock, sizebuf_t *data)
|
|||
|
||||
packetBuffer.length = BigLong(packetLen | NETFLAG_UNRELIABLE);
|
||||
packetBuffer.sequence = BigLong(sock->unreliableSendSequence++);
|
||||
Q_memcpy(packetBuffer.data, data->data, data->cursize);
|
||||
memcpy(packetBuffer.data, data->data, data->cursize);
|
||||
|
||||
if(sfunc.Write(sock->socket, (byte *)&packetBuffer, packetLen, &sock->addr) == -1)
|
||||
return -1;
|
||||
|
@ -420,7 +420,7 @@ int32_t Datagram_GetMessage(qsocket_t *sock)
|
|||
break;
|
||||
}
|
||||
|
||||
Q_memcpy(sock->receiveMessage + sock->receiveMessageLength, packetBuffer.data, length);
|
||||
memcpy(sock->receiveMessage + sock->receiveMessageLength, packetBuffer.data, length);
|
||||
sock->receiveMessageLength += length;
|
||||
continue;
|
||||
}
|
||||
|
@ -458,7 +458,7 @@ static void NET_Stats_f(void)
|
|||
Con_Printf("shortPacketCount = %" PRIi32 "\n", shortPacketCount);
|
||||
Con_Printf("droppedDatagrams = %" PRIi32 "\n", droppedDatagrams);
|
||||
}
|
||||
else if(Q_strcmp(Cmd_Argv(1), "*") == 0)
|
||||
else if(strcmp(Cmd_Argv(1), "*") == 0)
|
||||
{
|
||||
for(s = net_activeSockets; s; s = s->next)
|
||||
PrintStats(s);
|
||||
|
@ -501,10 +501,10 @@ static const char *Strip_Port(const char *host)
|
|||
if(!host || !*host)
|
||||
return host;
|
||||
q_strlcpy(noport, host, sizeof(noport));
|
||||
if((p = Q_strrchr(noport, ':')) == NULL)
|
||||
if((p = strrchr(noport, ':')) == NULL)
|
||||
return host;
|
||||
*p++ = '\0';
|
||||
port = Q_atoi(p);
|
||||
port = atoi(p);
|
||||
if(port > 0 && port < 65536 && port != net_hostport)
|
||||
{
|
||||
net_hostport = port;
|
||||
|
@ -559,11 +559,11 @@ static void Test_Poll(void *unused)
|
|||
Sys_Error("Unexpected repsonse to Player Info request\n");
|
||||
|
||||
MSG_ReadByte(); /* playerNumber */
|
||||
Q_strcpy(name, MSG_ReadString());
|
||||
strcpy(name, MSG_ReadString());
|
||||
colors = MSG_ReadLong();
|
||||
frags = MSG_ReadLong();
|
||||
connectTime = MSG_ReadLong();
|
||||
Q_strcpy(address, MSG_ReadString());
|
||||
strcpy(address, MSG_ReadString());
|
||||
|
||||
Con_Printf("%s\n frags:%3" PRIi32 " colors:%" PRIi32 " %" PRIi32 " time:%" PRIi32 "\n %s\n", name, frags, colors >> 4, colors & 0x0f, connectTime / 60, address);
|
||||
}
|
||||
|
@ -602,12 +602,12 @@ static void Test_f(void)
|
|||
continue;
|
||||
net_landriverlevel = hostcache[n].ldriver;
|
||||
maxusers = hostcache[n].maxusers;
|
||||
Q_memcpy(&sendaddr, &hostcache[n].addr, sizeof(struct qsockaddr));
|
||||
memcpy(&sendaddr, &hostcache[n].addr, sizeof(struct qsockaddr));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(n < hostCacheCount)
|
||||
goto JustDoIt;
|
||||
goto justdoit;
|
||||
}
|
||||
|
||||
for(net_landriverlevel = 0; net_landriverlevel < net_numlandrivers; net_landriverlevel++)
|
||||
|
@ -626,7 +626,7 @@ static void Test_f(void)
|
|||
return;
|
||||
}
|
||||
|
||||
JustDoIt:
|
||||
justdoit:
|
||||
testSocket = dfunc.Open_Socket(0);
|
||||
if(testSocket == INVALID_SOCKET)
|
||||
return;
|
||||
|
@ -672,7 +672,7 @@ static void Test2_Poll(void *unused)
|
|||
|
||||
len = dfunc.Read(test2Socket, net_message.data, net_message.maxsize, &clientaddr);
|
||||
if(len < (int32_t) sizeof(int32_t))
|
||||
goto Reschedule;
|
||||
goto reschedule;
|
||||
|
||||
net_message.cursize = len;
|
||||
|
||||
|
@ -680,19 +680,19 @@ static void Test2_Poll(void *unused)
|
|||
control = BigLong(*((int32_t *)net_message.data));
|
||||
MSG_ReadLong();
|
||||
if(control == -1)
|
||||
goto Error;
|
||||
goto error;
|
||||
if((control & (~NETFLAG_LENGTH_MASK)) != (int32_t)NETFLAG_CTL)
|
||||
goto Error;
|
||||
goto error;
|
||||
if((control & NETFLAG_LENGTH_MASK) != len)
|
||||
goto Error;
|
||||
goto error;
|
||||
|
||||
if(MSG_ReadByte() != CCREP_RULE_INFO)
|
||||
goto Error;
|
||||
goto error;
|
||||
|
||||
Q_strcpy(name, MSG_ReadString());
|
||||
strcpy(name, MSG_ReadString());
|
||||
if(name[0] == 0)
|
||||
goto Done;
|
||||
Q_strcpy(value, MSG_ReadString());
|
||||
goto done;
|
||||
strcpy(value, MSG_ReadString());
|
||||
|
||||
Con_Printf("%-16.16s %-16.16s\n", name, value);
|
||||
|
||||
|
@ -705,13 +705,13 @@ static void Test2_Poll(void *unused)
|
|||
dfunc.Write(test2Socket, net_message.data, net_message.cursize, &clientaddr);
|
||||
SZ_Clear(&net_message);
|
||||
|
||||
Reschedule:
|
||||
reschedule:
|
||||
SchedulePollProcedure(&test2PollProcedure, 0.05);
|
||||
return;
|
||||
|
||||
Error:
|
||||
error:
|
||||
Con_Printf("Unexpected repsonse to Rule Info request\n");
|
||||
Done:
|
||||
done:
|
||||
dfunc.Close_Socket(test2Socket);
|
||||
test2InProgress = false;
|
||||
return;
|
||||
|
@ -737,13 +737,13 @@ static void Test2_f(void)
|
|||
if(hostcache[n].driver != myDriverLevel)
|
||||
continue;
|
||||
net_landriverlevel = hostcache[n].ldriver;
|
||||
Q_memcpy(&sendaddr, &hostcache[n].addr, sizeof(struct qsockaddr));
|
||||
memcpy(&sendaddr, &hostcache[n].addr, sizeof(struct qsockaddr));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(n < hostCacheCount)
|
||||
goto JustDoIt;
|
||||
goto justdoit;
|
||||
}
|
||||
|
||||
for(net_landriverlevel = 0; net_landriverlevel < net_numlandrivers; net_landriverlevel++)
|
||||
|
@ -762,7 +762,7 @@ static void Test2_f(void)
|
|||
return;
|
||||
}
|
||||
|
||||
JustDoIt:
|
||||
justdoit:
|
||||
test2Socket = dfunc.Open_Socket(0);
|
||||
if(test2Socket == INVALID_SOCKET)
|
||||
return;
|
||||
|
@ -858,7 +858,7 @@ void Datagram_Listen(bool state)
|
|||
}
|
||||
|
||||
|
||||
static qsocket_t *_Datagram_CheckNewConnections(void)
|
||||
static qsocket_t *Datagram_CheckNewConnections_(void)
|
||||
{
|
||||
struct qsockaddr clientaddr;
|
||||
struct qsockaddr newaddr;
|
||||
|
@ -895,7 +895,7 @@ static qsocket_t *_Datagram_CheckNewConnections(void)
|
|||
command = MSG_ReadByte();
|
||||
if(command == CCREQ_SERVER_INFO)
|
||||
{
|
||||
if(Q_strcmp(MSG_ReadString(), "QUAKE") != 0)
|
||||
if(strcmp(MSG_ReadString(), "QUAKE") != 0)
|
||||
return NULL;
|
||||
|
||||
SZ_Clear(&net_message);
|
||||
|
@ -984,7 +984,7 @@ static qsocket_t *_Datagram_CheckNewConnections(void)
|
|||
if(command != CCREQ_CONNECT)
|
||||
return NULL;
|
||||
|
||||
if(Q_strcmp(MSG_ReadString(), "QUAKE") != 0)
|
||||
if(strcmp(MSG_ReadString(), "QUAKE") != 0)
|
||||
return NULL;
|
||||
|
||||
if(MSG_ReadByte() != NET_PROTOCOL_VERSION)
|
||||
|
@ -1087,7 +1087,7 @@ static qsocket_t *_Datagram_CheckNewConnections(void)
|
|||
sock->socket = newsock;
|
||||
sock->landriver = net_landriverlevel;
|
||||
sock->addr = clientaddr;
|
||||
Q_strcpy(sock->address, dfunc.AddrToString(&clientaddr));
|
||||
strcpy(sock->address, dfunc.AddrToString(&clientaddr));
|
||||
|
||||
// send him back the info about the server connection he has been allocated
|
||||
SZ_Clear(&net_message);
|
||||
|
@ -1112,7 +1112,7 @@ qsocket_t *Datagram_CheckNewConnections(void)
|
|||
{
|
||||
if(net_landrivers[net_landriverlevel].initialized)
|
||||
{
|
||||
if((ret = _Datagram_CheckNewConnections()) != NULL)
|
||||
if((ret = Datagram_CheckNewConnections_()) != NULL)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1120,7 +1120,7 @@ qsocket_t *Datagram_CheckNewConnections(void)
|
|||
}
|
||||
|
||||
|
||||
static void _Datagram_SearchForHosts(bool xmit)
|
||||
static void Datagram_SearchForHosts_(bool xmit)
|
||||
{
|
||||
int32_t ret;
|
||||
int32_t n;
|
||||
|
@ -1184,21 +1184,21 @@ static void _Datagram_SearchForHosts(bool xmit)
|
|||
|
||||
// add it
|
||||
hostCacheCount++;
|
||||
Q_strcpy(hostcache[n].name, MSG_ReadString());
|
||||
Q_strcpy(hostcache[n].map, MSG_ReadString());
|
||||
strcpy(hostcache[n].name, MSG_ReadString());
|
||||
strcpy(hostcache[n].map, MSG_ReadString());
|
||||
hostcache[n].users = MSG_ReadByte();
|
||||
hostcache[n].maxusers = MSG_ReadByte();
|
||||
if(MSG_ReadByte() != NET_PROTOCOL_VERSION)
|
||||
{
|
||||
Q_strcpy(hostcache[n].cname, hostcache[n].name);
|
||||
strcpy(hostcache[n].cname, hostcache[n].name);
|
||||
hostcache[n].cname[14] = 0;
|
||||
Q_strcpy(hostcache[n].name, "*");
|
||||
Q_strcat(hostcache[n].name, hostcache[n].cname);
|
||||
strcpy(hostcache[n].name, "*");
|
||||
strcat(hostcache[n].name, hostcache[n].cname);
|
||||
}
|
||||
Q_memcpy(&hostcache[n].addr, &readaddr, sizeof(struct qsockaddr));
|
||||
memcpy(&hostcache[n].addr, &readaddr, sizeof(struct qsockaddr));
|
||||
hostcache[n].driver = net_driverlevel;
|
||||
hostcache[n].ldriver = net_landriverlevel;
|
||||
Q_strcpy(hostcache[n].cname, dfunc.AddrToString(&readaddr));
|
||||
strcpy(hostcache[n].cname, dfunc.AddrToString(&readaddr));
|
||||
|
||||
// check for a name conflict
|
||||
for(i = 0; i < hostCacheCount; i++)
|
||||
|
@ -1207,7 +1207,7 @@ static void _Datagram_SearchForHosts(bool xmit)
|
|||
continue;
|
||||
if(q_strcasecmp(hostcache[n].name, hostcache[i].name) == 0)
|
||||
{
|
||||
i = Q_strlen(hostcache[n].name);
|
||||
i = strlen(hostcache[n].name);
|
||||
if(i < 15 && hostcache[n].name[i - 1] > '8')
|
||||
{
|
||||
hostcache[n].name[i] = '0';
|
||||
|
@ -1229,12 +1229,12 @@ void Datagram_SearchForHosts(bool xmit)
|
|||
if(hostCacheCount == HOSTCACHESIZE)
|
||||
break;
|
||||
if(net_landrivers[net_landriverlevel].initialized)
|
||||
_Datagram_SearchForHosts(xmit);
|
||||
Datagram_SearchForHosts_(xmit);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static qsocket_t *_Datagram_Connect(const char *host)
|
||||
static qsocket_t *Datagram_Connect_(const char *host)
|
||||
{
|
||||
struct qsockaddr sendaddr;
|
||||
struct qsockaddr readaddr;
|
||||
|
@ -1259,13 +1259,13 @@ static qsocket_t *_Datagram_Connect(const char *host)
|
|||
|
||||
sock = NET_NewQSocket();
|
||||
if(sock == NULL)
|
||||
goto ErrorReturn2;
|
||||
goto error2;
|
||||
sock->socket = newsock;
|
||||
sock->landriver = net_landriverlevel;
|
||||
|
||||
// connect to the host
|
||||
if(dfunc.Connect(newsock, &sendaddr) == -1)
|
||||
goto ErrorReturn;
|
||||
goto error;
|
||||
|
||||
// send the connection request
|
||||
Con_Printf("trying...\n");
|
||||
|
@ -1342,16 +1342,16 @@ static qsocket_t *_Datagram_Connect(const char *host)
|
|||
{
|
||||
reason = "No Response";
|
||||
Con_Printf("%s\n", reason);
|
||||
Q_strcpy(m_return_reason, reason);
|
||||
goto ErrorReturn;
|
||||
strcpy(m_return_reason, reason);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if(ret == -1)
|
||||
{
|
||||
reason = "Network Error";
|
||||
reason = "Network error";
|
||||
Con_Printf("%s\n", reason);
|
||||
Q_strcpy(m_return_reason, reason);
|
||||
goto ErrorReturn;
|
||||
strcpy(m_return_reason, reason);
|
||||
goto error;
|
||||
}
|
||||
|
||||
ret = MSG_ReadByte();
|
||||
|
@ -1360,20 +1360,20 @@ static qsocket_t *_Datagram_Connect(const char *host)
|
|||
reason = MSG_ReadString();
|
||||
Con_Printf("%s\n", reason);
|
||||
q_strlcpy(m_return_reason, reason, sizeof(m_return_reason));
|
||||
goto ErrorReturn;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if(ret == CCREP_ACCEPT)
|
||||
{
|
||||
Q_memcpy(&sock->addr, &sendaddr, sizeof(struct qsockaddr));
|
||||
memcpy(&sock->addr, &sendaddr, sizeof(struct qsockaddr));
|
||||
dfunc.SetSocketPort(&sock->addr, MSG_ReadLong());
|
||||
}
|
||||
else
|
||||
{
|
||||
reason = "Bad Response";
|
||||
Con_Printf("%s\n", reason);
|
||||
Q_strcpy(m_return_reason, reason);
|
||||
goto ErrorReturn;
|
||||
strcpy(m_return_reason, reason);
|
||||
goto error;
|
||||
}
|
||||
|
||||
dfunc.GetNameFromAddr(&sendaddr, sock->address);
|
||||
|
@ -1386,16 +1386,16 @@ static qsocket_t *_Datagram_Connect(const char *host)
|
|||
{
|
||||
reason = "Connect to Game failed";
|
||||
Con_Printf("%s\n", reason);
|
||||
Q_strcpy(m_return_reason, reason);
|
||||
goto ErrorReturn;
|
||||
strcpy(m_return_reason, reason);
|
||||
goto error;
|
||||
}
|
||||
|
||||
m_return_onerror = false;
|
||||
return sock;
|
||||
|
||||
ErrorReturn:
|
||||
error:
|
||||
NET_FreeQSocket(sock);
|
||||
ErrorReturn2:
|
||||
error2:
|
||||
dfunc.Close_Socket(newsock);
|
||||
if(m_return_onerror)
|
||||
{
|
||||
|
@ -1416,7 +1416,7 @@ qsocket_t *Datagram_Connect(const char *host)
|
|||
{
|
||||
if(net_landrivers[net_landriverlevel].initialized)
|
||||
{
|
||||
if((ret = _Datagram_Connect(host)) != NULL)
|
||||
if((ret = Datagram_Connect_(host)) != NULL)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,21 +56,21 @@ void Loop_SearchForHosts(bool xmit)
|
|||
return;
|
||||
|
||||
hostCacheCount = 1;
|
||||
if(Q_strcmp(hostname.string, "UNNAMED") == 0)
|
||||
Q_strcpy(hostcache[0].name, "local");
|
||||
if(strcmp(hostname.string, "UNNAMED") == 0)
|
||||
strcpy(hostcache[0].name, "local");
|
||||
else
|
||||
Q_strcpy(hostcache[0].name, hostname.string);
|
||||
Q_strcpy(hostcache[0].map, sv.name);
|
||||
strcpy(hostcache[0].name, hostname.string);
|
||||
strcpy(hostcache[0].map, sv.name);
|
||||
hostcache[0].users = net_activeconnections;
|
||||
hostcache[0].maxusers = svs.maxclients;
|
||||
hostcache[0].driver = net_driverlevel;
|
||||
Q_strcpy(hostcache[0].cname, "local");
|
||||
strcpy(hostcache[0].cname, "local");
|
||||
}
|
||||
|
||||
|
||||
qsocket_t *Loop_Connect(const char *host)
|
||||
{
|
||||
if(Q_strcmp(host, "local") != 0)
|
||||
if(strcmp(host, "local") != 0)
|
||||
return NULL;
|
||||
|
||||
localconnectpending = true;
|
||||
|
@ -82,7 +82,7 @@ qsocket_t *Loop_Connect(const char *host)
|
|||
Con_Printf("Loop_Connect: no qsocket available\n");
|
||||
return NULL;
|
||||
}
|
||||
Q_strcpy(loop_client->address, "localhost");
|
||||
strcpy(loop_client->address, "localhost");
|
||||
}
|
||||
loop_client->receiveMessageLength = 0;
|
||||
loop_client->sendMessageLength = 0;
|
||||
|
@ -95,7 +95,7 @@ qsocket_t *Loop_Connect(const char *host)
|
|||
Con_Printf("Loop_Connect: no qsocket available\n");
|
||||
return NULL;
|
||||
}
|
||||
Q_strcpy(loop_server->address, "LOCAL");
|
||||
strcpy(loop_server->address, "LOCAL");
|
||||
}
|
||||
loop_server->receiveMessageLength = 0;
|
||||
loop_server->sendMessageLength = 0;
|
||||
|
@ -183,7 +183,7 @@ int32_t Loop_SendMessage(qsocket_t *sock, sizebuf_t *data)
|
|||
buffer++;
|
||||
|
||||
// message
|
||||
Q_memcpy(buffer, data->data, data->cursize);
|
||||
memcpy(buffer, data->data, data->cursize);
|
||||
*bufferLength = IntAlign(*bufferLength + data->cursize + 4);
|
||||
|
||||
sock->canSend = false;
|
||||
|
@ -217,7 +217,7 @@ int32_t Loop_SendUnreliableMessage(qsocket_t *sock, sizebuf_t *data)
|
|||
buffer++;
|
||||
|
||||
// message
|
||||
Q_memcpy(buffer, data->data, data->cursize);
|
||||
memcpy(buffer, data->data, data->cursize);
|
||||
*bufferLength = IntAlign(*bufferLength + data->cursize + 4);
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ double SetNetTime(void)
|
|||
NET_NewQSocket
|
||||
|
||||
Called by drivers when a new communications endpoint is required
|
||||
The sequence and buffer fields will be filled in properly
|
||||
The sequence and buffer members will be filled in properly
|
||||
===================
|
||||
*/
|
||||
qsocket_t *NET_NewQSocket(void)
|
||||
|
@ -105,7 +105,7 @@ qsocket_t *NET_NewQSocket(void)
|
|||
|
||||
sock->disconnected = false;
|
||||
sock->connecttime = net_time;
|
||||
Q_strcpy(sock->address, "UNSET ADDRESS");
|
||||
strcpy(sock->address, "UNSET ADDRESS");
|
||||
sock->driver = net_driverlevel;
|
||||
sock->socket = 0;
|
||||
sock->driverdata = NULL;
|
||||
|
@ -173,7 +173,7 @@ static void NET_Listen_f(void)
|
|||
return;
|
||||
}
|
||||
|
||||
listening = Q_atoi(Cmd_Argv(1)) ? true : false;
|
||||
listening = atoi(Cmd_Argv(1)) ? true : false;
|
||||
|
||||
for(net_driverlevel = 0; net_driverlevel < net_numdrivers; net_driverlevel++)
|
||||
{
|
||||
|
@ -200,7 +200,7 @@ static void MaxPlayers_f(void)
|
|||
return;
|
||||
}
|
||||
|
||||
n = Q_atoi(Cmd_Argv(1));
|
||||
n = atoi(Cmd_Argv(1));
|
||||
if(n < 1)
|
||||
n = 1;
|
||||
if(n > svs.maxclientslimit)
|
||||
|
@ -233,7 +233,7 @@ static void NET_Port_f(void)
|
|||
return;
|
||||
}
|
||||
|
||||
n = Q_atoi(Cmd_Argv(1));
|
||||
n = atoi(Cmd_Argv(1));
|
||||
if(n < 1 || n > 65534)
|
||||
{
|
||||
Con_Printf("Bad value, must be between 1 and 65534\n");
|
||||
|
@ -429,7 +429,7 @@ qsocket_t *NET_Connect(const char *host)
|
|||
if(q_strcasecmp(host, "local") == 0)
|
||||
{
|
||||
numdrivers = 1;
|
||||
goto JustDoIt;
|
||||
goto justdoit;
|
||||
}
|
||||
|
||||
if(hostCacheCount)
|
||||
|
@ -441,7 +441,7 @@ qsocket_t *NET_Connect(const char *host)
|
|||
break;
|
||||
}
|
||||
if(n < hostCacheCount)
|
||||
goto JustDoIt;
|
||||
goto justdoit;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -471,7 +471,7 @@ qsocket_t *NET_Connect(const char *host)
|
|||
}
|
||||
}
|
||||
|
||||
JustDoIt:
|
||||
justdoit:
|
||||
for(net_driverlevel = 0; net_driverlevel < numdrivers; net_driverlevel++)
|
||||
{
|
||||
if(net_drivers[net_driverlevel].initialized == false)
|
||||
|
@ -772,7 +772,7 @@ void NET_Init(void)
|
|||
if(i)
|
||||
{
|
||||
if(i < com_argc - 1)
|
||||
DEFAULTnet_hostport = Q_atoi(com_argv[i + 1]);
|
||||
DEFAULTnet_hostport = atoi(com_argv[i + 1]);
|
||||
else
|
||||
Sys_Error("NET_Init: you must specify a number after -port");
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ static char *PR_GetTempString(void)
|
|||
return pr_string_temp[(STRINGTEMP_BUFFERS - 1) & ++pr_string_tempindex];
|
||||
}
|
||||
|
||||
#define RETURN_EDICT(e) (G_INT(GBL_RETURN) = EDICT_TO_PROG(e))
|
||||
#define RETURN_EDICT(e) (G_PEDICT(GBL_RETURN) = EDICT_TO_PROG(e))
|
||||
|
||||
#define MSG_BROADCAST 0 // unreliable to all
|
||||
#define MSG_ONE 1 // reliable to one (msg_entity)
|
||||
|
@ -94,7 +94,7 @@ static void PF_error(void)
|
|||
s = PF_VarString(0);
|
||||
Con_Printf("======SERVER ERROR in %s:\n%s\n",
|
||||
PR_GetString(pr_xfunction->s_name), s);
|
||||
ed = PROG_TO_EDICT(G_INT(GBL_self));
|
||||
ed = PROG_TO_EDICT(G_PEDICT(GBL_self));
|
||||
ED_Print(ed);
|
||||
|
||||
Host_Error("Program error");
|
||||
|
@ -118,7 +118,7 @@ static void PF_objerror(void)
|
|||
s = PF_VarString(0);
|
||||
Con_Printf("======OBJECT ERROR in %s:\n%s\n",
|
||||
PR_GetString(pr_xfunction->s_name), s);
|
||||
ed = PROG_TO_EDICT(G_INT(GBL_self));
|
||||
ed = PROG_TO_EDICT(G_PEDICT(GBL_self));
|
||||
ED_Print(ed);
|
||||
ED_Free(ed);
|
||||
|
||||
|
@ -714,9 +714,9 @@ static void PF_traceline(void)
|
|||
VectorCopy(trace.plane.normal, G_VECTOR(GBL_trace_plane_normal));
|
||||
G_FLOAT(GBL_trace_plane_dist) = trace.plane.dist;
|
||||
if(trace.ent)
|
||||
G_INT(GBL_trace_ent) = EDICT_TO_PROG(trace.ent);
|
||||
G_PEDICT(GBL_trace_ent) = EDICT_TO_PROG(trace.ent);
|
||||
else
|
||||
G_INT(GBL_trace_ent) = EDICT_TO_PROG(sv.edicts);
|
||||
G_PEDICT(GBL_trace_ent) = EDICT_TO_PROG(sv.edicts);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
|
@ -824,7 +824,7 @@ static void PF_checkclient(void)
|
|||
}
|
||||
|
||||
// if current entity can't possibly see the check entity, return 0
|
||||
self = PROG_TO_EDICT(G_INT(GBL_self));
|
||||
self = PROG_TO_EDICT(G_PEDICT(GBL_self));
|
||||
VectorAdd(ED_VECTOR(self, ED_origin), ED_VECTOR(self, ED_view_ofs), view);
|
||||
leaf = Mod_PointInLeaf(view, sv.worldmodel);
|
||||
l = (leaf - sv.worldmodel->leafs) - 1;
|
||||
|
@ -953,7 +953,7 @@ static void PF_findradius(void)
|
|||
if(VectorLength(eorg) > rad)
|
||||
continue;
|
||||
|
||||
ED_INT(ent, ED_chain) = EDICT_TO_PROG(chain);
|
||||
ED_PEDICT(ent, ED_chain) = EDICT_TO_PROG(chain);
|
||||
chain = ent;
|
||||
}
|
||||
|
||||
|
@ -981,7 +981,7 @@ static void PF_ftos(void)
|
|||
sprintf(s, "%" PRIi32 "", (int32_t)v);
|
||||
else
|
||||
sprintf(s, "%5.1f", v);
|
||||
G_INT(GBL_RETURN) = PR_SetEngineString(s);
|
||||
G_RSTRING(GBL_RETURN) = PR_SetEngineString(s);
|
||||
}
|
||||
|
||||
static void PF_fabs(void)
|
||||
|
@ -997,7 +997,7 @@ static void PF_vtos(void)
|
|||
|
||||
s = PR_GetTempString();
|
||||
sprintf(s, "'%5.1f %5.1f %5.1f'", G_VECTOR(GBL_PARM0)[0], G_VECTOR(GBL_PARM0)[1], G_VECTOR(GBL_PARM0)[2]);
|
||||
G_INT(GBL_RETURN) = PR_SetEngineString(s);
|
||||
G_RSTRING(GBL_RETURN) = PR_SetEngineString(s);
|
||||
}
|
||||
|
||||
static void PF_spawn(void)
|
||||
|
@ -1022,12 +1022,12 @@ static void PF_remove(void)
|
|||
static void PF_find(void)
|
||||
{
|
||||
int32_t e;
|
||||
int32_t f;
|
||||
pfield_t f;
|
||||
const char *s, *t;
|
||||
edict_t *ed;
|
||||
|
||||
e = G_EDICTNUM(GBL_PARM0);
|
||||
f = G_INT(GBL_PARM1);
|
||||
f = G_PFIELD(GBL_PARM1);
|
||||
s = G_STRING(GBL_PARM2);
|
||||
if(!s)
|
||||
PR_RunError("PF_find: bad search string");
|
||||
|
@ -1037,7 +1037,7 @@ static void PF_find(void)
|
|||
ed = EDICT_NUM(e);
|
||||
if(ed->free)
|
||||
continue;
|
||||
t = PR_GetString(ED_RSTRING(ed, f));
|
||||
t = ED_STRING(ed, f);
|
||||
if(!t)
|
||||
continue;
|
||||
if(!strcmp(t, s))
|
||||
|
@ -1059,7 +1059,7 @@ static void PR_CheckEmptyString(const char *s)
|
|||
static void PF_precache_file(void)
|
||||
{
|
||||
// precache_file is only used to copy files with qcc, it does nothing
|
||||
G_INT(GBL_RETURN) = G_INT(GBL_PARM0);
|
||||
G_RSTRING(GBL_RETURN) = G_RSTRING(GBL_PARM0);
|
||||
}
|
||||
|
||||
static void PF_precache_sound(void)
|
||||
|
@ -1071,7 +1071,7 @@ static void PF_precache_sound(void)
|
|||
PR_RunError("PF_Precache_*: Precache can only be done in spawn functions");
|
||||
|
||||
s = G_STRING(GBL_PARM0);
|
||||
G_INT(GBL_RETURN) = G_INT(GBL_PARM0);
|
||||
G_RSTRING(GBL_RETURN) = G_RSTRING(GBL_PARM0);
|
||||
PR_CheckEmptyString(s);
|
||||
|
||||
for(i = 0; i < MAX_SOUNDS; i++)
|
||||
|
@ -1096,7 +1096,7 @@ static void PF_precache_model(void)
|
|||
PR_RunError("PF_Precache_*: Precache can only be done in spawn functions");
|
||||
|
||||
s = G_STRING(GBL_PARM0);
|
||||
G_INT(GBL_RETURN) = G_INT(GBL_PARM0);
|
||||
G_RSTRING(GBL_RETURN) = G_RSTRING(GBL_PARM0);
|
||||
PR_CheckEmptyString(s);
|
||||
|
||||
for(i = 0; i < MAX_MODELS; i++)
|
||||
|
@ -1149,7 +1149,7 @@ static void PF_walkmove(void)
|
|||
dfunction_t *oldf;
|
||||
int32_t oldself;
|
||||
|
||||
ent = PROG_TO_EDICT(G_INT(GBL_self));
|
||||
ent = PROG_TO_EDICT(G_PEDICT(GBL_self));
|
||||
yaw = G_FLOAT(GBL_PARM0);
|
||||
dist = G_FLOAT(GBL_PARM1);
|
||||
|
||||
|
@ -1167,14 +1167,14 @@ static void PF_walkmove(void)
|
|||
|
||||
// save program state, because SV_movestep may call other functions
|
||||
oldf = pr_xfunction;
|
||||
oldself = G_INT(GBL_self);
|
||||
oldself = G_PEDICT(GBL_self);
|
||||
|
||||
G_FLOAT(GBL_RETURN) = SV_movestep(ent, move, true);
|
||||
|
||||
|
||||
// restore program state
|
||||
pr_xfunction = oldf;
|
||||
G_INT(GBL_self) = oldself;
|
||||
G_PEDICT(GBL_self) = oldself;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1190,7 +1190,7 @@ static void PF_droptofloor(void)
|
|||
vec3_t end;
|
||||
trace_t trace;
|
||||
|
||||
ent = PROG_TO_EDICT(G_INT(GBL_self));
|
||||
ent = PROG_TO_EDICT(G_PEDICT(GBL_self));
|
||||
|
||||
VectorCopy(ED_VECTOR(ent, ED_origin), end);
|
||||
end[2] -= 256;
|
||||
|
@ -1204,7 +1204,7 @@ static void PF_droptofloor(void)
|
|||
VectorCopy(trace.endpos, ED_VECTOR(ent, ED_origin));
|
||||
SV_LinkEdict(ent, false);
|
||||
ED_FLOAT(ent, ED_flags) = (int32_t)ED_FLOAT(ent, ED_flags) | FL_ONGROUND;
|
||||
ED_INT(ent, ED_groundentity) = EDICT_TO_PROG(trace.ent);
|
||||
ED_PEDICT(ent, ED_groundentity) = EDICT_TO_PROG(trace.ent);
|
||||
G_FLOAT(GBL_RETURN) = 1;
|
||||
}
|
||||
}
|
||||
|
@ -1422,7 +1422,7 @@ void PF_changeyaw(void)
|
|||
edict_t *ent;
|
||||
float ideal, current, move, speed;
|
||||
|
||||
ent = PROG_TO_EDICT(G_INT(GBL_self));
|
||||
ent = PROG_TO_EDICT(G_PEDICT(GBL_self));
|
||||
current = anglemod(ED_VECTOR(ent, ED_angles)[1]);
|
||||
ideal = ED_FLOAT(ent, ED_ideal_yaw);
|
||||
speed = ED_FLOAT(ent, ED_yaw_speed);
|
||||
|
@ -1475,7 +1475,7 @@ static sizebuf_t *WriteDest(void)
|
|||
return &sv.datagram;
|
||||
|
||||
case MSG_ONE:
|
||||
ent = PROG_TO_EDICT(G_INT(GBL_msg_entity));
|
||||
ent = PROG_TO_EDICT(G_PEDICT(GBL_msg_entity));
|
||||
entnum = NUM_FOR_EDICT(ent);
|
||||
if(entnum < 1 || entnum > svs.maxclients)
|
||||
PR_RunError("WriteDest: not a client");
|
||||
|
@ -1556,7 +1556,7 @@ static void PF_makestatic(void)
|
|||
//johnfitz -- PROTOCOL_FITZQUAKE
|
||||
if(sv.protocol == PROTOCOL_NETQUAKE)
|
||||
{
|
||||
if(SV_ModelIndex(PR_GetString(ED_RSTRING(ent, ED_model))) & 0xFF00 || (int32_t)(ED_FLOAT(ent, ED_frame)) & 0xFF00)
|
||||
if(SV_ModelIndex(ED_STRING(ent, ED_model)) & 0xFF00 || (int32_t)(ED_FLOAT(ent, ED_frame)) & 0xFF00)
|
||||
{
|
||||
ED_Free(ent);
|
||||
return; //can't display the correct model & frame, so don't show it at all
|
||||
|
@ -1564,7 +1564,7 @@ static void PF_makestatic(void)
|
|||
}
|
||||
else
|
||||
{
|
||||
if(SV_ModelIndex(PR_GetString(ED_RSTRING(ent, ED_model))) & 0xFF00)
|
||||
if(SV_ModelIndex(ED_STRING(ent, ED_model)) & 0xFF00)
|
||||
bits |= B_LARGEMODEL;
|
||||
if((int32_t)(ED_FLOAT(ent, ED_frame)) & 0xFF00)
|
||||
bits |= B_LARGEFRAME;
|
||||
|
@ -1581,9 +1581,9 @@ static void PF_makestatic(void)
|
|||
MSG_WriteByte(&sv.signon, svc_spawnstatic);
|
||||
|
||||
if(bits & B_LARGEMODEL)
|
||||
MSG_WriteShort(&sv.signon, SV_ModelIndex(PR_GetString(ED_RSTRING(ent, ED_model))));
|
||||
MSG_WriteShort(&sv.signon, SV_ModelIndex(ED_STRING(ent, ED_model)));
|
||||
else
|
||||
MSG_WriteByte(&sv.signon, SV_ModelIndex(PR_GetString(ED_RSTRING(ent, ED_model))));
|
||||
MSG_WriteByte(&sv.signon, SV_ModelIndex(ED_STRING(ent, ED_model)));
|
||||
|
||||
if(bits & B_LARGEFRAME)
|
||||
MSG_WriteShort(&sv.signon, ED_FLOAT(ent, ED_frame));
|
||||
|
|
328
source/pr_comp.h
328
source/pr_comp.h
|
@ -1,328 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 1996-2001 Id Software, Inc.
|
||||
Copyright (C) 2010-2014 QuakeSpasm developers
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef spingle__pr_comp_h
|
||||
#define spingle__pr_comp_h
|
||||
|
||||
enum
|
||||
{
|
||||
GBL_NULL,
|
||||
GBL_RETURN,
|
||||
GBL_PARM0 = GBL_RETURN + 3,
|
||||
GBL_PARM1 = GBL_PARM0 + 3,
|
||||
GBL_PARM2 = GBL_PARM1 + 3,
|
||||
GBL_PARM3 = GBL_PARM2 + 3,
|
||||
GBL_PARM4 = GBL_PARM3 + 3,
|
||||
GBL_PARM5 = GBL_PARM4 + 3,
|
||||
GBL_PARM6 = GBL_PARM5 + 3,
|
||||
GBL_PARM7 = GBL_PARM6 + 3,
|
||||
GBL_self = 28,
|
||||
GBL_other,
|
||||
GBL_world,
|
||||
GBL_time,
|
||||
GBL_frametime,
|
||||
GBL_force_retouch,
|
||||
GBL_mapname,
|
||||
GBL_deathmatch,
|
||||
GBL_coop,
|
||||
GBL_teamplay,
|
||||
GBL_serverflags,
|
||||
GBL_total_secrets,
|
||||
GBL_total_monsters,
|
||||
GBL_found_secrets,
|
||||
GBL_killed_monsters,
|
||||
GBL_parm1,
|
||||
GBL_parm2,
|
||||
GBL_parm3,
|
||||
GBL_parm4,
|
||||
GBL_parm5,
|
||||
GBL_parm6,
|
||||
GBL_parm7,
|
||||
GBL_parm8,
|
||||
GBL_parm9,
|
||||
GBL_parm10,
|
||||
GBL_parm11,
|
||||
GBL_parm12,
|
||||
GBL_parm13,
|
||||
GBL_parm14,
|
||||
GBL_parm15,
|
||||
GBL_parm16,
|
||||
GBL_v_forward,
|
||||
GBL_v_up = GBL_v_forward + 3,
|
||||
GBL_v_right = GBL_v_up + 3,
|
||||
GBL_trace_allsolid = GBL_v_right + 3,
|
||||
GBL_trace_startsolid,
|
||||
GBL_trace_fraction,
|
||||
GBL_trace_endpos,
|
||||
GBL_trace_plane_normal = GBL_trace_endpos + 3,
|
||||
GBL_trace_plane_dist = GBL_trace_plane_normal + 3,
|
||||
GBL_trace_ent,
|
||||
GBL_trace_inopen,
|
||||
GBL_trace_inwater,
|
||||
GBL_msg_entity,
|
||||
GBL_main,
|
||||
GBL_StartFrame,
|
||||
GBL_PlayerPreThink,
|
||||
GBL_PlayerPostThink,
|
||||
GBL_ClientKill,
|
||||
GBL_ClientConnect,
|
||||
GBL_PutClientInServer,
|
||||
GBL_ClientDisconnect,
|
||||
GBL_SetNewParms,
|
||||
GBL_SetChangeParms,
|
||||
GBL_SYSTEM_END,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
ED_modelindex,
|
||||
ED_absmin,
|
||||
ED_absmax = ED_absmin + 3,
|
||||
ED_ltime = ED_absmax + 3,
|
||||
ED_movetype,
|
||||
ED_solid,
|
||||
ED_origin,
|
||||
ED_oldorigin = ED_origin + 3,
|
||||
ED_velocity = ED_oldorigin + 3,
|
||||
ED_angles = ED_velocity + 3,
|
||||
ED_avelocity = ED_angles + 3,
|
||||
ED_punchangle = ED_avelocity + 3,
|
||||
ED_classname = ED_punchangle + 3,
|
||||
ED_model,
|
||||
ED_frame,
|
||||
ED_skin,
|
||||
ED_effects,
|
||||
ED_mins,
|
||||
ED_maxs = ED_mins + 3,
|
||||
ED_size = ED_maxs + 3,
|
||||
ED_touch = ED_size + 3,
|
||||
ED_use,
|
||||
ED_think,
|
||||
ED_blocked,
|
||||
ED_nextthink,
|
||||
ED_groundentity,
|
||||
ED_health,
|
||||
ED_frags,
|
||||
ED_weapon,
|
||||
ED_weaponmodel,
|
||||
ED_weaponframe,
|
||||
ED_currentammo,
|
||||
ED_ammo_shells,
|
||||
ED_ammo_nails,
|
||||
ED_ammo_rockets,
|
||||
ED_ammo_cells,
|
||||
ED_items,
|
||||
ED_takedamage,
|
||||
ED_chain,
|
||||
ED_deadflag,
|
||||
ED_view_ofs,
|
||||
ED_button0 = ED_view_ofs + 3,
|
||||
ED_button1,
|
||||
ED_button2,
|
||||
ED_impulse,
|
||||
ED_fixangle,
|
||||
ED_v_angle,
|
||||
ED_idealpitch = ED_v_angle + 3,
|
||||
ED_netname,
|
||||
ED_enemy,
|
||||
ED_flags,
|
||||
ED_colormap,
|
||||
ED_team,
|
||||
ED_max_health,
|
||||
ED_teleport_time,
|
||||
ED_armortype,
|
||||
ED_armorvalue,
|
||||
ED_waterlevel,
|
||||
ED_watertype,
|
||||
ED_ideal_yaw,
|
||||
ED_yaw_speed,
|
||||
ED_aiment,
|
||||
ED_goalentity,
|
||||
ED_spawnflags,
|
||||
ED_target,
|
||||
ED_targetname,
|
||||
ED_dmg_take,
|
||||
ED_dmg_save,
|
||||
ED_dmg_inflictor,
|
||||
ED_owner,
|
||||
ED_movedir,
|
||||
ED_message = ED_movedir + 3,
|
||||
ED_sounds,
|
||||
ED_noise,
|
||||
ED_noise1,
|
||||
ED_noise2,
|
||||
ED_noise3,
|
||||
};
|
||||
|
||||
#define DEF_SAVEGLOBAL (1 << 15)
|
||||
|
||||
#define PROG_VERSION 6
|
||||
|
||||
typedef int32_t func_t;
|
||||
typedef int32_t string_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ev_bad = -1,
|
||||
ev_void = 0,
|
||||
ev_string,
|
||||
ev_float,
|
||||
ev_vector,
|
||||
ev_entity,
|
||||
ev_field,
|
||||
ev_function,
|
||||
ev_pointer
|
||||
} etype_t;
|
||||
|
||||
enum
|
||||
{
|
||||
OP_DONE,
|
||||
OP_MUL_F,
|
||||
OP_MUL_V,
|
||||
OP_MUL_FV,
|
||||
OP_MUL_VF,
|
||||
OP_DIV_F,
|
||||
OP_ADD_F,
|
||||
OP_ADD_V,
|
||||
OP_SUB_F,
|
||||
OP_SUB_V,
|
||||
|
||||
OP_EQ_F,
|
||||
OP_EQ_V,
|
||||
OP_EQ_S,
|
||||
OP_EQ_E,
|
||||
OP_EQ_FNC,
|
||||
|
||||
OP_NE_F,
|
||||
OP_NE_V,
|
||||
OP_NE_S,
|
||||
OP_NE_E,
|
||||
OP_NE_FNC,
|
||||
|
||||
OP_LE,
|
||||
OP_GE,
|
||||
OP_LT,
|
||||
OP_GT,
|
||||
|
||||
OP_LOAD_F,
|
||||
OP_LOAD_V,
|
||||
OP_LOAD_S,
|
||||
OP_LOAD_ENT,
|
||||
OP_LOAD_FLD,
|
||||
OP_LOAD_FNC,
|
||||
|
||||
OP_ADDRESS,
|
||||
|
||||
OP_STORE_F,
|
||||
OP_STORE_V,
|
||||
OP_STORE_S,
|
||||
OP_STORE_ENT,
|
||||
OP_STORE_FLD,
|
||||
OP_STORE_FNC,
|
||||
|
||||
OP_STOREP_F,
|
||||
OP_STOREP_V,
|
||||
OP_STOREP_S,
|
||||
OP_STOREP_ENT,
|
||||
OP_STOREP_FLD,
|
||||
OP_STOREP_FNC,
|
||||
|
||||
OP_RETURN,
|
||||
OP_NOT_F,
|
||||
OP_NOT_V,
|
||||
OP_NOT_S,
|
||||
OP_NOT_ENT,
|
||||
OP_NOT_FNC,
|
||||
OP_IF,
|
||||
OP_IFNOT,
|
||||
OP_CALL0,
|
||||
OP_CALL1,
|
||||
OP_CALL2,
|
||||
OP_CALL3,
|
||||
OP_CALL4,
|
||||
OP_CALL5,
|
||||
OP_CALL6,
|
||||
OP_CALL7,
|
||||
OP_CALL8,
|
||||
OP_STATE,
|
||||
OP_GOTO,
|
||||
OP_AND,
|
||||
OP_OR,
|
||||
|
||||
OP_BITAND,
|
||||
OP_BITOR
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t op;
|
||||
int16_t a, b, c;
|
||||
} dstatement_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t type; /* if DEF_SAVEGLOBAL bit is set the variable needs to be saved in savegames */
|
||||
uint16_t ofs;
|
||||
int32_t s_name;
|
||||
} ddef_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int32_t first_statement; // negative numbers are builtins
|
||||
int32_t parm_start;
|
||||
int32_t locals; // total ints of parms + locals
|
||||
|
||||
int32_t profile; // runtime
|
||||
|
||||
int32_t s_name;
|
||||
int32_t s_file; // source file defined in
|
||||
|
||||
int32_t numparms;
|
||||
byte parm_size[8];
|
||||
} dfunction_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int32_t version;
|
||||
int32_t crc; // check of header file
|
||||
|
||||
int32_t ofs_statements;
|
||||
int32_t numstatements; // statement 0 is an error
|
||||
|
||||
int32_t ofs_globaldefs;
|
||||
int32_t numglobaldefs;
|
||||
|
||||
int32_t ofs_fielddefs;
|
||||
int32_t numfielddefs;
|
||||
|
||||
int32_t ofs_functions;
|
||||
int32_t numfunctions; // function 0 is an empty
|
||||
|
||||
int32_t ofs_strings;
|
||||
int32_t numstrings; // first string is a null string
|
||||
|
||||
int32_t ofs_globals;
|
||||
int32_t numglobals;
|
||||
|
||||
int32_t entityfields;
|
||||
} dprograms_t;
|
||||
|
||||
#endif
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
Copyright (C) 1996-2001 Id Software, Inc.
|
||||
Copyright (C) 2002-2009 John Fitzgibbons and others
|
||||
Copyright (C) 2010-2014 QuakeSpasm developers
|
||||
Copyright (C) 2019 Alison G. Watson
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef spingle__pr_defs_h
|
||||
#define spingle__pr_defs_h
|
||||
|
||||
enum
|
||||
{
|
||||
DEF_SAVEGLOBAL = 1 << 15
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ev_bad = -1,
|
||||
ev_void = 0,
|
||||
ev_string,
|
||||
ev_float,
|
||||
ev_vector,
|
||||
ev_entity,
|
||||
ev_field,
|
||||
ev_function,
|
||||
ev_pointer
|
||||
} etype_t;
|
||||
|
||||
typedef int32_t func_t;
|
||||
typedef int32_t string_t;
|
||||
typedef uint32_t pedict_t;
|
||||
typedef uint32_t pfield_t;
|
||||
typedef uint32_t prptr_t;
|
||||
typedef void (*builtin_t)(void);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t type; /* if DEF_SAVEGLOBAL bit is set the variable needs to be saved in savegames */
|
||||
uint16_t ofs;
|
||||
int32_t s_name;
|
||||
} ddef_t;
|
||||
|
||||
typedef union eval_s
|
||||
{
|
||||
float flt;
|
||||
vec3_t vec;
|
||||
func_t func;
|
||||
int32_t _int;
|
||||
pedict_t edict;
|
||||
pfield_t field;
|
||||
string_t string;
|
||||
prptr_t ptr;
|
||||
} eval_t;
|
||||
|
||||
#endif
|
|
@ -256,7 +256,7 @@ eval_t *GetEdictFieldValue(edict_t *ed, const char *field)
|
|||
if(!strcmp(field, gefvCache[i].field))
|
||||
{
|
||||
def = gefvCache[i].pcache;
|
||||
goto Done;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -269,7 +269,7 @@ eval_t *GetEdictFieldValue(edict_t *ed, const char *field)
|
|||
rep ^= 1;
|
||||
}
|
||||
|
||||
Done:
|
||||
done:
|
||||
if(!def)
|
||||
return NULL;
|
||||
|
||||
|
@ -311,7 +311,6 @@ void ED_Print(edict_t *ed)
|
|||
|
||||
// if the value is still all 0, skip the field
|
||||
type = d->type & ~DEF_SAVEGLOBAL;
|
||||
|
||||
for(j = 0; j < type_size[type]; j++)
|
||||
{
|
||||
if(v[j])
|
||||
|
@ -421,7 +420,7 @@ static void ED_PrintEdict_f(void)
|
|||
if(!sv.active)
|
||||
return;
|
||||
|
||||
i = Q_atoi(Cmd_Argv(1));
|
||||
i = atoi(Cmd_Argv(1));
|
||||
if(i < 0 || i >= sv.num_edicts)
|
||||
{
|
||||
Con_Printf("Bad edict number\n");
|
||||
|
@ -588,9 +587,6 @@ static string_t ED_NewString(const char *string)
|
|||
/*
|
||||
=============
|
||||
ED_ParseEval
|
||||
|
||||
Can parse either fields or globals
|
||||
returns false if error
|
||||
=============
|
||||
*/
|
||||
bool ED_ParseEpair(void *base, ddef_t *key, const char *s)
|
||||
|
@ -648,7 +644,7 @@ bool ED_ParseEpair(void *base, ddef_t *key, const char *s)
|
|||
def = ED_FindField(s);
|
||||
if(!def)
|
||||
{
|
||||
//johnfitz -- HACK -- suppress error becuase fog/sky fields might not be mentioned in defs.qc
|
||||
//johnfitz -- HACK -- suppress error becuase fog/sky might not be mentioned in defs.qc
|
||||
if(strncmp(s, "sky", 3) && strcmp(s, "fog"))
|
||||
Con_DPrintf("Can't find field %s\n", s);
|
||||
return false;
|
||||
|
@ -751,7 +747,7 @@ const char *ED_ParseEdict(const char *data, edict_t *ent)
|
|||
key = ED_FindField(keyname);
|
||||
if(!key)
|
||||
{
|
||||
//johnfitz -- HACK -- suppress error becuase fog/sky/alpha fields might not be mentioned in defs.qc
|
||||
//johnfitz -- HACK -- suppress error becuase fog/sky/alpha might not be mentioned in defs.qc
|
||||
if(strncmp(keyname, "sky", 3) && strcmp(keyname, "fog") && strcmp(keyname, "alpha"))
|
||||
Con_DPrintf("\"%s\" is not a field\n", keyname); //johnfitz -- was Con_Printf
|
||||
continue;
|
||||
|
@ -845,7 +841,7 @@ void ED_LoadFromFile(const char *data)
|
|||
}
|
||||
|
||||
// look for the spawn function
|
||||
func = ED_FindFunction(PR_GetString(ED_RSTRING(ent, ED_classname)));
|
||||
func = ED_FindFunction(ED_STRING(ent, ED_classname));
|
||||
|
||||
if(!func)
|
||||
{
|
||||
|
@ -855,7 +851,7 @@ void ED_LoadFromFile(const char *data)
|
|||
continue;
|
||||
}
|
||||
|
||||
G_INT(GBL_self) = EDICT_TO_PROG(ent);
|
||||
G_PEDICT(GBL_self) = EDICT_TO_PROG(ent);
|
||||
PR_ExecuteProgram(func - pr_functions);
|
||||
}
|
||||
|
||||
|
@ -882,17 +878,28 @@ edict_t *EDICT_NUM(int32_t n)
|
|||
{
|
||||
if(n < 0 || n >= sv.max_edicts)
|
||||
Host_Error("EDICT_NUM: bad number %" PRIi32 "", n);
|
||||
return (edict_t *)((byte *)sv.edicts + (n) * pr_edict_size);
|
||||
return PROG_TO_EDICT(n * pr_edict_size);
|
||||
}
|
||||
|
||||
int32_t NUM_FOR_EDICT(edict_t *e)
|
||||
{
|
||||
int32_t b;
|
||||
int32_t b;
|
||||
|
||||
b = (byte *)e - (byte *)sv.edicts;
|
||||
b = EDICT_TO_PROG(e);
|
||||
b = b / pr_edict_size;
|
||||
|
||||
if(b < 0 || b >= sv.num_edicts)
|
||||
Host_Error("NUM_FOR_EDICT: bad pointer");
|
||||
return b;
|
||||
}
|
||||
|
||||
pedict_t EDICT_TO_PROG(void *e)
|
||||
{
|
||||
return (byte *)e - (byte *)sv.edicts;
|
||||
}
|
||||
|
||||
void *PROG_TO_EDICT(pedict_t e)
|
||||
{
|
||||
return (byte *)sv.edicts + e;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,183 @@
|
|||
/*
|
||||
Copyright (C) 1996-2001 Id Software, Inc.
|
||||
Copyright (C) 2002-2009 John Fitzgibbons and others
|
||||
Copyright (C) 2010-2014 QuakeSpasm developers
|
||||
Copyright (C) 2019 Alison G. Watson
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef spingle__pr_edict_h
|
||||
#define spingle__pr_edict_h
|
||||
|
||||
#define EDICT_FROM_AREA(l) (edict_t *)((byte *)(l) - offsetof(edict_t, area))
|
||||
|
||||
#define ED_FLOAT(e, o) (((float *)((edict_t *)e)->fields)[o])
|
||||
#define ED_INT(e, o) (((int32_t *)((edict_t *)e)->fields)[o])
|
||||
#define ED_EDICT(e, o) PROG_TO_EDICT(ED_INT(e, o))
|
||||
#define ED_EDICTNUM(e, o) NUM_FOR_EDICT(ED_EDICT(e, o))
|
||||
#define ED_VECTOR(e, o) (&ED_FLOAT(e, o))
|
||||
#define ED_STRING(e, o) PR_GetString(ED_RSTRING(e, o))
|
||||
#define ED_RSTRING(e, o) (*(string_t *)&ED_INT(e, o))
|
||||
#define ED_FUNC(e, o) (*(func_t *)&ED_INT(e, o))
|
||||
#define ED_PEDICT(e, o) (*(pedict_t *)&ED_INT(e, o))
|
||||
#define ED_PFIELD(e, o) (*(pfield_t *)&ED_INT(e, o))
|
||||
#define ED_EVAL(e, o) ((eval_t *)&ED_INT(e, o))
|
||||
#define ED_VOID(e, o) ((void *)&ED_INT(o))
|
||||
|
||||
enum
|
||||
{
|
||||
MAX_ENT_LEAFS = 32
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
ED_modelindex,
|
||||
ED_absmin,
|
||||
ED_absmax = ED_absmin + 3,
|
||||
ED_ltime = ED_absmax + 3,
|
||||
ED_movetype,
|
||||
ED_solid,
|
||||
ED_origin,
|
||||
ED_oldorigin = ED_origin + 3,
|
||||
ED_velocity = ED_oldorigin + 3,
|
||||
ED_angles = ED_velocity + 3,
|
||||
ED_avelocity = ED_angles + 3,
|
||||
ED_punchangle = ED_avelocity + 3,
|
||||
ED_classname = ED_punchangle + 3,
|
||||
ED_model,
|
||||
ED_frame,
|
||||
ED_skin,
|
||||
ED_effects,
|
||||
ED_mins,
|
||||
ED_maxs = ED_mins + 3,
|
||||
ED_size = ED_maxs + 3,
|
||||
ED_touch = ED_size + 3,
|
||||
ED_use,
|
||||
ED_think,
|
||||
ED_blocked,
|
||||
ED_nextthink,
|
||||
ED_groundentity,
|
||||
ED_health,
|
||||
ED_frags,
|
||||
ED_weapon,
|
||||
ED_weaponmodel,
|
||||
ED_weaponframe,
|
||||
ED_currentammo,
|
||||
ED_ammo_shells,
|
||||
ED_ammo_nails,
|
||||
ED_ammo_rockets,
|
||||
ED_ammo_cells,
|
||||
ED_items,
|
||||
ED_takedamage,
|
||||
ED_chain,
|
||||
ED_deadflag,
|
||||
ED_view_ofs,
|
||||
ED_button0 = ED_view_ofs + 3,
|
||||
ED_button1,
|
||||
ED_button2,
|
||||
ED_impulse,
|
||||
ED_fixangle,
|
||||
ED_v_angle,
|
||||
ED_idealpitch = ED_v_angle + 3,
|
||||
ED_netname,
|
||||
ED_enemy,
|
||||
ED_flags,
|
||||
ED_colormap,
|
||||
ED_team,
|
||||
ED_max_health,
|
||||
ED_teleport_time,
|
||||
ED_armortype,
|
||||
ED_armorvalue,
|
||||
ED_waterlevel,
|
||||
ED_watertype,
|
||||
ED_ideal_yaw,
|
||||
ED_yaw_speed,
|
||||
ED_aiment,
|
||||
ED_goalentity,
|
||||
ED_spawnflags,
|
||||
ED_target,
|
||||
ED_targetname,
|
||||
ED_dmg_take,
|
||||
ED_dmg_save,
|
||||
ED_dmg_inflictor,
|
||||
ED_owner,
|
||||
ED_movedir,
|
||||
ED_message = ED_movedir + 3,
|
||||
ED_sounds,
|
||||
ED_noise,
|
||||
ED_noise1,
|
||||
ED_noise2,
|
||||
ED_noise3,
|
||||
ED_SYSTEM_END,
|
||||
};
|
||||
|
||||
typedef struct edict_s
|
||||
{
|
||||
bool free;
|
||||
link_t area; /* linked to a division node or leaf */
|
||||
|
||||
int32_t num_leafs;
|
||||
int32_t leafnums[MAX_ENT_LEAFS];
|
||||
|
||||
entity_state_t baseline;
|
||||
uint8_t alpha;
|
||||
bool sendinterval; /* johnfitz -- send time until nextthink to client for better lerp timing */
|
||||
|
||||
float freetime; /* sv.time when the object was freed */
|
||||
|
||||
byte fields[];
|
||||
} edict_t;
|
||||
|
||||
extern ddef_t *pr_fielddefs;
|
||||
extern int32_t pr_edict_size;
|
||||
|
||||
edict_t *ED_Alloc(void);
|
||||
void ED_Free(edict_t *ed);
|
||||
|
||||
void ED_Print(edict_t *ed);
|
||||
void ED_Write(FILE *f, edict_t *ed);
|
||||
const char *ED_ParseEdict(const char *data, edict_t *ent);
|
||||
|
||||
void ED_WriteGlobals(FILE *f);
|
||||
const char *ED_ParseGlobals(const char *data);
|
||||
|
||||
void ED_LoadFromFile(const char *data);
|
||||
|
||||
ddef_t *ED_GlobalAtOfs(int32_t ofs);
|
||||
ddef_t *ED_FieldAtOfs(int32_t ofs);
|
||||
bool ED_ParseEpair(void *base, ddef_t *key, const char *s);
|
||||
|
||||
void ED_Init(void);
|
||||
void ED_Load(void);
|
||||
|
||||
void ED_PrintEdicts(void);
|
||||
void ED_PrintNum(int32_t ent);
|
||||
|
||||
eval_t *GetEdictFieldValue(edict_t *ed, const char *field);
|
||||
|
||||
static inline edict_t *NEXT_EDICT(edict_t *e)
|
||||
{
|
||||
return (edict_t *)((byte *)e + pr_edict_size);
|
||||
}
|
||||
|
||||
pedict_t EDICT_TO_PROG(void *e);
|
||||
void *PROG_TO_EDICT(pedict_t e);
|
||||
edict_t *EDICT_NUM(int32_t n);
|
||||
int32_t NUM_FOR_EDICT(edict_t *e);
|
||||
|
||||
#endif
|
219
source/pr_exec.c
219
source/pr_exec.c
|
@ -142,7 +142,7 @@ PR_PrintStatement
|
|||
*/
|
||||
static void PR_PrintStatement(dstatement_t *s)
|
||||
{
|
||||
int32_t i;
|
||||
size_t i;
|
||||
|
||||
if((uint32_t)s->op < arraysizeof(pr_opnames))
|
||||
{
|
||||
|
@ -350,13 +350,8 @@ PR_ExecuteProgram
|
|||
The interpretation main loop
|
||||
====================
|
||||
*/
|
||||
#define OPA G_EVAL((uint16_t)st->a)
|
||||
#define OPB G_EVAL((uint16_t)st->b)
|
||||
#define OPC G_EVAL((uint16_t)st->c)
|
||||
|
||||
void PR_ExecuteProgram(func_t fnum)
|
||||
{
|
||||
eval_t *ptr;
|
||||
dstatement_t *st;
|
||||
dfunction_t *f, *newf;
|
||||
int32_t profile, startprofile;
|
||||
|
@ -365,8 +360,8 @@ void PR_ExecuteProgram(func_t fnum)
|
|||
|
||||
if(!fnum || fnum >= progs.numfunctions)
|
||||
{
|
||||
if(G_INT(GBL_self))
|
||||
ED_Print(PROG_TO_EDICT(G_INT(GBL_self)));
|
||||
if(G_PEDICT(GBL_self))
|
||||
ED_Print(PROG_TO_EDICT(G_PEDICT(GBL_self)));
|
||||
Host_Error("PR_ExecuteProgram: NULL function");
|
||||
}
|
||||
|
||||
|
@ -396,141 +391,103 @@ void PR_ExecuteProgram(func_t fnum)
|
|||
|
||||
switch(st->op)
|
||||
{
|
||||
case OP_ADD_F:
|
||||
OPC->_float = OPA->_float + OPB->_float;
|
||||
break;
|
||||
case OP_ADD_V:
|
||||
OPC->vector[0] = OPA->vector[0] + OPB->vector[0];
|
||||
OPC->vector[1] = OPA->vector[1] + OPB->vector[1];
|
||||
OPC->vector[2] = OPA->vector[2] + OPB->vector[2];
|
||||
#define OPA G_EVAL((uint16_t)st->a)
|
||||
#define OPB G_EVAL((uint16_t)st->b)
|
||||
#define OPC G_EVAL((uint16_t)st->c)
|
||||
#define PTR ((eval_t *)PROG_TO_EDICT(OPB->edict))
|
||||
|
||||
#define MakeOpArithF(op, exp) \
|
||||
case op: \
|
||||
OPC->flt = OPA->flt exp OPB->flt; \
|
||||
break;
|
||||
|
||||
case OP_SUB_F:
|
||||
OPC->_float = OPA->_float - OPB->_float;
|
||||
break;
|
||||
case OP_SUB_V:
|
||||
OPC->vector[0] = OPA->vector[0] - OPB->vector[0];
|
||||
OPC->vector[1] = OPA->vector[1] - OPB->vector[1];
|
||||
OPC->vector[2] = OPA->vector[2] - OPB->vector[2];
|
||||
#define MakeOpArithV(op, exp) \
|
||||
case op: \
|
||||
OPC->vec[0] = OPA->vec[0] exp OPB->vec[0]; \
|
||||
OPC->vec[1] = OPA->vec[1] exp OPB->vec[1]; \
|
||||
OPC->vec[2] = OPA->vec[2] exp OPB->vec[2]; \
|
||||
break;
|
||||
|
||||
case OP_MUL_F:
|
||||
OPC->_float = OPA->_float * OPB->_float;
|
||||
break;
|
||||
case OP_MUL_V:
|
||||
OPC->_float = OPA->vector[0] * OPB->vector[0] +
|
||||
OPA->vector[1] * OPB->vector[1] +
|
||||
OPA->vector[2] * OPB->vector[2];
|
||||
break;
|
||||
case OP_MUL_FV:
|
||||
OPC->vector[0] = OPA->_float * OPB->vector[0];
|
||||
OPC->vector[1] = OPA->_float * OPB->vector[1];
|
||||
OPC->vector[2] = OPA->_float * OPB->vector[2];
|
||||
break;
|
||||
case OP_MUL_VF:
|
||||
OPC->vector[0] = OPB->_float * OPA->vector[0];
|
||||
OPC->vector[1] = OPB->_float * OPA->vector[1];
|
||||
OPC->vector[2] = OPB->_float * OPA->vector[2];
|
||||
#define MakeOpArithB(op, exp) \
|
||||
case op: \
|
||||
OPC->flt = (int32_t)OPA->flt exp (int32_t)OPB->flt; \
|
||||
break;
|
||||
|
||||
case OP_DIV_F:
|
||||
OPC->_float = OPA->_float / OPB->_float;
|
||||
break;
|
||||
MakeOpArithF(OP_ADD_F, +)
|
||||
MakeOpArithF(OP_SUB_F, -)
|
||||
MakeOpArithF(OP_MUL_F, *)
|
||||
MakeOpArithF(OP_DIV_F, /)
|
||||
|
||||
case OP_BITAND:
|
||||
OPC->_float = (int32_t)OPA->_float & (int32_t)OPB->_float;
|
||||
break;
|
||||
MakeOpArithV(OP_ADD_V, +)
|
||||
MakeOpArithV(OP_SUB_V, -)
|
||||
|
||||
case OP_BITOR:
|
||||
OPC->_float = (int32_t)OPA->_float | (int32_t)OPB->_float;
|
||||
break;
|
||||
MakeOpArithB(OP_BITAND, &)
|
||||
MakeOpArithB(OP_BITOR, |)
|
||||
|
||||
case OP_GE: OPC->_float = OPA->_float >= OPB->_float; break;
|
||||
case OP_LE: OPC->_float = OPA->_float <= OPB->_float; break;
|
||||
case OP_GT: OPC->_float = OPA->_float > OPB->_float; break;
|
||||
case OP_LT: OPC->_float = OPA->_float < OPB->_float; break;
|
||||
case OP_AND: OPC->_float = OPA->_float && OPB->_float; break;
|
||||
case OP_OR: OPC->_float = OPA->_float || OPB->_float; break;
|
||||
case OP_MUL_V: OPC->flt = DotProduct(OPA->vec, OPB->vec); break;
|
||||
case OP_MUL_FV: VectorScale(OPB->vec, OPA->flt, OPC->vec); break;
|
||||
case OP_MUL_VF: VectorScale(OPA->vec, OPB->flt, OPC->vec); break;
|
||||
|
||||
MakeOpArithF(OP_GE, >=)
|
||||
MakeOpArithF(OP_LE, <=)
|
||||
MakeOpArithF(OP_GT, >)
|
||||
MakeOpArithF(OP_LT, <)
|
||||
MakeOpArithF(OP_AND, &&)
|
||||
MakeOpArithF(OP_OR, ||)
|
||||
MakeOpArithF(OP_EQ_F, ==)
|
||||
MakeOpArithF(OP_NE_F, !=)
|
||||
|
||||
case OP_NOT_F:
|
||||
OPC->_float = !OPA->_float;
|
||||
OPC->flt = !OPA->flt;
|
||||
break;
|
||||
case OP_NOT_V:
|
||||
OPC->_float = !OPA->vector[0] && !OPA->vector[1] && !OPA->vector[2];
|
||||
OPC->flt = !OPA->vec[0] && !OPA->vec[1] && !OPA->vec[2];
|
||||
break;
|
||||
case OP_NOT_S:
|
||||
OPC->_float = !OPA->string || !*PR_GetString(OPA->string);
|
||||
OPC->flt = !OPA->string || !*PR_GetString(OPA->string);
|
||||
break;
|
||||
case OP_NOT_FNC:
|
||||
OPC->_float = !OPA->function;
|
||||
OPC->flt = !OPA->func;
|
||||
break;
|
||||
case OP_NOT_ENT:
|
||||
OPC->_float = (PROG_TO_EDICT(OPA->edict) == sv.edicts);
|
||||
OPC->flt = PROG_TO_EDICT(OPA->edict) == sv.edicts;
|
||||
break;
|
||||
|
||||
case OP_EQ_F:
|
||||
OPC->_float = OPA->_float == OPB->_float;
|
||||
break;
|
||||
case OP_EQ_V:
|
||||
OPC->_float = (OPA->vector[0] == OPB->vector[0]) &&
|
||||
(OPA->vector[1] == OPB->vector[1]) &&
|
||||
(OPA->vector[2] == OPB->vector[2]);
|
||||
OPC->flt = OPA->vec[0] == OPB->vec[0] &&
|
||||
OPA->vec[1] == OPB->vec[1] &&
|
||||
OPA->vec[2] == OPB->vec[2];
|
||||
break;
|
||||
case OP_EQ_S:
|
||||
OPC->_float = !strcmp(PR_GetString(OPA->string), PR_GetString(OPB->string));
|
||||
break;
|
||||
case OP_EQ_E:
|
||||
OPC->_float = OPA->_int == OPB->_int;
|
||||
break;
|
||||
case OP_EQ_FNC:
|
||||
OPC->_float = OPA->function == OPB->function;
|
||||
OPC->flt = !strcmp(PR_GetString(OPA->string), PR_GetString(OPB->string));
|
||||
break;
|
||||
case OP_EQ_E: OPC->flt = OPA->edict == OPB->edict; break;
|
||||
case OP_EQ_FNC: OPC->flt = OPA->func == OPB->func; break;
|
||||
|
||||
case OP_NE_F:
|
||||
OPC->_float = OPA->_float != OPB->_float;
|
||||
break;
|
||||
case OP_NE_V:
|
||||
OPC->_float = (OPA->vector[0] != OPB->vector[0]) ||
|
||||
(OPA->vector[1] != OPB->vector[1]) ||
|
||||
(OPA->vector[2] != OPB->vector[2]);
|
||||
OPC->flt = OPA->vec[0] != OPB->vec[0] ||
|
||||
OPA->vec[1] != OPB->vec[1] ||
|
||||
OPA->vec[2] != OPB->vec[2];
|
||||
break;
|
||||
case OP_NE_S:
|
||||
OPC->_float = strcmp(PR_GetString(OPA->string), PR_GetString(OPB->string));
|
||||
break;
|
||||
case OP_NE_E:
|
||||
OPC->_float = OPA->_int != OPB->_int;
|
||||
break;
|
||||
case OP_NE_FNC:
|
||||
OPC->_float = OPA->function != OPB->function;
|
||||
OPC->flt = strcmp(PR_GetString(OPA->string), PR_GetString(OPB->string));
|
||||
break;
|
||||
case OP_NE_E: OPC->flt = OPA->edict != OPB->edict; break;
|
||||
case OP_NE_FNC: OPC->flt = OPA->func != OPB->func; break;
|
||||
|
||||
case OP_STORE_F:
|
||||
case OP_STORE_ENT:
|
||||
case OP_STORE_FLD:
|
||||
case OP_STORE_S:
|
||||
case OP_STORE_FNC:
|
||||
OPB->_int = OPA->_int;
|
||||
break;
|
||||
case OP_STORE_V:
|
||||
OPB->vector[0] = OPA->vector[0];
|
||||
OPB->vector[1] = OPA->vector[1];
|
||||
OPB->vector[2] = OPA->vector[2];
|
||||
break;
|
||||
case OP_STORE_F: OPB->flt = OPA->flt; break;
|
||||
case OP_STORE_ENT: OPB->edict = OPA->edict; break;
|
||||
case OP_STORE_FLD: OPB->field = OPA->field; break;
|
||||
case OP_STORE_S: OPB->string = OPA->string; break;
|
||||
case OP_STORE_FNC: OPB->func = OPA->func; break;
|
||||
case OP_STORE_V: VectorCopy(OPA->vec, OPB->vec); break;
|
||||
|
||||
case OP_STOREP_F:
|
||||
case OP_STOREP_ENT:
|
||||
case OP_STOREP_FLD: // integers
|
||||
case OP_STOREP_S:
|
||||
case OP_STOREP_FNC: // pointers
|
||||
ptr = (eval_t *)((byte *)sv.edicts + OPB->_int);
|
||||
ptr->_int = OPA->_int;
|
||||
break;
|
||||
case OP_STOREP_V:
|
||||
ptr = (eval_t *)((byte *)sv.edicts + OPB->_int);
|
||||
ptr->vector[0] = OPA->vector[0];
|
||||
ptr->vector[1] = OPA->vector[1];
|
||||
ptr->vector[2] = OPA->vector[2];
|
||||
break;
|
||||
case OP_STOREP_F: PTR->flt = OPA->flt; break;
|
||||
case OP_STOREP_ENT: PTR->edict = OPA->edict; break;
|
||||
case OP_STOREP_FLD: PTR->field = OPA->field; break;
|
||||
case OP_STOREP_S: PTR->string = OPA->string; break;
|
||||
case OP_STOREP_FNC: PTR->func = OPA->func; break;
|
||||
case OP_STOREP_V: VectorCopy(OPA->vec, PTR->vec); break;
|
||||
|
||||
case OP_ADDRESS:
|
||||
ed = PROG_TO_EDICT(OPA->edict);
|
||||
|
@ -542,7 +499,7 @@ void PR_ExecuteProgram(func_t fnum)
|
|||
pr_xstatement = st - pr_statements;
|
||||
PR_RunError("assignment to world entity");
|
||||
}
|
||||
OPC->_int = (byte *)&ED_INT(ed, OPB->_int) - (byte *)sv.edicts;
|
||||
OPC->field = EDICT_TO_PROG(&ED_PFIELD(ed, OPB->field));
|
||||
break;
|
||||
|
||||
case OP_LOAD_F:
|
||||
|
@ -550,22 +507,22 @@ void PR_ExecuteProgram(func_t fnum)
|
|||
case OP_LOAD_ENT:
|
||||
case OP_LOAD_S:
|
||||
case OP_LOAD_FNC:
|
||||
ed = PROG_TO_EDICT(OPA->edict);
|
||||
#if defined(PARANOID)
|
||||
NUM_FOR_EDICT(ed); // Make sure it's in range
|
||||
#endif
|
||||
OPC->_int = ED_EVAL(ed, OPB->_int)->_int;
|
||||
break;
|
||||
|
||||
case OP_LOAD_V:
|
||||
ed = PROG_TO_EDICT(OPA->edict);
|
||||
#if defined(PARANOID)
|
||||
NUM_FOR_EDICT(ed); // Make sure it's in range
|
||||
#endif
|
||||
ptr = ED_EVAL(ed, OPB->_int);
|
||||
OPC->vector[0] = ptr->vector[0];
|
||||
OPC->vector[1] = ptr->vector[1];
|
||||
OPC->vector[2] = ptr->vector[2];
|
||||
switch(st->op)
|
||||
{
|
||||
case OP_LOAD_F: OPC->flt = ED_FLOAT(ed, OPB->field); break;
|
||||
case OP_LOAD_FLD: OPC->field = ED_PFIELD(ed, OPB->field); break;
|
||||
case OP_LOAD_ENT: OPC->edict = ED_PEDICT(ed, OPB->field); break;
|
||||
case OP_LOAD_S: OPC->string = ED_RSTRING(ed, OPB->field); break;
|
||||
case OP_LOAD_FNC: OPC->func = ED_FUNC(ed, OPB->field); break;
|
||||
case OP_LOAD_V:
|
||||
VectorCopy(ED_VECTOR(ed, OPB->field), OPC->vec);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case OP_IFNOT: if(!OPA->_int) st += st->b - 1; break;
|
||||
|
@ -585,9 +542,9 @@ void PR_ExecuteProgram(func_t fnum)
|
|||
startprofile = profile;
|
||||
pr_xstatement = st - pr_statements;
|
||||
pr_argc = st->op - OP_CALL0;
|
||||
if(!OPA->function)
|
||||
if(!OPA->func)
|
||||
PR_RunError("NULL function");
|
||||
newf = &pr_functions[OPA->function];
|
||||
newf = &pr_functions[OPA->func];
|
||||
if(newf->first_statement < 0)
|
||||
{
|
||||
// Built-in function
|
||||
|
@ -611,17 +568,14 @@ void PR_ExecuteProgram(func_t fnum)
|
|||
G_FLOAT(GBL_RETURN + 2) = G_FLOAT((uint16_t)st->a + 2);
|
||||
st = &pr_statements[PR_LeaveFunction()];
|
||||
if(pr_depth == exitdepth)
|
||||
{
|
||||
// Done
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
case OP_STATE:
|
||||
ed = PROG_TO_EDICT(G_INT(GBL_self));
|
||||
ed = PROG_TO_EDICT(G_PEDICT(GBL_self));
|
||||
ED_FLOAT(ed, ED_nextthink) = G_FLOAT(GBL_time) + 0.1;
|
||||
ED_FLOAT(ed, ED_frame) = OPA->_float;
|
||||
ED_FUNC(ed, ED_think) = OPB->function;
|
||||
ED_FLOAT(ed, ED_frame) = OPA->flt;
|
||||
ED_FUNC(ed, ED_think) = OPB->func;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -630,7 +584,4 @@ void PR_ExecuteProgram(func_t fnum)
|
|||
}
|
||||
}
|
||||
}
|
||||
#undef OPA
|
||||
#undef OPB
|
||||
#undef OPC
|
||||
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
Copyright (C) 1996-2001 Id Software, Inc.
|
||||
Copyright (C) 2002-2009 John Fitzgibbons and others
|
||||
Copyright (C) 2010-2014 QuakeSpasm developers
|
||||
Copyright (C) 2019 Alison G. Watson
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef spingle__pr_global_h
|
||||
#define spingle__pr_global_h
|
||||
|
||||
#define G_FLOAT(o) (((float *)pr_global_data)[o])
|
||||
#define G_INT(o) (((int32_t *)pr_global_data)[o])
|
||||
#define G_EDICT(o) PROG_TO_EDICT(G_INT(o))
|
||||
#define G_EDICTNUM(o) NUM_FOR_EDICT(G_EDICT(o))
|
||||
#define G_VECTOR(o) (&G_FLOAT(o))
|
||||
#define G_STRING(o) PR_GetString(G_RSTRING(o))
|
||||
#define G_RSTRING(o) (*(string_t *)&G_INT(o))
|
||||
#define G_FUNC(o) (*(func_t *)&G_INT(o))
|
||||
#define G_PEDICT(o) (*(pedict_t *)&G_INT(o))
|
||||
#define G_PFIELD(o) (*(pfield_t *)&G_INT(o))
|
||||
#define G_EVAL(o) ((eval_t *)&G_INT(o))
|
||||
#define G_VOID(o) ((void *)&G_INT(o))
|
||||
|
||||
enum
|
||||
{
|
||||
GBL_NULL,
|
||||
GBL_RETURN,
|
||||
GBL_PARM0 = GBL_RETURN + 3,
|
||||
GBL_PARM1 = GBL_PARM0 + 3,
|
||||
GBL_PARM2 = GBL_PARM1 + 3,
|
||||
GBL_PARM3 = GBL_PARM2 + 3,
|
||||
GBL_PARM4 = GBL_PARM3 + 3,
|
||||
GBL_PARM5 = GBL_PARM4 + 3,
|
||||
GBL_PARM6 = GBL_PARM5 + 3,
|
||||
GBL_PARM7 = GBL_PARM6 + 3,
|
||||
GBL_self = 28,
|
||||
GBL_other,
|
||||
GBL_world,
|
||||
GBL_time,
|
||||
GBL_frametime,
|
||||
GBL_force_retouch,
|
||||
GBL_mapname,
|
||||
GBL_deathmatch,
|
||||
GBL_coop,
|
||||
GBL_teamplay,
|
||||
GBL_serverflags,
|
||||
GBL_total_secrets,
|
||||
GBL_total_monsters,
|
||||
GBL_found_secrets,
|
||||
GBL_killed_monsters,
|
||||
GBL_parm1,
|
||||
GBL_parm2,
|
||||
GBL_parm3,
|
||||
GBL_parm4,
|
||||
GBL_parm5,
|
||||
GBL_parm6,
|
||||
GBL_parm7,
|
||||
GBL_parm8,
|
||||
GBL_parm9,
|
||||
GBL_parm10,
|
||||
GBL_parm11,
|
||||
GBL_parm12,
|
||||
GBL_parm13,
|
||||
GBL_parm14,
|
||||
GBL_parm15,
|
||||
GBL_parm16,
|
||||
GBL_v_forward,
|
||||
GBL_v_up = GBL_v_forward + 3,
|
||||
GBL_v_right = GBL_v_up + 3,
|
||||
GBL_trace_allsolid = GBL_v_right + 3,
|
||||
GBL_trace_startsolid,
|
||||
GBL_trace_fraction,
|
||||
GBL_trace_endpos,
|
||||
GBL_trace_plane_normal = GBL_trace_endpos + 3,
|
||||
GBL_trace_plane_dist = GBL_trace_plane_normal + 3,
|
||||
GBL_trace_ent,
|
||||
GBL_trace_inopen,
|
||||
GBL_trace_inwater,
|
||||
GBL_msg_entity,
|
||||
GBL_main,
|
||||
GBL_StartFrame,
|
||||
GBL_PlayerPreThink,
|
||||
GBL_PlayerPostThink,
|
||||
GBL_ClientKill,
|
||||
GBL_ClientConnect,
|
||||
GBL_PutClientInServer,
|
||||
GBL_ClientDisconnect,
|
||||
GBL_SetNewParms,
|
||||
GBL_SetChangeParms,
|
||||
GBL_SYSTEM_END,
|
||||
};
|
||||
|
||||
extern byte *pr_global_data;
|
||||
extern ddef_t *pr_globaldefs;
|
||||
|
||||
#endif
|
|
@ -80,6 +80,9 @@ static void PR_LoadProgHeader(byte const *data)
|
|||
|
||||
if(progs.numglobals < GBL_SYSTEM_END)
|
||||
Host_Error("PR_LoadProgHeader: not enough globals\n");
|
||||
|
||||
if(progs.entityfields < ED_SYSTEM_END)
|
||||
Host_Error("PR_LoadProgHeader: not enough entity fields\n");
|
||||
}
|
||||
|
||||
static void PR_LoadFunctions(byte const *data)
|
||||
|
|
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
Copyright (C) 1996-2001 Id Software, Inc.
|
||||
Copyright (C) 2002-2009 John Fitzgibbons and others
|
||||
Copyright (C) 2010-2014 QuakeSpasm developers
|
||||
Copyright (C) 2019 Alison G. Watson
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef spingle__pr_ops_h
|
||||
#define spingle__pr_ops_h
|
||||
|
||||
enum
|
||||
{
|
||||
OP_DONE,
|
||||
OP_MUL_F,
|
||||
OP_MUL_V,
|
||||
OP_MUL_FV,
|
||||
OP_MUL_VF,
|
||||
OP_DIV_F,
|
||||
OP_ADD_F,
|
||||
OP_ADD_V,
|
||||
OP_SUB_F,
|
||||
OP_SUB_V,
|
||||
|
||||
OP_EQ_F,
|
||||
OP_EQ_V,
|
||||
OP_EQ_S,
|
||||
OP_EQ_E,
|
||||
OP_EQ_FNC,
|
||||
|
||||
OP_NE_F,
|
||||
OP_NE_V,
|
||||
OP_NE_S,
|
||||
OP_NE_E,
|
||||
OP_NE_FNC,
|
||||
|
||||
OP_LE,
|
||||
OP_GE,
|
||||
OP_LT,
|
||||
OP_GT,
|
||||
|
||||
OP_LOAD_F,
|
||||
OP_LOAD_V,
|
||||
OP_LOAD_S,
|
||||
OP_LOAD_ENT,
|
||||
OP_LOAD_FLD,
|
||||
OP_LOAD_FNC,
|
||||
|
||||
OP_ADDRESS,
|
||||
|
||||
OP_STORE_F,
|
||||
OP_STORE_V,
|
||||
OP_STORE_S,
|
||||
OP_STORE_ENT,
|
||||
OP_STORE_FLD,
|
||||
OP_STORE_FNC,
|
||||
|
||||
OP_STOREP_F,
|
||||
OP_STOREP_V,
|
||||
OP_STOREP_S,
|
||||
OP_STOREP_ENT,
|
||||
OP_STOREP_FLD,
|
||||
OP_STOREP_FNC,
|
||||
|
||||
OP_RETURN,
|
||||
OP_NOT_F,
|
||||
OP_NOT_V,
|
||||
OP_NOT_S,
|
||||
OP_NOT_ENT,
|
||||
OP_NOT_FNC,
|
||||
OP_IF,
|
||||
OP_IFNOT,
|
||||
OP_CALL0,
|
||||
OP_CALL1,
|
||||
OP_CALL2,
|
||||
OP_CALL3,
|
||||
OP_CALL4,
|
||||
OP_CALL5,
|
||||
OP_CALL6,
|
||||
OP_CALL7,
|
||||
OP_CALL8,
|
||||
OP_STATE,
|
||||
OP_GOTO,
|
||||
OP_AND,
|
||||
OP_OR,
|
||||
|
||||
OP_BITAND,
|
||||
OP_BITOR
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t op;
|
||||
int16_t a, b, c;
|
||||
} dstatement_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int32_t first_statement; // negative numbers are builtins
|
||||
int32_t parm_start;
|
||||
int32_t locals; // total ints of parms + locals
|
||||
|
||||
int32_t profile; // runtime
|
||||
|
||||
int32_t s_name;
|
||||
int32_t s_file; // source file defined in
|
||||
|
||||
int32_t numparms;
|
||||
byte parm_size[8];
|
||||
} dfunction_t;
|
||||
|
||||
extern dfunction_t *pr_functions;
|
||||
extern dstatement_t *pr_statements;
|
||||
|
||||
void PR_ExecuteProgram(func_t fnum);
|
||||
void PR_LoadProgs(void);
|
||||
|
||||
#endif
|
|
@ -53,21 +53,21 @@ const char *PR_ValueString(int32_t type, eval_t *val)
|
|||
sprintf(line, "entity %" PRIi32 "", NUM_FOR_EDICT(PROG_TO_EDICT(val->edict)));
|
||||
break;
|
||||
case ev_function:
|
||||
f = pr_functions + val->function;
|
||||
f = pr_functions + val->func;
|
||||
sprintf(line, "%s()", PR_GetString(f->s_name));
|
||||
break;
|
||||
case ev_field:
|
||||
def = ED_FieldAtOfs(val->_int);
|
||||
def = ED_FieldAtOfs(val->field);
|
||||
sprintf(line, ".%s", PR_GetString(def->s_name));
|
||||
break;
|
||||
case ev_void:
|
||||
sprintf(line, "void");
|
||||
break;
|
||||
case ev_float:
|
||||
sprintf(line, "%5.1f", val->_float);
|
||||
sprintf(line, "%5.1f", val->flt);
|
||||
break;
|
||||
case ev_vector:
|
||||
sprintf(line, "'%5.1f %5.1f %5.1f'", val->vector[0], val->vector[1], val->vector[2]);
|
||||
sprintf(line, "'%5.1f %5.1f %5.1f'", val->vec[0], val->vec[1], val->vec[2]);
|
||||
break;
|
||||
case ev_pointer:
|
||||
sprintf(line, "pointer");
|
||||
|
@ -106,21 +106,21 @@ const char *PR_UglyValueString(int32_t type, eval_t *val)
|
|||
sprintf(line, "%" PRIi32 "", NUM_FOR_EDICT(PROG_TO_EDICT(val->edict)));
|
||||
break;
|
||||
case ev_function:
|
||||
f = pr_functions + val->function;
|
||||
f = pr_functions + val->func;
|
||||
sprintf(line, "%s", PR_GetString(f->s_name));
|
||||
break;
|
||||
case ev_field:
|
||||
def = ED_FieldAtOfs(val->_int);
|
||||
def = ED_FieldAtOfs(val->field);
|
||||
sprintf(line, "%s", PR_GetString(def->s_name));
|
||||
break;
|
||||
case ev_void:
|
||||
sprintf(line, "void");
|
||||
break;
|
||||
case ev_float:
|
||||
sprintf(line, "%f", val->_float);
|
||||
sprintf(line, "%f", val->flt);
|
||||
break;
|
||||
case ev_vector:
|
||||
sprintf(line, "%f %f %f", val->vector[0], val->vector[1], val->vector[2]);
|
||||
sprintf(line, "%f %f %f", val->vec[0], val->vec[1], val->vec[2]);
|
||||
break;
|
||||
default:
|
||||
sprintf(line, "bad type %" PRIi32 "", type);
|
||||
|
|
137
source/progs.h
137
source/progs.h
|
@ -23,119 +23,50 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#ifndef spingle__progs_h
|
||||
#define spingle__progs_h
|
||||
|
||||
#include "pr_comp.h" /* defs shared with qcc */
|
||||
#include "pr_defs.h"
|
||||
#include "pr_edict.h"
|
||||
#include "pr_global.h"
|
||||
#include "pr_ops.h"
|
||||
|
||||
#define PROGHEADER_CRC 5927
|
||||
|
||||
typedef union eval_s
|
||||
enum
|
||||
{
|
||||
string_t string;
|
||||
float _float;
|
||||
float vector[3];
|
||||
func_t function;
|
||||
int32_t _int;
|
||||
int32_t edict;
|
||||
} eval_t;
|
||||
PROGHEADER_CRC = 5927,
|
||||
PROG_VERSION = 6
|
||||
};
|
||||
|
||||
#define MAX_ENT_LEAFS 32
|
||||
typedef struct edict_s
|
||||
typedef struct
|
||||
{
|
||||
bool free;
|
||||
link_t area; /* linked to a division node or leaf */
|
||||
int32_t version;
|
||||
int32_t crc; // check of header file
|
||||
|
||||
int32_t num_leafs;
|
||||
int32_t leafnums[MAX_ENT_LEAFS];
|
||||
int32_t ofs_statements;
|
||||
int32_t numstatements; // statement 0 is an error
|
||||
|
||||
entity_state_t baseline;
|
||||
uint8_t alpha;
|
||||
bool sendinterval; /* johnfitz -- send time until nextthink to client for better lerp timing */
|
||||
int32_t ofs_globaldefs;
|
||||
int32_t numglobaldefs;
|
||||
|
||||
float freetime; /* sv.time when the object was freed */
|
||||
int32_t ofs_fielddefs;
|
||||
int32_t numfielddefs;
|
||||
|
||||
byte fields[];
|
||||
} edict_t;
|
||||
int32_t ofs_functions;
|
||||
int32_t numfunctions; // function 0 is an empty
|
||||
|
||||
#define EDICT_FROM_AREA(l) (edict_t *)((byte *)(l) - offsetof(edict_t, area))
|
||||
#define ED_VARS(e) ((entvars_t *)e->fields)
|
||||
int32_t ofs_strings;
|
||||
int32_t numstrings; // first string is a null string
|
||||
|
||||
#define ED_FLOAT(e, o) (((float *)e->fields)[o])
|
||||
#define ED_INT(e, o) (((int32_t *)e->fields)[o])
|
||||
#define ED_VECTOR(e, o) (&ED_FLOAT(e, o))
|
||||
#define ED_EVAL(e, o) ((eval_t *)&ED_FLOAT(e, o))
|
||||
#define ED_RSTRING(e, o) (*(string_t *)&ED_INT(e, o))
|
||||
#define ED_FUNC(e, o) (*(func_t *)&ED_INT(e, o))
|
||||
int32_t ofs_globals;
|
||||
int32_t numglobals;
|
||||
|
||||
//============================================================================
|
||||
int32_t entityfields;
|
||||
} dprograms_t;
|
||||
|
||||
extern dprograms_t progs;
|
||||
extern dfunction_t *pr_functions;
|
||||
extern dstatement_t *pr_statements;
|
||||
extern byte *pr_global_data;
|
||||
|
||||
extern ddef_t *pr_fielddefs;
|
||||
extern int32_t pr_edict_size;
|
||||
extern dprograms_t progs;
|
||||
|
||||
extern char const *pr_strings;
|
||||
extern char const **pr_knownstrings;
|
||||
extern int32_t pr_maxknownstrings;
|
||||
extern int32_t pr_numknownstrings;
|
||||
|
||||
extern ddef_t *pr_globaldefs;
|
||||
|
||||
const char *PR_ValueString(int32_t type, eval_t *val);
|
||||
const char *PR_UglyValueString(int32_t type, eval_t *val);
|
||||
|
||||
void PR_Init(void);
|
||||
|
||||
void PR_ExecuteProgram(func_t fnum);
|
||||
void PR_LoadProgs(void);
|
||||
|
||||
const char *PR_GetString(int32_t num);
|
||||
int32_t PR_SetEngineString(const char *s);
|
||||
int32_t PR_AllocString(int32_t bufferlength, char **ptr);
|
||||
|
||||
void PR_Profile_f(void);
|
||||
|
||||
edict_t *ED_Alloc(void);
|
||||
void ED_Free(edict_t *ed);
|
||||
|
||||
void ED_Print(edict_t *ed);
|
||||
void ED_Write(FILE *f, edict_t *ed);
|
||||
const char *ED_ParseEdict(const char *data, edict_t *ent);
|
||||
|
||||
void ED_WriteGlobals(FILE *f);
|
||||
const char *ED_ParseGlobals(const char *data);
|
||||
|
||||
void ED_LoadFromFile(const char *data);
|
||||
|
||||
ddef_t *ED_GlobalAtOfs(int32_t ofs);
|
||||
ddef_t *ED_FieldAtOfs(int32_t ofs);
|
||||
bool ED_ParseEpair(void *base, ddef_t *key, const char *s);
|
||||
|
||||
void ED_Init(void);
|
||||
void ED_Load(void);
|
||||
|
||||
edict_t *EDICT_NUM(int32_t n);
|
||||
int32_t NUM_FOR_EDICT(edict_t *e);
|
||||
|
||||
#define NEXT_EDICT(e) ((edict_t *)((byte *)(e) + pr_edict_size))
|
||||
|
||||
#define EDICT_TO_PROG(e) ((byte *)(e) - (byte *)sv.edicts)
|
||||
#define PROG_TO_EDICT(e) ((edict_t *)((byte *)sv.edicts + (e)))
|
||||
|
||||
#define G_FLOAT(o) (((float *)pr_global_data)[o])
|
||||
#define G_INT(o) (((int32_t *)pr_global_data)[o])
|
||||
#define G_EDICT(o) ((edict_t *)(&((byte *)sv.edicts)[G_INT(o)]))
|
||||
#define G_EDICTNUM(o) NUM_FOR_EDICT(G_EDICT(o))
|
||||
#define G_VECTOR(o) (&G_FLOAT(o))
|
||||
#define G_STRING(o) (PR_GetString(G_RSTRING(o)))
|
||||
#define G_RSTRING(o) (*(string_t *)&G_INT(o))
|
||||
#define G_FUNC(o) (*(func_t *)&G_INT(o))
|
||||
#define G_EVAL(o) ((eval_t *)&G_FLOAT(o))
|
||||
#define G_VOID(o) ((void *)&G_FLOAT(o))
|
||||
|
||||
typedef void (*builtin_t)(void);
|
||||
|
||||
extern builtin_t pr_builtins[];
|
||||
extern int32_t pr_numbuiltins;
|
||||
|
||||
|
@ -149,11 +80,17 @@ extern uint16_t pr_crc;
|
|||
|
||||
extern bool pr_alpha_supported; //johnfitz
|
||||
|
||||
const char *PR_ValueString(int32_t type, eval_t *val);
|
||||
const char *PR_UglyValueString(int32_t type, eval_t *val);
|
||||
|
||||
void PR_Init(void);
|
||||
|
||||
const char *PR_GetString(int32_t num);
|
||||
int32_t PR_SetEngineString(const char *s);
|
||||
int32_t PR_AllocString(int32_t bufferlength, char **ptr);
|
||||
|
||||
void PR_Profile_f(void);
|
||||
|
||||
noreturn void PR_RunError(const char *error, ...) FUNC_PRINTF(1, 2);
|
||||
|
||||
void ED_PrintEdicts(void);
|
||||
void ED_PrintNum(int32_t ent);
|
||||
|
||||
eval_t *GetEdictFieldValue(edict_t *ed, const char *field);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -155,7 +155,7 @@ void R_InitParticles(void)
|
|||
|
||||
if(i)
|
||||
{
|
||||
r_numparticles = (int32_t)(Q_atoi(com_argv[i + 1]));
|
||||
r_numparticles = (int32_t)(atoi(com_argv[i + 1]));
|
||||
if(r_numparticles < ABSOLUTE_MIN_PARTICLES)
|
||||
r_numparticles = ABSOLUTE_MIN_PARTICLES;
|
||||
}
|
||||
|
|
|
@ -320,7 +320,7 @@ scroll the string inside a glscissor region
|
|||
void Sbar_DrawScrollString(int32_t x, int32_t y, int32_t width, const char *str)
|
||||
{
|
||||
float scale;
|
||||
int32_t len, ofs, left;
|
||||
size_t len, ofs, left;
|
||||
|
||||
scale = CLAMP(1.0, scr_sbarscale.value, (float)glwidth / 320.0);
|
||||
left = x * scale;
|
||||
|
@ -331,7 +331,7 @@ void Sbar_DrawScrollString(int32_t x, int32_t y, int32_t width, const char *str)
|
|||
glScissor(left, 0, width * scale, glheight);
|
||||
|
||||
len = strlen(str) * 8 + 40;
|
||||
ofs = ((int32_t)(realtime * 30)) % len;
|
||||
ofs = (size_t)(realtime * 30) % len;
|
||||
Sbar_DrawString(x - ofs, y, str);
|
||||
Sbar_DrawCharacter(x - ofs + len - 32, y, '/');
|
||||
Sbar_DrawCharacter(x - ofs + len - 24, y, '/');
|
||||
|
@ -498,7 +498,7 @@ void Sbar_SoloScoreboard(void)
|
|||
{
|
||||
char str[256];
|
||||
int32_t minutes, seconds, tens, units;
|
||||
int32_t len;
|
||||
size_t len;
|
||||
|
||||
sprintf(str, "Kills: %" PRIi32 "/%" PRIi32 "", cl.stats[STAT_MONSTERS], cl.stats[STAT_TOTALMONSTERS]);
|
||||
Sbar_DrawString(8, 12, str);
|
||||
|
|
|
@ -1485,7 +1485,7 @@ void VID_Init(void)
|
|||
p = COM_CheckParm("-width");
|
||||
if(p && p < com_argc - 1)
|
||||
{
|
||||
width = Q_atoi(com_argv[p + 1]);
|
||||
width = atoi(com_argv[p + 1]);
|
||||
|
||||
if(!COM_CheckParm("-height"))
|
||||
height = width * 3 / 4;
|
||||
|
@ -1494,7 +1494,7 @@ void VID_Init(void)
|
|||
p = COM_CheckParm("-height");
|
||||
if(p && p < com_argc - 1)
|
||||
{
|
||||
height = Q_atoi(com_argv[p + 1]);
|
||||
height = atoi(com_argv[p + 1]);
|
||||
|
||||
if(!COM_CheckParm("-width"))
|
||||
width = height * 4 / 3;
|
||||
|
@ -1502,11 +1502,11 @@ void VID_Init(void)
|
|||
|
||||
p = COM_CheckParm("-refreshrate");
|
||||
if(p && p < com_argc - 1)
|
||||
refreshrate = Q_atoi(com_argv[p + 1]);
|
||||
refreshrate = atoi(com_argv[p + 1]);
|
||||
|
||||
p = COM_CheckParm("-bpp");
|
||||
if(p && p < com_argc - 1)
|
||||
bpp = Q_atoi(com_argv[p + 1]);
|
||||
bpp = atoi(com_argv[p + 1]);
|
||||
|
||||
if(COM_CheckParm("-window") || COM_CheckParm("-w"))
|
||||
fullscreen = false;
|
||||
|
|
|
@ -93,7 +93,7 @@ int32_t main(int32_t argc, char *argv[])
|
|||
{
|
||||
t = COM_CheckParm("-heapsize") + 1;
|
||||
if(t < com_argc)
|
||||
parms.memsize = Q_atoi(com_argv[t]) * 1024;
|
||||
parms.memsize = atoi(com_argv[t]) * 1024;
|
||||
}
|
||||
|
||||
parms.membase = malloc(parms.memsize);
|
||||
|
@ -103,7 +103,7 @@ int32_t main(int32_t argc, char *argv[])
|
|||
|
||||
Sys_Printf(ENGINE_NAME " " VERSION " (c) id Software, John Fitzgibbons, "
|
||||
"SleepwalkR, Baker, Ozkan Sezer, Eric Wasylishen, "
|
||||
"Alison Watson, et al.\n");
|
||||
"Alison G. Watson, et al.\n");
|
||||
|
||||
Host_Init();
|
||||
|
||||
|
|
|
@ -27,15 +27,6 @@
|
|||
#include "snd_codec.h"
|
||||
#include "snd_codeci.h"
|
||||
|
||||
/* headers for individual codecs */
|
||||
#include "snd_mikmod.h"
|
||||
#include "snd_umx.h"
|
||||
#include "snd_flac.h"
|
||||
#include "snd_mp3.h"
|
||||
#include "snd_vorbis.h"
|
||||
#include "snd_opus.h"
|
||||
|
||||
|
||||
static snd_codec_t *codecs;
|
||||
|
||||
/*
|
||||
|
@ -61,22 +52,24 @@ void S_CodecInit(void)
|
|||
|
||||
/* Register in the inverse order
|
||||
* of codec choice preference: */
|
||||
extern snd_codec_t umx_codec;
|
||||
S_CodecRegister(&umx_codec);
|
||||
#if defined(USE_CODEC_MIKMOD)
|
||||
extern snd_codec_t mikmod_codec;
|
||||
S_CodecRegister(&mikmod_codec);
|
||||
#endif
|
||||
#if defined(USE_CODEC_FLAC)
|
||||
extern snd_codec_t flac_codec;
|
||||
S_CodecRegister(&flac_codec);
|
||||
#endif
|
||||
#if defined(USE_CODEC_OPUS)
|
||||
extern snd_codec_t opus_codec;
|
||||
S_CodecRegister(&opus_codec);
|
||||
#endif
|
||||
#if defined(USE_CODEC_VORBIS)
|
||||
extern snd_codec_t vorbis_codec;
|
||||
S_CodecRegister(&vorbis_codec);
|
||||
#endif
|
||||
#if defined(USE_CODEC_MP3)
|
||||
S_CodecRegister(&mp3_codec);
|
||||
#endif
|
||||
|
||||
codec = codecs;
|
||||
while(codec)
|
||||
|
|
|
@ -94,7 +94,7 @@ static cvar_t ambient_level = {"ambient_level", "0.3", CVAR_NONE};
|
|||
static cvar_t ambient_fade = {"ambient_fade", "100", CVAR_NONE};
|
||||
static cvar_t snd_noextraupdate = {"snd_noextraupdate", "0", CVAR_NONE};
|
||||
static cvar_t snd_show = {"snd_show", "0", CVAR_NONE};
|
||||
static cvar_t _snd_mixahead = {"_snd_mixahead", "0.1", CVAR_ARCHIVE};
|
||||
static cvar_t snd_mixahead = {"_snd_mixahead", "0.1", CVAR_ARCHIVE};
|
||||
|
||||
|
||||
static void S_SoundInfo_f(void)
|
||||
|
@ -181,7 +181,7 @@ void S_Init(void)
|
|||
Cvar_RegisterVariable(&ambient_fade);
|
||||
Cvar_RegisterVariable(&snd_noextraupdate);
|
||||
Cvar_RegisterVariable(&snd_show);
|
||||
Cvar_RegisterVariable(&_snd_mixahead);
|
||||
Cvar_RegisterVariable(&snd_mixahead);
|
||||
Cvar_RegisterVariable(&sndspeed);
|
||||
Cvar_RegisterVariable(&snd_mixspeed);
|
||||
Cvar_RegisterVariable(&snd_filterquality);
|
||||
|
@ -276,13 +276,13 @@ static sfx_t *S_FindName(const char *name)
|
|||
if(!name)
|
||||
Sys_Error("S_FindName: NULL");
|
||||
|
||||
if(Q_strlen(name) >= MAX_QPATH)
|
||||
if(strlen(name) >= MAX_QPATH)
|
||||
Sys_Error("Sound name too long: %s", name);
|
||||
|
||||
// see if already loaded
|
||||
for(i = 0; i < num_sfx; i++)
|
||||
{
|
||||
if(!Q_strcmp(known_sfx[i].name, name))
|
||||
if(!strcmp(known_sfx[i].name, name))
|
||||
{
|
||||
return &known_sfx[i];
|
||||
}
|
||||
|
@ -925,7 +925,7 @@ static void S_Update_(void)
|
|||
}
|
||||
|
||||
// mix ahead of current position
|
||||
endtime = soundtime + (uint32_t)(_snd_mixahead.value * shm->speed);
|
||||
endtime = soundtime + (uint32_t)(snd_mixahead.value * shm->speed);
|
||||
samps = shm->samples >> (shm->channels - 1);
|
||||
endtime = q_min(endtime, (uint32_t)(soundtime + samps));
|
||||
|
||||
|
@ -979,7 +979,7 @@ static void S_Play(void)
|
|||
while(i < Cmd_Argc())
|
||||
{
|
||||
q_strlcpy(name, Cmd_Argv(i), sizeof(name));
|
||||
if(!Q_strrchr(Cmd_Argv(i), '.'))
|
||||
if(!strrchr(Cmd_Argv(i), '.'))
|
||||
{
|
||||
q_strlcat(name, ".wav", sizeof(name));
|
||||
}
|
||||
|
@ -1001,12 +1001,12 @@ static void S_PlayVol(void)
|
|||
while(i < Cmd_Argc())
|
||||
{
|
||||
q_strlcpy(name, Cmd_Argv(i), sizeof(name));
|
||||
if(!Q_strrchr(Cmd_Argv(i), '.'))
|
||||
if(!strrchr(Cmd_Argv(i), '.'))
|
||||
{
|
||||
q_strlcat(name, ".wav", sizeof(name));
|
||||
}
|
||||
sfx = S_PrecacheSound(name);
|
||||
vol = Q_atof(Cmd_Argv(i + 1));
|
||||
vol = atof(Cmd_Argv(i + 1));
|
||||
S_StartSound(hash++, 0, sfx, listener_origin, vol, 1.0);
|
||||
i += 2;
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#if defined(USE_CODEC_FLAC)
|
||||
#include "snd_codec.h"
|
||||
#include "snd_codeci.h"
|
||||
#include "snd_flac.h"
|
||||
|
||||
#undef LEGACY_FLAC
|
||||
#include <FLAC/stream_decoder.h>
|
||||
|
@ -255,7 +254,7 @@ static bool S_FLAC_CodecOpenStream(snd_stream_t *stream)
|
|||
if(ff->decoder == NULL)
|
||||
{
|
||||
Con_Printf("Unable to create fLaC decoder\n");
|
||||
goto _fail;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
stream->priv = ff;
|
||||
|
@ -289,7 +288,7 @@ static bool S_FLAC_CodecOpenStream(snd_stream_t *stream)
|
|||
if(rc != FLAC__STREAM_DECODER_INIT_STATUS_OK) /* unlikely */
|
||||
{
|
||||
Con_Printf("FLAC: decoder init error %" PRIi32 "\n", rc);
|
||||
goto _fail;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
rc = FLAC__stream_decoder_process_until_end_of_metadata(ff->decoder);
|
||||
|
@ -298,29 +297,29 @@ static bool S_FLAC_CodecOpenStream(snd_stream_t *stream)
|
|||
rc = FLAC__stream_decoder_get_state(ff->decoder);
|
||||
Con_Printf("%s not a valid flac file? (decoder state %" PRIi32 ")\n",
|
||||
stream->name, rc);
|
||||
goto _fail;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if(ff->info->dataofs < 0)
|
||||
{
|
||||
Con_Printf("%s has no STREAMINFO\n", stream->name);
|
||||
goto _fail;
|
||||
goto fail;
|
||||
}
|
||||
if(ff->info->bits != 8 && ff->info->bits != 16)
|
||||
{
|
||||
Con_Printf("%s is not 8 or 16 bit\n", stream->name);
|
||||
goto _fail;
|
||||
goto fail;
|
||||
}
|
||||
if(ff->info->channels != 1 && ff->info->channels != 2)
|
||||
{
|
||||
Con_Printf("Unsupported number of channels %" PRIi32 " in %s\n",
|
||||
ff->info->channels, stream->name);
|
||||
goto _fail;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
_fail:
|
||||
fail:
|
||||
if(ff->decoder)
|
||||
{
|
||||
FLAC__stream_decoder_finish(ff->decoder);
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
/* fLaC streaming music support. */
|
||||
|
||||
#ifndef spingle__snd_flac_h
|
||||
#define spingle__snd_flac_h
|
||||
|
||||
#if defined(USE_CODEC_FLAC)
|
||||
|
||||
extern snd_codec_t flac_codec;
|
||||
|
||||
#endif /* USE_CODEC_FLAC */
|
||||
|
||||
#endif
|
|
@ -217,7 +217,7 @@ static void FindNextChunk(const char *name)
|
|||
}
|
||||
last_chunk = data_p + ((iff_chunk_len + 1) & ~1);
|
||||
data_p -= 8;
|
||||
if(!Q_strncmp((char *)data_p, name, 4))
|
||||
if(!strncmp((char *)data_p, name, 4))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -250,7 +250,7 @@ wavinfo_t GetWavinfo(const char *name, byte *wav, int32_t wavlength)
|
|||
|
||||
// find "RIFF" chunk
|
||||
FindChunk("RIFF");
|
||||
if(!(data_p && !Q_strncmp((char *)data_p + 8, "WAVE", 4)))
|
||||
if(!(data_p && !strncmp((char *)data_p + 8, "WAVE", 4)))
|
||||
{
|
||||
Con_Printf("%s missing RIFF/WAVE chunks\n", name);
|
||||
return info;
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#if defined(USE_CODEC_MIKMOD)
|
||||
#include "snd_codec.h"
|
||||
#include "snd_codeci.h"
|
||||
#include "snd_mikmod.h"
|
||||
#include <mikmod.h>
|
||||
|
||||
#if ((LIBMIKMOD_VERSION+0) < 0x030105)
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
/* module tracker decoding support using libmikmod */
|
||||
|
||||
#ifndef spingle__snd_mikmod_h
|
||||
#define spingle__snd_mikmod_h
|
||||
|
||||
#if defined(USE_CODEC_MIKMOD)
|
||||
|
||||
extern snd_codec_t mikmod_codec;
|
||||
|
||||
#endif /* USE_CODEC_MIKMOD */
|
||||
|
||||
#endif
|
556
source/snd_mp3.c
556
source/snd_mp3.c
|
@ -1,556 +0,0 @@
|
|||
/*
|
||||
* MP3 decoding support using libmad: Adapted from the SoX library at
|
||||
* http://sourceforge.net/projects/sox/, LGPLv2, Copyright (c) 2007-2009
|
||||
* SoX contributors, written by Fabrizio Gennari <fabrizio.ge@tiscali.it>,
|
||||
* with the decoding part based on the decoder tutorial program madlld
|
||||
* written by Bertrand Petit <madlld@phoe.fmug.org> (BSD license, see at
|
||||
* http://www.bsd-dk.dk/~elrond/audio/madlld/). The tag identification
|
||||
* functions were adapted from the GPL-licensed libid3tag library, see at
|
||||
* http://www.underbit.com/products/mad/. Adapted to Quake and Hexen II
|
||||
* game engines by O.Sezer :
|
||||
* Copyright (C) 2010-2015 O.Sezer <sezero@users.sourceforge.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "q_defs.h"
|
||||
|
||||
#if defined(USE_CODEC_MP3)
|
||||
#include "snd_codec.h"
|
||||
#include "snd_codeci.h"
|
||||
#include "snd_mp3.h"
|
||||
#include <mad.h>
|
||||
|
||||
#define ID3_TAG_FLAG_FOOTERPRESENT 0x10
|
||||
|
||||
/* Under Windows, importing data from DLLs is a dicey proposition. This is true
|
||||
* when using dlopen, but also true if linking directly against the DLL if the
|
||||
* header does not mark the data as __declspec(dllexport), which mad.h does not.
|
||||
* Sidestep the issue by defining our own mad_timer_zero. This is needed because
|
||||
* mad_timer_zero is used in some of the mad.h macros.
|
||||
*/
|
||||
#define mad_timer_zero mad_timer_zero_stub
|
||||
static mad_timer_t const mad_timer_zero_stub = {0, 0};
|
||||
|
||||
/* MAD returns values with MAD_F_FRACBITS (28) bits of precision, though it's
|
||||
not certain that all of them are meaningful. Default to 16 bits to
|
||||
align with most users expectation of output file should be 16 bits. */
|
||||
#define MP3_MAD_SAMPLEBITS 16
|
||||
#define MP3_MAD_SAMPLEWIDTH 2
|
||||
#define MP3_BUFFER_SIZE (5 * 8192)
|
||||
|
||||
/* Private data */
|
||||
typedef struct _mp3_priv_t
|
||||
{
|
||||
uint8_t mp3_buffer[MP3_BUFFER_SIZE];
|
||||
struct mad_stream stream;
|
||||
struct mad_frame frame;
|
||||
struct mad_synth synth;
|
||||
mad_timer_t timer;
|
||||
ptrdiff_t cursamp;
|
||||
size_t frame_count;
|
||||
} mp3_priv_t;
|
||||
|
||||
/* This function merges the functions tagtype() and id3_tag_query()
|
||||
* from MAD's libid3tag, so we don't have to link to it
|
||||
* Returns 0 if the frame is not an ID3 tag, tag length if it is */
|
||||
static inline bool tag_is_id3v1(const uint8_t *data, size_t length)
|
||||
{
|
||||
if(length >= 3 &&
|
||||
data[0] == 'T' && data[1] == 'A' && data[2] == 'G')
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool tag_is_id3v2(const uint8_t *data, size_t length)
|
||||
{
|
||||
if(length >= 10 &&
|
||||
(data[0] == 'I' && data[1] == 'D' && data[2] == '3') &&
|
||||
data[3] < 0xff && data[4] < 0xff &&
|
||||
data[6] < 0x80 && data[7] < 0x80 && data[8] < 0x80 && data[9] < 0x80)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* http://wiki.hydrogenaud.io/index.php?title=APEv1_specification
|
||||
* http://wiki.hydrogenaud.io/index.php?title=APEv2_specification
|
||||
* Detect an APEv2 tag. (APEv1 has no header, so no luck.)
|
||||
*/
|
||||
static inline bool tag_is_apetag(const uint8_t *data, size_t length)
|
||||
{
|
||||
uint32_t v;
|
||||
|
||||
if(length < 32) return false;
|
||||
if(memcmp(data, "APETAGEX", 8) != 0)
|
||||
return false;
|
||||
v = LittleLong(BytesLong(&data[8]));
|
||||
if(v != 2000)
|
||||
return false;
|
||||
v = 0;
|
||||
if(memcmp(&data[24], &v, 4) != 0 || memcmp(&data[28], &v, 4) != 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static size_t mp3_tagsize(const uint8_t *data, size_t length)
|
||||
{
|
||||
size_t size;
|
||||
|
||||
if(tag_is_id3v1(data, length))
|
||||
return 128;
|
||||
|
||||
if(tag_is_id3v2(data, length))
|
||||
{
|
||||
uint8_t flags = data[5];
|
||||
size = 10 + (data[6] << 21) + (data[7] << 14) + (data[8] << 7) + data[9];
|
||||
if(flags & ID3_TAG_FLAG_FOOTERPRESENT)
|
||||
size += 10;
|
||||
for(; size < length && !data[size]; ++size)
|
||||
; /* Consume padding */
|
||||
return size;
|
||||
}
|
||||
|
||||
if(tag_is_apetag(data, length))
|
||||
{
|
||||
size = LittleLong(BytesLong(&data[12]));
|
||||
size += 32;
|
||||
return size;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Attempts to read an ID3 tag at the current location in stream and
|
||||
* consume it all. Returns -1 if no tag is found. Its up to caller
|
||||
* to recover. */
|
||||
static int32_t mp3_inputtag(snd_stream_t *stream)
|
||||
{
|
||||
mp3_priv_t *p = (mp3_priv_t *) stream->priv;
|
||||
int32_t rc = -1;
|
||||
size_t remaining;
|
||||
size_t tagsize;
|
||||
|
||||
/* FIXME: This needs some more work if we are to ever
|
||||
* look at the ID3 frame. This is because the stream
|
||||
* may not be able to hold the complete ID3 frame.
|
||||
* We should consume the whole frame inside tagtype()
|
||||
* instead of outside of tagframe(). That would support
|
||||
* recovering when stream contains less then 8-bytes (header)
|
||||
* and also when ID3v2 is bigger then stream buffer size.
|
||||
* Need to pass in stream so that buffer can be
|
||||
* consumed as well as letting additional data to be
|
||||
* read in.
|
||||
*/
|
||||
remaining = p->stream.bufend - p->stream.next_frame;
|
||||
tagsize = mp3_tagsize(p->stream.this_frame, remaining);
|
||||
if(tagsize != 0)
|
||||
{
|
||||
mad_stream_skip(&p->stream, tagsize);
|
||||
rc = 0;
|
||||
}
|
||||
|
||||
/* We know that a valid frame hasn't been found yet
|
||||
* so help libmad out and go back into frame seek mode.
|
||||
* This is true whether an ID3 tag was found or not.
|
||||
*/
|
||||
mad_stream_sync(&p->stream);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* (Re)fill the stream buffer that is to be decoded. If any data
|
||||
* still exists in the buffer then they are first shifted to be
|
||||
* front of the stream buffer. */
|
||||
static int32_t mp3_inputdata(snd_stream_t *stream)
|
||||
{
|
||||
mp3_priv_t *p = (mp3_priv_t *) stream->priv;
|
||||
size_t bytes_read;
|
||||
size_t remaining;
|
||||
|
||||
remaining = p->stream.bufend - p->stream.next_frame;
|
||||
|
||||
/* libmad does not consume all the buffer it's given. Some
|
||||
* data, part of a truncated frame, is left unused at the
|
||||
* end of the buffer. That data must be put back at the
|
||||
* beginning of the buffer and taken in account for
|
||||
* refilling the buffer. This means that the input buffer
|
||||
* must be large enough to hold a complete frame at the
|
||||
* highest observable bit-rate (currently 448 kb/s).
|
||||
* TODO: Is 2016 bytes the size of the largest frame?
|
||||
* (448000*(1152/32000))/8
|
||||
*/
|
||||
memmove(p->mp3_buffer, p->stream.next_frame, remaining);
|
||||
|
||||
bytes_read = FS_fread(p->mp3_buffer + remaining, 1,
|
||||
MP3_BUFFER_SIZE - remaining, &stream->fh);
|
||||
if(bytes_read == 0)
|
||||
return -1;
|
||||
|
||||
mad_stream_buffer(&p->stream, p->mp3_buffer, bytes_read + remaining);
|
||||
p->stream.error = MAD_ERROR_NONE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mp3_startread(snd_stream_t *stream)
|
||||
{
|
||||
mp3_priv_t *p = (mp3_priv_t *) stream->priv;
|
||||
size_t ReadSize;
|
||||
|
||||
mad_stream_init(&p->stream);
|
||||
mad_frame_init(&p->frame);
|
||||
mad_synth_init(&p->synth);
|
||||
mad_timer_reset(&p->timer);
|
||||
|
||||
/* Decode at least one valid frame to find out the input
|
||||
* format. The decoded frame will be saved off so that it
|
||||
* can be processed later.
|
||||
*/
|
||||
ReadSize = FS_fread(p->mp3_buffer, 1, MP3_BUFFER_SIZE, &stream->fh);
|
||||
if(!ReadSize || FS_ferror(&stream->fh))
|
||||
return -1;
|
||||
|
||||
mad_stream_buffer(&p->stream, p->mp3_buffer, ReadSize);
|
||||
|
||||
/* Find a valid frame before starting up. This makes sure
|
||||
* that we have a valid MP3 and also skips past ID3v2 tags
|
||||
* at the beginning of the audio file.
|
||||
*/
|
||||
p->stream.error = MAD_ERROR_NONE;
|
||||
while(mad_frame_decode(&p->frame, &p->stream))
|
||||
{
|
||||
/* check whether input buffer needs a refill */
|
||||
if(p->stream.error == MAD_ERROR_BUFLEN)
|
||||
{
|
||||
if(mp3_inputdata(stream) == -1)
|
||||
return -1;/* EOF with no valid data */
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Consume any ID3 tags */
|
||||
mp3_inputtag(stream);
|
||||
|
||||
/* FIXME: We should probably detect when we've read
|
||||
* a bunch of non-ID3 data and still haven't found a
|
||||
* frame. In that case we can abort early without
|
||||
* scanning the whole file.
|
||||
*/
|
||||
p->stream.error = MAD_ERROR_NONE;
|
||||
}
|
||||
|
||||
if(p->stream.error)
|
||||
{
|
||||
Con_Printf("MP3: No valid MP3 frame found\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch(p->frame.header.mode)
|
||||
{
|
||||
case MAD_MODE_SINGLE_CHANNEL:
|
||||
case MAD_MODE_DUAL_CHANNEL:
|
||||
case MAD_MODE_JOINT_STEREO:
|
||||
case MAD_MODE_STEREO:
|
||||
stream->info.channels = MAD_NCHANNELS(&p->frame.header);
|
||||
break;
|
||||
default:
|
||||
Con_Printf("MP3: Cannot determine number of channels\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
p->frame_count = 1;
|
||||
|
||||
mad_timer_add(&p->timer, p->frame.header.duration);
|
||||
mad_synth_frame(&p->synth, &p->frame);
|
||||
stream->info.rate = p->synth.pcm.samplerate;
|
||||
stream->info.bits = MP3_MAD_SAMPLEBITS;
|
||||
stream->info.width = MP3_MAD_SAMPLEWIDTH;
|
||||
|
||||
p->cursamp = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Read up to len samples from p->synth
|
||||
* If needed, read some more MP3 data, decode them and synth them
|
||||
* Place in buf[].
|
||||
* Return number of samples read. */
|
||||
static int32_t mp3_decode(snd_stream_t *stream, byte *buf, int32_t len)
|
||||
{
|
||||
mp3_priv_t *p = (mp3_priv_t *) stream->priv;
|
||||
int32_t donow, i, done = 0;
|
||||
mad_fixed_t sample;
|
||||
int32_t chan, x;
|
||||
|
||||
do
|
||||
{
|
||||
x = (p->synth.pcm.length - p->cursamp) * stream->info.channels;
|
||||
donow = q_min(len, x);
|
||||
i = 0;
|
||||
while(i < donow)
|
||||
{
|
||||
for(chan = 0; chan < stream->info.channels; chan++)
|
||||
{
|
||||
sample = p->synth.pcm.samples[chan][p->cursamp];
|
||||
/* convert from fixed to int16_t,
|
||||
* write in host-endian format. */
|
||||
if(sample <= -MAD_F_ONE)
|
||||
sample = -0x7FFF;
|
||||
else if(sample >= MAD_F_ONE)
|
||||
sample = 0x7FFF;
|
||||
else
|
||||
sample >>= (MAD_F_FRACBITS + 1 - 16);
|
||||
#if HOST_BIGENDIAN
|
||||
*buf++ = (sample >> 8) & 0xFF;
|
||||
*buf++ = sample & 0xFF;
|
||||
#else
|
||||
*buf++ = sample & 0xFF;
|
||||
*buf++ = (sample >> 8) & 0xFF;
|
||||
#endif
|
||||
i++;
|
||||
}
|
||||
p->cursamp++;
|
||||
}
|
||||
|
||||
len -= donow;
|
||||
done += donow;
|
||||
|
||||
if(len == 0)
|
||||
break;
|
||||
|
||||
/* check whether input buffer needs a refill */
|
||||
if(p->stream.error == MAD_ERROR_BUFLEN)
|
||||
{
|
||||
if(mp3_inputdata(stream) == -1)
|
||||
{
|
||||
/* check feof() ?? */
|
||||
Con_DPrintf("mp3 EOF\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(mad_frame_decode(&p->frame, &p->stream))
|
||||
{
|
||||
if(MAD_RECOVERABLE(p->stream.error))
|
||||
{
|
||||
mp3_inputtag(stream);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(p->stream.error == MAD_ERROR_BUFLEN)
|
||||
continue;
|
||||
else
|
||||
{
|
||||
Con_Printf("MP3: unrecoverable frame level error (%s)\n",
|
||||
mad_stream_errorstr(&p->stream));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
p->frame_count++;
|
||||
mad_timer_add(&p->timer, p->frame.header.duration);
|
||||
mad_synth_frame(&p->synth, &p->frame);
|
||||
p->cursamp = 0;
|
||||
}
|
||||
while(1);
|
||||
|
||||
return done;
|
||||
}
|
||||
|
||||
static int32_t mp3_stopread(snd_stream_t *stream)
|
||||
{
|
||||
mp3_priv_t *p = (mp3_priv_t*) stream->priv;
|
||||
|
||||
mad_synth_finish(&p->synth);
|
||||
mad_frame_finish(&p->frame);
|
||||
mad_stream_finish(&p->stream);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool S_MP3_CodecInitialize(void)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
static void S_MP3_CodecShutdown(void)
|
||||
{
|
||||
}
|
||||
|
||||
static bool S_MP3_CodecOpenStream(snd_stream_t *stream)
|
||||
{
|
||||
int32_t err;
|
||||
|
||||
stream->priv = calloc(1, sizeof(mp3_priv_t));
|
||||
if(!stream->priv)
|
||||
{
|
||||
Con_Printf("Insufficient memory for MP3 audio\n");
|
||||
return false;
|
||||
}
|
||||
err = mp3_startread(stream);
|
||||
if(err != 0)
|
||||
{
|
||||
Con_Printf("%s is not a valid mp3 file\n", stream->name);
|
||||
}
|
||||
else if(stream->info.channels != 1 && stream->info.channels != 2)
|
||||
{
|
||||
Con_Printf("Unsupported number of channels %" PRIi32 " in %s\n",
|
||||
stream->info.channels, stream->name);
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
free(stream->priv);
|
||||
return false;
|
||||
}
|
||||
|
||||
static int32_t S_MP3_CodecReadStream(snd_stream_t *stream, int32_t bytes, void *buffer)
|
||||
{
|
||||
int32_t res = mp3_decode(stream, (byte *)buffer, bytes / stream->info.width);
|
||||
return res * stream->info.width;
|
||||
}
|
||||
|
||||
static void S_MP3_CodecCloseStream(snd_stream_t *stream)
|
||||
{
|
||||
mp3_stopread(stream);
|
||||
free(stream->priv);
|
||||
S_CodecUtilClose(&stream);
|
||||
}
|
||||
|
||||
static int32_t S_MP3_CodecRewindStream(snd_stream_t *stream)
|
||||
{
|
||||
mp3_priv_t *p = (mp3_priv_t *) stream->priv;
|
||||
size_t initial_bitrate = p->frame.header.bitrate;
|
||||
size_t tagsize = 0, consumed = 0;
|
||||
int32_t vbr = 0; /* Variable Bit Rate, bool */
|
||||
bool depadded = false;
|
||||
|
||||
/* Reset all */
|
||||
FS_rewind(&stream->fh);
|
||||
mad_timer_reset(&p->timer);
|
||||
p->frame_count = 0;
|
||||
|
||||
/* They where opened in startread */
|
||||
mad_synth_finish(&p->synth);
|
||||
mad_frame_finish(&p->frame);
|
||||
mad_stream_finish(&p->stream);
|
||||
|
||||
mad_stream_init(&p->stream);
|
||||
mad_frame_init(&p->frame);
|
||||
mad_synth_init(&p->synth);
|
||||
|
||||
while(1) /* Read data from the MP3 file */
|
||||
{
|
||||
int32_t bytes_read, padding = 0;
|
||||
size_t leftover = p->stream.bufend - p->stream.next_frame;
|
||||
|
||||
memcpy(p->mp3_buffer, p->stream.this_frame, leftover);
|
||||
bytes_read = FS_fread(p->mp3_buffer + leftover, (size_t) 1,
|
||||
MP3_BUFFER_SIZE - leftover, &stream->fh);
|
||||
if(bytes_read <= 0)
|
||||
{
|
||||
Con_DPrintf("seek failure. unexpected EOF (frames=%" PRIu32 " leftover=%" PRIu32 ")\n",
|
||||
p->frame_count, leftover);
|
||||
break;
|
||||
}
|
||||
for(; !depadded && padding < bytes_read && !p->mp3_buffer[padding]; ++padding)
|
||||
;
|
||||
depadded = true;
|
||||
mad_stream_buffer(&p->stream, p->mp3_buffer + padding, leftover + bytes_read - padding);
|
||||
|
||||
while(1) /* Decode frame headers */
|
||||
{
|
||||
static uint16_t samples;
|
||||
p->stream.error = MAD_ERROR_NONE;
|
||||
|
||||
/* Not an audio frame */
|
||||
if(mad_header_decode(&p->frame.header, &p->stream) == -1)
|
||||
{
|
||||
if(p->stream.error == MAD_ERROR_BUFLEN)
|
||||
break; /* Normal behaviour; get some more data from the file */
|
||||
if(!MAD_RECOVERABLE(p->stream.error))
|
||||
{
|
||||
Con_DPrintf("unrecoverable MAD error\n");
|
||||
break;
|
||||
}
|
||||
if(p->stream.error == MAD_ERROR_LOSTSYNC)
|
||||
{
|
||||
size_t available = (p->stream.bufend - p->stream.this_frame);
|
||||
tagsize = mp3_tagsize(p->stream.this_frame, (size_t) available);
|
||||
if(tagsize)
|
||||
{
|
||||
/* It's some ID3 tags, so just skip */
|
||||
if(tagsize >= available)
|
||||
{
|
||||
FS_fseek(&stream->fh,
|
||||
(ptrdiff_t)tagsize - (ptrdiff_t)available,
|
||||
SEEK_CUR);
|
||||
depadded = false;
|
||||
}
|
||||
mad_stream_skip(&p->stream, q_min(tagsize, available));
|
||||
}
|
||||
else
|
||||
{
|
||||
Con_DPrintf("MAD lost sync\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Con_DPrintf("recoverable MAD error\n");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
consumed += p->stream.next_frame - p->stream.this_frame;
|
||||
vbr |= (p->frame.header.bitrate != initial_bitrate);
|
||||
|
||||
samples = 32 * MAD_NSBSAMPLES(&p->frame.header);
|
||||
|
||||
p->frame_count++;
|
||||
mad_timer_add(&p->timer, p->frame.header.duration);
|
||||
|
||||
mad_frame_decode(&p->frame, &p->stream);
|
||||
mad_synth_frame(&p->synth, &p->frame);
|
||||
p->cursamp = 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
snd_codec_t mp3_codec =
|
||||
{
|
||||
CODECTYPE_MP3,
|
||||
true, /* always available. */
|
||||
"mp3",
|
||||
S_MP3_CodecInitialize,
|
||||
S_MP3_CodecShutdown,
|
||||
S_MP3_CodecOpenStream,
|
||||
S_MP3_CodecReadStream,
|
||||
S_MP3_CodecRewindStream,
|
||||
S_MP3_CodecCloseStream,
|
||||
NULL
|
||||
};
|
||||
|
||||
#endif /* USE_CODEC_MP3 */
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
/* MP3 decoding support using libmad or libmpg123. */
|
||||
|
||||
#ifndef spingle__snd_mp3_h
|
||||
#define spingle__snd_mp3_h
|
||||
|
||||
#if defined(USE_CODEC_MP3)
|
||||
|
||||
extern snd_codec_t mp3_codec;
|
||||
|
||||
#endif /* USE_CODEC_MP3 */
|
||||
|
||||
#endif
|
|
@ -1,226 +0,0 @@
|
|||
/*
|
||||
* MP3 decoding support using libmpg123, loosely based on an SDL_mixer
|
||||
* See: http://bubu.lv/changeset/4/public/libs/SDL/generated/SDL_mixer
|
||||
*
|
||||
* Copyright (C) 2011-2012 O.Sezer <sezero@users.sourceforge.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "q_defs.h"
|
||||
|
||||
#if defined(USE_CODEC_MP3)
|
||||
#include "snd_codec.h"
|
||||
#include "snd_codeci.h"
|
||||
#include "snd_mp3.h"
|
||||
#include <errno.h>
|
||||
#include <mpg123.h>
|
||||
|
||||
#if !defined(MPG123_API_VERSION) || (MPG123_API_VERSION < 24)
|
||||
#error minimum required libmpg123 version is 1.12.0 (api version 24)
|
||||
#endif /* MPG123_API_VERSION */
|
||||
|
||||
/* Private data */
|
||||
typedef struct _mp3_priv_t
|
||||
{
|
||||
int32_t handle_newed, handle_opened;
|
||||
mpg123_handle* handle;
|
||||
} mp3_priv_t;
|
||||
|
||||
/* CALLBACK FUNCTIONS: */
|
||||
/* CAREFUL: libmpg123 expects POSIX read() and lseek() behavior,
|
||||
* however our FS_fread() and FS_fseek() return fread() and fseek()
|
||||
* compatible values. */
|
||||
|
||||
static ssize_t mp3_read(void *f, void *buf, size_t size)
|
||||
{
|
||||
ssize_t ret = (ssize_t) FS_fread(buf, 1, size, (fshandle_t *)f);
|
||||
if(ret == 0 && errno != 0)
|
||||
ret = -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static off_t mp3_seek(void *f, off_t offset, int32_t whence)
|
||||
{
|
||||
if(f == NULL) return (-1);
|
||||
if(FS_fseek((fshandle_t *)f, (long) offset, whence) < 0)
|
||||
return (off_t) -1;
|
||||
return (off_t) FS_ftell((fshandle_t *)f);
|
||||
}
|
||||
|
||||
static bool S_MP3_CodecInitialize(void)
|
||||
{
|
||||
if(!mp3_codec.initialized)
|
||||
{
|
||||
if(mpg123_init() != MPG123_OK)
|
||||
{
|
||||
Con_Printf("Could not initialize mpg123\n");
|
||||
return false;
|
||||
}
|
||||
mp3_codec.initialized = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void S_MP3_CodecShutdown(void)
|
||||
{
|
||||
if(mp3_codec.initialized)
|
||||
{
|
||||
mp3_codec.initialized = false;
|
||||
mpg123_exit();
|
||||
}
|
||||
}
|
||||
|
||||
static bool S_MP3_CodecOpenStream(snd_stream_t *stream)
|
||||
{
|
||||
long rate = 0;
|
||||
int32_t encoding = 0, channels = 0;
|
||||
mp3_priv_t *priv = NULL;
|
||||
|
||||
stream->priv = Z_Malloc(sizeof(mp3_priv_t));
|
||||
priv = (mp3_priv_t *) stream->priv;
|
||||
priv->handle = mpg123_new(NULL, NULL);
|
||||
if(priv->handle == NULL)
|
||||
{
|
||||
Con_Printf("Unable to allocate mpg123 handle\n");
|
||||
goto _fail;
|
||||
}
|
||||
priv->handle_newed = 1;
|
||||
|
||||
if(mpg123_replace_reader_handle(priv->handle, mp3_read, mp3_seek, NULL) != MPG123_OK ||
|
||||
mpg123_open_handle(priv->handle, &stream->fh) != MPG123_OK)
|
||||
{
|
||||
Con_Printf("Unable to open mpg123 handle\n");
|
||||
goto _fail;
|
||||
}
|
||||
priv->handle_opened = 1;
|
||||
|
||||
if(mpg123_getformat(priv->handle, &rate, &channels, &encoding) != MPG123_OK)
|
||||
{
|
||||
Con_Printf("Unable to retrieve mpg123 format for %s\n", stream->name);
|
||||
goto _fail;
|
||||
}
|
||||
|
||||
switch(channels)
|
||||
{
|
||||
case MPG123_MONO:
|
||||
stream->info.channels = 1;
|
||||
break;
|
||||
case MPG123_STEREO:
|
||||
stream->info.channels = 2;
|
||||
break;
|
||||
default:
|
||||
Con_Printf("Unsupported number of channels %" PRIi32 " in %s\n", channels, stream->name);
|
||||
goto _fail;
|
||||
}
|
||||
|
||||
stream->info.rate = rate;
|
||||
|
||||
switch(encoding)
|
||||
{
|
||||
case MPG123_ENC_UNSIGNED_8:
|
||||
stream->info.bits = 8;
|
||||
stream->info.width = 1;
|
||||
break;
|
||||
case MPG123_ENC_SIGNED_8:
|
||||
/* unsupported: force mpg123 to convert */
|
||||
stream->info.bits = 8;
|
||||
stream->info.width = 1;
|
||||
encoding = MPG123_ENC_UNSIGNED_8;
|
||||
break;
|
||||
case MPG123_ENC_SIGNED_16:
|
||||
stream->info.bits = 16;
|
||||
stream->info.width = 2;
|
||||
break;
|
||||
case MPG123_ENC_UNSIGNED_16:
|
||||
default:
|
||||
/* unsupported: force mpg123 to convert */
|
||||
stream->info.bits = 16;
|
||||
stream->info.width = 2;
|
||||
encoding = MPG123_ENC_SIGNED_16;
|
||||
break;
|
||||
}
|
||||
if(mpg123_format_support(priv->handle, rate, encoding) == 0)
|
||||
{
|
||||
Con_Printf("Unsupported format for %s\n", stream->name);
|
||||
goto _fail;
|
||||
}
|
||||
mpg123_format_none(priv->handle);
|
||||
mpg123_format(priv->handle, rate, channels, encoding);
|
||||
|
||||
return true;
|
||||
_fail:
|
||||
if(priv)
|
||||
{
|
||||
if(priv->handle_opened)
|
||||
mpg123_close(priv->handle);
|
||||
if(priv->handle_newed)
|
||||
mpg123_delete(priv->handle);
|
||||
Z_Free(stream->priv);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static int32_t S_MP3_CodecReadStream(snd_stream_t *stream, int32_t bytes, void *buffer)
|
||||
{
|
||||
mp3_priv_t *priv = (mp3_priv_t *) stream->priv;
|
||||
size_t bytes_read = 0;
|
||||
int32_t res = mpg123_read(priv->handle, (uint8_t *)buffer, (size_t)bytes, &bytes_read);
|
||||
switch(res)
|
||||
{
|
||||
case MPG123_DONE:
|
||||
Con_DPrintf("mp3 EOF\n");
|
||||
case MPG123_OK:
|
||||
return (int32_t)bytes_read;
|
||||
}
|
||||
return -1; /* error */
|
||||
}
|
||||
|
||||
static void S_MP3_CodecCloseStream(snd_stream_t *stream)
|
||||
{
|
||||
mp3_priv_t *priv = (mp3_priv_t *) stream->priv;
|
||||
mpg123_close(priv->handle);
|
||||
mpg123_delete(priv->handle);
|
||||
Z_Free(stream->priv);
|
||||
S_CodecUtilClose(&stream);
|
||||
}
|
||||
|
||||
static int32_t S_MP3_CodecRewindStream(snd_stream_t *stream)
|
||||
{
|
||||
mp3_priv_t *priv = (mp3_priv_t *) stream->priv;
|
||||
off_t res = mpg123_seek(priv->handle, 0, SEEK_SET);
|
||||
if(res >= 0) return (0);
|
||||
return res;
|
||||
}
|
||||
|
||||
snd_codec_t mp3_codec =
|
||||
{
|
||||
CODECTYPE_MP3,
|
||||
false,
|
||||
"mp3",
|
||||
S_MP3_CodecInitialize,
|
||||
S_MP3_CodecShutdown,
|
||||
S_MP3_CodecOpenStream,
|
||||
S_MP3_CodecReadStream,
|
||||
S_MP3_CodecRewindStream,
|
||||
S_MP3_CodecCloseStream,
|
||||
NULL
|
||||
};
|
||||
|
||||
#endif /* USE_CODEC_MP3 */
|
||||
|
|
@ -26,7 +26,6 @@
|
|||
#if defined(USE_CODEC_OPUS)
|
||||
#include "snd_codec.h"
|
||||
#include "snd_codeci.h"
|
||||
#include "snd_opus.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <opusfile.h>
|
||||
|
@ -94,7 +93,7 @@ static bool S_OPUS_CodecOpenStream(snd_stream_t *stream)
|
|||
{
|
||||
Con_Printf("%s is not a valid Opus file (error %" PRIi32 ").\n",
|
||||
stream->name, res);
|
||||
goto _fail;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
stream->priv = opFile;
|
||||
|
@ -102,14 +101,14 @@ static bool S_OPUS_CodecOpenStream(snd_stream_t *stream)
|
|||
if(!op_seekable(opFile))
|
||||
{
|
||||
Con_Printf("Opus stream %s not seekable.\n", stream->name);
|
||||
goto _fail;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
op_info = op_head(opFile, -1);
|
||||
if(!op_info)
|
||||
{
|
||||
Con_Printf("Unable to get stream information for %s.\n", stream->name);
|
||||
goto _fail;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* FIXME: handle section changes */
|
||||
|
@ -118,14 +117,14 @@ static bool S_OPUS_CodecOpenStream(snd_stream_t *stream)
|
|||
{
|
||||
Con_Printf("More than one (%" PRIi64 ") stream in %s\n",
|
||||
(long)op_info->stream_count, stream->name);
|
||||
goto _fail;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if(op_info->channel_count != 1 && op_info->channel_count != 2)
|
||||
{
|
||||
Con_Printf("Unsupported number of channels %" PRIi32 " in %s\n",
|
||||
op_info->channel_count, stream->name);
|
||||
goto _fail;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* All Opus audio is coded at 48 kHz, and should also be decoded
|
||||
|
@ -139,7 +138,7 @@ static bool S_OPUS_CodecOpenStream(snd_stream_t *stream)
|
|||
stream->info.width = 2;
|
||||
|
||||
return true;
|
||||
_fail:
|
||||
fail:
|
||||
if(opFile)
|
||||
op_free(opFile);
|
||||
return false;
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
/* Ogg/Opus streaming music support. */
|
||||
|
||||
#ifndef spingle__snd_opus
|
||||
#define spingle__snd_opus
|
||||
|
||||
#if defined(USE_CODEC_OPUS)
|
||||
|
||||
extern snd_codec_t opus_codec;
|
||||
|
||||
#endif /* USE_CODEC_OPUS */
|
||||
|
||||
#endif
|
|
@ -31,18 +31,11 @@
|
|||
|
||||
#include "snd_codec.h"
|
||||
#include "snd_codeci.h"
|
||||
#include "snd_umx.h"
|
||||
|
||||
typedef int32_t fci_t; /* FCompactIndex */
|
||||
|
||||
#define UPKG_HDR_TAG 0x9e2a83c1
|
||||
|
||||
struct _genhist /* for upkg versions >= 68 */
|
||||
{
|
||||
int32_t export_count;
|
||||
int32_t name_count;
|
||||
};
|
||||
|
||||
struct upkg_hdr
|
||||
{
|
||||
uint32_t tag; /* UPKG_HDR_TAG */
|
||||
|
@ -64,7 +57,6 @@ struct upkg_hdr
|
|||
uint32_t guid[4];
|
||||
int32_t generation_count;
|
||||
#define UPKG_HDR_SIZE 64 /* 64 bytes up until here */
|
||||
/*struct _genhist *gen;*/
|
||||
};
|
||||
_Static_assert(sizeof(struct upkg_hdr) == UPKG_HDR_SIZE,
|
||||
"upkg_hdr not correct size");
|
||||
|
@ -131,7 +123,7 @@ static fci_t get_fci(const char *in, int32_t *pos)
|
|||
static int32_t get_objtype(fshandle_t *f, int32_t ofs, int32_t type)
|
||||
{
|
||||
char sig[16];
|
||||
_retry:
|
||||
retry:
|
||||
FS_fseek(f, ofs, SEEK_SET);
|
||||
FS_fread(sig, 16, 1, f);
|
||||
if(type == UMUSIC_IT)
|
||||
|
@ -175,7 +167,7 @@ _retry:
|
|||
/* SpaceMarines.umx and Starseek.umx from Return to NaPali
|
||||
* report as "s3m" whereas the actual music format is "it" */
|
||||
type = UMUSIC_IT;
|
||||
goto _retry;
|
||||
goto retry;
|
||||
}
|
||||
|
||||
FS_fseek(f, ofs + 1080, SEEK_SET);
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
/* Unreal UMX format support */
|
||||
#ifndef spingle__snd_umx_h
|
||||
#define spingle__snd_umx_h
|
||||
|
||||
extern snd_codec_t umx_codec;
|
||||
|
||||
#endif
|
|
@ -26,7 +26,6 @@
|
|||
#if defined(USE_CODEC_VORBIS)
|
||||
#include "snd_codec.h"
|
||||
#include "snd_codeci.h"
|
||||
#include "snd_vorbis.h"
|
||||
|
||||
#define OV_EXCLUDE_STATIC_CALLBACKS
|
||||
#include <vorbis/vorbisfile.h>
|
||||
|
@ -91,20 +90,20 @@ static bool S_VORBIS_CodecOpenStream(snd_stream_t *stream)
|
|||
{
|
||||
Con_Printf("%s is not a valid Ogg Vorbis file (error %" PRIi32 ").\n",
|
||||
stream->name, res);
|
||||
goto _fail;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if(!ov_seekable(ovFile))
|
||||
{
|
||||
Con_Printf("Stream %s not seekable.\n", stream->name);
|
||||
goto _fail;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ovf_info = ov_info(ovFile, 0);
|
||||
if(!ovf_info)
|
||||
{
|
||||
Con_Printf("Unable to get stream info for %s.\n", stream->name);
|
||||
goto _fail;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* FIXME: handle section changes */
|
||||
|
@ -113,14 +112,14 @@ static bool S_VORBIS_CodecOpenStream(snd_stream_t *stream)
|
|||
{
|
||||
Con_Printf("More than one (%" PRIi64 ") stream in %s.\n",
|
||||
numstreams, stream->name);
|
||||
goto _fail;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if(ovf_info->channels != 1 && ovf_info->channels != 2)
|
||||
{
|
||||
Con_Printf("Unsupported number of channels %" PRIi32 " in %s\n",
|
||||
ovf_info->channels, stream->name);
|
||||
goto _fail;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
stream->info.rate = ovf_info->rate;
|
||||
|
@ -129,7 +128,7 @@ static bool S_VORBIS_CodecOpenStream(snd_stream_t *stream)
|
|||
stream->info.width = VORBIS_SAMPLEWIDTH;
|
||||
|
||||
return true;
|
||||
_fail:
|
||||
fail:
|
||||
if(res == 0)
|
||||
ov_clear(ovFile);
|
||||
Z_Free(ovFile);
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
/* Ogg/Vorbis streaming music support. */
|
||||
|
||||
#ifndef spingle__snd_vorbis_h
|
||||
#define spingle__snd_vorbis_h
|
||||
|
||||
#if defined(USE_CODEC_VORBIS)
|
||||
|
||||
extern snd_codec_t vorbis_codec;
|
||||
|
||||
#endif /* USE_CODEC_VORBIS */
|
||||
|
||||
#endif
|
|
@ -19,7 +19,7 @@
|
|||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "strl_fn.h"
|
||||
#include "q_defs.h"
|
||||
|
||||
/*
|
||||
* Appends src to string dst of size siz (unlike strncat, siz is the
|
||||
|
@ -29,8 +29,7 @@
|
|||
* If retval >= siz, truncation occurred.
|
||||
*/
|
||||
|
||||
size_t
|
||||
q_strlcat(char *dst, const char *src, size_t siz)
|
||||
size_t q_strlcat(char *dst, const char *src, size_t siz)
|
||||
{
|
||||
char *d = dst;
|
||||
const char *s = src;
|
||||
|
@ -56,6 +55,40 @@ q_strlcat(char *dst, const char *src, size_t siz)
|
|||
}
|
||||
*d = '\0';
|
||||
|
||||
return(dlen + (s - src)); /* count does not include NUL */
|
||||
return dlen + (s - src); /* count does not include NUL */
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy src to string dst of size siz. At most siz-1 characters
|
||||
* will be copied. Always NUL terminates (unless siz == 0).
|
||||
* Returns strlen(src); if retval >= siz, truncation occurred.
|
||||
*/
|
||||
|
||||
size_t q_strlcpy(char *dst, const char *src, size_t siz)
|
||||
{
|
||||
char *d = dst;
|
||||
const char *s = src;
|
||||
size_t n = siz;
|
||||
|
||||
/* Copy as many bytes as will fit */
|
||||
if(n != 0)
|
||||
{
|
||||
while(--n != 0)
|
||||
{
|
||||
if((*d++ = *s++) == '\0')
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Not enough room in dst, add NUL and traverse rest of src */
|
||||
if(n == 0)
|
||||
{
|
||||
if(siz != 0)
|
||||
*d = '\0'; /* NUL-terminate dst */
|
||||
while(*s++)
|
||||
;
|
||||
}
|
||||
|
||||
return s - src - 1; /* count does not include NUL */
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
/* header file for BSD strlcat and strlcpy */
|
||||
|
||||
#ifndef spingle__strl_fn_h
|
||||
#define spingle__strl_fn_h
|
||||
|
||||
/* use our own copies of strlcpy and strlcat taken from OpenBSD */
|
||||
extern size_t q_strlcpy(char *dst, const char *src, size_t size);
|
||||
extern size_t q_strlcat(char *dst, const char *src, size_t size);
|
||||
|
||||
#endif
|
|
@ -1,58 +0,0 @@
|
|||
/* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "strl_fn.h"
|
||||
|
||||
/*
|
||||
* Copy src to string dst of size siz. At most siz-1 characters
|
||||
* will be copied. Always NUL terminates (unless siz == 0).
|
||||
* Returns strlen(src); if retval >= siz, truncation occurred.
|
||||
*/
|
||||
|
||||
size_t
|
||||
q_strlcpy(char *dst, const char *src, size_t siz)
|
||||
{
|
||||
char *d = dst;
|
||||
const char *s = src;
|
||||
size_t n = siz;
|
||||
|
||||
/* Copy as many bytes as will fit */
|
||||
if(n != 0)
|
||||
{
|
||||
while(--n != 0)
|
||||
{
|
||||
if((*d++ = *s++) == '\0')
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Not enough room in dst, add NUL and traverse rest of src */
|
||||
if(n == 0)
|
||||
{
|
||||
if(siz != 0)
|
||||
*d = '\0'; /* NUL-terminate dst */
|
||||
while(*s++)
|
||||
;
|
||||
}
|
||||
|
||||
return(s - src - 1); /* count does not include NUL */
|
||||
}
|
||||
|
|
@ -306,7 +306,7 @@ void SV_SendServerinfo(client_t *client)
|
|||
else
|
||||
MSG_WriteByte(&client->message, GAME_COOP);
|
||||
|
||||
MSG_WriteString(&client->message, PR_GetString(ED_RSTRING(sv.edicts, ED_message)));
|
||||
MSG_WriteString(&client->message, ED_STRING(sv.edicts, ED_message));
|
||||
|
||||
//johnfitz -- only send the first 256 model and sound precaches if protocol is 15
|
||||
for(i = 0, s = sv.model_precache + 1 ; *s; s++, i++)
|
||||
|
@ -517,7 +517,7 @@ byte *SV_FatPVS(vec3_t org, qmodel_t *worldmodel) //johnfitz -- added worldmode
|
|||
Sys_Error("SV_FatPVS: realloc() failed on %" PRIi32 " bytes", fatpvs_capacity);
|
||||
}
|
||||
|
||||
Q_memset(fatpvs, 0, fatbytes);
|
||||
memset(fatpvs, 0, fatbytes);
|
||||
SV_AddToFatPVS(org, worldmodel->nodes, worldmodel); //johnfitz -- worldmodel as a parameter
|
||||
return fatpvs;
|
||||
}
|
||||
|
@ -574,7 +574,7 @@ void SV_WriteEntitiesToClient(edict_t *clent, sizebuf_t *msg)
|
|||
if(ent != clent) // clent is ALLWAYS sent
|
||||
{
|
||||
// ignore ents without visible models
|
||||
if(!ED_FLOAT(ent, ED_modelindex) || !PR_GetString(ED_RSTRING(ent, ED_model))[0])
|
||||
if(!ED_FLOAT(ent, ED_modelindex) || !ED_STRING(ent, ED_model)[0])
|
||||
continue;
|
||||
|
||||
//johnfitz -- don't send model>255 entities if protocol is 15
|
||||
|
@ -654,7 +654,7 @@ void SV_WriteEntitiesToClient(edict_t *clent, sizebuf_t *msg)
|
|||
eval_t *val;
|
||||
val = GetEdictFieldValue(ent, "alpha");
|
||||
if(val)
|
||||
ent->alpha = ENTALPHA_ENCODE(val->_float);
|
||||
ent->alpha = ENTALPHA_ENCODE(val->flt);
|
||||
}
|
||||
|
||||
//don't send invisible entities unless they have effects
|
||||
|
@ -782,7 +782,7 @@ void SV_WriteClientdataToMessage(edict_t *ent, sizebuf_t *msg)
|
|||
//
|
||||
if(ED_FLOAT(ent, ED_dmg_take) || ED_FLOAT(ent, ED_dmg_save))
|
||||
{
|
||||
other = PROG_TO_EDICT(ED_INT(ent, ED_dmg_inflictor));
|
||||
other = PROG_TO_EDICT(ED_PEDICT(ent, ED_dmg_inflictor));
|
||||
MSG_WriteByte(msg, svc_damage);
|
||||
MSG_WriteByte(msg, ED_FLOAT(ent, ED_dmg_save));
|
||||
MSG_WriteByte(msg, ED_FLOAT(ent, ED_dmg_take));
|
||||
|
@ -820,7 +820,7 @@ void SV_WriteClientdataToMessage(edict_t *ent, sizebuf_t *msg)
|
|||
val = GetEdictFieldValue(ent, "items2");
|
||||
|
||||
if(val)
|
||||
items = (int32_t)ED_FLOAT(ent, ED_items) | ((int32_t)val->_float << 23);
|
||||
items = (int32_t)ED_FLOAT(ent, ED_items) | ((int32_t)val->flt << 23);
|
||||
else
|
||||
items = (int32_t)ED_FLOAT(ent, ED_items) | ((int32_t)G_FLOAT(GBL_serverflags) << 28);
|
||||
|
||||
|
@ -852,7 +852,7 @@ void SV_WriteClientdataToMessage(edict_t *ent, sizebuf_t *msg)
|
|||
//johnfitz -- PROTOCOL_FITZQUAKE
|
||||
if(sv.protocol != PROTOCOL_NETQUAKE)
|
||||
{
|
||||
if(bits & SU_WEAPON && SV_ModelIndex(PR_GetString(ED_RSTRING(ent, ED_weaponmodel))) & 0xFF00) bits |= SU_WEAPON2;
|
||||
if(bits & SU_WEAPON && SV_ModelIndex(ED_STRING(ent, ED_weaponmodel)) & 0xFF00) bits |= SU_WEAPON2;
|
||||
if((int32_t)ED_FLOAT(ent, ED_armorvalue) & 0xFF00) bits |= SU_ARMOR2;
|
||||
if((int32_t)ED_FLOAT(ent, ED_currentammo) & 0xFF00) bits |= SU_AMMO2;
|
||||
if((int32_t)ED_FLOAT(ent, ED_ammo_shells) & 0xFF00) bits |= SU_SHELLS2;
|
||||
|
@ -898,7 +898,7 @@ void SV_WriteClientdataToMessage(edict_t *ent, sizebuf_t *msg)
|
|||
if(bits & SU_ARMOR)
|
||||
MSG_WriteByte(msg, ED_FLOAT(ent, ED_armorvalue));
|
||||
if(bits & SU_WEAPON)
|
||||
MSG_WriteByte(msg, SV_ModelIndex(PR_GetString(ED_RSTRING(ent, ED_weaponmodel))));
|
||||
MSG_WriteByte(msg, SV_ModelIndex(ED_STRING(ent, ED_weaponmodel)));
|
||||
|
||||
MSG_WriteShort(msg, ED_FLOAT(ent, ED_health));
|
||||
MSG_WriteByte(msg, ED_FLOAT(ent, ED_currentammo));
|
||||
|
@ -925,7 +925,7 @@ void SV_WriteClientdataToMessage(edict_t *ent, sizebuf_t *msg)
|
|||
|
||||
//johnfitz -- PROTOCOL_FITZQUAKE
|
||||
if(bits & SU_WEAPON2)
|
||||
MSG_WriteByte(msg, SV_ModelIndex(PR_GetString(ED_RSTRING(ent, ED_weaponmodel))) >> 8);
|
||||
MSG_WriteByte(msg, SV_ModelIndex(ED_STRING(ent, ED_weaponmodel)) >> 8);
|
||||
if(bits & SU_ARMOR2)
|
||||
MSG_WriteByte(msg, (int32_t)ED_FLOAT(ent, ED_armorvalue) >> 8);
|
||||
if(bits & SU_AMMO2)
|
||||
|
@ -960,7 +960,7 @@ bool SV_SendClientDatagram(client_t *client)
|
|||
msg.cursize = 0;
|
||||
|
||||
//johnfitz -- if client is nonlocal, use smaller max size so packets aren't fragmented
|
||||
if(Q_strcmp(NET_QSocketGetAddressString(client->netconnection), "LOCAL") != 0)
|
||||
if(strcmp(NET_QSocketGetAddressString(client->netconnection), "LOCAL") != 0)
|
||||
msg.maxsize = DATAGRAM_MTU;
|
||||
//johnfitz
|
||||
|
||||
|
@ -1191,7 +1191,7 @@ void SV_CreateBaseline(void)
|
|||
else
|
||||
{
|
||||
svent->baseline.colormap = 0;
|
||||
svent->baseline.modelindex = SV_ModelIndex(PR_GetString(ED_RSTRING(svent, ED_model)));
|
||||
svent->baseline.modelindex = SV_ModelIndex(ED_STRING(svent, ED_model));
|
||||
svent->baseline.alpha = svent->alpha; //johnfitz -- alpha support
|
||||
}
|
||||
|
||||
|
@ -1304,7 +1304,7 @@ void SV_SaveSpawnparms(void)
|
|||
continue;
|
||||
|
||||
// call the progs to get default spawn parms for the new client
|
||||
G_INT(GBL_self) = EDICT_TO_PROG(host_client->edict);
|
||||
G_PEDICT(GBL_self) = EDICT_TO_PROG(host_client->edict);
|
||||
PR_ExecuteProgram(G_FUNC(GBL_SetChangeParms));
|
||||
for(j = 0 ; j < NUM_SPAWN_PARMS ; j++)
|
||||
host_client->spawn_parms[j] = (&G_FLOAT(GBL_parm1))[j];
|
||||
|
|
|
@ -128,10 +128,10 @@ bool SV_movestep(edict_t *ent, vec3_t move, bool relink)
|
|||
for(i = 0 ; i < 2 ; i++)
|
||||
{
|
||||
VectorAdd(ED_VECTOR(ent, ED_origin), move, neworg);
|
||||
enemy = PROG_TO_EDICT(ED_INT(ent, ED_enemy));
|
||||
enemy = PROG_TO_EDICT(ED_PEDICT(ent, ED_enemy));
|
||||
if(i == 0 && enemy != sv.edicts)
|
||||
{
|
||||
dz = ED_VECTOR(ent, ED_origin)[2] - ED_VECTOR(PROG_TO_EDICT(ED_INT(ent, ED_enemy)), ED_origin)[2];
|
||||
dz = ED_VECTOR(ent, ED_origin)[2] - ED_VECTOR(PROG_TO_EDICT(ED_PEDICT(ent, ED_enemy)), ED_origin)[2];
|
||||
if(dz > 40)
|
||||
neworg[2] -= 8;
|
||||
if(dz < 30)
|
||||
|
@ -212,7 +212,7 @@ bool SV_movestep(edict_t *ent, vec3_t move, bool relink)
|
|||
// Con_Printf ("back on ground\n");
|
||||
ED_FLOAT(ent, ED_flags) = (int32_t)ED_FLOAT(ent, ED_flags) & ~FL_PARTIALGROUND;
|
||||
}
|
||||
ED_INT(ent, ED_groundentity) = EDICT_TO_PROG(trace.ent);
|
||||
ED_PEDICT(ent, ED_groundentity) = EDICT_TO_PROG(trace.ent);
|
||||
|
||||
// the move is ok
|
||||
if(relink)
|
||||
|
@ -399,8 +399,8 @@ void SV_MoveToGoal(void)
|
|||
edict_t *ent, *goal;
|
||||
float dist;
|
||||
|
||||
ent = PROG_TO_EDICT(G_INT(GBL_self));
|
||||
goal = PROG_TO_EDICT(ED_INT(ent, ED_goalentity));
|
||||
ent = PROG_TO_EDICT(G_PEDICT(GBL_self));
|
||||
goal = PROG_TO_EDICT(ED_PEDICT(ent, ED_goalentity));
|
||||
dist = G_FLOAT(GBL_PARM0);
|
||||
|
||||
if(!((int32_t)ED_FLOAT(ent, ED_flags) & (FL_ONGROUND | FL_FLY | FL_SWIM)))
|
||||
|
@ -410,7 +410,7 @@ void SV_MoveToGoal(void)
|
|||
}
|
||||
|
||||
// if the next step hits the enemy, return immediately
|
||||
if(PROG_TO_EDICT(ED_INT(ent, ED_enemy)) != sv.edicts && SV_CloseEnough(ent, goal, dist))
|
||||
if(PROG_TO_EDICT(ED_PEDICT(ent, ED_enemy)) != sv.edicts && SV_CloseEnough(ent, goal, dist))
|
||||
return;
|
||||
|
||||
// bump around...
|
||||
|
|
|
@ -26,7 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
/*
|
||||
|
||||
|
||||
pushmove objects do not obey gravity, and do not interact with each other or trigger fields, but block normal movement and push normal objects when they move.
|
||||
pushmove objects do not obey gravity, and do not interact with each other or trigger, but block normal movement and push normal objects when they move.
|
||||
|
||||
onground is set for toss objects when they come to a complete rest. it is set for steping or walking objects
|
||||
|
||||
|
@ -95,12 +95,12 @@ void SV_CheckVelocity(edict_t *ent)
|
|||
{
|
||||
if(isnan(ED_VECTOR(ent, ED_velocity)[i]))
|
||||
{
|
||||
Con_Printf("Got a NaN velocity on %s\n", PR_GetString(ED_RSTRING(ent, ED_classname)));
|
||||
Con_Printf("Got a NaN velocity on %s\n", ED_STRING(ent, ED_classname));
|
||||
ED_VECTOR(ent, ED_velocity)[i] = 0;
|
||||
}
|
||||
if(isnan(ED_VECTOR(ent, ED_origin)[i]))
|
||||
{
|
||||
Con_Printf("Got a NaN origin on %s\n", PR_GetString(ED_RSTRING(ent, ED_classname)));
|
||||
Con_Printf("Got a NaN origin on %s\n", ED_STRING(ent, ED_classname));
|
||||
ED_VECTOR(ent, ED_origin)[i] = 0;
|
||||
}
|
||||
if(ED_VECTOR(ent, ED_velocity)[i] > sv_maxvelocity.value)
|
||||
|
@ -139,8 +139,8 @@ bool SV_RunThink(edict_t *ent)
|
|||
|
||||
ED_FLOAT(ent, ED_nextthink) = 0;
|
||||
G_FLOAT(GBL_time) = thinktime;
|
||||
G_INT(GBL_self) = EDICT_TO_PROG(ent);
|
||||
G_INT(GBL_other) = EDICT_TO_PROG(sv.edicts);
|
||||
G_PEDICT(GBL_self) = EDICT_TO_PROG(ent);
|
||||
G_PEDICT(GBL_other) = EDICT_TO_PROG(sv.edicts);
|
||||
PR_ExecuteProgram(ED_FUNC(ent, ED_think));
|
||||
|
||||
//johnfitz -- PROTOCOL_FITZQUAKE
|
||||
|
@ -167,28 +167,28 @@ Two entities have touched, so run their touch functions
|
|||
*/
|
||||
void SV_Impact(edict_t *e1, edict_t *e2)
|
||||
{
|
||||
int32_t old_self, old_other;
|
||||
pedict_t old_self, old_other;
|
||||
|
||||
old_self = G_INT(GBL_self);
|
||||
old_other = G_INT(GBL_other);
|
||||
old_self = G_PEDICT(GBL_self);
|
||||
old_other = G_PEDICT(GBL_other);
|
||||
|
||||
G_FLOAT(GBL_time) = sv.time;
|
||||
if(ED_FUNC(e1, ED_touch) && ED_FLOAT(e1, ED_solid) != SOLID_NOT)
|
||||
{
|
||||
G_INT(GBL_self) = EDICT_TO_PROG(e1);
|
||||
G_INT(GBL_other) = EDICT_TO_PROG(e2);
|
||||
G_PEDICT(GBL_self) = EDICT_TO_PROG(e1);
|
||||
G_PEDICT(GBL_other) = EDICT_TO_PROG(e2);
|
||||
PR_ExecuteProgram(ED_FUNC(e1, ED_touch));
|
||||
}
|
||||
|
||||
if(ED_FUNC(e2, ED_touch) && ED_FLOAT(e2, ED_solid) != SOLID_NOT)
|
||||
{
|
||||
G_INT(GBL_self) = EDICT_TO_PROG(e2);
|
||||
G_INT(GBL_other) = EDICT_TO_PROG(e1);
|
||||
G_PEDICT(GBL_self) = EDICT_TO_PROG(e2);
|
||||
G_PEDICT(GBL_other) = EDICT_TO_PROG(e1);
|
||||
PR_ExecuteProgram(ED_FUNC(e2, ED_touch));
|
||||
}
|
||||
|
||||
G_INT(GBL_self) = old_self;
|
||||
G_INT(GBL_other) = old_other;
|
||||
G_PEDICT(GBL_self) = old_self;
|
||||
G_PEDICT(GBL_other) = old_other;
|
||||
}
|
||||
|
||||
|
||||
|
@ -301,7 +301,7 @@ int32_t SV_FlyMove(edict_t *ent, float time, trace_t *steptrace)
|
|||
if(ED_FLOAT(trace.ent, ED_solid) == SOLID_BSP)
|
||||
{
|
||||
ED_FLOAT(ent, ED_flags) = (int32_t)ED_FLOAT(ent, ED_flags) | FL_ONGROUND;
|
||||
ED_INT(ent, ED_groundentity) = EDICT_TO_PROG(trace.ent);
|
||||
ED_PEDICT(ent, ED_groundentity) = EDICT_TO_PROG(trace.ent);
|
||||
}
|
||||
}
|
||||
if(!trace.plane.normal[2])
|
||||
|
@ -394,8 +394,8 @@ void SV_AddGravity(edict_t *ent)
|
|||
eval_t *val;
|
||||
|
||||
val = GetEdictFieldValue(ent, "gravity");
|
||||
if(val && val->_float)
|
||||
ent_gravity = val->_float;
|
||||
if(val && val->flt)
|
||||
ent_gravity = val->flt;
|
||||
else
|
||||
ent_gravity = 1.0;
|
||||
|
||||
|
@ -500,7 +500,7 @@ void SV_PushMove(edict_t *pusher, float movetime)
|
|||
|
||||
// if the entity is standing on the pusher, it will definately be moved
|
||||
if(!(((int32_t)ED_FLOAT(check, ED_flags) & FL_ONGROUND)
|
||||
&& PROG_TO_EDICT(ED_INT(check, ED_groundentity)) == pusher))
|
||||
&& PROG_TO_EDICT(ED_PEDICT(check, ED_groundentity)) == pusher))
|
||||
{
|
||||
if(ED_VECTOR(check, ED_absmin)[0] >= maxs[0]
|
||||
|| ED_VECTOR(check, ED_absmin)[1] >= maxs[1]
|
||||
|
@ -555,8 +555,8 @@ void SV_PushMove(edict_t *pusher, float movetime)
|
|||
// otherwise, just stay in place until the obstacle is gone
|
||||
if(ED_FUNC(pusher, ED_blocked))
|
||||
{
|
||||
G_INT(GBL_self) = EDICT_TO_PROG(pusher);
|
||||
G_INT(GBL_other) = EDICT_TO_PROG(check);
|
||||
G_PEDICT(GBL_self) = EDICT_TO_PROG(pusher);
|
||||
G_PEDICT(GBL_other) = EDICT_TO_PROG(check);
|
||||
PR_ExecuteProgram(ED_FUNC(pusher, ED_blocked));
|
||||
}
|
||||
|
||||
|
@ -608,8 +608,8 @@ void SV_Physics_Pusher(edict_t *ent)
|
|||
{
|
||||
ED_FLOAT(ent, ED_nextthink) = 0;
|
||||
G_FLOAT(GBL_time) = sv.time;
|
||||
G_INT(GBL_self) = EDICT_TO_PROG(ent);
|
||||
G_INT(GBL_other) = EDICT_TO_PROG(sv.edicts);
|
||||
G_PEDICT(GBL_self) = EDICT_TO_PROG(ent);
|
||||
G_PEDICT(GBL_other) = EDICT_TO_PROG(sv.edicts);
|
||||
PR_ExecuteProgram(ED_FUNC(ent, ED_think));
|
||||
if(ent->free)
|
||||
return;
|
||||
|
@ -913,7 +913,7 @@ void SV_WalkMove(edict_t *ent)
|
|||
if(ED_FLOAT(ent, ED_solid) == SOLID_BSP)
|
||||
{
|
||||
ED_FLOAT(ent, ED_flags) = (int32_t)ED_FLOAT(ent, ED_flags) | FL_ONGROUND;
|
||||
ED_INT(ent, ED_groundentity) = EDICT_TO_PROG(downtrace.ent);
|
||||
ED_PEDICT(ent, ED_groundentity) = EDICT_TO_PROG(downtrace.ent);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -943,7 +943,7 @@ void SV_Physics_Client(edict_t *ent, int32_t num)
|
|||
// call standard client pre-think
|
||||
//
|
||||
G_FLOAT(GBL_time) = sv.time;
|
||||
G_INT(GBL_self) = EDICT_TO_PROG(ent);
|
||||
G_PEDICT(GBL_self) = EDICT_TO_PROG(ent);
|
||||
PR_ExecuteProgram(G_FUNC(GBL_PlayerPreThink));
|
||||
|
||||
//
|
||||
|
@ -997,7 +997,7 @@ void SV_Physics_Client(edict_t *ent, int32_t num)
|
|||
SV_LinkEdict(ent, true);
|
||||
|
||||
G_FLOAT(GBL_time) = sv.time;
|
||||
G_INT(GBL_self) = EDICT_TO_PROG(ent);
|
||||
G_PEDICT(GBL_self) = EDICT_TO_PROG(ent);
|
||||
PR_ExecuteProgram(G_FUNC(GBL_PlayerPostThink));
|
||||
}
|
||||
|
||||
|
@ -1137,7 +1137,7 @@ void SV_Physics_Toss(edict_t *ent)
|
|||
if(ED_VECTOR(ent, ED_velocity)[2] < 60 || ED_FLOAT(ent, ED_movetype) != MOVETYPE_BOUNCE)
|
||||
{
|
||||
ED_FLOAT(ent, ED_flags) = (int32_t)ED_FLOAT(ent, ED_flags) | FL_ONGROUND;
|
||||
ED_INT(ent, ED_groundentity) = EDICT_TO_PROG(trace.ent);
|
||||
ED_PEDICT(ent, ED_groundentity) = EDICT_TO_PROG(trace.ent);
|
||||
VectorCopy(vec3_origin, ED_VECTOR(ent, ED_velocity));
|
||||
VectorCopy(vec3_origin, ED_VECTOR(ent, ED_avelocity));
|
||||
}
|
||||
|
@ -1212,8 +1212,8 @@ void SV_Physics(void)
|
|||
edict_t *ent;
|
||||
|
||||
// let the progs know that a new frame has started
|
||||
G_INT(GBL_self) = EDICT_TO_PROG(sv.edicts);
|
||||
G_INT(GBL_other) = EDICT_TO_PROG(sv.edicts);
|
||||
G_PEDICT(GBL_self) = EDICT_TO_PROG(sv.edicts);
|
||||
G_PEDICT(GBL_other) = EDICT_TO_PROG(sv.edicts);
|
||||
G_FLOAT(GBL_time) = sv.time;
|
||||
PR_ExecuteProgram(G_FUNC(GBL_StartFrame));
|
||||
|
||||
|
|
|
@ -375,8 +375,8 @@ void SV_AirMove(void)
|
|||
===================
|
||||
SV_ClientThink
|
||||
|
||||
the move fields specify an intended velocity in pix/sec
|
||||
the angle fields specify an exact angular motion in degrees
|
||||
moves specify an intended velocity in pix/sec
|
||||
angles specify an exact angular motion in degrees
|
||||
===================
|
||||
*/
|
||||
void SV_ClientThink(void)
|
||||
|
|
|
@ -140,7 +140,7 @@ sys_socket_t UDP_OpenSocket(int32_t port)
|
|||
{
|
||||
sys_socket_t newsocket;
|
||||
struct sockaddr_in address;
|
||||
int32_t _true = 1;
|
||||
int32_t istrue = 1;
|
||||
int32_t err;
|
||||
|
||||
if((newsocket = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == INVALID_SOCKET)
|
||||
|
@ -150,8 +150,8 @@ sys_socket_t UDP_OpenSocket(int32_t port)
|
|||
return INVALID_SOCKET;
|
||||
}
|
||||
|
||||
if(ioctlsocket(newsocket, FIONBIO, &_true) == SOCKET_ERROR)
|
||||
goto ErrorReturn;
|
||||
if(ioctlsocket(newsocket, FIONBIO, &istrue) == SOCKET_ERROR)
|
||||
goto error;
|
||||
|
||||
memset(&address, 0, sizeof(struct sockaddr_in));
|
||||
address.sin_family = AF_INET;
|
||||
|
@ -160,7 +160,7 @@ sys_socket_t UDP_OpenSocket(int32_t port)
|
|||
if(bind(newsocket, (struct sockaddr *)&address, sizeof(address)) == 0)
|
||||
return newsocket;
|
||||
|
||||
ErrorReturn:
|
||||
error:
|
||||
err = SOCKETERRNO;
|
||||
Con_SafePrintf("UDP_OpenSocket: %s\n", socketerror(err));
|
||||
UDP_CloseSocket(newsocket);
|
||||
|
|
|
@ -269,13 +269,13 @@ static void Sys_GetBasedir(char *argv0, char *dst, size_t dstsize)
|
|||
{
|
||||
perror("realpath");
|
||||
if(getcwd(dst, dstsize - 1) == NULL)
|
||||
_fail:
|
||||
fail:
|
||||
Sys_Error("Couldn't determine current directory");
|
||||
}
|
||||
else
|
||||
{
|
||||
/* strip off the binary name */
|
||||
if(!(tmp = strdup(dst))) goto _fail;
|
||||
if(!(tmp = strdup(dst))) goto fail;
|
||||
q_strlcpy(dst, dirname(tmp), dstsize);
|
||||
free(tmp);
|
||||
}
|
||||
|
|
|
@ -230,7 +230,7 @@ sys_socket_t WINS_OpenSocket(int32_t port)
|
|||
}
|
||||
|
||||
if(ioctlsocket(newsocket, FIONBIO, &_true) == SOCKET_ERROR)
|
||||
goto ErrorReturn;
|
||||
goto error;
|
||||
|
||||
memset(&address, 0, sizeof(struct sockaddr_in));
|
||||
address.sin_family = AF_INET;
|
||||
|
@ -249,7 +249,7 @@ sys_socket_t WINS_OpenSocket(int32_t port)
|
|||
}
|
||||
/* else: we are still in init phase, no need to error */
|
||||
|
||||
ErrorReturn:
|
||||
error:
|
||||
err = SOCKETERRNO;
|
||||
Con_SafePrintf("WINS_OpenSocket: %s\n", socketerror(err));
|
||||
closesocket(newsocket);
|
||||
|
@ -309,7 +309,7 @@ static int32_t PartialIPAddress(const char *in, struct qsockaddr *hostaddr)
|
|||
}
|
||||
|
||||
if(*b++ == ':')
|
||||
port = Q_atoi(b);
|
||||
port = atoi(b);
|
||||
else
|
||||
port = net_hostport;
|
||||
|
||||
|
@ -478,11 +478,11 @@ int32_t WINS_GetNameFromAddr(struct qsockaddr *addr, char *name)
|
|||
sizeof(struct in_addr), AF_INET);
|
||||
if(hostentry)
|
||||
{
|
||||
Q_strncpy(name, (char *)hostentry->h_name, NET_NAMELEN - 1);
|
||||
strncpy(name, (char *)hostentry->h_name, NET_NAMELEN - 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Q_strcpy(name, WINS_AddrToString(addr));
|
||||
strcpy(name, WINS_AddrToString(addr));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -96,8 +96,8 @@ sys_socket_t WIPX_Init(void)
|
|||
broadcastaddr.sa_socket = htons((uint16_t)net_hostport);
|
||||
|
||||
WIPX_GetSocketAddr(net_controlsocket, &addr);
|
||||
Q_strcpy(my_ipx_address, WIPX_AddrToString(&addr));
|
||||
colon = Q_strrchr(my_ipx_address, ':');
|
||||
strcpy(my_ipx_address, WIPX_AddrToString(&addr));
|
||||
colon = strrchr(my_ipx_address, ':');
|
||||
if(colon)
|
||||
*colon = 0;
|
||||
|
||||
|
@ -166,11 +166,11 @@ sys_socket_t WIPX_OpenSocket(int32_t port)
|
|||
}
|
||||
|
||||
if(ioctlsocket(newsocket, FIONBIO, &_true) == SOCKET_ERROR)
|
||||
goto ErrorReturn;
|
||||
goto error;
|
||||
|
||||
if(setsockopt(newsocket, SOL_SOCKET, SO_BROADCAST, (char *)&_true, sizeof(_true))
|
||||
== SOCKET_ERROR)
|
||||
goto ErrorReturn;
|
||||
goto error;
|
||||
|
||||
address.sa_family = AF_IPX;
|
||||
memset(address.sa_netnum, 0, 4);
|
||||
|
@ -191,7 +191,7 @@ sys_socket_t WIPX_OpenSocket(int32_t port)
|
|||
}
|
||||
/* else: we are still in init phase, no need to error */
|
||||
|
||||
ErrorReturn:
|
||||
error:
|
||||
err = SOCKETERRNO;
|
||||
Con_SafePrintf("WIPX_OpenSocket: %s\n", socketerror(err));
|
||||
closesocket(newsocket);
|
||||
|
@ -327,7 +327,7 @@ int32_t WIPX_StringToAddr(const char *string, struct qsockaddr *addr)
|
|||
char buf[3];
|
||||
|
||||
buf[2] = 0;
|
||||
Q_memset(addr, 0, sizeof(struct qsockaddr));
|
||||
memset(addr, 0, sizeof(struct qsockaddr));
|
||||
addr->qsa_family = AF_IPX;
|
||||
|
||||
#define DO(src,dest) do { \
|
||||
|
@ -363,7 +363,7 @@ int32_t WIPX_GetSocketAddr(sys_socket_t handle, struct qsockaddr *addr)
|
|||
sys_socket_t socketid = ipxsocket[handle];
|
||||
socklen_t addrlen = sizeof(struct qsockaddr);
|
||||
|
||||
Q_memset(addr, 0, sizeof(struct qsockaddr));
|
||||
memset(addr, 0, sizeof(struct qsockaddr));
|
||||
if(getsockname(socketid, (struct sockaddr *)addr, &addrlen) != 0)
|
||||
{
|
||||
int32_t err = SOCKETERRNO;
|
||||
|
@ -378,7 +378,7 @@ int32_t WIPX_GetSocketAddr(sys_socket_t handle, struct qsockaddr *addr)
|
|||
|
||||
int32_t WIPX_GetNameFromAddr(struct qsockaddr *addr, char *name)
|
||||
{
|
||||
Q_strcpy(name, WIPX_AddrToString(addr));
|
||||
strcpy(name, WIPX_AddrToString(addr));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -389,7 +389,7 @@ int32_t WIPX_GetAddrFromName(const char *name, struct qsockaddr *addr)
|
|||
int32_t n;
|
||||
char buf[32];
|
||||
|
||||
n = Q_strlen(name);
|
||||
n = strlen(name);
|
||||
|
||||
if(n == 12)
|
||||
{
|
||||
|
|
|
@ -142,13 +142,13 @@ hull_t *SV_HullForEntity(edict_t *ent, vec3_t mins, vec3_t maxs, vec3_t offset)
|
|||
// explicit hulls in the BSP model
|
||||
if(ED_FLOAT(ent, ED_movetype) != MOVETYPE_PUSH)
|
||||
Host_Error("SOLID_BSP without MOVETYPE_PUSH (%s at %f %f %f)",
|
||||
PR_GetString(ED_RSTRING(ent, ED_classname)), ED_VECTOR(ent, ED_origin)[0], ED_VECTOR(ent, ED_origin)[1], ED_VECTOR(ent, ED_origin)[2]);
|
||||
ED_STRING(ent, ED_classname), ED_VECTOR(ent, ED_origin)[0], ED_VECTOR(ent, ED_origin)[1], ED_VECTOR(ent, ED_origin)[2]);
|
||||
|
||||
model = sv.models[(int32_t)ED_FLOAT(ent, ED_modelindex) ];
|
||||
|
||||
if(!model || model->type != mod_brush)
|
||||
Host_Error("SOLID_BSP with a non bsp model (%s at %f %f %f)",
|
||||
PR_GetString(ED_RSTRING(ent, ED_classname)), ED_VECTOR(ent, ED_origin)[0], ED_VECTOR(ent, ED_origin)[1], ED_VECTOR(ent, ED_origin)[2]);
|
||||
ED_STRING(ent, ED_classname), ED_VECTOR(ent, ED_origin)[0], ED_VECTOR(ent, ED_origin)[1], ED_VECTOR(ent, ED_origin)[2]);
|
||||
|
||||
VectorSubtract(maxs, mins, size);
|
||||
if(size[0] < 3)
|
||||
|
@ -364,16 +364,16 @@ void SV_TouchLinks(edict_t *ent)
|
|||
|| ED_VECTOR(ent, ED_absmax)[1] < ED_VECTOR(touch, ED_absmin)[1]
|
||||
|| ED_VECTOR(ent, ED_absmax)[2] < ED_VECTOR(touch, ED_absmin)[2])
|
||||
continue;
|
||||
old_self = G_INT(GBL_self);
|
||||
old_other = G_INT(GBL_other);
|
||||
old_self = G_PEDICT(GBL_self);
|
||||
old_other = G_PEDICT(GBL_other);
|
||||
|
||||
G_INT(GBL_self) = EDICT_TO_PROG(touch);
|
||||
G_INT(GBL_other) = EDICT_TO_PROG(ent);
|
||||
G_PEDICT(GBL_self) = EDICT_TO_PROG(touch);
|
||||
G_PEDICT(GBL_other) = EDICT_TO_PROG(ent);
|
||||
G_FLOAT(GBL_time) = sv.time;
|
||||
PR_ExecuteProgram(ED_FUNC(touch, ED_touch));
|
||||
|
||||
G_INT(GBL_self) = old_self;
|
||||
G_INT(GBL_other) = old_other;
|
||||
G_PEDICT(GBL_self) = old_self;
|
||||
G_PEDICT(GBL_other) = old_other;
|
||||
}
|
||||
|
||||
// free hunk-allocated edicts array
|
||||
|
@ -820,10 +820,10 @@ void SV_ClipToLinks(areanode_t *node, moveclip_t *clip)
|
|||
return;
|
||||
if(clip->passedict)
|
||||
{
|
||||
if(PROG_TO_EDICT(ED_INT(touch, ED_owner)) == clip->passedict)
|
||||
continue; // don't clip against own missiles
|
||||
if(PROG_TO_EDICT(ED_INT(clip->passedict, ED_owner)) == touch)
|
||||
continue; // don't clip against owner
|
||||
if(PROG_TO_EDICT(ED_PEDICT(touch, ED_owner)) == clip->passedict)
|
||||
continue; // don't clip against own missiles
|
||||
if(PROG_TO_EDICT(ED_PEDICT(clip->passedict, ED_owner)) == touch)
|
||||
continue; // don't clip against owner
|
||||
}
|
||||
|
||||
if((int32_t)ED_FLOAT(touch, ED_flags) & FL_MONSTER)
|
||||
|
|
|
@ -207,7 +207,7 @@ void *Z_Malloc(int32_t size)
|
|||
buf = Z_TagMalloc(size, 1);
|
||||
if(!buf)
|
||||
Sys_Error("Z_Malloc: failed on allocation of %" PRIi32 " bytes", size);
|
||||
Q_memset(buf, 0, size);
|
||||
memset(buf, 0, size);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
@ -618,9 +618,9 @@ void Cache_Move(cache_system_t *c)
|
|||
{
|
||||
// Con_Printf ("cache_move ok\n");
|
||||
|
||||
Q_memcpy(new_cs + 1, c + 1, c->size - sizeof(cache_system_t));
|
||||
memcpy(new_cs + 1, c + 1, c->size - sizeof(cache_system_t));
|
||||
new_cs->user = c->user;
|
||||
Q_memcpy(new_cs->name, c->name, sizeof(new_cs->name));
|
||||
memcpy(new_cs->name, c->name, sizeof(new_cs->name));
|
||||
Cache_Free(c->user, false); //johnfitz -- added second argument
|
||||
new_cs->user->data = new_cs + 1;
|
||||
}
|
||||
|
@ -977,7 +977,7 @@ void Memory_Init(void *buf, int32_t size)
|
|||
if(p)
|
||||
{
|
||||
if(p < com_argc - 1)
|
||||
zonesize = Q_atoi(com_argv[p + 1]) * 1024;
|
||||
zonesize = atoi(com_argv[p + 1]) * 1024;
|
||||
else
|
||||
Sys_Error("Memory_Init: you must specify a size in KB after -zone");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue