ghoul2_shared.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. #pragma once
  2. #if !defined(GHOUL2_SHARED_H_INC)
  3. #define GHOUL2_SHARED_H_INC
  4. /*
  5. Ghoul2 Insert Start
  6. */
  7. #pragma warning (push, 3) //go back down to 3 for the stl include
  8. #pragma warning (disable:4503) // decorated name length xceeded, name was truncated
  9. #pragma warning(disable:4702) //unreachable code
  10. #include <vector>
  11. #include <map>
  12. #pragma warning (pop)
  13. #pragma warning (disable:4503) // decorated name length xceeded, name was truncated
  14. using namespace std;
  15. /*
  16. Ghoul2 Insert End
  17. */
  18. #define G2T_SV_TIME (0)
  19. #define G2T_CG_TIME (1)
  20. #define NUM_G2T_TIME (2)
  21. void G2API_SetTime(int currentTime,int clock);
  22. int G2API_GetTime(int argTime); // this may or may not return arg depending on ghoul2_time cvar
  23. //===================================================================
  24. //
  25. // G H O U L I I D E F I N E S
  26. //
  27. // we save the whole surfaceInfo_t struct
  28. struct surfaceInfo_t
  29. {
  30. int offFlags; // what the flags are for this model
  31. int surface; // index into array held inside the model definition of pointers to the actual surface data loaded in - used by both client and game
  32. float genBarycentricJ; // point 0 barycentric coors
  33. float genBarycentricI; // point 1 barycentric coors - point 2 is 1 - point0 - point1
  34. int genPolySurfaceIndex; // used to point back to the original surface and poly if this is a generated surface
  35. int genLod; // used to determine original lod of original surface and poly hit location
  36. surfaceInfo_t():
  37. offFlags(0),
  38. surface(0),
  39. genBarycentricJ(0),
  40. genBarycentricI(0),
  41. genPolySurfaceIndex(0),
  42. genLod(0)
  43. {}
  44. };
  45. #define BONE_ANGLES_PREMULT 0x0001
  46. #define BONE_ANGLES_POSTMULT 0x0002
  47. #define BONE_ANGLES_REPLACE 0x0004
  48. //rww - RAGDOLL_BEGIN
  49. #define BONE_ANGLES_RAGDOLL 0x2000 // the rag flags give more details
  50. #define BONE_ANGLES_IK 0x4000 // the rag flags give more details
  51. //rww - RAGDOLL_END
  52. #define BONE_ANGLES_TOTAL ( BONE_ANGLES_PREMULT | BONE_ANGLES_POSTMULT | BONE_ANGLES_REPLACE )
  53. #define BONE_ANIM_OVERRIDE 0x0008
  54. #define BONE_ANIM_OVERRIDE_LOOP 0x0010 // Causes Last Frame To Lerp to First Frame And Start Over
  55. #define BONE_ANIM_OVERRIDE_FREEZE (0x0040 + BONE_ANIM_OVERRIDE) // Causes Last Frame To Freeze And Not Loop To Beginning
  56. #define BONE_ANIM_BLEND 0x0080 // Blends to and from previously played frame on same bone for given time
  57. #define BONE_ANIM_NO_LERP 0x1000
  58. #define BONE_ANIM_TOTAL (BONE_ANIM_NO_LERP| BONE_ANIM_OVERRIDE | BONE_ANIM_OVERRIDE_LOOP | BONE_ANIM_OVERRIDE_FREEZE | BONE_ANIM_BLEND )
  59. #define BONE_INDEX_INVALID -1
  60. /*#define MDXABONEDEF // used in the mdxformat.h file to stop redefinitions of the bone struct.
  61. typedef struct {
  62. float matrix[3][4];
  63. } mdxaBone_t;
  64. */
  65. #include "../renderer/mdx_format.h"
  66. // we save the whole structure here.
  67. struct boneInfo_t
  68. {
  69. int boneNumber; // what bone are we overriding?
  70. mdxaBone_t matrix; // details of bone angle overrides - some are pre-done on the server, some in ghoul2
  71. int flags; // flags for override
  72. int startFrame; // start frame for animation
  73. int endFrame; // end frame for animation NOTE anim actually ends on endFrame+1
  74. int startTime; // time we started this animation
  75. int pauseTime; // time we paused this animation - 0 if not paused
  76. float animSpeed; // speed at which this anim runs. 1.0f means full speed of animation incoming - ie if anim is 20hrtz, we run at 20hrts. If 5hrts, we run at 5 hrts
  77. float blendFrame; // frame PLUS LERP value to blend from
  78. int blendLerpFrame; // frame to lerp the blend frame with.
  79. int blendTime; // Duration time for blending - used to calc amount each frame of new anim is blended with last frame of the last anim
  80. int blendStart; // Time when blending starts - not necessarily the same as startTime since we might start half way through an anim
  81. int boneBlendTime; // time for duration of bone angle blend with normal animation
  82. int boneBlendStart; // time bone angle blend with normal animation began
  83. mdxaBone_t newMatrix; // This is the lerped matrix that Ghoul2 uses on the client side - does not go across the network
  84. //rww - RAGDOLL_BEGIN
  85. int lastTimeUpdated; // if non-zero this is all intialized
  86. int lastContents;
  87. vec3_t lastPosition;
  88. vec3_t velocityEffector;
  89. vec3_t lastAngles;
  90. vec3_t minAngles;
  91. vec3_t maxAngles;
  92. vec3_t currentAngles;
  93. vec3_t anglesOffset;
  94. vec3_t positionOffset;
  95. float radius;
  96. float weight; // current radius cubed
  97. int ragIndex;
  98. vec3_t velocityRoot; // I am really tired of recomiling the whole game to add a param here
  99. int ragStartTime;
  100. int firstTime;
  101. int firstCollisionTime;
  102. int restTime;
  103. int RagFlags;
  104. int DependentRagIndexMask;
  105. mdxaBone_t originalTrueBoneMatrix;
  106. mdxaBone_t parentTrueBoneMatrix; // figure I will need this sooner or later
  107. mdxaBone_t parentOriginalTrueBoneMatrix; // figure I will need this sooner or later
  108. vec3_t originalOrigin;
  109. vec3_t originalAngles;
  110. vec3_t lastShotDir;
  111. mdxaBone_t *basepose;
  112. mdxaBone_t *baseposeInv;
  113. mdxaBone_t *baseposeParent;
  114. mdxaBone_t *baseposeInvParent;
  115. int parentRawBoneIndex;
  116. mdxaBone_t ragOverrideMatrix; // figure I will need this sooner or later
  117. mdxaBone_t extraMatrix; // figure I will need this sooner or later
  118. vec3_t extraVec1; // I am really tired of recomiling the whole game to add a param here
  119. float extraFloat1;
  120. int extraInt1;
  121. vec3_t ikPosition;
  122. float ikSpeed;
  123. //new ragdoll stuff -rww
  124. vec3_t epVelocity; //velocity factor, can be set, and is also maintained by physics based on gravity, mass, etc.
  125. float epGravFactor; //gravity factor maintained by bone physics
  126. int solidCount; //incremented every time we try to move and are in solid - if we get out of solid, it is reset to 0
  127. bool physicsSettled; //true when the bone is on ground and finished bouncing, etc. but may still be pushed into solid by other bones
  128. bool snapped; //the bone is broken out of standard constraints
  129. int parentBoneIndex;
  130. float offsetRotation;
  131. //user api overrides
  132. float overGradSpeed;
  133. vec3_t overGoalSpot;
  134. bool hasOverGoal;
  135. mdxaBone_t animFrameMatrix; //matrix for the bone in the desired settling pose -rww
  136. int hasAnimFrameMatrix;
  137. int airTime; //base is in air, be more quick and sensitive about collisions
  138. //rww - RAGDOLL_END
  139. boneInfo_t():
  140. boneNumber(-1),
  141. flags(0),
  142. startFrame(0),
  143. endFrame(0),
  144. startTime(0),
  145. pauseTime(0),
  146. animSpeed(0),
  147. blendFrame(0),
  148. blendLerpFrame(0),
  149. blendTime(0),
  150. blendStart(0),
  151. boneBlendTime(0),
  152. boneBlendStart(0)
  153. {
  154. matrix.matrix[0][0] = matrix.matrix[0][1] = matrix.matrix[0][2] = matrix.matrix[0][3] =
  155. matrix.matrix[1][0] = matrix.matrix[1][1] = matrix.matrix[1][2] = matrix.matrix[1][3] =
  156. matrix.matrix[2][0] = matrix.matrix[2][1] = matrix.matrix[2][2] = matrix.matrix[2][3] = 0.0f;
  157. }
  158. };
  159. //we save from top to boltUsed here. Don't bother saving the position, it gets rebuilt every frame anyway
  160. struct boltInfo_t{
  161. int boneNumber; // bone number bolt attaches to
  162. int surfaceNumber; // surface number bolt attaches to
  163. int surfaceType; // if we attach to a surface, this tells us if it is an original surface or a generated one - doesn't go across the network
  164. int boltUsed; // nor does this
  165. boltInfo_t():
  166. boneNumber(-1),
  167. surfaceNumber(-1),
  168. surfaceType(0),
  169. boltUsed(0)
  170. {}
  171. };
  172. #define MAX_GHOUL_COUNT_BITS 8 // bits required to send across the MAX_G2_MODELS inside of the networking - this is the only restriction on ghoul models possible per entity
  173. typedef vector <surfaceInfo_t> surfaceInfo_v;
  174. typedef vector <boneInfo_t> boneInfo_v;
  175. typedef vector <boltInfo_t> boltInfo_v;
  176. typedef vector <mdxaBone_t> mdxaBone_v;
  177. // defines for stuff to go into the mflags
  178. #define GHOUL2_NOCOLLIDE 0x001
  179. #define GHOUL2_NORENDER 0x002
  180. #define GHOUL2_NOMODEL 0x004
  181. #define GHOUL2_NEWORIGIN 0x008
  182. // NOTE order in here matters. We save out from mModelindex to mFlags, but not the STL vectors that are at the top or the bottom.
  183. class CBoneCache;
  184. struct model_s;
  185. //struct mdxaHeader_t;
  186. #ifdef VV_GHOUL_HACKS
  187. class CRenderableSurface
  188. {
  189. public:
  190. int ident; // ident of this surface - required so the materials renderer knows what sort of surface this refers to
  191. CBoneCache *boneCache; // pointer to transformed bone list for this surf
  192. mdxmSurface_t *surfaceData; // pointer to surface data loaded into file - only used by client renderer DO NOT USE IN GAME SIDE - if there is a vid restart this will be out of wack on the game
  193. CRenderableSurface():
  194. ident(8), //SF_MDX
  195. boneCache(0),
  196. surfaceData(0)
  197. {}
  198. CRenderableSurface(const CRenderableSurface& rs):
  199. ident(rs.ident),
  200. boneCache(rs.boneCache),
  201. surfaceData(rs.surfaceData)
  202. {}
  203. };
  204. #endif
  205. class CGhoul2Info
  206. {
  207. public:
  208. surfaceInfo_v mSlist;
  209. boltInfo_v mBltlist;
  210. boneInfo_v mBlist;
  211. // save from here (do not put any ptrs etc within this save block unless you adds special handlers to G2_SaveGhoul2Models / G2_LoadGhoul2Models!!!!!!!!!!!!
  212. #define BSAVE_START_FIELD mModelindex // this is the start point for loadsave, keep it up to date it you change anything
  213. int mModelindex;
  214. int animModelIndexOffset;
  215. qhandle_t mCustomShader;
  216. qhandle_t mCustomSkin;
  217. int mModelBoltLink;
  218. int mSurfaceRoot;
  219. int mLodBias;
  220. int mNewOrigin; // this contains the bolt index of the new origin for this model
  221. #ifdef _G2_GORE
  222. int mGoreSetTag;
  223. #endif
  224. qhandle_t mModel; // this and the next entries do NOT go across the network. They are for gameside access ONLY
  225. char mFileName[MAX_QPATH];
  226. int mAnimFrameDefault;
  227. int mSkelFrameNum;
  228. int mMeshFrameNum;
  229. int mFlags; // used for determining whether to do full collision detection against this object
  230. // to here
  231. #define BSAVE_END_FIELD mTransformedVertsArray // this is the end point for loadsave, keep it up to date it you change anything
  232. int *mTransformedVertsArray; // used to create an array of pointers to transformed verts per surface for collision detection
  233. CBoneCache *mBoneCache;
  234. int mSkin;
  235. // these occasionally are not valid (like after a vid_restart)
  236. // call the questionably efficient G2_SetupModelPointers(this) to insure validity
  237. bool mValid; // all the below are proper and valid
  238. const model_s *currentModel;
  239. int currentModelSize;
  240. const model_s *animModel;
  241. int currentAnimModelSize;
  242. const mdxaHeader_t *aHeader;
  243. CGhoul2Info():
  244. mModelindex(-1),
  245. mCustomShader(0),
  246. mCustomSkin(0),
  247. mModelBoltLink(0),
  248. mModel(0),
  249. mSurfaceRoot(0),
  250. mAnimFrameDefault(0),
  251. mSkelFrameNum(-1),
  252. mMeshFrameNum(-1),
  253. mFlags(0),
  254. mTransformedVertsArray(0),
  255. mLodBias(0),
  256. mSkin(0),
  257. mNewOrigin(-1),
  258. #ifdef _G2_GORE
  259. mGoreSetTag(0),
  260. #endif
  261. mBoneCache(0),
  262. currentModel(0),
  263. currentModelSize(0),
  264. animModel(0),
  265. animModelIndexOffset(0),
  266. currentAnimModelSize(0),
  267. aHeader(0),
  268. mValid(false)
  269. {
  270. mFileName[0] = 0;
  271. }
  272. };
  273. class CGhoul2Info_v;
  274. class IGhoul2InfoArray
  275. {
  276. public:
  277. virtual int New()=0;
  278. virtual void Delete(int handle)=0;
  279. virtual bool IsValid(int handle) const=0;
  280. virtual vector<CGhoul2Info> &Get(int handle)=0;
  281. virtual const vector<CGhoul2Info> &Get(int handle) const=0;
  282. };
  283. IGhoul2InfoArray &TheGhoul2InfoArray();
  284. IGhoul2InfoArray &TheGameGhoul2InfoArray();
  285. class CGhoul2Info_v
  286. {
  287. int mItem;
  288. IGhoul2InfoArray &InfoArray() const
  289. {
  290. #ifdef _JK2EXE
  291. return TheGhoul2InfoArray();
  292. #else
  293. return TheGameGhoul2InfoArray();
  294. #endif
  295. }
  296. void Alloc()
  297. {
  298. assert(!mItem); //already alloced
  299. mItem=InfoArray().New();
  300. assert(!Array().size());
  301. }
  302. void Free()
  303. {
  304. if (mItem)
  305. {
  306. assert(InfoArray().IsValid(mItem));
  307. InfoArray().Delete(mItem);
  308. mItem=0;
  309. }
  310. }
  311. vector<CGhoul2Info> &Array()
  312. {
  313. assert(InfoArray().IsValid(mItem));
  314. return InfoArray().Get(mItem);
  315. }
  316. const vector<CGhoul2Info> &Array() const
  317. {
  318. assert(InfoArray().IsValid(mItem));
  319. return InfoArray().Get(mItem);
  320. }
  321. public:
  322. CGhoul2Info_v()
  323. {
  324. mItem=0;
  325. }
  326. ~CGhoul2Info_v()
  327. {
  328. Free(); //this had better be taken care of via the clean ghoul2 models call
  329. }
  330. void operator=(const CGhoul2Info_v &other)
  331. {
  332. mItem=other.mItem;
  333. }
  334. void DeepCopy(const CGhoul2Info_v &other)
  335. {
  336. Free();
  337. if (other.mItem)
  338. {
  339. Alloc();
  340. Array()=other.Array();
  341. int i;
  342. for (i=0;i<size();i++)
  343. {
  344. Array()[i].mBoneCache=0;
  345. Array()[i].mTransformedVertsArray=0;
  346. Array()[i].mSkelFrameNum=0;
  347. Array()[i].mMeshFrameNum=0;
  348. }
  349. }
  350. }
  351. CGhoul2Info &operator[](int idx)
  352. {
  353. assert(mItem);
  354. assert(idx>=0&&idx<size());
  355. return Array()[idx];
  356. }
  357. const CGhoul2Info &operator[](int idx) const
  358. {
  359. assert(mItem);
  360. assert(idx>=0&&idx<size());
  361. return Array()[idx];
  362. }
  363. void resize(int num)
  364. {
  365. assert(num>=0);
  366. if (num)
  367. {
  368. if (!mItem)
  369. {
  370. Alloc();
  371. }
  372. }
  373. if (mItem||num)
  374. {
  375. Array().resize(num);
  376. }
  377. }
  378. void clear()
  379. {
  380. Free();
  381. }
  382. void push_back(const CGhoul2Info &model)
  383. {
  384. if (!mItem)
  385. {
  386. Alloc();
  387. }
  388. Array().push_back(model);
  389. }
  390. int size() const
  391. {
  392. if (!IsValid())
  393. {
  394. return 0;
  395. }
  396. return Array().size();
  397. }
  398. bool IsValid() const
  399. {
  400. return InfoArray().IsValid(mItem);
  401. }
  402. void kill()
  403. {
  404. // this scary method zeros the infovector handle without actually freeing it
  405. // it is used for some places where a copy is made, but we don't want to go through the trouble
  406. // of making a deep copy
  407. mItem=0;
  408. }
  409. };
  410. // collision detection stuff
  411. #define G2_FRONTFACE 1
  412. #define G2_BACKFACE 0
  413. class CCollisionRecord
  414. {
  415. public:
  416. float mDistance;
  417. int mEntityNum;
  418. int mModelIndex;
  419. int mPolyIndex;
  420. int mSurfaceIndex;
  421. vec3_t mCollisionPosition;
  422. vec3_t mCollisionNormal;
  423. int mFlags;
  424. int mMaterial;
  425. int mLocation;
  426. float mBarycentricI; // two barycentic coodinates for the hit point
  427. float mBarycentricJ; // K = 1-I-J
  428. CCollisionRecord():
  429. mEntityNum(-1),
  430. mDistance(100000)
  431. {}
  432. };
  433. // calling defines for the trace function
  434. enum EG2_Collision
  435. {
  436. G2_NOCOLLIDE,
  437. G2_COLLIDE,
  438. G2_RETURNONHIT
  439. };
  440. //====================================================================
  441. #endif // GHOUL2_SHARED_H_INC