progs.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. Copyright (C) 1996-1997 Id Software, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #include "pr_comp.h" // defs shared with qcc
  16. #include "progdefs.h" // generated by program cdefs
  17. typedef union eval_s
  18. {
  19. string_t string;
  20. float _float;
  21. float vector[3];
  22. func_t function;
  23. int _int;
  24. int edict;
  25. } eval_t;
  26. #define MAX_ENT_LEAFS 16
  27. typedef struct edict_s
  28. {
  29. qboolean free;
  30. link_t area; // linked to a division node or leaf
  31. int num_leafs;
  32. short leafnums[MAX_ENT_LEAFS];
  33. entity_state_t baseline;
  34. float freetime; // sv.time when the object was freed
  35. entvars_t v; // C exported fields from progs
  36. // other fields from progs come immediately after
  37. } edict_t;
  38. #define EDICT_FROM_AREA(l) STRUCT_FROM_LINK(l,edict_t,area)
  39. //============================================================================
  40. extern dprograms_t *progs;
  41. extern dfunction_t *pr_functions;
  42. extern char *pr_strings;
  43. extern ddef_t *pr_globaldefs;
  44. extern ddef_t *pr_fielddefs;
  45. extern dstatement_t *pr_statements;
  46. extern globalvars_t *pr_global_struct;
  47. extern float *pr_globals; // same as pr_global_struct
  48. extern int pr_edict_size; // in bytes
  49. //============================================================================
  50. void PR_Init (void);
  51. void PR_ExecuteProgram (func_t fnum);
  52. void PR_LoadProgs (void);
  53. void PR_Profile_f (void);
  54. edict_t *ED_Alloc (void);
  55. void ED_Free (edict_t *ed);
  56. char *ED_NewString (char *string);
  57. // returns a copy of the string allocated from the server's string heap
  58. void ED_Print (edict_t *ed);
  59. void ED_Write (FILE *f, edict_t *ed);
  60. char *ED_ParseEdict (char *data, edict_t *ent);
  61. void ED_WriteGlobals (FILE *f);
  62. void ED_ParseGlobals (char *data);
  63. void ED_LoadFromFile (char *data);
  64. //define EDICT_NUM(n) ((edict_t *)(sv.edicts+ (n)*pr_edict_size))
  65. //define NUM_FOR_EDICT(e) (((byte *)(e) - sv.edicts)/pr_edict_size)
  66. edict_t *EDICT_NUM(int n);
  67. int NUM_FOR_EDICT(edict_t *e);
  68. #define NEXT_EDICT(e) ((edict_t *)( (byte *)e + pr_edict_size))
  69. #define EDICT_TO_PROG(e) ((byte *)e - (byte *)sv.edicts)
  70. #define PROG_TO_EDICT(e) ((edict_t *)((byte *)sv.edicts + e))
  71. //============================================================================
  72. #define G_FLOAT(o) (pr_globals[o])
  73. #define G_INT(o) (*(int *)&pr_globals[o])
  74. #define G_EDICT(o) ((edict_t *)((byte *)sv.edicts+ *(int *)&pr_globals[o]))
  75. #define G_EDICTNUM(o) NUM_FOR_EDICT(G_EDICT(o))
  76. #define G_VECTOR(o) (&pr_globals[o])
  77. #define G_STRING(o) (PR_GetString(*(string_t *)&pr_globals[o]))
  78. #define G_FUNCTION(o) (*(func_t *)&pr_globals[o])
  79. #define E_FLOAT(e,o) (((float*)&e->v)[o])
  80. #define E_INT(e,o) (*(int *)&((float*)&e->v)[o])
  81. #define E_VECTOR(e,o) (&((float*)&e->v)[o])
  82. #define E_STRING(e,o) (PR_GetString(*(string_t *)&((float*)&e->v)[o]))
  83. extern int type_size[8];
  84. typedef void (*builtin_t) (void);
  85. extern builtin_t *pr_builtins;
  86. extern int pr_numbuiltins;
  87. extern int pr_argc;
  88. extern qboolean pr_trace;
  89. extern dfunction_t *pr_xfunction;
  90. extern int pr_xstatement;
  91. extern func_t SpectatorConnect;
  92. extern func_t SpectatorThink;
  93. extern func_t SpectatorDisconnect;
  94. void PR_RunError (char *error, ...);
  95. void ED_PrintEdicts (void);
  96. void ED_PrintNum (int ent);
  97. eval_t *GetEdictFieldValue(edict_t *ed, char *field);
  98. //
  99. // PR STrings stuff
  100. //
  101. #define MAX_PRSTR 1024
  102. extern char *pr_strtbl[MAX_PRSTR];
  103. extern int num_prstr;
  104. char *PR_GetString(int num);
  105. int PR_SetString(char *s);