-
Notifications
You must be signed in to change notification settings - Fork 0
/
execloop.h
1141 lines (1024 loc) · 28.8 KB
/
execloop.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//qc execution code.
//we have two conditions.
//one allows us to debug and trace through our code, the other doesn't.
//hopefully, the compiler will do a great job at optimising this code for us, where required.
//if it dosn't, then bum.
//the general overhead should be reduced significantly, and I would be supprised if it did run slower.
//run away loops are checked for ONLY on gotos and function calls. This might give a poorer check, but it will run faster overall.
//Appears to work fine.
#if INTSIZE == 16
#define cont cont16
#define reeval reeval16
#define st st16
#define pr_statements pr_statements16
#define fakeop fakeop16
#define dstatement_t dstatement16_t
#define sofs signed short
#define uofs unsigned short
#elif INTSIZE == 32
#define cont cont32
#define reeval reeval32
#define st st32
#define pr_statements pr_statements32
#define fakeop fakeop32
#define dstatement_t dstatement32_t
#define sofs signed int
#define uofs unsigned int
#elif INTSIZE == 24
#error INTSIZE should be set to 32.
#else
#error Bad cont size
#endif
#define ENGINEPOINTER(p) ((char*)(p) - progfuncs->stringtable)
#define QCPOINTER(p) (eval_t *)(p->_int+progfuncs->stringtable)
#define QCPOINTERM(p) (eval_t *)((p)+progfuncs->stringtable)
//rely upon just st
{
#ifdef DEBUGABLE
cont: //last statement may have been a breakpoint
s = st-pr_statements;
s+=1;
s=ShowStep(progfuncs, s);
st = pr_statements + s;
reeval:
#else
st++;
#endif
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];
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];
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];
break;
case OP_DIV_F:
OPC->_float = OPA->_float / OPB->_float;
break;
case OP_DIV_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];
break;
case OP_BITAND:
OPC->_float = (float)((int)OPA->_float & (int)OPB->_float);
break;
case OP_BITOR:
OPC->_float = (float)((int)OPA->_float | (int)OPB->_float);
break;
case OP_GE:
OPC->_float = (float)(OPA->_float >= OPB->_float);
break;
case OP_GE_I:
OPC->_int = (int)(OPA->_int >= OPB->_int);
break;
case OP_GE_IF:
OPC->_float = (float)(OPA->_int >= OPB->_float);
break;
case OP_GE_FI:
OPC->_float = (float)(OPA->_float >= OPB->_int);
break;
case OP_LE:
OPC->_float = (float)(OPA->_float <= OPB->_float);
break;
case OP_LE_I:
OPC->_int = (int)(OPA->_int <= OPB->_int);
break;
case OP_LE_IF:
OPC->_float = (float)(OPA->_int <= OPB->_float);
break;
case OP_LE_FI:
OPC->_float = (float)(OPA->_float <= OPB->_int);
break;
case OP_GT:
OPC->_float = (float)(OPA->_float > OPB->_float);
break;
case OP_GT_I:
OPC->_int = (int)(OPA->_int > OPB->_int);
break;
case OP_GT_IF:
OPC->_float = (float)(OPA->_int > OPB->_float);
break;
case OP_GT_FI:
OPC->_float = (float)(OPA->_float > OPB->_int);
break;
case OP_LT:
OPC->_float = (float)(OPA->_float < OPB->_float);
break;
case OP_LT_I:
OPC->_int = (int)(OPA->_int < OPB->_int);
break;
case OP_LT_IF:
OPC->_float = (float)(OPA->_int < OPB->_float);
break;
case OP_LT_FI:
OPC->_float = (float)(OPA->_float < OPB->_int);
break;
case OP_AND:
OPC->_float = (float)(OPA->_float && OPB->_float);
break;
case OP_OR:
OPC->_float = (float)(OPA->_float || OPB->_float);
break;
case OP_NOT_F:
OPC->_float = (float)(!OPA->_float);
break;
case OP_NOT_V:
OPC->_float = (float)(!OPA->_vector[0] && !OPA->_vector[1] && !OPA->_vector[2]);
break;
case OP_NOT_S:
OPC->_float = (float)(!(OPA->string) || !*PR_StringToNative(progfuncs, OPA->string));
break;
case OP_NOT_FNC:
OPC->_float = (float)(!(OPA->function & ~0xff000000));
break;
case OP_NOT_ENT:
OPC->_float = (float)(PROG_TO_EDICT(progfuncs, OPA->edict) == (edictrun_t *)sv_edicts);
break;
case OP_EQ_F:
OPC->_float = (float)(OPA->_float == OPB->_float);
break;
case OP_EQ_IF:
OPC->_float = (float)(OPA->_int == OPB->_float);
break;
case OP_EQ_FI:
OPC->_float = (float)(OPA->_float == OPB->_int);
break;
case OP_EQ_V:
OPC->_float = (float)((OPA->_vector[0] == OPB->_vector[0]) &&
(OPA->_vector[1] == OPB->_vector[1]) &&
(OPA->_vector[2] == OPB->_vector[2]));
break;
case OP_EQ_S:
if (OPA->string==OPB->string)
OPC->_float = true;
else if (!OPA->string)
{
if (!OPB->string || !*PR_StringToNative(progfuncs, OPB->string))
OPC->_float = true;
else
OPC->_float = false;
}
else if (!OPB->string)
{
if (!OPA->string || !*PR_StringToNative(progfuncs, OPA->string))
OPC->_float = true;
else
OPC->_float = false;
}
else
OPC->_float = (float)(!strcmp(PR_StringToNative(progfuncs, OPA->string),PR_StringToNative(progfuncs, OPB->string)));
break;
case OP_EQ_E:
OPC->_float = (float)(OPA->_int == OPB->_int);
break;
case OP_EQ_FNC:
OPC->_float = (float)(OPA->function == OPB->function);
break;
case OP_NE_F:
OPC->_float = (float)(OPA->_float != OPB->_float);
break;
case OP_NE_V:
OPC->_float = (float)((OPA->_vector[0] != OPB->_vector[0]) ||
(OPA->_vector[1] != OPB->_vector[1]) ||
(OPA->_vector[2] != OPB->_vector[2]));
break;
case OP_NE_S:
if (OPA->string==OPB->string)
OPC->_float = false;
else if (!OPA->string)
{
if (!OPB->string || !*(PR_StringToNative(progfuncs, OPB->string)))
OPC->_float = false;
else
OPC->_float = true;
}
else if (!OPB->string)
{
if (!OPA->string || !*PR_StringToNative(progfuncs, OPA->string))
OPC->_float = false;
else
OPC->_float = true;
}
else
OPC->_float = (float)(strcmp(PR_StringToNative(progfuncs, OPA->string),PR_StringToNative(progfuncs, OPB->string)));
break;
case OP_NE_E:
OPC->_float = (float)(OPA->_int != OPB->_int);
break;
case OP_NE_FNC:
OPC->_float = (float)(OPA->function != OPB->function);
break;
//==================
case OP_STORE_IF:
OPB->_float = (float)OPA->_int;
break;
case OP_STORE_FI:
OPB->_int = (int)OPA->_float;
break;
case OP_STORE_F:
case OP_STORE_ENT:
case OP_STORE_FLD: // integers
case OP_STORE_S:
case OP_STORE_I:
case OP_STORE_FNC: // pointers
case OP_STORE_P:
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;
//store a value to a pointer
case OP_STOREP_IF:
if ((unsigned int)OPB->_int >= addressableused)
{
pr_xstatement = st-pr_statements;
PR_RunError (progfuncs, "bad pointer write in %s", progfuncs->stringtable + pr_xfunction->s_name);
}
ptr = QCPOINTER(OPB);
ptr->_float = (float)OPA->_int;
break;
case OP_STOREP_FI:
if ((unsigned int)OPB->_int >= addressableused)
{
pr_xstatement = st-pr_statements;
PR_RunError (progfuncs, "bad pointer write in %s", progfuncs->stringtable + pr_xfunction->s_name);
}
ptr = QCPOINTER(OPB);
ptr->_int = (int)OPA->_float;
break;
case OP_STOREP_I:
if ((unsigned int)OPB->_int >= addressableused)
{
pr_xstatement = st-pr_statements;
PR_RunError (progfuncs, "bad pointer write in %s", progfuncs->stringtable + pr_xfunction->s_name);
}
ptr = QCPOINTER(OPB);
ptr->_int = OPA->_int;
break;
case OP_STOREP_F:
case OP_STOREP_ENT:
case OP_STOREP_FLD: // integers
case OP_STOREP_S:
case OP_STOREP_FNC: // pointers
if ((unsigned int)OPB->_int >= addressableused)
{
pr_xstatement = st-pr_statements;
PR_RunError (progfuncs, "bad pointer write in %s", progfuncs->stringtable + pr_xfunction->s_name);
}
ptr = QCPOINTER(OPB);
ptr->_int = OPA->_int;
break;
case OP_STOREP_V:
if ((unsigned int)OPB->_int >= addressableused)
{
pr_xstatement = st-pr_statements;
PR_RunError (progfuncs, "bad pointer write in %s", progfuncs->stringtable + pr_xfunction->s_name);
}
ptr = QCPOINTER(OPB);
ptr->_vector[0] = OPA->_vector[0];
ptr->_vector[1] = OPA->_vector[1];
ptr->_vector[2] = OPA->_vector[2];
break;
case OP_STOREP_C: //store character in a string
if ((unsigned int)OPB->_int >= addressableused)
{
pr_xstatement = st-pr_statements;
PR_RunError (progfuncs, "bad pointer write in %s", progfuncs->stringtable + pr_xfunction->s_name);
}
ptr = QCPOINTER(OPB);
*(unsigned char *)ptr = (char)OPA->_float;
break;
case OP_MULSTORE_F: // f *= f
OPB->_float *= OPA->_float;
break;
case OP_MULSTORE_V: // v *= f
OPB->_vector[0] *= OPA->_float;
OPB->_vector[1] *= OPA->_float;
OPB->_vector[2] *= OPA->_float;
break;
case OP_MULSTOREP_F: // e.f *= f
if ((unsigned int)OPB->_int >= addressableused)
{
pr_xstatement = st-pr_statements;
PR_RunError (progfuncs, "bad pointer write in %s", progfuncs->stringtable + pr_xfunction->s_name);
}
ptr = QCPOINTER(OPB);
OPC->_float = (ptr->_float *= OPA->_float);
break;
case OP_MULSTOREP_V: // e.v *= f
ptr = QCPOINTER(OPB);
OPC->_vector[0] = (ptr->_vector[0] *= OPA->_float);
OPC->_vector[0] = (ptr->_vector[1] *= OPA->_float);
OPC->_vector[0] = (ptr->_vector[2] *= OPA->_float);
break;
case OP_DIVSTORE_F: // f /= f
OPB->_float /= OPA->_float;
break;
case OP_DIVSTOREP_F: // e.f /= f
ptr = QCPOINTER(OPB);
OPC->_float = (ptr->_float /= OPA->_float);
break;
case OP_ADDSTORE_F: // f += f
OPB->_float += OPA->_float;
break;
case OP_ADDSTORE_V: // v += v
OPB->_vector[0] += OPA->_vector[0];
OPB->_vector[1] += OPA->_vector[1];
OPB->_vector[2] += OPA->_vector[2];
break;
case OP_ADDSTOREP_F: // e.f += f
ptr = QCPOINTER(OPB);
OPC->_float = (ptr->_float += OPA->_float);
break;
case OP_ADDSTOREP_V: // e.v += v
ptr = QCPOINTER(OPB);
OPC->_vector[0] = (ptr->_vector[0] += OPA->_vector[0]);
OPC->_vector[1] = (ptr->_vector[1] += OPA->_vector[1]);
OPC->_vector[2] = (ptr->_vector[2] += OPA->_vector[2]);
break;
case OP_SUBSTORE_F: // f -= f
OPB->_float -= OPA->_float;
break;
case OP_SUBSTORE_V: // v -= v
OPB->_vector[0] -= OPA->_vector[0];
OPB->_vector[1] -= OPA->_vector[1];
OPB->_vector[2] -= OPA->_vector[2];
break;
case OP_SUBSTOREP_F: // e.f -= f
ptr = QCPOINTER(OPB);
OPC->_float = (ptr->_float -= OPA->_float);
break;
case OP_SUBSTOREP_V: // e.v -= v
ptr = QCPOINTER(OPB);
OPC->_vector[0] = (ptr->_vector[0] -= OPA->_vector[0]);
OPC->_vector[1] = (ptr->_vector[1] -= OPA->_vector[1]);
OPC->_vector[2] = (ptr->_vector[2] -= OPA->_vector[2]);
break;
//get a pointer to a field var
case OP_ADDRESS:
if ((unsigned)OPA->edict >= (unsigned)maxedicts)
{
#ifndef DEBUGABLE
pr_trace++;
printf("OP_ADDRESS references invalid entity in %s", progfuncs->stringtable + pr_xfunction->s_name);
st--;
goto cont;
#else
PR_RunError (progfuncs, "OP_ADDRESS references invalid entity in %s", PR_StringToNative(progfuncs, pr_xfunction->s_name));
#endif
}
ed = PROG_TO_EDICT(progfuncs, OPA->edict);
#ifdef PARANOID
NUM_FOR_EDICT(ed); // make sure it's in range
#endif
if (!ed || ed->readonly)
{
pr_xstatement = st-pr_statements;
#ifndef DEBUGABLE
//boot it over to the debugger
pr_trace++;
printf("assignment to read-only entity in %s", progfuncs->stringtable + pr_xfunction->s_name);
st--;
goto cont;
#else
{
ddef16_t *d16;
fdef_t *f;
d16 = ED_GlobalAtOfs16(progfuncs, st->a);
f = ED_FieldAtOfs(progfuncs, OPB->_int + progfuncs->fieldadjust);
PR_RunError (progfuncs, "assignment to read-only entity in %s (%s.%s)", PR_StringToNative(progfuncs, pr_xfunction->s_name), PR_StringToNative(progfuncs, d16->s_name), f?f->name:NULL);
}
#endif
}
//Whilst the next block would technically be correct, we don't use it as it breaks too many quake mods.
// if (ed->isfree)
// {
// pr_xstatement = st-pr_statements;
// PR_RunError (progfuncs, "assignment to free entitiy in %s", progfuncs->stringtable + pr_xfunction->s_name);
// }
OPC->_int = ENGINEPOINTER((((int *)edvars(ed)) + OPB->_int + progfuncs->fieldadjust));
break;
//load a field to a value
case OP_LOAD_I:
case OP_LOAD_F:
case OP_LOAD_FLD:
case OP_LOAD_ENT:
case OP_LOAD_S:
case OP_LOAD_FNC:
if ((unsigned)OPA->edict >= (unsigned)maxedicts)
PR_RunError (progfuncs, "OP_LOAD references invalid entity in %s", progfuncs->stringtable + pr_xfunction->s_name);
ed = PROG_TO_EDICT(progfuncs, OPA->edict);
#ifdef PARANOID
NUM_FOR_EDICT(ed); // make sure it's in range
#endif
ptr = (eval_t *)(((int *)edvars(ed)) + OPB->_int + progfuncs->fieldadjust);
OPC->_int = ptr->_int;
break;
case OP_LOAD_V:
if ((unsigned)OPA->edict >= (unsigned)maxedicts)
PR_RunError (progfuncs, "OP_LOAD_V references invalid entity in %s", progfuncs->stringtable + pr_xfunction->s_name);
ed = PROG_TO_EDICT(progfuncs, OPA->edict);
#ifdef PARANOID
NUM_FOR_EDICT(ed); // make sure it's in range
#endif
ptr = (eval_t *)(((int *)edvars(ed)) + OPB->_int + progfuncs->fieldadjust);
OPC->_vector[0] = ptr->_vector[0];
OPC->_vector[1] = ptr->_vector[1];
OPC->_vector[2] = ptr->_vector[2];
break;
//==================
case OP_IFNOT_S:
RUNAWAYCHECK();
if (!OPA->string || !PR_StringToNative(progfuncs, OPA->string))
st += (sofs)st->b - 1; // offset the s++
break;
case OP_IFNOT_F:
RUNAWAYCHECK();
if (!OPA->_float)
st += (sofs)st->b - 1; // offset the s++
break;
case OP_IFNOT:
RUNAWAYCHECK();
if (!OPA->_int)
st += (sofs)st->b - 1; // offset the s++
break;
case OP_IF_S:
RUNAWAYCHECK();
if (OPA->string && PR_StringToNative(progfuncs, OPA->string))
st += (sofs)st->b - 1; // offset the s++
break;
case OP_IF_F:
RUNAWAYCHECK();
if (OPA->_int)
st += (sofs)st->b - 1; // offset the s++
break;
case OP_IF:
RUNAWAYCHECK();
if (OPA->_int)
st += (sofs)st->b - 1; // offset the s++
break;
case OP_GOTO:
RUNAWAYCHECK();
st += (sofs)st->a - 1; // offset the s++
break;
case OP_CALL8H:
case OP_CALL7H:
case OP_CALL6H:
case OP_CALL5H:
case OP_CALL4H:
case OP_CALL3H:
case OP_CALL2H:
G_VECTOR(OFS_PARM1)[0] = OPC->_vector[0];
G_VECTOR(OFS_PARM1)[1] = OPC->_vector[1];
G_VECTOR(OFS_PARM1)[2] = OPC->_vector[2];
case OP_CALL1H:
G_VECTOR(OFS_PARM0)[0] = OPB->_vector[0];
G_VECTOR(OFS_PARM0)[1] = OPB->_vector[1];
G_VECTOR(OFS_PARM0)[2] = OPB->_vector[2];
case OP_CALL8:
case OP_CALL7:
case OP_CALL6:
case OP_CALL5:
case OP_CALL4:
case OP_CALL3:
case OP_CALL2:
case OP_CALL1:
case OP_CALL0:
RUNAWAYCHECK();
pr_xstatement = st-pr_statements;
if (st->op > OP_CALL8)
pr_argc = st->op - (OP_CALL1H-1);
else
pr_argc = st->op - OP_CALL0;
fnum = OPA->function;
if ((fnum & ~0xff000000)==0)
{
pr_trace++;
printf("NULL function from qc (%s).\n", progfuncs->stringtable + pr_xfunction->s_name);
#ifndef DEBUGABLE
goto cont;
#endif
break;
}
/*
{
static char buffer[1024*1024*8];
int size = sizeof buffer;
progfuncs->save_ents(progfuncs, buffer, &size, 0);
}*/
p=pr_typecurrent;
//about to switch. needs caching.
//if it's an external call, switch now (before any function pointers are used)
PR_MoveParms(progfuncs, (fnum & 0xff000000)>>24, p);
PR_SwitchProgs(progfuncs, (fnum & 0xff000000)>>24);
newf = &pr_functions[fnum & ~0xff000000];
if (newf->first_statement < 0)
{ // negative statements are built in functions
if (pr_typecurrent != 0)
{
PR_MoveParms(progfuncs, 0, pr_typecurrent);
PR_SwitchProgs(progfuncs, 0);
}
i = -newf->first_statement;
// p = pr_typecurrent;
progfuncs->lastcalledbuiltinnumber = i;
if (i < externs->numglobalbuiltins)
{
prinst->numtempstringsstack = prinst->numtempstrings;
(*externs->globalbuiltins[i]) (progfuncs, (struct globalvars_s *)current_progstate->globals);
if (prinst->continuestatement!=-1)
{
st=&pr_statements[prinst->continuestatement];
prinst->continuestatement=-1;
break;
}
}
else
{
i -= externs->numglobalbuiltins;
if (i >= current_progstate->numbuiltins)
{
// if (newf->first_statement == -0x7fffffff)
// ((builtin_t)newf->profile) (progfuncs, (struct globalvars_s *)current_progstate->globals);
// else
PR_RunError (progfuncs, "Bad builtin call number - %i", -newf->first_statement);
}
else
current_progstate->builtins [i] (progfuncs, (struct globalvars_s *)current_progstate->globals);
}
PR_MoveParms(progfuncs, p, pr_typecurrent);
// memcpy(&pr_progstate[p].globals[OFS_RETURN], ¤t_progstate->globals[OFS_RETURN], sizeof(vec3_t));
PR_SwitchProgs(progfuncs, (progsnum_t)p);
//#ifndef DEBUGABLE //decide weather non debugger wants to start debugging.
s = st-pr_statements;
goto restart;
//#endif
// break;
}
// PR_MoveParms((OPA->function & 0xff000000)>>24, pr_typecurrent);
// PR_SwitchProgs((OPA->function & 0xff000000)>>24);
s = PR_EnterFunction (progfuncs, newf, p);
st = &pr_statements[s];
goto restart;
// break;
case OP_DONE:
case OP_RETURN:
RUNAWAYCHECK();
pr_globals[OFS_RETURN] = pr_globals[st->a];
pr_globals[OFS_RETURN+1] = pr_globals[st->a+1];
pr_globals[OFS_RETURN+2] = pr_globals[st->a+2];
/*
{
static char buffer[1024*1024*8];
int size = sizeof buffer;
progfuncs->save_ents(progfuncs, buffer, &size, 0);
}
*/
s = PR_LeaveFunction (progfuncs);
st = &pr_statements[s];
if (pr_depth == prinst->exitdepth)
{
return; // all done
}
goto restart;
// break;
case OP_STATE:
externs->stateop(progfuncs, OPA->_float, OPB->function);
break;
case OP_ADD_I:
OPC->_int = OPA->_int + OPB->_int;
break;
case OP_ADD_FI:
OPC->_float = OPA->_float + (float)OPB->_int;
break;
case OP_ADD_IF:
OPC->_float = (float)OPA->_int + OPB->_float;
break;
case OP_SUB_I:
OPC->_int = OPA->_int - OPB->_int;
break;
case OP_SUB_FI:
OPC->_float = OPA->_float - (float)OPB->_int;
break;
case OP_SUB_IF:
OPC->_float = (float)OPA->_int - OPB->_float;
break;
case OP_CONV_ITOF:
OPC->_float = (float)OPA->_int;
break;
case OP_CONV_FTOI:
OPC->_int = (int)OPA->_float;
break;
case OP_CP_ITOF:
ptr = (eval_t *)(((qbyte *)sv_edicts) + OPA->_int);
OPC->_float = (float)ptr->_int;
break;
case OP_CP_FTOI:
ptr = (eval_t *)(((qbyte *)sv_edicts) + OPA->_int);
OPC->_int = (int)ptr->_float;
break;
case OP_BITAND_I:
OPC->_int = (OPA->_int & OPB->_int);
break;
case OP_BITOR_I:
OPC->_int = (OPA->_int | OPB->_int);
break;
case OP_MUL_I:
OPC->_int = OPA->_int * OPB->_int;
break;
case OP_DIV_I:
if (OPB->_int == 0) //no division by zero allowed...
OPC->_int = 0;
else
OPC->_int = OPA->_int / OPB->_int;
break;
case OP_EQ_I:
OPC->_int = (OPA->_int == OPB->_int);
break;
case OP_NE_I:
OPC->_int = (OPA->_int != OPB->_int);
break;
//array/structure reading/riting.
case OP_GLOBALADDRESS:
OPC->_int = ENGINEPOINTER(&OPA->_int + OPB->_int);
break;
case OP_POINTER_ADD: //pointer to 32 bit (remember to *3 for vectors)
OPC->_int = OPA->_int + OPB->_int*4;
break;
case OP_LOADA_I:
case OP_LOADA_F:
case OP_LOADA_FLD:
case OP_LOADA_ENT:
case OP_LOADA_S:
case OP_LOADA_FNC:
ptr = (eval_t *)(&OPA->_int + OPB->_int);
OPC->_int = ptr->_int;
break;
case OP_LOADA_V:
ptr = (eval_t *)(&OPA->_int + OPB->_int);
OPC->_vector[0] = ptr->_vector[0];
OPC->_vector[1] = ptr->_vector[1];
OPC->_vector[2] = ptr->_vector[2];
break;
case OP_ADD_SF: //(char*)c = (char*)a + (float)b
OPC->_int = OPA->_int + (int)OPB->_float;
break;
case OP_SUB_S: //(float)c = (char*)a - (char*)b
OPC->_int = OPA->_int - OPB->_int;
break;
case OP_LOADP_C: //load character from a string
ptr = QCPOINTERM(OPA->_int + (int)OPB->_float);
OPC->_float = *(unsigned char *)ptr;
break;
case OP_LOADP_I:
case OP_LOADP_F:
case OP_LOADP_FLD:
case OP_LOADP_ENT:
case OP_LOADP_S:
case OP_LOADP_FNC:
ptr = QCPOINTERM(OPA->_int + OPB->_int);
OPC->_int = ptr->_int;
break;
case OP_LOADP_V:
ptr = QCPOINTERM(OPA->_int + OPB->_int);
OPC->_vector[0] = ptr->_vector[0];
OPC->_vector[1] = ptr->_vector[1];
OPC->_vector[2] = ptr->_vector[2];
break;
case OP_XOR_I:
OPC->_int = OPA->_int ^ OPB->_int;
break;
case OP_RSHIFT_I:
OPC->_int = OPA->_int >> OPB->_int;
break;
case OP_LSHIFT_I:
OPC->_int = OPA->_int << OPB->_int;
break;
case OP_FETCH_GBL_F:
case OP_FETCH_GBL_S:
case OP_FETCH_GBL_E:
case OP_FETCH_GBL_FNC:
i = (int)OPB->_float;
if(i < 0 || i > ((eval_t *)&glob[st->a-1])->_int)
{
PR_RunError(progfuncs, "array index out of bounds: %s[%d]", PR_GlobalStringNoContents(progfuncs, st->a), i);
}
t = (eval_t *)&pr_globals[(uofs)st->a + i];
OPC->_int = t->_int;
break;
case OP_FETCH_GBL_V:
i = (int)OPB->_float;
if(i < 0 || i > ((eval_t *)&glob[st->a-1])->_int)
{
PR_RunError(progfuncs, "array index out of bounds: %s[%d]", PR_GlobalStringNoContents(progfuncs, st->a), i);
}
t = (eval_t *)&pr_globals[(uofs)st->a
+((int)OPB->_float)*3];
OPC->_vector[0] = t->_vector[0];
OPC->_vector[1] = t->_vector[1];
OPC->_vector[2] = t->_vector[2];
break;
case OP_CSTATE:
externs->cstateop(progfuncs, OPA->_float, OPB->_float, fnum);
break;
case OP_CWSTATE:
externs->cwstateop(progfuncs, OPA->_float, OPB->_float, fnum);
break;
case OP_THINKTIME:
externs->thinktimeop(progfuncs, (struct edict_s *)PROG_TO_EDICT(progfuncs, OPA->edict), OPB->_float);
break;
case OP_BITSET: // b (+) a
OPB->_float = (float)((int)OPB->_float | (int)OPA->_float);
break;
case OP_BITSETP: // .b (+) a
ptr = QCPOINTER(OPB);
ptr->_float = (float)((int)ptr->_float | (int)OPA->_float);
break;
case OP_BITCLR: // b (-) a
OPB->_float = (float)((int)OPB->_float & ~((int)OPA->_float));
break;
case OP_BITCLRP: // .b (-) a
ptr = QCPOINTER(OPB);
ptr->_float = (float)((int)ptr->_float & ~((int)OPA->_float));
break;
case OP_RAND0:
G_FLOAT(OFS_RETURN) = (rand()&0x7fff)/((float)0x7fff);
break;
case OP_RAND1:
G_FLOAT(OFS_RETURN) = (rand()&0x7fff)/((float)0x7fff)*OPA->_float;
break;
case OP_RAND2:
if(OPA->_float < OPB->_float)
{
G_FLOAT(OFS_RETURN) = OPA->_float+((rand()&0x7fff)/((float)0x7fff)
*(OPB->_float-OPA->_float));
}
else
{
G_FLOAT(OFS_RETURN) = OPB->_float+((rand()&0x7fff)/((float)0x7fff)
*(OPA->_float-OPB->_float));
}
break;
case OP_RANDV0:
G_FLOAT(OFS_RETURN+0) = (rand()&0x7fff)/((float)0x7fff);
G_FLOAT(OFS_RETURN+1) = (rand()&0x7fff)/((float)0x7fff);
G_FLOAT(OFS_RETURN+2) = (rand()&0x7fff)/((float)0x7fff);
break;
case OP_RANDV1:
G_FLOAT(OFS_RETURN+0) = (rand()&0x7fff)/((float)0x7fff)*OPA->_vector[0];
G_FLOAT(OFS_RETURN+1) = (rand()&0x7fff)/((float)0x7fff)*OPA->_vector[1];
G_FLOAT(OFS_RETURN+2) = (rand()&0x7fff)/((float)0x7fff)*OPA->_vector[2];
break;
case OP_RANDV2:
for(i = 0; i < 3; i++)
{
if(OPA->_vector[i] < OPB->_vector[i])
{
G_FLOAT(OFS_RETURN+i) = OPA->_vector[i]+((rand()&0x7fff)/((float)0x7fff)
*(OPB->_vector[i]-OPA->_vector[i]));
}
else
{
G_FLOAT(OFS_RETURN+i) = OPB->_vector[i]+(rand()*(1.0f/RAND_MAX)
*(OPA->_vector[i]-OPB->_vector[i]));
}
}
break;
case OP_SWITCH_F:
case OP_SWITCH_V:
case OP_SWITCH_S:
case OP_SWITCH_E:
case OP_SWITCH_FNC:
swtch = OPA;
swtchtype = st->op;
RUNAWAYCHECK();
st += (sofs)st->b - 1; // offset the st++
break;
case OP_CASE:
switch(swtchtype)
{
case OP_SWITCH_F:
if (swtch->_float == OPA->_float)
{
RUNAWAYCHECK();
st += (sofs)st->b-1; // -1 to offset the s++
}
break;
case OP_SWITCH_E:
case OP_SWITCH_FNC:
if (swtch->_int == OPA->_int)
{
RUNAWAYCHECK();
st += (sofs)st->b-1; // -1 to offset the s++
}
break;
case OP_SWITCH_S:
if (swtch->_int == OPA->_int)
{
RUNAWAYCHECK();
st += (sofs)st->b-1; // -1 to offset the s++
}
if ((!swtch->_int && PR_StringToNative(progfuncs, OPA->string)) || (!OPA->_int && PR_StringToNative(progfuncs, swtch->string))) //one is null (cannot be not both).
break;
if (!strcmp(PR_StringToNative(progfuncs, swtch->string), PR_StringToNative(progfuncs, OPA->string)))
{
RUNAWAYCHECK();
st += (sofs)st->b-1; // -1 to offset the s++
}
break;
case OP_SWITCH_V:
if (swtch->_vector[0] == OPA->_vector[0] && swtch->_vector[1] == OPA->_vector[1] && swtch->_vector[2] == OPA->_vector[2])
{
RUNAWAYCHECK();
st += (sofs)st->b-1; // -1 to offset the s++
}
break;
default:
PR_RunError (progfuncs, "OP_CASE with bad/missing OP_SWITCH %i", swtchtype);
break;
}
break;
case OP_CASERANGE:
switch(swtchtype)
{
case OP_SWITCH_F:
if (swtch->_float >= OPA->_float && swtch->_float <= OPB->_float)
{
RUNAWAYCHECK();
st += (sofs)st->c-1; // -1 to offset the s++
}
break;
default:
PR_RunError (progfuncs, "OP_CASERANGE with bad/missing OP_SWITCH %i", swtchtype);
}
break;
case OP_BITAND_IF:
OPC->_int = (OPA->_int & (int)OPB->_float);
break;
case OP_BITOR_IF:
OPC->_int = (OPA->_int | (int)OPB->_float);
break;
case OP_BITAND_FI:
OPC->_int = ((int)OPA->_float & OPB->_int);
break;
case OP_BITOR_FI:
OPC->_int = ((int)OPA->_float | OPB->_int);
break;
case OP_MUL_IF:
OPC->_float = (OPA->_int * OPB->_float);
break;