2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #define MAX_STACK_DEPTH 32
35 prstack_t pr_stack[MAX_STACK_DEPTH];
38 #define LOCALSTACK_SIZE 2048
39 int localstack[LOCALSTACK_SIZE];
44 dfunction_t *pr_xfunction;
139 char *PR_GlobalString (int ofs);
140 char *PR_GlobalStringNoContents (int ofs);
143 //=============================================================================
150 void PR_PrintStatement (dstatement_t *s)
154 if ( (unsigned)s->op < sizeof(pr_opnames)/sizeof(pr_opnames[0]))
156 Con_Printf ("%s ", pr_opnames[s->op]);
157 i = strlen(pr_opnames[s->op]);
162 if (s->op == OP_IF || s->op == OP_IFNOT)
163 Con_Printf ("%sbranch %i",PR_GlobalString((unsigned short) s->a),s->b);
164 else if (s->op == OP_GOTO)
166 Con_Printf ("branch %i",s->a);
168 else if ( (unsigned)(s->op - OP_STORE_F) < 6)
170 Con_Printf ("%s",PR_GlobalString((unsigned short) s->a));
171 Con_Printf ("%s", PR_GlobalStringNoContents((unsigned short) s->b));
176 Con_Printf ("%s",PR_GlobalString((unsigned short) s->a));
178 Con_Printf ("%s",PR_GlobalString((unsigned short) s->b));
180 Con_Printf ("%s", PR_GlobalStringNoContents((unsigned short) s->c));
190 void PR_StackTrace (void)
197 Con_Printf ("<NO STACK>\n");
201 pr_stack[pr_depth].f = pr_xfunction;
202 for (i=pr_depth ; i>=0 ; i--)
208 Con_Printf ("<NO FUNCTION>\n");
211 Con_Printf ("%12s : %s\n", pr_strings + f->s_file, pr_strings + f->s_name);
222 void PR_Profile_f (void)
224 dfunction_t *f, *best;
234 for (i=0 ; i<progs->numfunctions ; i++)
236 f = &pr_functions[i];
237 if (f->profile > max)
246 Con_Printf ("%7i %s\n", best->profile, pr_strings+best->s_name);
258 Aborts the currently executing function
261 void PR_RunError (char *error, ...)
266 va_start (argptr,error);
267 vsprintf (string,error,argptr);
270 PR_PrintStatement (pr_statements + pr_xstatement);
272 Con_Printf ("%s\n", string);
274 pr_depth = 0; // dump the stack so host_error can shutdown functions
276 Host_Error ("Program error");
280 ============================================================================
283 The interpretation main loop
284 ============================================================================
291 Returns the new program statement counter
294 int PR_EnterFunction (dfunction_t *f)
298 pr_stack[pr_depth].s = pr_xstatement;
299 pr_stack[pr_depth].f = pr_xfunction;
301 if (pr_depth >= MAX_STACK_DEPTH)
302 PR_RunError ("stack overflow");
304 // save off any locals that the new function steps on
306 if (localstack_used + c > LOCALSTACK_SIZE)
307 PR_RunError ("PR_ExecuteProgram: locals stack overflow\n");
309 for (i=0 ; i < c ; i++)
310 localstack[localstack_used+i] = ((int *)pr_globals)[f->parm_start + i];
311 localstack_used += c;
315 for (i=0 ; i<f->numparms ; i++)
317 for (j=0 ; j<f->parm_size[i] ; j++)
319 ((int *)pr_globals)[o] = ((int *)pr_globals)[OFS_PARM0+i*3+j];
325 return f->first_statement - 1; // offset the s++
333 int PR_LeaveFunction (void)
338 Host_Error ("prog stack underflow");
340 // restore locals from the stack
341 c = pr_xfunction->locals;
342 localstack_used -= c;
343 if (localstack_used < 0)
344 PR_RunError ("PR_ExecuteProgram: locals stack underflow\n");
346 for (i=0 ; i < c ; i++)
347 ((int *)pr_globals)[pr_xfunction->parm_start + i] = localstack[localstack_used+i];
351 pr_xfunction = pr_stack[pr_depth].f;
352 return pr_stack[pr_depth].s;
362 void PR_ExecuteProgram (func_t fnum)
367 dfunction_t *f, *newf;
374 if (!fnum || fnum >= progs->numfunctions)
376 if (pr_global_struct->self)
377 ED_Print (PROG_TO_EDICT(pr_global_struct->self));
378 Host_Error ("PR_ExecuteProgram: NULL function");
381 f = &pr_functions[fnum];
386 // make a stack frame
387 exitdepth = pr_depth;
389 s = PR_EnterFunction (f);
393 s++; // next statement
395 st = &pr_statements[s];
396 // LordHavoc: fix for 32768 QC def limit (just added unsigned short typecast)
397 a = (eval_t *)&pr_globals[(unsigned short) st->a];
398 b = (eval_t *)&pr_globals[(unsigned short) st->b];
399 c = (eval_t *)&pr_globals[(unsigned short) st->c];
402 PR_RunError ("runaway loop error");
404 pr_xfunction->profile++;
408 PR_PrintStatement (st);
413 c->_float = a->_float + b->_float;
416 c->vector[0] = a->vector[0] + b->vector[0];
417 c->vector[1] = a->vector[1] + b->vector[1];
418 c->vector[2] = a->vector[2] + b->vector[2];
422 c->_float = a->_float - b->_float;
425 c->vector[0] = a->vector[0] - b->vector[0];
426 c->vector[1] = a->vector[1] - b->vector[1];
427 c->vector[2] = a->vector[2] - b->vector[2];
431 c->_float = a->_float * b->_float;
434 c->_float = a->vector[0]*b->vector[0]
435 + a->vector[1]*b->vector[1]
436 + a->vector[2]*b->vector[2];
439 c->vector[0] = a->_float * b->vector[0];
440 c->vector[1] = a->_float * b->vector[1];
441 c->vector[2] = a->_float * b->vector[2];
444 c->vector[0] = b->_float * a->vector[0];
445 c->vector[1] = b->_float * a->vector[1];
446 c->vector[2] = b->_float * a->vector[2];
450 c->_float = a->_float / b->_float;
454 c->_float = (int)a->_float & (int)b->_float;
458 c->_float = (int)a->_float | (int)b->_float;
463 c->_float = a->_float >= b->_float;
466 c->_float = a->_float <= b->_float;
469 c->_float = a->_float > b->_float;
472 c->_float = a->_float < b->_float;
475 c->_float = a->_float && b->_float;
478 c->_float = a->_float || b->_float;
482 c->_float = !a->_float;
485 c->_float = !a->vector[0] && !a->vector[1] && !a->vector[2];
488 c->_float = !a->string || !pr_strings[a->string];
491 c->_float = !a->function;
494 c->_float = (PROG_TO_EDICT(a->edict) == sv.edicts);
498 c->_float = a->_float == b->_float;
501 c->_float = (a->vector[0] == b->vector[0]) &&
502 (a->vector[1] == b->vector[1]) &&
503 (a->vector[2] == b->vector[2]);
506 c->_float = !strcmp(pr_strings+a->string,pr_strings+b->string);
509 c->_float = a->_int == b->_int;
512 c->_float = a->function == b->function;
517 c->_float = a->_float != b->_float;
520 c->_float = (a->vector[0] != b->vector[0]) ||
521 (a->vector[1] != b->vector[1]) ||
522 (a->vector[2] != b->vector[2]);
525 c->_float = strcmp(pr_strings+a->string,pr_strings+b->string);
528 c->_float = a->_int != b->_int;
531 c->_float = a->function != b->function;
537 case OP_STORE_FLD: // integers
539 case OP_STORE_FNC: // pointers
543 b->vector[0] = a->vector[0];
544 b->vector[1] = a->vector[1];
545 b->vector[2] = a->vector[2];
550 case OP_STOREP_FLD: // integers
552 case OP_STOREP_FNC: // pointers
553 ptr = (eval_t *)((byte *)sv.edicts + b->_int);
557 ptr = (eval_t *)((byte *)sv.edicts + b->_int);
558 ptr->vector[0] = a->vector[0];
559 ptr->vector[1] = a->vector[1];
560 ptr->vector[2] = a->vector[2];
564 ed = PROG_TO_EDICT(a->edict);
566 NUM_FOR_EDICT(ed); // make sure it's in range
568 if (ed == (edict_t *)sv.edicts && sv.state == ss_active)
569 PR_RunError ("assignment to world entity");
570 c->_int = (byte *)((int *)&ed->v + b->_int) - (byte *)sv.edicts;
578 ed = PROG_TO_EDICT(a->edict);
580 NUM_FOR_EDICT(ed); // make sure it's in range
582 a = (eval_t *)((int *)&ed->v + b->_int);
587 ed = PROG_TO_EDICT(a->edict);
589 NUM_FOR_EDICT(ed); // make sure it's in range
591 a = (eval_t *)((int *)&ed->v + b->_int);
592 c->vector[0] = a->vector[0];
593 c->vector[1] = a->vector[1];
594 c->vector[2] = a->vector[2];
601 s += st->b - 1; // offset the s++
606 s += st->b - 1; // offset the s++
610 s += st->a - 1; // offset the s++
622 pr_argc = st->op - OP_CALL0;
624 PR_RunError ("NULL function");
626 newf = &pr_functions[a->function];
628 if (newf->first_statement < 0)
629 { // negative statements are built in functions
630 i = -newf->first_statement;
631 if (i >= pr_numbuiltins)
632 PR_RunError ("Bad builtin call number");
637 s = PR_EnterFunction (newf);
642 pr_globals[OFS_RETURN] = pr_globals[st->a];
643 pr_globals[OFS_RETURN+1] = pr_globals[st->a+1];
644 pr_globals[OFS_RETURN+2] = pr_globals[st->a+2];
646 s = PR_LeaveFunction ();
647 if (pr_depth == exitdepth)
652 ed = PROG_TO_EDICT(pr_global_struct->self);
654 ed->v.nextthink = pr_global_struct->time + 0.05;
656 ed->v.nextthink = pr_global_struct->time + 0.1;
658 //if (a->_float != ed->v.frame) // LordHavoc: this was silly
660 ed->v.frame = a->_float;
662 ed->v.think = b->function;
666 PR_RunError ("Bad opcode %i", st->op);
673 // LordHavoc: optimized
674 #define OPA ((eval_t *)&pr_globals[(unsigned short) st->a])
675 #define OPB ((eval_t *)&pr_globals[(unsigned short) st->b])
676 #define OPC ((eval_t *)&pr_globals[(unsigned short) st->c])
677 extern cvar_t pr_boundscheck;
678 void PR_ExecuteProgram (func_t fnum)
681 dfunction_t *f, *newf;
685 int profile, startprofile;
687 if (!fnum || fnum >= progs->numfunctions)
689 if (pr_global_struct->self)
690 ED_Print (PROG_TO_EDICT(pr_global_struct->self));
691 Host_Error ("PR_ExecuteProgram: NULL function");
694 f = &pr_functions[fnum];
698 // make a stack frame
699 exitdepth = pr_depth;
701 st = &pr_statements[PR_EnterFunction (f)];
702 startprofile = profile = 0;
704 if (pr_boundscheck.value)
709 if (++profile > 100000)
711 pr_xstatement = st - pr_statements;
712 PR_RunError ("runaway loop error");
716 PR_PrintStatement (st);
721 OPC->_float = OPA->_float + OPB->_float;
724 OPC->vector[0] = OPA->vector[0] + OPB->vector[0];
725 OPC->vector[1] = OPA->vector[1] + OPB->vector[1];
726 OPC->vector[2] = OPA->vector[2] + OPB->vector[2];
729 OPC->_float = OPA->_float - OPB->_float;
732 OPC->vector[0] = OPA->vector[0] - OPB->vector[0];
733 OPC->vector[1] = OPA->vector[1] - OPB->vector[1];
734 OPC->vector[2] = OPA->vector[2] - OPB->vector[2];
737 OPC->_float = OPA->_float * OPB->_float;
740 OPC->_float = OPA->vector[0]*OPB->vector[0] + OPA->vector[1]*OPB->vector[1] + OPA->vector[2]*OPB->vector[2];
743 OPC->vector[0] = OPA->_float * OPB->vector[0];
744 OPC->vector[1] = OPA->_float * OPB->vector[1];
745 OPC->vector[2] = OPA->_float * OPB->vector[2];
748 OPC->vector[0] = OPB->_float * OPA->vector[0];
749 OPC->vector[1] = OPB->_float * OPA->vector[1];
750 OPC->vector[2] = OPB->_float * OPA->vector[2];
753 OPC->_float = OPA->_float / OPB->_float;
756 OPC->_float = (int)OPA->_float & (int)OPB->_float;
759 OPC->_float = (int)OPA->_float | (int)OPB->_float;
762 OPC->_float = OPA->_float >= OPB->_float;
765 OPC->_float = OPA->_float <= OPB->_float;
768 OPC->_float = OPA->_float > OPB->_float;
771 OPC->_float = OPA->_float < OPB->_float;
774 OPC->_float = OPA->_float && OPB->_float;
777 OPC->_float = OPA->_float || OPB->_float;
780 OPC->_float = !OPA->_float;
783 OPC->_float = !OPA->vector[0] && !OPA->vector[1] && !OPA->vector[2];
786 OPC->_float = !OPA->string || !pr_strings[OPA->string];
789 OPC->_float = !OPA->function;
792 OPC->_float = (PROG_TO_EDICT(OPA->edict) == sv.edicts);
795 OPC->_float = OPA->_float == OPB->_float;
798 OPC->_float = (OPA->vector[0] == OPB->vector[0]) && (OPA->vector[1] == OPB->vector[1]) && (OPA->vector[2] == OPB->vector[2]);
801 OPC->_float = !strcmp(pr_strings+OPA->string,pr_strings+OPB->string);
804 OPC->_float = OPA->_int == OPB->_int;
807 OPC->_float = OPA->function == OPB->function;
810 OPC->_float = OPA->_float != OPB->_float;
813 OPC->_float = (OPA->vector[0] != OPB->vector[0]) || (OPA->vector[1] != OPB->vector[1]) || (OPA->vector[2] != OPB->vector[2]);
816 OPC->_float = strcmp(pr_strings+OPA->string,pr_strings+OPB->string);
819 OPC->_float = OPA->_int != OPB->_int;
822 OPC->_float = OPA->function != OPB->function;
828 case OP_STORE_FLD: // integers
830 case OP_STORE_FNC: // pointers
831 OPB->_int = OPA->_int;
834 OPB->vector[0] = OPA->vector[0];
835 OPB->vector[1] = OPA->vector[1];
836 OPB->vector[2] = OPA->vector[2];
841 case OP_STOREP_FLD: // integers
843 case OP_STOREP_FNC: // pointers
844 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
846 pr_xstatement = st - pr_statements;
847 PR_RunError("Progs attempted to write to an out of bounds edict\n");
850 if (OPB->_int % pr_edict_size < ((byte *)&sv.edicts->v - (byte *)sv.edicts))
852 pr_xstatement = st - pr_statements;
853 PR_RunError("Progs attempted to write to an engine edict field\n");
856 ptr = (eval_t *)((byte *)sv.edicts + OPB->_int);
857 ptr->_int = OPA->_int;
860 if (OPB->_int < 0 || OPB->_int + 12 > pr_edictareasize)
862 pr_xstatement = st - pr_statements;
863 PR_RunError("Progs attempted to write to an out of bounds edict\n");
866 ptr = (eval_t *)((byte *)sv.edicts + OPB->_int);
867 ptr->vector[0] = OPA->vector[0];
868 ptr->vector[1] = OPA->vector[1];
869 ptr->vector[2] = OPA->vector[2];
873 if (OPA->edict < 0 || OPA->edict >= pr_edictareasize)
875 pr_xstatement = st - pr_statements;
876 PR_RunError("Progs attempted to address an out of bounds edict\n");
879 if (OPA->edict == 0 && sv.state == ss_active)
881 pr_xstatement = st - pr_statements;
882 PR_RunError ("assignment to world entity");
885 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
887 pr_xstatement = st - pr_statements;
888 PR_RunError("Progs attempted to address an invalid field in an edict\n");
891 ed = PROG_TO_EDICT(OPA->edict);
892 OPC->_int = (byte *)((int *)&ed->v + OPB->_int) - (byte *)sv.edicts;
900 if (OPA->edict < 0 || OPA->edict >= pr_edictareasize)
902 pr_xstatement = st - pr_statements;
903 PR_RunError("Progs attempted to read an out of bounds edict number\n");
906 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
908 pr_xstatement = st - pr_statements;
909 PR_RunError("Progs attempted to read an invalid field in an edict\n");
912 ed = PROG_TO_EDICT(OPA->edict);
913 OPC->_int = ((eval_t *)((int *)&ed->v + OPB->_int))->_int;
917 if (OPA->edict < 0 || OPA->edict >= pr_edictareasize)
919 pr_xstatement = st - pr_statements;
920 PR_RunError("Progs attempted to read an out of bounds edict number\n");
923 if (OPB->_int < 0 || OPB->_int + 2 >= progs->entityfields)
925 pr_xstatement = st - pr_statements;
926 PR_RunError("Progs attempted to read an invalid field in an edict\n");
929 ed = PROG_TO_EDICT(OPA->edict);
930 OPC->vector[0] = ((eval_t *)((int *)&ed->v + OPB->_int))->vector[0];
931 OPC->vector[1] = ((eval_t *)((int *)&ed->v + OPB->_int))->vector[1];
932 OPC->vector[2] = ((eval_t *)((int *)&ed->v + OPB->_int))->vector[2];
939 st += st->b - 1; // offset the s++
944 st += st->b - 1; // offset the s++
948 st += st->a - 1; // offset the s++
960 pr_xfunction->profile += profile - startprofile;
961 startprofile = profile;
962 pr_xstatement = st - pr_statements;
963 pr_argc = st->op - OP_CALL0;
965 PR_RunError ("NULL function");
967 newf = &pr_functions[OPA->function];
969 if (newf->first_statement < 0)
970 { // negative statements are built in functions
971 int i = -newf->first_statement;
972 if (i >= pr_numbuiltins)
973 PR_RunError ("Bad builtin call number");
978 st = &pr_statements[PR_EnterFunction (newf)];
983 pr_globals[OFS_RETURN] = pr_globals[(unsigned short) st->a];
984 pr_globals[OFS_RETURN+1] = pr_globals[(unsigned short) st->a+1];
985 pr_globals[OFS_RETURN+2] = pr_globals[(unsigned short) st->a+2];
987 st = &pr_statements[PR_LeaveFunction ()];
988 if (pr_depth == exitdepth)
993 ed = PROG_TO_EDICT(pr_global_struct->self);
995 ed->v.nextthink = pr_global_struct->time + 0.05;
997 ed->v.nextthink = pr_global_struct->time + 0.1;
999 ed->v.frame = OPA->_float;
1000 ed->v.think = OPB->function;
1004 pr_xstatement = st - pr_statements;
1005 PR_RunError ("Bad opcode %i", st->op);
1014 if (++profile > 100000)
1016 pr_xstatement = st - pr_statements;
1017 PR_RunError ("runaway loop error");
1021 PR_PrintStatement (st);
1026 OPC->_float = OPA->_float + OPB->_float;
1029 OPC->vector[0] = OPA->vector[0] + OPB->vector[0];
1030 OPC->vector[1] = OPA->vector[1] + OPB->vector[1];
1031 OPC->vector[2] = OPA->vector[2] + OPB->vector[2];
1034 OPC->_float = OPA->_float - OPB->_float;
1037 OPC->vector[0] = OPA->vector[0] - OPB->vector[0];
1038 OPC->vector[1] = OPA->vector[1] - OPB->vector[1];
1039 OPC->vector[2] = OPA->vector[2] - OPB->vector[2];
1042 OPC->_float = OPA->_float * OPB->_float;
1045 OPC->_float = OPA->vector[0]*OPB->vector[0] + OPA->vector[1]*OPB->vector[1] + OPA->vector[2]*OPB->vector[2];
1048 OPC->vector[0] = OPA->_float * OPB->vector[0];
1049 OPC->vector[1] = OPA->_float * OPB->vector[1];
1050 OPC->vector[2] = OPA->_float * OPB->vector[2];
1053 OPC->vector[0] = OPB->_float * OPA->vector[0];
1054 OPC->vector[1] = OPB->_float * OPA->vector[1];
1055 OPC->vector[2] = OPB->_float * OPA->vector[2];
1058 OPC->_float = OPA->_float / OPB->_float;
1061 OPC->_float = (int)OPA->_float & (int)OPB->_float;
1064 OPC->_float = (int)OPA->_float | (int)OPB->_float;
1067 OPC->_float = OPA->_float >= OPB->_float;
1070 OPC->_float = OPA->_float <= OPB->_float;
1073 OPC->_float = OPA->_float > OPB->_float;
1076 OPC->_float = OPA->_float < OPB->_float;
1079 OPC->_float = OPA->_float && OPB->_float;
1082 OPC->_float = OPA->_float || OPB->_float;
1085 OPC->_float = !OPA->_float;
1088 OPC->_float = !OPA->vector[0] && !OPA->vector[1] && !OPA->vector[2];
1091 OPC->_float = !OPA->string || !pr_strings[OPA->string];
1094 OPC->_float = !OPA->function;
1097 OPC->_float = (PROG_TO_EDICT(OPA->edict) == sv.edicts);
1100 OPC->_float = OPA->_float == OPB->_float;
1103 OPC->_float = (OPA->vector[0] == OPB->vector[0]) && (OPA->vector[1] == OPB->vector[1]) && (OPA->vector[2] == OPB->vector[2]);
1106 OPC->_float = !strcmp(pr_strings+OPA->string,pr_strings+OPB->string);
1109 OPC->_float = OPA->_int == OPB->_int;
1112 OPC->_float = OPA->function == OPB->function;
1115 OPC->_float = OPA->_float != OPB->_float;
1118 OPC->_float = (OPA->vector[0] != OPB->vector[0]) || (OPA->vector[1] != OPB->vector[1]) || (OPA->vector[2] != OPB->vector[2]);
1121 OPC->_float = strcmp(pr_strings+OPA->string,pr_strings+OPB->string);
1124 OPC->_float = OPA->_int != OPB->_int;
1127 OPC->_float = OPA->function != OPB->function;
1130 //==================
1133 case OP_STORE_FLD: // integers
1135 case OP_STORE_FNC: // pointers
1136 OPB->_int = OPA->_int;
1139 OPB->vector[0] = OPA->vector[0];
1140 OPB->vector[1] = OPA->vector[1];
1141 OPB->vector[2] = OPA->vector[2];
1146 case OP_STOREP_FLD: // integers
1148 case OP_STOREP_FNC: // pointers
1149 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
1151 pr_xstatement = st - pr_statements;
1152 PR_RunError("Progs attempted to write to an out of bounds edict\n");
1155 if (OPB->_int % pr_edict_size < ((byte *)&sv.edicts->v - (byte *)sv.edicts))
1157 pr_xstatement = st - pr_statements;
1158 PR_RunError("Progs attempted to write to an engine edict field\n");
1161 ptr = (eval_t *)((byte *)sv.edicts + OPB->_int);
1162 ptr->_int = OPA->_int;
1165 if (OPB->_int < 0 || OPB->_int + 12 > pr_edictareasize)
1167 pr_xstatement = st - pr_statements;
1168 PR_RunError("Progs attempted to write to an out of bounds edict\n");
1171 ptr = (eval_t *)((byte *)sv.edicts + OPB->_int);
1172 ptr->vector[0] = OPA->vector[0];
1173 ptr->vector[1] = OPA->vector[1];
1174 ptr->vector[2] = OPA->vector[2];
1178 if (OPA->edict < 0 || OPA->edict >= pr_edictareasize)
1180 pr_xstatement = st - pr_statements;
1181 PR_RunError("Progs attempted to address an out of bounds edict\n");
1184 if (OPA->edict == 0 && sv.state == ss_active)
1186 pr_xstatement = st - pr_statements;
1187 PR_RunError ("assignment to world entity");
1190 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
1192 pr_xstatement = st - pr_statements;
1193 PR_RunError("Progs attempted to address an invalid field in an edict\n");
1196 ed = PROG_TO_EDICT(OPA->edict);
1197 OPC->_int = (byte *)((int *)&ed->v + OPB->_int) - (byte *)sv.edicts;
1205 if (OPA->edict < 0 || OPA->edict >= pr_edictareasize)
1207 pr_xstatement = st - pr_statements;
1208 PR_RunError("Progs attempted to read an out of bounds edict number\n");
1211 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
1213 pr_xstatement = st - pr_statements;
1214 PR_RunError("Progs attempted to read an invalid field in an edict\n");
1217 ed = PROG_TO_EDICT(OPA->edict);
1218 OPC->_int = ((eval_t *)((int *)&ed->v + OPB->_int))->_int;
1222 if (OPA->edict < 0 || OPA->edict >= pr_edictareasize)
1224 pr_xstatement = st - pr_statements;
1225 PR_RunError("Progs attempted to read an out of bounds edict number\n");
1228 if (OPB->_int < 0 || OPB->_int + 2 >= progs->entityfields)
1230 pr_xstatement = st - pr_statements;
1231 PR_RunError("Progs attempted to read an invalid field in an edict\n");
1234 ed = PROG_TO_EDICT(OPA->edict);
1235 OPC->vector[0] = ((eval_t *)((int *)&ed->v + OPB->_int))->vector[0];
1236 OPC->vector[1] = ((eval_t *)((int *)&ed->v + OPB->_int))->vector[1];
1237 OPC->vector[2] = ((eval_t *)((int *)&ed->v + OPB->_int))->vector[2];
1240 //==================
1244 st += st->b - 1; // offset the s++
1249 st += st->b - 1; // offset the s++
1253 st += st->a - 1; // offset the s++
1265 pr_xfunction->profile += profile - startprofile;
1266 startprofile = profile;
1267 pr_xstatement = st - pr_statements;
1268 pr_argc = st->op - OP_CALL0;
1270 PR_RunError ("NULL function");
1272 newf = &pr_functions[OPA->function];
1274 if (newf->first_statement < 0)
1275 { // negative statements are built in functions
1276 int i = -newf->first_statement;
1277 if (i >= pr_numbuiltins)
1278 PR_RunError ("Bad builtin call number");
1283 st = &pr_statements[PR_EnterFunction (newf)];
1288 pr_globals[OFS_RETURN] = pr_globals[(unsigned short) st->a];
1289 pr_globals[OFS_RETURN+1] = pr_globals[(unsigned short) st->a+1];
1290 pr_globals[OFS_RETURN+2] = pr_globals[(unsigned short) st->a+2];
1292 st = &pr_statements[PR_LeaveFunction ()];
1293 if (pr_depth == exitdepth)
1298 ed = PROG_TO_EDICT(pr_global_struct->self);
1300 ed->v.nextthink = pr_global_struct->time + 0.05;
1302 ed->v.nextthink = pr_global_struct->time + 0.1;
1304 ed->v.frame = OPA->_float;
1305 ed->v.think = OPB->function;
1309 pr_xstatement = st - pr_statements;
1310 PR_RunError ("Bad opcode %i", st->op);