cm_local.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. ===========================================================================
  3. Copyright (C) 1999-2005 Id Software, Inc.
  4. This file is part of Quake III Arena source code.
  5. Quake III Arena source code is free software; you can redistribute it
  6. and/or modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of the License,
  8. or (at your option) any later version.
  9. Quake III Arena source code is distributed in the hope that it will be
  10. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Foobar; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. ===========================================================================
  17. */
  18. #include "../game/q_shared.h"
  19. #include "qcommon.h"
  20. #include "cm_polylib.h"
  21. #define MAX_SUBMODELS 256
  22. #define BOX_MODEL_HANDLE 255
  23. #define CAPSULE_MODEL_HANDLE 254
  24. typedef struct {
  25. cplane_t *plane;
  26. int children[2]; // negative numbers are leafs
  27. } cNode_t;
  28. typedef struct {
  29. int cluster;
  30. int area;
  31. int firstLeafBrush;
  32. int numLeafBrushes;
  33. int firstLeafSurface;
  34. int numLeafSurfaces;
  35. } cLeaf_t;
  36. typedef struct cmodel_s {
  37. vec3_t mins, maxs;
  38. cLeaf_t leaf; // submodels don't reference the main tree
  39. } cmodel_t;
  40. typedef struct {
  41. cplane_t *plane;
  42. int surfaceFlags;
  43. int shaderNum;
  44. } cbrushside_t;
  45. typedef struct {
  46. int shaderNum; // the shader that determined the contents
  47. int contents;
  48. vec3_t bounds[2];
  49. int numsides;
  50. cbrushside_t *sides;
  51. int checkcount; // to avoid repeated testings
  52. } cbrush_t;
  53. typedef struct {
  54. int checkcount; // to avoid repeated testings
  55. int surfaceFlags;
  56. int contents;
  57. struct patchCollide_s *pc;
  58. } cPatch_t;
  59. typedef struct {
  60. int floodnum;
  61. int floodvalid;
  62. } cArea_t;
  63. typedef struct {
  64. char name[MAX_QPATH];
  65. int numShaders;
  66. dshader_t *shaders;
  67. int numBrushSides;
  68. cbrushside_t *brushsides;
  69. int numPlanes;
  70. cplane_t *planes;
  71. int numNodes;
  72. cNode_t *nodes;
  73. int numLeafs;
  74. cLeaf_t *leafs;
  75. int numLeafBrushes;
  76. int *leafbrushes;
  77. int numLeafSurfaces;
  78. int *leafsurfaces;
  79. int numSubModels;
  80. cmodel_t *cmodels;
  81. int numBrushes;
  82. cbrush_t *brushes;
  83. int numClusters;
  84. int clusterBytes;
  85. byte *visibility;
  86. qboolean vised; // if false, visibility is just a single cluster of ffs
  87. int numEntityChars;
  88. char *entityString;
  89. int numAreas;
  90. cArea_t *areas;
  91. int *areaPortals; // [ numAreas*numAreas ] reference counts
  92. int numSurfaces;
  93. cPatch_t **surfaces; // non-patches will be NULL
  94. int floodvalid;
  95. int checkcount; // incremented on each trace
  96. } clipMap_t;
  97. // keep 1/8 unit away to keep the position valid before network snapping
  98. // and to avoid various numeric issues
  99. #define SURFACE_CLIP_EPSILON (0.125)
  100. extern clipMap_t cm;
  101. extern int c_pointcontents;
  102. extern int c_traces, c_brush_traces, c_patch_traces;
  103. extern cvar_t *cm_noAreas;
  104. extern cvar_t *cm_noCurves;
  105. extern cvar_t *cm_playerCurveClip;
  106. // cm_test.c
  107. // Used for oriented capsule collision detection
  108. typedef struct
  109. {
  110. qboolean use;
  111. float radius;
  112. float halfheight;
  113. vec3_t offset;
  114. } sphere_t;
  115. typedef struct {
  116. vec3_t start;
  117. vec3_t end;
  118. vec3_t size[2]; // size of the box being swept through the model
  119. vec3_t offsets[8]; // [signbits][x] = either size[0][x] or size[1][x]
  120. float maxOffset; // longest corner length from origin
  121. vec3_t extents; // greatest of abs(size[0]) and abs(size[1])
  122. vec3_t bounds[2]; // enclosing box of start and end surrounding by size
  123. vec3_t modelOrigin;// origin of the model tracing through
  124. int contents; // ored contents of the model tracing through
  125. qboolean isPoint; // optimized case
  126. trace_t trace; // returned from trace call
  127. sphere_t sphere; // sphere for oriendted capsule collision
  128. } traceWork_t;
  129. typedef struct leafList_s {
  130. int count;
  131. int maxcount;
  132. qboolean overflowed;
  133. int *list;
  134. vec3_t bounds[2];
  135. int lastLeaf; // for overflows where each leaf can't be stored individually
  136. void (*storeLeafs)( struct leafList_s *ll, int nodenum );
  137. } leafList_t;
  138. int CM_BoxBrushes( const vec3_t mins, const vec3_t maxs, cbrush_t **list, int listsize );
  139. void CM_StoreLeafs( leafList_t *ll, int nodenum );
  140. void CM_StoreBrushes( leafList_t *ll, int nodenum );
  141. void CM_BoxLeafnums_r( leafList_t *ll, int nodenum );
  142. cmodel_t *CM_ClipHandleToModel( clipHandle_t handle );
  143. // cm_patch.c
  144. struct patchCollide_s *CM_GeneratePatchCollide( int width, int height, vec3_t *points );
  145. void CM_TraceThroughPatchCollide( traceWork_t *tw, const struct patchCollide_s *pc );
  146. qboolean CM_PositionTestInPatchCollide( traceWork_t *tw, const struct patchCollide_s *pc );
  147. void CM_ClearLevelPatches( void );