-
Notifications
You must be signed in to change notification settings - Fork 0
/
pr_edict.c
3118 lines (2738 loc) · 75.6 KB
/
pr_edict.c
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
#define PROGSUSED
struct edict_s;
#include "progsint.h"
//#include "crc.h"
/*int maxedicts;
evalc_t spawnflagscache;
*/
#ifdef _WIN32
//this is windows all files are written with this endian standard. we do this to try to get a little more speed.
#define NOENDIAN
#endif
vec3_t vec3_origin;
//edictrun_t *sv_edicts;
//int sv_num_edicts;
//int pr_edict_size; // in bytes
//int pr_max_edict_size;
//unsigned short pr_crc;
fdef_t *ED_FieldAtOfs (progfuncs_t *progfuncs, unsigned int ofs);
pbool ED_ParseEpair (progfuncs_t *progfuncs, void *base, ddefXX_t *key, char *s, int bits);
/*
#define MAX_FIELD_LEN 64
#define GEFV_CACHESIZE 5
typedef struct {
ddef_t *pcache;
char field[MAX_FIELD_LEN];
} gefv_cache;
static gefv_cache gefvCache[GEFV_CACHESIZE] = {{NULL, ""}, {NULL, ""}};
*/
/*
=================
QC_ClearEdict
Sets everything to NULL
=================
*/
void QC_ClearEdict (progfuncs_t *progfuncs, struct edict_s *ed)
{
edictrun_t *e = (edictrun_t *)ed;
int num = e->entnum;
memset (e->fields, 0, fields_size);
e->isfree = false;
e->entnum = num;
}
edictrun_t *ED_AllocIntoTable (progfuncs_t *progfuncs, int num)
{
edictrun_t *e;
prinst->edicttable[num] = *(struct edict_s **)&e = (void*)memalloc(externs->edictsize);
memset(e, 0, externs->edictsize);
e->fields = PRAddressableAlloc(progfuncs, fields_size);
e->entnum = num;
QC_ClearEdict(progfuncs, (struct edict_s*)e);
return e;
}
/*
=================
ED_Alloc
Either finds a free edict, or allocates a new one.
Try to avoid reusing an entity that was recently freed, because it
can cause the client to think the entity morphed into something else
instead of being removed and recreated, which can cause interpolated
angles and bad trails.
=================
*/
struct edict_s *ED_Alloc (progfuncs_t *progfuncs)
{
unsigned int i;
edictrun_t *e;
for ( i=0 ; i<sv_num_edicts ; i++)
{
e = (edictrun_t*)EDICT_NUM(progfuncs, i);
// the first couple seconds of server time can involve a lot of
// freeing and allocating, so relax the replacement policy
if (!e || (e->isfree && ( e->freetime < 2 || *externs->gametime - e->freetime > 0.5 ) ))
{
if (!e)
e = ED_AllocIntoTable(progfuncs, i);
else
QC_ClearEdict (progfuncs, (struct edict_s*)e);
if (externs->entspawn)
externs->entspawn((struct edict_s *) e, false);
return (struct edict_s *)e;
}
}
if (i >= maxedicts-1) //try again, but use timed out ents.
{
for ( i=0 ; i<sv_num_edicts ; i++)
{
e = (edictrun_t*)EDICT_NUM(progfuncs, i);
// the first couple seconds of server time can involve a lot of
// freeing and allocating, so relax the replacement policy
if (!e || (e->isfree))
{
if (!e)
e = ED_AllocIntoTable(progfuncs, i);
else
QC_ClearEdict (progfuncs, (struct edict_s*)e);
if (externs->entspawn)
externs->entspawn((struct edict_s *) e, false);
return (struct edict_s *)e;
}
}
if (i >= maxedicts-2)
{
printf("Running out of edicts\n");
pr_trace = 1; //trip the debugger whilst it's still valid
}
if (i >= maxedicts-1)
{
int size;
char *buf;
buf = progfuncs->save_ents(progfuncs, NULL, &size, 0);
progfuncs->parms->WriteFile("edalloc.dump", buf, size);
Sys_Error ("ED_Alloc: no free edicts");
}
}
sv_num_edicts++;
e = (edictrun_t*)EDICT_NUM(progfuncs, i);
if (!e)
e = ED_AllocIntoTable(progfuncs, i);
else
QC_ClearEdict (progfuncs, (struct edict_s*)e);
if (externs->entspawn)
externs->entspawn((struct edict_s *) e, false);
return (struct edict_s *)e;
}
/*
=================
ED_Free
Marks the edict as free
FIXME: walk all entities and NULL out references to this entity
=================
*/
void ED_Free (progfuncs_t *progfuncs, struct edict_s *ed)
{
edictrun_t *e = (edictrun_t *)ed;
// SV_UnlinkEdict (ed); // unlink from world bsp
if (e->isfree) //this happens on start.bsp where an onlyregistered trigger killtargets itself (when all of this sort die after 1 trigger anyway).
{
if (pr_depth)
printf("Tried to free free entity within %s\n", pr_xfunction->s_name+progfuncs->stringtable);
else
printf("Engine tried to free free entity\n");
// if (developer.value == 1)
// pr_trace = true;
return;
}
if (externs->entcanfree)
if (!externs->entcanfree(ed)) //can stop an ent from being freed.
return;
e->isfree = true;
e->freetime = (float)*externs->gametime;
/*
ed->v.model = 0;
ed->v.takedamage = 0;
ed->v.modelindex = 0;
ed->v.colormap = 0;
ed->v.skin = 0;
ed->v.frame = 0;
VectorCopy (vec3_origin, ed->v.origin);
VectorCopy (vec3_origin, ed->v.angles);
ed->v.nextthink = -1;
ed->v.solid = 0;
*/
}
//===========================================================================
/*
============
ED_GlobalAtOfs
============
*/
ddef16_t *ED_GlobalAtOfs16 (progfuncs_t *progfuncs, int ofs)
{
ddef16_t *def;
unsigned int i;
for (i=0 ; i<pr_progs->numglobaldefs ; i++)
{
def = &pr_globaldefs16[i];
if (def->ofs == ofs)
return def;
}
return NULL;
}
ddef32_t *ED_GlobalAtOfs32 (progfuncs_t *progfuncs, unsigned int ofs)
{
ddef32_t *def;
unsigned int i;
for (i=0 ; i<pr_progs->numglobaldefs ; i++)
{
def = &pr_globaldefs32[i];
if (def->ofs == ofs)
return def;
}
return NULL;
}
/*
============
ED_FieldAtOfs
============
*/
fdef_t *ED_FieldAtOfs (progfuncs_t *progfuncs, unsigned int ofs)
{
// ddef_t *def;
unsigned int i;
for (i=0 ; i<numfields ; i++)
{
if (field[i].ofs == ofs)
return &field[i];
}
return NULL;
}
/*
============
ED_FindField
============
*/
fdef_t *ED_FindField (progfuncs_t *progfuncs, char *name)
{
unsigned int i;
for (i=0 ; i<numfields ; i++)
{
if (!strcmp(field[i].name, name) )
return &field[i];
}
return NULL;
}
/*
============
ED_FindGlobal
============
*/
ddef16_t *ED_FindGlobal16 (progfuncs_t *progfuncs, char *name)
{
ddef16_t *def;
unsigned int i;
for (i=1 ; i<pr_progs->numglobaldefs ; i++)
{
def = &pr_globaldefs16[i];
if (!strcmp(def->s_name+progfuncs->stringtable,name) )
return def;
}
return NULL;
}
ddef32_t *ED_FindGlobal32 (progfuncs_t *progfuncs, char *name)
{
ddef32_t *def;
unsigned int i;
for (i=1 ; i<pr_progs->numglobaldefs ; i++)
{
def = &pr_globaldefs32[i];
if (!strcmp(def->s_name+progfuncs->stringtable,name) )
return def;
}
return NULL;
}
unsigned int ED_FindGlobalOfs (progfuncs_t *progfuncs, char *name)
{
ddef16_t *d16;
ddef32_t *d32;
switch(current_progstate->intsize)
{
case 24:
case 16:
d16 = ED_FindGlobal16(progfuncs, name);
return d16?d16->ofs:0;
case 32:
d32 = ED_FindGlobal32(progfuncs, name);
return d32?d32->ofs:0;
}
Sys_Error("ED_FindGlobalOfs - bad intsize");
return 0;
}
ddef16_t *ED_FindGlobalFromProgs16 (progfuncs_t *progfuncs, char *name, progsnum_t prnum)
{
ddef16_t *def;
unsigned int i;
for (i=1 ; i<pr_progstate[prnum].progs->numglobaldefs ; i++)
{
def = &pr_progstate[prnum].globaldefs16[i];
if (!strcmp(def->s_name+progfuncs->stringtable,name) )
return def;
}
return NULL;
}
ddef32_t *ED_FindGlobalFromProgs32 (progfuncs_t *progfuncs, char *name, progsnum_t prnum)
{
ddef32_t *def;
unsigned int i;
for (i=1 ; i<pr_progstate[prnum].progs->numglobaldefs ; i++)
{
def = &pr_progstate[prnum].globaldefs32[i];
if (!strcmp(def->s_name+progfuncs->stringtable,name) )
return def;
}
return NULL;
}
ddef16_t *ED_FindTypeGlobalFromProgs16 (progfuncs_t *progfuncs, char *name, progsnum_t prnum, int type)
{
ddef16_t *def;
unsigned int i;
for (i=1 ; i<pr_progstate[prnum].progs->numglobaldefs ; i++)
{
def = &pr_progstate[prnum].globaldefs16[i];
if (!strcmp(def->s_name+progfuncs->stringtable,name) )
{
if (pr_progstate[prnum].types)
{
if (pr_progstate[prnum].types[def->type&~DEF_SAVEGLOBAL].type != type)
continue;
}
else if ((def->type&(~DEF_SAVEGLOBAL)) != type)
continue;
return def;
}
}
return NULL;
}
ddef32_t *ED_FindTypeGlobalFromProgs32 (progfuncs_t *progfuncs, char *name, progsnum_t prnum, int type)
{
ddef32_t *def;
unsigned int i;
for (i=1 ; i<pr_progstate[prnum].progs->numglobaldefs ; i++)
{
def = &pr_progstate[prnum].globaldefs32[i];
if (!strcmp(def->s_name+progfuncs->stringtable,name) )
{
if (pr_progstate[prnum].types)
{
if (pr_progstate[prnum].types[def->type&~DEF_SAVEGLOBAL].type != type)
continue;
}
else if ((def->type&(~DEF_SAVEGLOBAL)) != (unsigned)type)
continue;
return def;
}
}
return NULL;
}
unsigned int *ED_FindGlobalOfsFromProgs (progfuncs_t *progfuncs, char *name, progsnum_t prnum, int type)
{
ddef16_t *def16;
ddef32_t *def32;
static unsigned int pos;
switch(pr_progstate[prnum].intsize)
{
case 16:
case 24:
def16 = ED_FindTypeGlobalFromProgs16(progfuncs, name, prnum, type);
if (!def16)
return NULL;
pos = def16->ofs;
return &pos;
case 32:
def32 = ED_FindTypeGlobalFromProgs32(progfuncs, name, prnum, type);
if (!def32)
return NULL;
return &def32->ofs;
}
Sys_Error("ED_FindGlobalOfsFromProgs - bad intsize");
return 0;
}
/*
============
ED_FindFunction
============
*/
dfunction_t *ED_FindFunction (progfuncs_t *progfuncs, char *name, progsnum_t *prnum, progsnum_t fromprogs)
{
dfunction_t *func;
unsigned int i;
char *sep;
progsnum_t pnum;
if (prnum)
{
sep = strchr(name, ':');
if (sep)
{
pnum = atoi(name);
name = sep+1;
}
else
{
if (fromprogs>=0)
pnum = fromprogs;
else
pnum = pr_typecurrent;
}
*prnum = pnum;
}
else
pnum = pr_typecurrent;
if ((unsigned)pnum > (unsigned)maxprogs)
{
printf("Progsnum %i out of bounds\n", pnum);
return NULL;
}
if (!pr_progstate[pnum].progs)
return NULL;
for (i=1 ; i<pr_progstate[pnum].progs->numfunctions ; i++)
{
func = &pr_progstate[pnum].functions[i];
if (!strcmp(func->s_name+progfuncs->stringtable,name) )
return func;
}
return NULL;
}
/*
============
PR_ValueString
Returns a string describing *data in a type specific manner
=============
*/
char *PR_ValueString (progfuncs_t *progfuncs, etype_t type, eval_t *val)
{
static char line[256];
fdef_t *fielddef;
dfunction_t *f;
#ifdef DEF_SAVEGLOBAL
type &= ~DEF_SAVEGLOBAL;
#endif
if (pr_types)
type = pr_types[type].type;
switch (type)
{
case ev_struct:
sprintf (line, "struct");
break;
case ev_union:
sprintf (line, "union");
break;
case ev_string:
sprintf (line, "%s", PR_StringToNative(progfuncs, val->string));
break;
case ev_entity:
sprintf (line, "entity %i", NUM_FOR_EDICT(progfuncs, (struct edict_s *)PROG_TO_EDICT(progfuncs, val->edict)) );
break;
case ev_function:
if (!val->function)
sprintf (line, "NULL function");
else
{
if ((val->function & 0xff000000)>>24 >= (unsigned)maxprogs || !pr_progstate[(val->function & 0xff000000)>>24].functions)
sprintf (line, "Bad function");
else
{
f = pr_progstate[(val->function & 0xff000000)>>24].functions + (val->function & ~0xff000000);
sprintf (line, "%i:%s()", (val->function & 0xff000000)>>24, f->s_name+progfuncs->stringtable);
}
}
break;
case ev_field:
fielddef = ED_FieldAtOfs (progfuncs, val->_int );
if (!fielddef)
sprintf (line, ".??? (%i)", val->_int);
else
sprintf (line, ".%s (%i)", fielddef->name, val->_int);
break;
case ev_void:
sprintf (line, "void type");
break;
case ev_float:
sprintf (line, "%5.1f", val->_float);
break;
case ev_integer:
sprintf (line, "%i", val->_int);
break;
case ev_vector:
sprintf (line, "'%5.1f %5.1f %5.1f'", val->_vector[0], val->_vector[1], val->_vector[2]);
break;
case ev_pointer:
sprintf (line, "pointer");
{
// int entnum;
// int valofs;
if (val->_int == 0)
{
sprintf (line, "NULL pointer");
break;
}
//FIXME: :/
sprintf(line, "UNKNOWN");
// entnum = ((qbyte *)val->edict - (qbyte *)sv_edicts) / pr_edict_size;
// valofs = (int *)val->edict - (int *)edvars(EDICT_NUM(progfuncs, entnum));
// fielddef = ED_FieldAtOfs (progfuncs, valofs );
// if (!fielddef)
// sprintf(line, "ent%i.%s", entnum, "UNKNOWN");
// else
// sprintf(line, "ent%i.%s", entnum, fielddef->s_name);
}
break;
default:
sprintf (line, "bad type %i", type);
break;
}
return line;
}
/*
============
PR_UglyValueString
Returns a string describing *data in a type specific manner
Easier to parse than PR_ValueString
=============
*/
char *PR_UglyValueString (progfuncs_t *progfuncs, etype_t type, eval_t *val)
{
static char line[256];
fdef_t *fielddef;
dfunction_t *f;
int i, j;
#ifdef DEF_SAVEGLOBAL
type &= ~DEF_SAVEGLOBAL;
#endif
if (pr_types)
type = pr_types[type].type;
switch (type)
{
case ev_struct:
sprintf (line, "structures cannot yet be saved");
break;
case ev_union:
sprintf (line, "unions cannot yet be saved");
break;
case ev_string:
{
char *outs = line;
int outb = sizeof(line)-2;
char *ins = PR_StringToNative(progfuncs, val->string);
//markup the output string.
while(*ins && outb > 0)
{
switch(*ins)
{
case '\n':
*outs++ = '\\';
*outs++ = 'n';
ins++;
outb-=2;
break;
case '\"':
*outs++ = '\\';
*outs++ = '"';
ins++;
outb-=2;
break;
case '\\':
*outs++ = '\\';
*outs++ = '\\';
ins++;
outb-=2;
break;
default:
*outs++ = *ins++;
outb--;
break;
}
}
*outs = 0;
}
break;
case ev_entity:
sprintf (line, "%i", val->_int);
break;
case ev_function:
i = (val->function & 0xff000000)>>24; //progs number
if ((unsigned)i >= maxprogs || !pr_progstate[(unsigned)i].progs)
sprintf (line, "BAD FUNCTION INDEX: %i", val->function);
else
{
j = (val->function & ~0xff000000); //function number
if ((unsigned)j >= pr_progstate[(unsigned)i].progs->numfunctions)
sprintf(line, "%i:%s", i, "CORRUPT FUNCTION POINTER");
else
{
f = pr_progstate[(unsigned)i].functions + j;
sprintf (line, "%i:%s", i, f->s_name+progfuncs->stringtable);
}
}
break;
case ev_field:
fielddef = ED_FieldAtOfs (progfuncs, val->_int );
sprintf (line, "%s", fielddef->name);
break;
case ev_void:
sprintf (line, "void");
break;
case ev_float:
if (val->_float == (int)val->_float)
sprintf (line, "%i", (int)val->_float); //an attempt to cut down on the number of .000000 vars..
else
sprintf (line, "%f", val->_float);
break;
case ev_integer:
sprintf (line, "%i", val->_int);
break;
case ev_vector:
if (val->_vector[0] == (int)val->_vector[0] && val->_vector[1] == (int)val->_vector[1] && val->_vector[2] == (int)val->_vector[2])
sprintf (line, "%i %i %i", (int)val->_vector[0], (int)val->_vector[1], (int)val->_vector[2]);
else
sprintf (line, "%f %f %f", val->_vector[0], val->_vector[1], val->_vector[2]);
break;
default:
sprintf (line, "bad type %i", type);
break;
}
return line;
}
//compatible with Q1 (for savegames)
char *PR_UglyOldValueString (progfuncs_t *progfuncs, etype_t type, eval_t *val)
{
static char line[256];
fdef_t *fielddef;
dfunction_t *f;
#ifdef DEF_SAVEGLOBAL
type &= ~DEF_SAVEGLOBAL;
#endif
if (pr_types)
type = pr_types[type].type;
switch (type)
{
case ev_struct:
sprintf (line, "structures cannot yet be saved");
break;
case ev_union:
sprintf (line, "unions cannot yet be saved");
break;
case ev_string:
sprintf (line, "%s", PR_StringToNative(progfuncs, val->string));
break;
case ev_entity:
sprintf (line, "%i", NUM_FOR_EDICT(progfuncs, (struct edict_s *)PROG_TO_EDICT(progfuncs, val->edict)));
break;
case ev_function:
f = pr_progstate[(val->function & 0xff000000)>>24].functions + (val->function & ~0xff000000);
sprintf (line, "%s", f->s_name+progfuncs->stringtable);
break;
case ev_field:
fielddef = ED_FieldAtOfs (progfuncs, val->_int );
sprintf (line, "%s", fielddef->name);
break;
case ev_void:
sprintf (line, "void");
break;
case ev_float:
if (val->_float == (int)val->_float)
sprintf (line, "%i", (int)val->_float); //an attempt to cut down on the number of .000000 vars..
else
sprintf (line, "%f", val->_float);
break;
case ev_integer:
sprintf (line, "%i", val->_int);
break;
case ev_vector:
if (val->_vector[0] == (int)val->_vector[0] && val->_vector[1] == (int)val->_vector[1] && val->_vector[2] == (int)val->_vector[2])
sprintf (line, "%i %i %i", (int)val->_vector[0], (int)val->_vector[1], (int)val->_vector[2]);
else
sprintf (line, "%f %f %f", val->_vector[0], val->_vector[1], val->_vector[2]);
break;
break;
default:
sprintf (line, "bad type %i", type);
break;
}
return line;
}
char *PR_TypeString(progfuncs_t *progfuncs, etype_t type)
{
#ifdef DEF_SAVEGLOBAL
type &= ~DEF_SAVEGLOBAL;
#endif
if (pr_types)
type = pr_types[type].type;
switch (type)
{
case ev_struct:
return "struct";
case ev_union:
return "union";
case ev_string:
return "string";
case ev_entity:
return "entity";
case ev_function:
return "function";
case ev_field:
return "field";
case ev_void:
return "void";
case ev_float:
return "float";
case ev_vector:
return "vector";
case ev_integer:
return "integer";
default:
return "BAD TYPE";
}
}
/*
============
PR_GlobalString
Returns a string with a description and the contents of a global,
padded to 20 field width
============
*/
char *PR_GlobalString (progfuncs_t *progfuncs, int ofs)
{
char *s;
int i;
ddef16_t *def16;
ddef32_t *def32;
void *val;
static char line[128];
switch (current_progstate->intsize)
{
case 16:
case 24:
val = (void *)&pr_globals[ofs];
def16 = ED_GlobalAtOfs16(progfuncs, ofs);
if (!def16)
sprintf (line,"%i(?""?""?)", ofs);
else
{
s = PR_ValueString (progfuncs, def16->type, val);
sprintf (line,"%i(%s)%s", ofs, def16->s_name+progfuncs->stringtable, s);
}
i = strlen(line);
for ( ; i<20 ; i++)
strcat (line," ");
strcat (line," ");
return line;
case 32:
val = (void *)&pr_globals[ofs];
def32 = ED_GlobalAtOfs32(progfuncs, ofs);
if (!def32)
sprintf (line,"%i(?""?""?)", ofs);
else
{
s = PR_ValueString (progfuncs, def32->type, val);
sprintf (line,"%i(%s)%s", ofs, def32->s_name+progfuncs->stringtable, s);
}
i = strlen(line);
for ( ; i<20 ; i++)
strcat (line," ");
strcat (line," ");
return line;
}
Sys_Error("Bad offset size in PR_GlobalString");
return "";
}
char *PR_GlobalStringNoContents (progfuncs_t *progfuncs, int ofs)
{
int i;
ddef16_t *def16;
ddef32_t *def32;
static char line[128];
switch (current_progstate->intsize)
{
case 16:
case 24:
def16 = ED_GlobalAtOfs16(progfuncs, ofs);
if (!def16)
sprintf (line,"%i(?""?""?)", ofs);
else
sprintf (line,"%i(%s)", ofs, def16->s_name+progfuncs->stringtable);
break;
case 32:
def32 = ED_GlobalAtOfs32(progfuncs, ofs);
if (!def32)
sprintf (line,"%i(?""?""?)", ofs);
else
sprintf (line,"%i(%s)", ofs, def32->s_name+progfuncs->stringtable);
break;
default:
Sys_Error("Bad offset size in PR_GlobalStringNoContents");
}
i = strlen(line);
for ( ; i<20 ; i++)
strcat (line," ");
strcat (line," ");
return line;
}
/*
=============
ED_Print
For debugging
=============
*/
void ED_Print (progfuncs_t *progfuncs, struct edict_s *ed)
{
int l;
fdef_t *d;
int *v;
unsigned int i;unsigned int j;
char *name;
int type;
if (((edictrun_t *)ed)->isfree)
{
printf ("FREE\n");
return;
}
printf("\nEDICT %i:\n", NUM_FOR_EDICT(progfuncs, (struct edict_s *)ed));
for (i=1 ; i<numfields ; i++)
{
d = &field[i];
name = d->name;
l = strlen(name);
if (l >= 2 && name[l-2] == '_')
continue; // skip _x, _y, _z vars
v = (int *)((char *)edvars(ed) + d->ofs*4);
// if the value is still all 0, skip the field
#ifdef DEF_SAVEGLOBAL
type = d->type & ~DEF_SAVEGLOBAL;
#else
type = d->type;
#endif
for (j=0 ; j<type_size[type] ; j++)
if (v[j])
break;
if (j == type_size[type])
continue;
printf ("%s",name);
l = strlen (name);
while (l++ < 15)
printf (" ");
printf ("%s\n", PR_ValueString(progfuncs, d->type, (eval_t *)v));
}
}
void ED_PrintNum (progfuncs_t *progfuncs, int ent)
{
ED_Print (progfuncs, EDICT_NUM(progfuncs, ent));
}
/*
=============
ED_PrintEdicts
For debugging, prints all the entities in the current server
=============
*/
void ED_PrintEdicts (progfuncs_t *progfuncs)
{
unsigned int i;
printf ("%i entities\n", sv_num_edicts);
for (i=0 ; i<sv_num_edicts ; i++)
ED_PrintNum (progfuncs, i);
}
/*
=============
ED_Count
For debugging
=============
*/
void ED_Count (progfuncs_t *progfuncs)
{
unsigned int i;
edictrun_t *ent;
unsigned int active, models, solid, step;
active = models = solid = step = 0;
for (i=0 ; i<sv_num_edicts ; i++)
{
ent = (edictrun_t *)EDICT_NUM(progfuncs, i);
if (ent->isfree)
continue;
active++;
// if (ent->v.solid)
// solid++;
// if (ent->v.model)
// models++;
// if (ent->v.movetype == MOVETYPE_STEP)
// step++;
}
printf ("num_edicts:%3i\n", sv_num_edicts);
printf ("active :%3i\n", active);
// Con_Printf ("view :%3i\n", models);
// Con_Printf ("touch :%3i\n", solid);
// Con_Printf ("step :%3i\n", step);
}
//============================================================================
/*
=============
ED_NewString
=============
*/
char *ED_NewString (progfuncs_t *progfuncs, char *string, int minlength)
{
char *newc, *new_p;