2010-02-15 23:26:55 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 1996-2001 Id Software, Inc.
|
2014-09-22 08:55:46 +00:00
|
|
|
Copyright (C) 2010-2014 QuakeSpasm developers
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "quakedef.h"
|
|
|
|
|
2011-12-12 08:56:25 +00:00
|
|
|
static const char *pr_opnames[] =
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2011-12-12 08:56:25 +00:00
|
|
|
"DONE",
|
|
|
|
|
|
|
|
"MUL_F",
|
|
|
|
"MUL_V",
|
|
|
|
"MUL_FV",
|
|
|
|
"MUL_VF",
|
|
|
|
|
|
|
|
"DIV",
|
|
|
|
|
|
|
|
"ADD_F",
|
|
|
|
"ADD_V",
|
|
|
|
|
|
|
|
"SUB_F",
|
|
|
|
"SUB_V",
|
|
|
|
|
|
|
|
"EQ_F",
|
|
|
|
"EQ_V",
|
|
|
|
"EQ_S",
|
|
|
|
"EQ_E",
|
|
|
|
"EQ_FNC",
|
|
|
|
|
|
|
|
"NE_F",
|
|
|
|
"NE_V",
|
|
|
|
"NE_S",
|
|
|
|
"NE_E",
|
|
|
|
"NE_FNC",
|
|
|
|
|
|
|
|
"LE",
|
|
|
|
"GE",
|
|
|
|
"LT",
|
|
|
|
"GT",
|
|
|
|
|
|
|
|
"INDIRECT",
|
|
|
|
"INDIRECT",
|
|
|
|
"INDIRECT",
|
|
|
|
"INDIRECT",
|
|
|
|
"INDIRECT",
|
|
|
|
"INDIRECT",
|
|
|
|
|
|
|
|
"ADDRESS",
|
|
|
|
|
|
|
|
"STORE_F",
|
|
|
|
"STORE_V",
|
|
|
|
"STORE_S",
|
|
|
|
"STORE_ENT",
|
|
|
|
"STORE_FLD",
|
|
|
|
"STORE_FNC",
|
|
|
|
|
|
|
|
"STOREP_F",
|
|
|
|
"STOREP_V",
|
|
|
|
"STOREP_S",
|
|
|
|
"STOREP_ENT",
|
|
|
|
"STOREP_FLD",
|
|
|
|
"STOREP_FNC",
|
|
|
|
|
|
|
|
"RETURN",
|
|
|
|
|
|
|
|
"NOT_F",
|
|
|
|
"NOT_V",
|
|
|
|
"NOT_S",
|
|
|
|
"NOT_ENT",
|
|
|
|
"NOT_FNC",
|
|
|
|
|
|
|
|
"IF",
|
|
|
|
"IFNOT",
|
|
|
|
|
|
|
|
"CALL0",
|
|
|
|
"CALL1",
|
|
|
|
"CALL2",
|
|
|
|
"CALL3",
|
|
|
|
"CALL4",
|
|
|
|
"CALL5",
|
|
|
|
"CALL6",
|
|
|
|
"CALL7",
|
|
|
|
"CALL8",
|
|
|
|
|
|
|
|
"STATE",
|
|
|
|
|
|
|
|
"GOTO",
|
|
|
|
|
|
|
|
"AND",
|
|
|
|
"OR",
|
|
|
|
|
|
|
|
"BITAND",
|
|
|
|
"BITOR"
|
2010-02-15 23:26:55 +00:00
|
|
|
};
|
|
|
|
|
2010-08-29 02:22:55 +00:00
|
|
|
const char *PR_GlobalString (int ofs);
|
|
|
|
const char *PR_GlobalStringNoContents (int ofs);
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
PR_PrintStatement
|
|
|
|
=================
|
|
|
|
*/
|
2011-12-12 08:56:25 +00:00
|
|
|
static void PR_PrintStatement (dstatement_t *s)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2011-12-12 08:56:25 +00:00
|
|
|
int i;
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2011-12-12 08:56:25 +00:00
|
|
|
if ((unsigned int)s->op < sizeof(pr_opnames)/sizeof(pr_opnames[0]))
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2011-12-12 08:56:25 +00:00
|
|
|
Con_Printf("%s ", pr_opnames[s->op]);
|
2010-02-15 23:26:55 +00:00
|
|
|
i = strlen(pr_opnames[s->op]);
|
2011-12-12 08:56:25 +00:00
|
|
|
for ( ; i < 10; i++)
|
|
|
|
Con_Printf(" ");
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (s->op == OP_IF || s->op == OP_IFNOT)
|
2011-12-12 08:56:25 +00:00
|
|
|
Con_Printf("%sbranch %i", PR_GlobalString(s->a), s->b);
|
2010-02-15 23:26:55 +00:00
|
|
|
else if (s->op == OP_GOTO)
|
|
|
|
{
|
2011-12-12 08:56:25 +00:00
|
|
|
Con_Printf("branch %i", s->a);
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
2011-12-12 08:56:25 +00:00
|
|
|
else if ((unsigned int)(s->op-OP_STORE_F) < 6)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2011-12-12 08:56:25 +00:00
|
|
|
Con_Printf("%s", PR_GlobalString(s->a));
|
|
|
|
Con_Printf("%s", PR_GlobalStringNoContents(s->b));
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (s->a)
|
2011-12-12 08:56:25 +00:00
|
|
|
Con_Printf("%s", PR_GlobalString(s->a));
|
2010-02-15 23:26:55 +00:00
|
|
|
if (s->b)
|
2011-12-12 08:56:25 +00:00
|
|
|
Con_Printf("%s", PR_GlobalString(s->b));
|
2010-02-15 23:26:55 +00:00
|
|
|
if (s->c)
|
2011-12-12 08:56:25 +00:00
|
|
|
Con_Printf("%s", PR_GlobalStringNoContents(s->c));
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
2011-12-12 08:56:25 +00:00
|
|
|
Con_Printf("\n");
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
PR_StackTrace
|
|
|
|
============
|
|
|
|
*/
|
2011-12-12 08:56:25 +00:00
|
|
|
static void PR_StackTrace (void)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2011-12-12 08:56:25 +00:00
|
|
|
int i;
|
2010-02-15 23:26:55 +00:00
|
|
|
dfunction_t *f;
|
|
|
|
|
2018-05-01 00:35:14 +00:00
|
|
|
if (qcvm->depth == 0)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2011-12-12 08:56:25 +00:00
|
|
|
Con_Printf("<NO STACK>\n");
|
2010-02-15 23:26:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-01 00:35:14 +00:00
|
|
|
qcvm->stack[qcvm->depth].f = qcvm->xfunction;
|
|
|
|
for (i = qcvm->depth; i >= 0; i--)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2018-05-01 00:35:14 +00:00
|
|
|
f = qcvm->stack[i].f;
|
2010-02-15 23:26:55 +00:00
|
|
|
if (!f)
|
|
|
|
{
|
2011-12-12 08:56:25 +00:00
|
|
|
Con_Printf("<NO FUNCTION>\n");
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
else
|
2011-12-12 08:56:25 +00:00
|
|
|
{
|
|
|
|
Con_Printf("%12s : %s\n", PR_GetString(f->s_file), PR_GetString(f->s_name));
|
|
|
|
}
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
PR_Profile_f
|
|
|
|
|
|
|
|
============
|
|
|
|
*/
|
|
|
|
void PR_Profile_f (void)
|
|
|
|
{
|
2011-12-12 08:56:25 +00:00
|
|
|
int i, num;
|
|
|
|
int pmax;
|
2010-02-15 23:26:55 +00:00
|
|
|
dfunction_t *f, *best;
|
|
|
|
|
2010-02-20 00:00:40 +00:00
|
|
|
if (!sv.active)
|
|
|
|
return;
|
|
|
|
|
2018-05-01 00:35:14 +00:00
|
|
|
PR_SwitchQCVM(&sv.qcvm);
|
|
|
|
|
2010-02-15 23:26:55 +00:00
|
|
|
num = 0;
|
|
|
|
do
|
|
|
|
{
|
2010-06-01 12:10:49 +00:00
|
|
|
pmax = 0;
|
2010-02-15 23:26:55 +00:00
|
|
|
best = NULL;
|
2018-05-01 00:35:14 +00:00
|
|
|
for (i = 0; i < qcvm->progs->numfunctions; i++)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2018-05-01 00:35:14 +00:00
|
|
|
f = &qcvm->functions[i];
|
2010-06-01 12:10:49 +00:00
|
|
|
if (f->profile > pmax)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2010-06-01 12:10:49 +00:00
|
|
|
pmax = f->profile;
|
2010-02-15 23:26:55 +00:00
|
|
|
best = f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (best)
|
|
|
|
{
|
|
|
|
if (num < 10)
|
2011-12-12 08:56:25 +00:00
|
|
|
Con_Printf("%7i %s\n", best->profile, PR_GetString(best->s_name));
|
2010-02-15 23:26:55 +00:00
|
|
|
num++;
|
|
|
|
best->profile = 0;
|
|
|
|
}
|
|
|
|
} while (best);
|
2018-05-01 00:35:14 +00:00
|
|
|
|
|
|
|
PR_SwitchQCVM(NULL);
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
PR_RunError
|
|
|
|
|
|
|
|
Aborts the currently executing function
|
|
|
|
============
|
|
|
|
*/
|
Constified Con_DebugLog, Con_Print, Con_Printf, Con_Warning, Con_DPrintf,
Con_DPrintf2, Con_SafePrintf, Con_CenterPrintf, Con_LogCenterPrint,
Con_NotifyBox, PL_ErrorDialog, PR_RunError, Host_EndGame, Host_Error,
SV_ClientPrintf, SV_BroadcastPrintf, Host_ClientCommands, Sys_DebugLog,
Sys_Error, Sys_Printf, BOPS_Error and va. Added noreturn attribute to
Sys_Error, Sys_Quit, BOPS_Error, PR_RunError, Host_EndGame and Host_Error.
Added format printf attribute to Con_DebugLog, Con_Printf, Con_Warning,
Con_DPrintf, Con_DPrintf2, Con_SafePrintf, Con_CenterPrintf, PL_ErrorDialog,
PR_RunError, Host_EndGame, Host_Error, SV_ClientPrintf, SV_BroadcastPrintf,
Host_ClientCommands, Sys_DebugLog, Sys_Error, Sys_Printf and va. Adjusted
Host_Status_f and NET_Ban_f for the new attributes. Fixed broken format
strings in Con_Dump_f, Mod_LoadTexinfo, PR_AllocStringSlots and FloorDivMod.
Defined __attribute__ macros in quakedef.h so that we don't break non-gcc
compilers.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@154 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-04-26 16:30:40 +00:00
|
|
|
void PR_RunError (const char *error, ...)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2011-12-12 08:56:25 +00:00
|
|
|
va_list argptr;
|
|
|
|
char string[1024];
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2011-12-12 08:56:25 +00:00
|
|
|
va_start (argptr, error);
|
2010-08-31 16:57:12 +00:00
|
|
|
q_vsnprintf (string, sizeof(string), error, argptr);
|
2010-02-15 23:26:55 +00:00
|
|
|
va_end (argptr);
|
|
|
|
|
2018-05-01 00:35:14 +00:00
|
|
|
PR_PrintStatement(qcvm->statements + qcvm->xstatement);
|
2011-12-12 08:56:25 +00:00
|
|
|
PR_StackTrace();
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2011-12-12 08:56:25 +00:00
|
|
|
Con_Printf("%s\n", string);
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2018-05-01 00:35:14 +00:00
|
|
|
qcvm->depth = 0; // dump the stack so host_error can shutdown functions
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2011-12-12 08:56:25 +00:00
|
|
|
Host_Error("Program error");
|
|
|
|
}
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
PR_EnterFunction
|
|
|
|
|
|
|
|
Returns the new program statement counter
|
|
|
|
====================
|
|
|
|
*/
|
2011-12-12 08:56:25 +00:00
|
|
|
static int PR_EnterFunction (dfunction_t *f)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2011-12-12 08:56:25 +00:00
|
|
|
int i, j, c, o;
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2018-05-01 00:35:14 +00:00
|
|
|
qcvm->stack[qcvm->depth].s = qcvm->xstatement;
|
|
|
|
qcvm->stack[qcvm->depth].f = qcvm->xfunction;
|
|
|
|
qcvm->depth++;
|
|
|
|
if (qcvm->depth >= MAX_STACK_DEPTH)
|
2011-12-12 08:56:25 +00:00
|
|
|
PR_RunError("stack overflow");
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2011-12-12 08:56:25 +00:00
|
|
|
// save off any locals that the new function steps on
|
2010-02-15 23:26:55 +00:00
|
|
|
c = f->locals;
|
2018-05-01 00:35:14 +00:00
|
|
|
if (qcvm->localstack_used + c > LOCALSTACK_SIZE)
|
2011-12-12 08:56:25 +00:00
|
|
|
PR_RunError("PR_ExecuteProgram: locals stack overflow\n");
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2011-12-12 08:56:25 +00:00
|
|
|
for (i = 0; i < c ; i++)
|
2018-05-01 00:35:14 +00:00
|
|
|
qcvm->localstack[qcvm->localstack_used + i] = ((int *)qcvm->globals)[f->parm_start + i];
|
|
|
|
qcvm->localstack_used += c;
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2011-12-12 08:56:25 +00:00
|
|
|
// copy parameters
|
2010-02-15 23:26:55 +00:00
|
|
|
o = f->parm_start;
|
2011-12-12 08:56:25 +00:00
|
|
|
for (i = 0; i < f->numparms; i++)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2011-12-12 08:56:25 +00:00
|
|
|
for (j = 0; j < f->parm_size[i]; j++)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2018-05-01 00:35:14 +00:00
|
|
|
((int *)qcvm->globals)[o] = ((int *)qcvm->globals)[OFS_PARM0 + i*3 + j];
|
2010-02-15 23:26:55 +00:00
|
|
|
o++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-01 00:35:14 +00:00
|
|
|
qcvm->xfunction = f;
|
2010-02-15 23:26:55 +00:00
|
|
|
return f->first_statement - 1; // offset the s++
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
PR_LeaveFunction
|
|
|
|
====================
|
|
|
|
*/
|
2011-12-12 08:56:25 +00:00
|
|
|
static int PR_LeaveFunction (void)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2011-12-12 08:56:25 +00:00
|
|
|
int i, c;
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2018-05-01 00:35:14 +00:00
|
|
|
if (qcvm->depth <= 0)
|
2012-11-15 17:30:43 +00:00
|
|
|
Host_Error("prog stack underflow");
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2011-12-12 08:56:25 +00:00
|
|
|
// Restore locals from the stack
|
2018-05-01 00:35:14 +00:00
|
|
|
c = qcvm->xfunction->locals;
|
|
|
|
qcvm->localstack_used -= c;
|
|
|
|
if (qcvm->localstack_used < 0)
|
2011-12-12 08:56:25 +00:00
|
|
|
PR_RunError("PR_ExecuteProgram: locals stack underflow");
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2011-12-12 08:56:25 +00:00
|
|
|
for (i = 0; i < c; i++)
|
2018-05-01 00:35:14 +00:00
|
|
|
((int *)qcvm->globals)[qcvm->xfunction->parm_start + i] = qcvm->localstack[qcvm->localstack_used + i];
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2011-12-12 08:56:25 +00:00
|
|
|
// up stack
|
2018-05-01 00:35:14 +00:00
|
|
|
qcvm->depth--;
|
|
|
|
qcvm->xfunction = qcvm->stack[qcvm->depth].f;
|
|
|
|
return qcvm->stack[qcvm->depth].s;
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
PR_ExecuteProgram
|
2011-12-12 08:56:25 +00:00
|
|
|
|
|
|
|
The interpretation main loop
|
2010-02-15 23:26:55 +00:00
|
|
|
====================
|
|
|
|
*/
|
2018-05-01 00:35:14 +00:00
|
|
|
#define OPA ((eval_t *)&qcvm->globals[(unsigned short)st->a])
|
|
|
|
#define OPB ((eval_t *)&qcvm->globals[(unsigned short)st->b])
|
|
|
|
#define OPC ((eval_t *)&qcvm->globals[(unsigned short)st->c])
|
2011-12-12 09:03:34 +00:00
|
|
|
|
2010-02-15 23:26:55 +00:00
|
|
|
void PR_ExecuteProgram (func_t fnum)
|
|
|
|
{
|
2011-12-12 08:56:25 +00:00
|
|
|
eval_t *ptr;
|
2010-02-15 23:26:55 +00:00
|
|
|
dstatement_t *st;
|
|
|
|
dfunction_t *f, *newf;
|
2011-12-12 09:03:34 +00:00
|
|
|
int profile, startprofile;
|
2011-12-12 08:56:25 +00:00
|
|
|
edict_t *ed;
|
2010-02-15 23:26:55 +00:00
|
|
|
int exitdepth;
|
|
|
|
|
2018-05-01 00:35:14 +00:00
|
|
|
if (!fnum || fnum >= qcvm->progs->numfunctions)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
if (pr_global_struct->self)
|
|
|
|
ED_Print (PROG_TO_EDICT(pr_global_struct->self));
|
|
|
|
Host_Error ("PR_ExecuteProgram: NULL function");
|
|
|
|
}
|
|
|
|
|
2018-05-01 00:35:14 +00:00
|
|
|
f = &qcvm->functions[fnum];
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2017-09-17 02:12:53 +00:00
|
|
|
//FIXME: if this is a builtin, then we're going to crash.
|
|
|
|
|
2018-05-01 00:35:14 +00:00
|
|
|
qcvm->trace = false;
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
// make a stack frame
|
2018-05-01 00:35:14 +00:00
|
|
|
exitdepth = qcvm->depth;
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2018-05-01 00:35:14 +00:00
|
|
|
st = &qcvm->statements[PR_EnterFunction(f)];
|
2011-12-12 09:03:34 +00:00
|
|
|
startprofile = profile = 0;
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2011-12-12 08:56:25 +00:00
|
|
|
while (1)
|
|
|
|
{
|
2011-12-12 09:03:34 +00:00
|
|
|
st++; /* next statement */
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2018-07-07 14:05:34 +00:00
|
|
|
if (++profile > 0x10000000) //spike -- was decimal 100000
|
2011-12-12 09:03:34 +00:00
|
|
|
{
|
2018-05-01 00:35:14 +00:00
|
|
|
qcvm->xstatement = st - qcvm->statements;
|
2011-12-12 08:56:25 +00:00
|
|
|
PR_RunError("runaway loop error");
|
2011-12-12 09:03:34 +00:00
|
|
|
}
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2018-05-01 00:35:14 +00:00
|
|
|
if (qcvm->trace)
|
2011-12-12 08:56:25 +00:00
|
|
|
PR_PrintStatement(st);
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
switch (st->op)
|
|
|
|
{
|
|
|
|
case OP_ADD_F:
|
2011-12-12 09:03:34 +00:00
|
|
|
OPC->_float = OPA->_float + OPB->_float;
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
case OP_ADD_V:
|
2011-12-12 09:03:34 +00:00
|
|
|
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];
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_SUB_F:
|
2011-12-12 09:03:34 +00:00
|
|
|
OPC->_float = OPA->_float - OPB->_float;
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
case OP_SUB_V:
|
2011-12-12 09:03:34 +00:00
|
|
|
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];
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_MUL_F:
|
2011-12-12 09:03:34 +00:00
|
|
|
OPC->_float = OPA->_float * OPB->_float;
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
case OP_MUL_V:
|
2011-12-12 09:03:34 +00:00
|
|
|
OPC->_float = OPA->vector[0] * OPB->vector[0] +
|
|
|
|
OPA->vector[1] * OPB->vector[1] +
|
|
|
|
OPA->vector[2] * OPB->vector[2];
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
case OP_MUL_FV:
|
2011-12-12 09:03:34 +00:00
|
|
|
OPC->vector[0] = OPA->_float * OPB->vector[0];
|
|
|
|
OPC->vector[1] = OPA->_float * OPB->vector[1];
|
|
|
|
OPC->vector[2] = OPA->_float * OPB->vector[2];
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
case OP_MUL_VF:
|
2011-12-12 09:03:34 +00:00
|
|
|
OPC->vector[0] = OPB->_float * OPA->vector[0];
|
|
|
|
OPC->vector[1] = OPB->_float * OPA->vector[1];
|
|
|
|
OPC->vector[2] = OPB->_float * OPA->vector[2];
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_DIV_F:
|
2011-12-12 09:03:34 +00:00
|
|
|
OPC->_float = OPA->_float / OPB->_float;
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_BITAND:
|
2011-12-12 09:03:34 +00:00
|
|
|
OPC->_float = (int)OPA->_float & (int)OPB->_float;
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_BITOR:
|
2011-12-12 09:03:34 +00:00
|
|
|
OPC->_float = (int)OPA->_float | (int)OPB->_float;
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_GE:
|
2011-12-12 09:03:34 +00:00
|
|
|
OPC->_float = OPA->_float >= OPB->_float;
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
case OP_LE:
|
2011-12-12 09:03:34 +00:00
|
|
|
OPC->_float = OPA->_float <= OPB->_float;
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
case OP_GT:
|
2011-12-12 09:03:34 +00:00
|
|
|
OPC->_float = OPA->_float > OPB->_float;
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
case OP_LT:
|
2011-12-12 09:03:34 +00:00
|
|
|
OPC->_float = OPA->_float < OPB->_float;
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
case OP_AND:
|
2011-12-12 09:03:34 +00:00
|
|
|
OPC->_float = OPA->_float && OPB->_float;
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
case OP_OR:
|
2011-12-12 09:03:34 +00:00
|
|
|
OPC->_float = OPA->_float || OPB->_float;
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_NOT_F:
|
2011-12-12 09:03:34 +00:00
|
|
|
OPC->_float = !OPA->_float;
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
case OP_NOT_V:
|
2011-12-12 09:03:34 +00:00
|
|
|
OPC->_float = !OPA->vector[0] && !OPA->vector[1] && !OPA->vector[2];
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
case OP_NOT_S:
|
2011-12-12 09:03:34 +00:00
|
|
|
OPC->_float = !OPA->string || !*PR_GetString(OPA->string);
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
case OP_NOT_FNC:
|
2011-12-12 09:03:34 +00:00
|
|
|
OPC->_float = !OPA->function;
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
case OP_NOT_ENT:
|
2018-05-01 00:35:14 +00:00
|
|
|
OPC->_float = (PROG_TO_EDICT(OPA->edict) == qcvm->edicts);
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_EQ_F:
|
2011-12-12 09:03:34 +00:00
|
|
|
OPC->_float = OPA->_float == OPB->_float;
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
case OP_EQ_V:
|
2011-12-12 09:03:34 +00:00
|
|
|
OPC->_float = (OPA->vector[0] == OPB->vector[0]) &&
|
|
|
|
(OPA->vector[1] == OPB->vector[1]) &&
|
|
|
|
(OPA->vector[2] == OPB->vector[2]);
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
case OP_EQ_S:
|
2011-12-12 09:03:34 +00:00
|
|
|
OPC->_float = !strcmp(PR_GetString(OPA->string), PR_GetString(OPB->string));
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
case OP_EQ_E:
|
2011-12-12 09:03:34 +00:00
|
|
|
OPC->_float = OPA->_int == OPB->_int;
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
case OP_EQ_FNC:
|
2011-12-12 09:03:34 +00:00
|
|
|
OPC->_float = OPA->function == OPB->function;
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_NE_F:
|
2011-12-12 09:03:34 +00:00
|
|
|
OPC->_float = OPA->_float != OPB->_float;
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
case OP_NE_V:
|
2011-12-12 09:03:34 +00:00
|
|
|
OPC->_float = (OPA->vector[0] != OPB->vector[0]) ||
|
|
|
|
(OPA->vector[1] != OPB->vector[1]) ||
|
|
|
|
(OPA->vector[2] != OPB->vector[2]);
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
case OP_NE_S:
|
2011-12-12 09:03:34 +00:00
|
|
|
OPC->_float = strcmp(PR_GetString(OPA->string), PR_GetString(OPB->string));
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
case OP_NE_E:
|
2011-12-12 09:03:34 +00:00
|
|
|
OPC->_float = OPA->_int != OPB->_int;
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
case OP_NE_FNC:
|
2011-12-12 09:03:34 +00:00
|
|
|
OPC->_float = OPA->function != OPB->function;
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_STORE_F:
|
|
|
|
case OP_STORE_ENT:
|
2011-12-12 08:56:25 +00:00
|
|
|
case OP_STORE_FLD: // integers
|
2010-02-15 23:26:55 +00:00
|
|
|
case OP_STORE_S:
|
2011-12-12 08:56:25 +00:00
|
|
|
case OP_STORE_FNC: // pointers
|
2011-12-12 09:03:34 +00:00
|
|
|
OPB->_int = OPA->_int;
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
case OP_STORE_V:
|
2011-12-12 09:03:34 +00:00
|
|
|
OPB->vector[0] = OPA->vector[0];
|
|
|
|
OPB->vector[1] = OPA->vector[1];
|
|
|
|
OPB->vector[2] = OPA->vector[2];
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_STOREP_F:
|
|
|
|
case OP_STOREP_ENT:
|
2011-12-12 08:56:25 +00:00
|
|
|
case OP_STOREP_FLD: // integers
|
2010-02-15 23:26:55 +00:00
|
|
|
case OP_STOREP_S:
|
2011-12-12 08:56:25 +00:00
|
|
|
case OP_STOREP_FNC: // pointers
|
2018-05-01 00:35:14 +00:00
|
|
|
ptr = (eval_t *)((byte *)qcvm->edicts + OPB->_int);
|
2011-12-12 09:03:34 +00:00
|
|
|
ptr->_int = OPA->_int;
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
case OP_STOREP_V:
|
2018-05-01 00:35:14 +00:00
|
|
|
ptr = (eval_t *)((byte *)qcvm->edicts + OPB->_int);
|
2011-12-12 09:03:34 +00:00
|
|
|
ptr->vector[0] = OPA->vector[0];
|
|
|
|
ptr->vector[1] = OPA->vector[1];
|
|
|
|
ptr->vector[2] = OPA->vector[2];
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_ADDRESS:
|
2011-12-12 09:03:34 +00:00
|
|
|
ed = PROG_TO_EDICT(OPA->edict);
|
2010-02-15 23:26:55 +00:00
|
|
|
#ifdef PARANOID
|
2011-12-12 08:56:25 +00:00
|
|
|
NUM_FOR_EDICT(ed); // Make sure it's in range
|
2010-02-15 23:26:55 +00:00
|
|
|
#endif
|
2018-05-01 00:35:14 +00:00
|
|
|
if (ed == (edict_t *)qcvm->edicts && sv.state == ss_active)
|
2011-12-12 09:03:34 +00:00
|
|
|
{
|
2018-05-01 00:35:14 +00:00
|
|
|
qcvm->xstatement = st - qcvm->statements;
|
2011-12-12 08:56:25 +00:00
|
|
|
PR_RunError("assignment to world entity");
|
2011-12-12 09:03:34 +00:00
|
|
|
}
|
2018-05-01 00:35:14 +00:00
|
|
|
OPC->_int = (byte *)((int *)&ed->v + OPB->_int) - (byte *)qcvm->edicts;
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_LOAD_F:
|
|
|
|
case OP_LOAD_FLD:
|
|
|
|
case OP_LOAD_ENT:
|
|
|
|
case OP_LOAD_S:
|
|
|
|
case OP_LOAD_FNC:
|
2011-12-12 09:03:34 +00:00
|
|
|
ed = PROG_TO_EDICT(OPA->edict);
|
2010-02-15 23:26:55 +00:00
|
|
|
#ifdef PARANOID
|
2011-12-12 08:56:25 +00:00
|
|
|
NUM_FOR_EDICT(ed); // Make sure it's in range
|
2010-02-15 23:26:55 +00:00
|
|
|
#endif
|
2011-12-12 09:03:34 +00:00
|
|
|
OPC->_int = ((eval_t *)((int *)&ed->v + OPB->_int))->_int;
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_LOAD_V:
|
2011-12-12 09:03:34 +00:00
|
|
|
ed = PROG_TO_EDICT(OPA->edict);
|
2010-02-15 23:26:55 +00:00
|
|
|
#ifdef PARANOID
|
2011-12-12 08:56:25 +00:00
|
|
|
NUM_FOR_EDICT(ed); // Make sure it's in range
|
2010-02-15 23:26:55 +00:00
|
|
|
#endif
|
2011-12-12 09:03:34 +00:00
|
|
|
ptr = (eval_t *)((int *)&ed->v + OPB->_int);
|
|
|
|
OPC->vector[0] = ptr->vector[0];
|
|
|
|
OPC->vector[1] = ptr->vector[1];
|
|
|
|
OPC->vector[2] = ptr->vector[2];
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_IFNOT:
|
2011-12-12 09:03:34 +00:00
|
|
|
if (!OPA->_int)
|
|
|
|
st += st->b - 1; /* -1 to offset the st++ */
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_IF:
|
2011-12-12 09:03:34 +00:00
|
|
|
if (OPA->_int)
|
|
|
|
st += st->b - 1; /* -1 to offset the st++ */
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_GOTO:
|
2011-12-12 09:03:34 +00:00
|
|
|
st += st->a - 1; /* -1 to offset the st++ */
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_CALL0:
|
|
|
|
case OP_CALL1:
|
|
|
|
case OP_CALL2:
|
|
|
|
case OP_CALL3:
|
|
|
|
case OP_CALL4:
|
|
|
|
case OP_CALL5:
|
|
|
|
case OP_CALL6:
|
|
|
|
case OP_CALL7:
|
|
|
|
case OP_CALL8:
|
2018-05-01 00:35:14 +00:00
|
|
|
qcvm->xfunction->profile += profile - startprofile;
|
2011-12-12 09:03:34 +00:00
|
|
|
startprofile = profile;
|
2018-05-01 00:35:14 +00:00
|
|
|
qcvm->xstatement = st - qcvm->statements;
|
|
|
|
qcvm->argc = st->op - OP_CALL0;
|
2011-12-12 09:03:34 +00:00
|
|
|
if (!OPA->function)
|
2011-12-12 08:56:25 +00:00
|
|
|
PR_RunError("NULL function");
|
2018-05-01 00:35:14 +00:00
|
|
|
newf = &qcvm->functions[OPA->function];
|
2010-02-15 23:26:55 +00:00
|
|
|
if (newf->first_statement < 0)
|
2011-12-12 08:56:25 +00:00
|
|
|
{ // Built-in function
|
2011-12-12 09:03:34 +00:00
|
|
|
int i = -newf->first_statement;
|
2018-05-01 00:35:14 +00:00
|
|
|
if (i >= qcvm->numbuiltins)
|
2017-09-17 02:12:53 +00:00
|
|
|
i = 0; //just invoke the fixme builtin.
|
2018-05-01 00:35:14 +00:00
|
|
|
qcvm->builtins[i]();
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-12-12 08:56:25 +00:00
|
|
|
// Normal function
|
2018-05-01 00:35:14 +00:00
|
|
|
st = &qcvm->statements[PR_EnterFunction(newf)];
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_DONE:
|
|
|
|
case OP_RETURN:
|
2018-05-01 00:35:14 +00:00
|
|
|
qcvm->xfunction->profile += profile - startprofile;
|
2011-12-12 09:03:34 +00:00
|
|
|
startprofile = profile;
|
2018-05-01 00:35:14 +00:00
|
|
|
qcvm->xstatement = st - qcvm->statements;
|
|
|
|
qcvm->globals[OFS_RETURN] = qcvm->globals[(unsigned short)st->a];
|
|
|
|
qcvm->globals[OFS_RETURN + 1] = qcvm->globals[(unsigned short)st->a + 1];
|
|
|
|
qcvm->globals[OFS_RETURN + 2] = qcvm->globals[(unsigned short)st->a + 2];
|
|
|
|
st = &qcvm->statements[PR_LeaveFunction()];
|
|
|
|
if (qcvm->depth == exitdepth)
|
2011-12-12 08:56:25 +00:00
|
|
|
{ // Done
|
|
|
|
return;
|
|
|
|
}
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OP_STATE:
|
|
|
|
ed = PROG_TO_EDICT(pr_global_struct->self);
|
|
|
|
ed->v.nextthink = pr_global_struct->time + 0.1;
|
2011-12-12 09:03:34 +00:00
|
|
|
ed->v.frame = OPA->_float;
|
|
|
|
ed->v.think = OPB->function;
|
2010-02-15 23:26:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-05-01 00:35:14 +00:00
|
|
|
qcvm->xstatement = st - qcvm->statements;
|
2011-12-12 08:56:25 +00:00
|
|
|
PR_RunError("Bad opcode %i", st->op);
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
2011-12-12 08:56:25 +00:00
|
|
|
} /* end of while(1) loop */
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
2011-12-12 09:03:34 +00:00
|
|
|
#undef OPA
|
|
|
|
#undef OPB
|
|
|
|
#undef OPC
|
2010-02-15 23:26:55 +00:00
|
|
|
|