Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

917 lines
29 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef BONE_SETUP_PS3_H
  8. #define BONE_SETUP_PS3_H
  9. #ifndef __SPU__
  10. #include "studio.h"
  11. #endif
  12. #include "studio_PS3.h"
  13. #ifndef __SPU__
  14. #include "bone_setup.h"
  15. #include "vjobs/root.h"
  16. #include "vjobs/accumpose_shared.h"
  17. #include <vjobs_interface.h>
  18. #include <ps3/vjobutils.h>
  19. #include <ps3/vjobutils_shared.h>
  20. #endif // __SPU__
  21. #if defined( _PS3 )
  22. #if defined(__SPU__)
  23. #include "ps3/spu_job_shared.h"
  24. #define SNPROF(name) ((void)0)
  25. #define SNPROF_ANIM(name) ((void)0)
  26. #endif
  27. //#define _DEBUG_SPUvPPU_ANIMATION 1
  28. #define ANIM_EPS 0.3f
  29. //-----------------------------------------------------------------------------
  30. // Purpose: SPU version of data collected and required by AccumulatePose
  31. // this data gets sent to SPU
  32. //-----------------------------------------------------------------------------
  33. #define MAX_ACCUMPOSECALLS (20) //(MAX_OVERLAYS)
  34. #define MAX_LAYERS_SPU MAX_ACCUMPOSECALLS
  35. #define MAX_PQSTACKLEVEL 4
  36. #define MAX_IKCHAINELEMENTS 32
  37. #define MAX_IKCHAINS 16
  38. #define MAX_IKLOCKS 16
  39. #define MAX_IKRULES 48
  40. #define MAX_IKTARGETS 12
  41. #define MAX_BLENDANIMS 4
  42. class CBoneBitList_PS3
  43. {
  44. public:
  45. CBoneBitList_PS3()
  46. {
  47. memset( &m_markedBones, 0, MAXSTUDIOBONES_PS3 );
  48. }
  49. inline void MarkBone( int iBone )
  50. {
  51. m_markedBones[ iBone ] = 1;
  52. }
  53. inline bool IsBoneMarked( int iBone )
  54. {
  55. return m_markedBones[ iBone ];
  56. }
  57. inline void ResetMarkedBones( int numbones )
  58. {
  59. memset( &m_markedBones, 0, numbones );
  60. }
  61. byte m_markedBones[ MAXSTUDIOBONES_PS3 ];
  62. };
  63. struct animData_SPU
  64. {
  65. void *pEA_animdesc; // mstudioanimdesc_t *
  66. int animstudiohdr_numbones;
  67. int seqdesc_anim;
  68. float flStall;
  69. float seqdesc_weight;
  70. int animdesc_iLocalFrame;
  71. void *pEA_animdesc_panim; // mstudio_rle_anim_t *
  72. void *pEA_animdesc_pFrameanim; // mstudio_frame_anim_t_PS3 *
  73. void *pEA_animdesc_ikrule; // mstudioikrule_t_PS3 *
  74. void *pEA_animdesc_ikrulezeroframe; // zero frame rule of above
  75. void *pEA_animgroup_masterbone; // int *
  76. void *pEA_anim_bones_pos; // Vector *, start of Vector pos, Quaternion quat, RadianEuler rot, Vector posscale, Vector rotscale, matrix3x4_t poseToBone, Quaternion qAlignment, int flags
  77. void *pEA_anim_bones_flags; // int *, start of flags
  78. void *pEA_anim_linearBones; // mstudiolinearbone_t_PS3 *
  79. };
  80. struct ALIGN128 accumposeentry_SPU
  81. {
  82. void *pEA_seqdesc; // mstudioseqdesc_t_PS3 *
  83. void *pEA_seqgroup_boneMap; // const int *
  84. void *pEA_seqgroup_masterBone; // const int *
  85. void *pEA_seqdesc_boneWeight; // float *
  86. void *pEA_seqdesc_iklocks; // mstudioiklock_t *
  87. // from seqstudiohdr
  88. void *pEA_seq_linearBones; // mstudiolinearbone_t_PS3 *
  89. void *pEA_seq_linearbones_pos; // Vector *
  90. void *pEA_seq_linearbones_quat; // Quaternion *
  91. void *pEA_seq_bones_pos; // mstudiobone_t_PS3 * offset to .pos
  92. int seqdesc_flags;
  93. int cpsPath; // CalcPoseSingle path
  94. animData_SPU anims[ MAX_BLENDANIMS ];
  95. int8 animIndices[ MAX_BLENDANIMS ]; // index into anims[]
  96. int pqStackLevel;
  97. int iSeq;
  98. float cycle;
  99. float weight;
  100. int i0;
  101. int i1;
  102. int seqdesc_numiklocks;
  103. int seqdesc_numikrules;
  104. float s0;
  105. float s1;
  106. float cyclePoseSingle;
  107. int numLocalLayers;
  108. int numSequenceLayers;
  109. #if !defined(__SPU__)
  110. bool SetAnimData( const CStudioHdr *pStudioHdr, mstudioseqdesc_t &seqdesc, int x, int y, int animIndex );
  111. #endif
  112. } ALIGN128_POST;
  113. struct ALIGN128 bonejob_SPU
  114. {
  115. accumposeentry_SPU accumPoseEntry[ MAX_LAYERS_SPU ];
  116. int numTotalPoses;
  117. int numPoses_PreAutoSeq;
  118. int numPoses_AutoSeq;
  119. // same for all calls
  120. int boneFlags[ MAXSTUDIOBONES_PS3 ]; // 1k
  121. int boneParent[ MAXSTUDIOBONES_PS3 ]; // 1k
  122. float poseparam[ MAXSTUDIOPOSEPARAM_PS3 ]; // 96B
  123. void *pEA_IKAutoplayLocks[ MAX_IKLOCKS ]; // mstudioiklock_t
  124. float currentTime;
  125. int numBones;
  126. int maxBones; // takes into account virtual bonemapping, used for SPU mem worst-case allocations
  127. int numikchains;
  128. int boneMask;
  129. int studiobone_posoffset; // mstudiobone_t offset in bytes to pos field
  130. BoneVector autoikOrigin;
  131. QAngle autoikAngles;
  132. int autoikFramecount;
  133. int numikAutoplayLocks;
  134. void *pEA_hdr; // CStudioHdr*
  135. void *pEA_IKContext; // CIKContext *
  136. void *pEA_studiohdr_ikchains; // mstudioikchain_t *
  137. void *pEA_studiohdr_ikautoplaylocks; // mstudioiklock_t *
  138. void *pEA_studiohdr_vmodel; // virtualmodel_t *
  139. void *pEA_studiohdr_bones; // mstudiobone_t_PS3 *
  140. void *pEA_studiohdr_bones_pos; // Vector *, start of Vector pos, Quaternion quat, RadianEuler rot, Vector posscale, Vector rotscale, matrix3x4_t poseToBone, Quaternion qAlignment, int flags
  141. void *pEA_studiohdr_linearBones; // mstudiolinearbone_t_PS3 *
  142. void *pEA_linearbones_posscale; // Vector *
  143. void *pEA_linearbones_pos; // Vector *
  144. void *pEA_linearbones_rot; // RadianEuler *
  145. void *pEA_linearbones_rotscale; // Vector *
  146. void *pEA_linearbones_flags; // int *
  147. void *pEA_linearbones_quat; // Quaternion *
  148. void *pEA_linearbones_qalignment; // Quaternion *
  149. // dst data ea ptrs
  150. void *pEA_pos; // BoneVector *
  151. void *pEA_q; // BoneQuaternion *
  152. void *pEA_addDep_IKRules; // ikcontextikrule_t *
  153. void *pEA_addDep_numIKRules; // int *
  154. void *pEA_flags; // int *
  155. int debugJob; // for dynamic switching of DebuggerBreak
  156. } ALIGN128_POST;
  157. #if !defined(__SPU__)
  158. struct bonejob_PPU
  159. {
  160. public:
  161. matrix3x4_t parentTransform;
  162. float cycle;
  163. int maxBones;
  164. int boneMask;
  165. int bonesMaskNeedsRecalc;
  166. int oldReadableBones;
  167. void *pBaseAnimating; // C_BaseAnimating*
  168. CStudioHdr *pStudioHdr;
  169. matrix3x4a_t *pBoneToWorldOut;
  170. };
  171. struct ALIGN128 PS3BoneJobData
  172. {
  173. public:
  174. job_accumpose::JobDescriptor_t jobDescriptor ALIGN128;
  175. // dst. SPU in/out - could be init'd entirely from SPU, in which case it's out only
  176. BoneVector pos[ MAXSTUDIOBONES_PS3 ] ALIGN16; // 2k
  177. BoneQuaternion q[ MAXSTUDIOBONES_PS3 ] ALIGN16; // 2k
  178. // dst, SPU out only
  179. ikcontextikrule_t addDep_IKRules[ MAX_IKRULES ] ALIGN16; // 4k
  180. int addDep_numIKRules ALIGN16; // [4] to pad to 16B
  181. int pad[3];
  182. // src, SPU in only, going to SPU at start of job
  183. bonejob_SPU bonejobSPU;
  184. // src, PPU only, work data, and data required if job needs to be executed from scratch on PPU if SPU fails
  185. bonejob_PPU bonejobPPU;
  186. } ALIGN128_POST;
  187. class CBoneJobs : public VJobInstance
  188. {
  189. public:
  190. CBoneJobs()
  191. {
  192. }
  193. ~CBoneJobs()
  194. {
  195. Shutdown();
  196. }
  197. void Init( void );
  198. void Shutdown( void );
  199. void OnVjobsInit( void ); // gets called after m_pRoot was created and assigned
  200. void OnVjobsShutdown( void ); // gets called before m_pRoot is about to be destructed and NULL'ed
  201. void StartFrame( int maxBoneJobs );
  202. void EndFrame( void );
  203. void ResetBoneJobs( void );
  204. int AddBoneJob( void );
  205. int GetNumBoneJobs( void );
  206. int GetNextFreeSPURSPort( void );
  207. PS3BoneJobData *GetJobData( int job );
  208. private:
  209. CUtlVector<PS3BoneJobData> m_boneJobData;
  210. int m_boneJobCount;
  211. int m_boneJobNextSPURSPort;
  212. bool m_bEnabled;
  213. };
  214. extern CBoneJobs* g_pBoneJobs;
  215. #endif // #if !defined SPU
  216. //-----------------------------------------------------------------------------
  217. //
  218. // Main spu job class
  219. //
  220. //-----------------------------------------------------------------------------
  221. class C_AccumulatePose_SPU
  222. {
  223. public:
  224. C_AccumulatePose_SPU( bonejob_SPU *pBoneJob ) { m_pBoneJob = pBoneJob; };
  225. inline void ResetCount() { m_iCount = 0; };
  226. inline int GetCount() { return m_iCount; };
  227. void AccumulatePose( BoneVector pos[], BoneQuaternion q[] );
  228. void AddLocalLayers( accumposeentry_SPU *pAccPoseEntry, BoneVector pos[], BoneQuaternion q[] );
  229. void AddSequenceLayers( accumposeentry_SPU *pAccPoseEntry, BoneVector pos[], BoneQuaternion q[] );
  230. void SetIKContext( void *pIKContext ) { m_pIKContext = pIKContext; };
  231. void *GetIKContext( void ) { return m_pIKContext; };
  232. private:
  233. bool CalcPoseSingle(
  234. const bonejob_SPU *pBonejob,
  235. accumposeentry_SPU *pPoseEntry,
  236. BoneVector *pos,
  237. BoneQuaternion *q,
  238. int *boneMap,
  239. float *boneWeight,
  240. int sequence,
  241. const float poseParameter[],
  242. int boneMask,
  243. float flTime
  244. );
  245. void *m_pIKContext; // CIKContext *
  246. bonejob_SPU *m_pBoneJob;
  247. // next index into bonejob accumposeentry to execute
  248. int m_iCount;
  249. };
  250. //-----------------------------------------------------------------------------
  251. // Purpose: blends together all the bones from two p:q lists
  252. //
  253. // p1 = p1 * (1 - s) + p2 * s
  254. // q1 = q1 * (1 - s) + q2 * s
  255. //-----------------------------------------------------------------------------
  256. void SlerpBones_SPU(
  257. bonejob_SPU* pSPUJob,
  258. accumposeentry_SPU *pPoseEntry,
  259. BoneQuaternion *q1,
  260. BoneVector *pos1,
  261. const BoneQuaternion *q2,
  262. const BoneVector *pos2,
  263. const int *boneMap,
  264. const float *boneWeight,
  265. float s,
  266. int boneMask );
  267. #if !defined(__SPU__)
  268. class CBoneSetup_PS3;
  269. class IBoneSetup_PS3
  270. {
  271. public:
  272. IBoneSetup_PS3( const CStudioHdr *pStudioHdr, int boneMask, const float poseParameter[], bonejob_SPU *pBoneJobSPU );
  273. ~IBoneSetup_PS3( void );
  274. void InitPose_PS3( BoneVector pos[], BoneQuaternion q[] );
  275. void CalcAutoplaySequences_AddPoseCalls( float flRealTime );
  276. void AccumulatePose_AddToBoneJob( bonejob_SPU* pBonejobSPU, int sequence, float cycle, float flWeight, CIKContext *pIKContext, int pqStackLevel );
  277. int RunAccumulatePoseJobs_PPU( bonejob_SPU *pBoneJobSPU );
  278. int RunAccumulatePoseJobs_SPU( bonejob_SPU *pBoneJobSPU, job_accumpose::JobDescriptor_t *pJobDescriptor );
  279. CStudioHdr *GetStudioHdr();
  280. void ResetErrorFlags();
  281. int ErrorFlags();
  282. bonejob_SPU *GetBoneJobSPU();
  283. private:
  284. CBoneSetup_PS3 *m_pBoneSetup;
  285. };
  286. #endif
  287. // Given two samples of a bone separated in time by dt,
  288. // compute the velocity and angular velocity of that bone
  289. //void CalcBoneDerivatives( Vector &velocity, AngularImpulse &angVel, const matrix3x4_t &prev, const matrix3x4_t &current, float dt );
  290. // Give a derivative of a bone, compute the velocity & angular velocity of that bone
  291. //void CalcBoneVelocityFromDerivative( const QAngle &vecAngles, Vector &velocity, AngularImpulse &angVel, const matrix3x4_t &current );
  292. // This function sets up the local transform for a single frame of animation. It doesn't handle
  293. // pose parameters or interpolation between frames.
  294. // void SetupSingleBoneMatrix_PS3(
  295. // CStudioHdr_PS3 *pOwnerHdr,
  296. // int nSequence,
  297. // int iFrame,
  298. // int iBone,
  299. // matrix3x4_t &mBoneLocal );
  300. // Purpose: build boneToWorld transforms for a specific bone
  301. void BuildBoneChain_PS3(
  302. const int *pBoneParent,
  303. const matrix3x4a_t &rootxform,
  304. const BoneVector pos[],
  305. const BoneQuaternion q[],
  306. int iBone,
  307. matrix3x4a_t *pBoneToWorld
  308. );
  309. void BuildBoneChain_PS3(
  310. const int *pBoneParent,
  311. const matrix3x4a_t &rootxform,
  312. const BoneVector pos[],
  313. const BoneQuaternion q[],
  314. int iBone,
  315. matrix3x4a_t *pBoneToWorld,
  316. CBoneBitList_PS3 &boneComputed );
  317. //-----------------------------------------------------------------------------
  318. // Purpose:
  319. //-----------------------------------------------------------------------------
  320. // ik info
  321. class CIKTarget_PS3
  322. {
  323. public:
  324. // void SetOwner( int entindex, const Vector &pos, const QAngle &angles );
  325. // void ClearOwner( void );
  326. // int GetOwner( void );
  327. // void UpdateOwner( int entindex, const Vector &pos, const QAngle &angles );
  328. // void SetPos( const Vector &pos );
  329. // void SetAngles( const QAngle &angles );
  330. // void SetQuaternion( const Quaternion &q );
  331. // void SetNormal( const Vector &normal );
  332. // void SetPosWithNormalOffset( const Vector &pos, const Vector &normal );
  333. // void SetOnWorld( bool bOnWorld = true );
  334. // bool IsActive( void );
  335. // void IKFailed( void );
  336. int chain;
  337. int type;
  338. // void MoveReferenceFrame( Vector &deltaPos, QAngle &deltaAngles );
  339. // accumulated offset from ideal footplant location
  340. public:
  341. struct x2 {
  342. char *pAttachmentName;
  343. Vector pos;
  344. Quaternion q;
  345. } offset;
  346. //private:
  347. struct x3 {
  348. Vector pos;
  349. Quaternion q;
  350. } ideal;
  351. public:
  352. struct x4 {
  353. float latched;
  354. float release;
  355. float height;
  356. float floor;
  357. float radius;
  358. float flTime;
  359. float flWeight;
  360. Vector pos;
  361. Quaternion q;
  362. bool onWorld;
  363. } est; // estimate contact position
  364. struct x5 {
  365. float hipToFoot; // distance from hip
  366. float hipToKnee; // distance from hip to knee
  367. float kneeToFoot; // distance from knee to foot
  368. Vector hip; // location of hip
  369. Vector closest; // closest valid location from hip to foot that the foot can move to
  370. Vector knee; // pre-ik location of knee
  371. Vector farthest; // farthest valid location from hip to foot that the foot can move to
  372. Vector lowest; // lowest position directly below hip that the foot can drop to
  373. } trace;
  374. //private:
  375. // internally latched footset, position
  376. struct x1 {
  377. // matrix3x4a_t worldTarget;
  378. bool bNeedsLatch;
  379. bool bHasLatch;
  380. float influence;
  381. int iFramecounter;
  382. int owner;
  383. Vector absOrigin;
  384. QAngle absAngles;
  385. Vector pos;
  386. Quaternion q;
  387. Vector deltaPos; // accumulated error
  388. Quaternion deltaQ;
  389. Vector debouncePos;
  390. Quaternion debounceQ;
  391. } latched;
  392. struct x6 {
  393. float flTime; // time last error was detected
  394. float flErrorTime;
  395. float ramp;
  396. bool bInError;
  397. } error;
  398. // friend class CIKContext_PS3;
  399. };
  400. struct ikchainresult_t_PS3
  401. {
  402. // accumulated offset from ideal footplant location
  403. int target;
  404. Vector pos;
  405. Quaternion q;
  406. float flWeight;
  407. };
  408. struct ikcontextikrule_t_PS3
  409. {
  410. int index;
  411. int type;
  412. int chain;
  413. int bone;
  414. int slot; // iktarget slot. Usually same as chain.
  415. float height;
  416. float radius;
  417. float floor;
  418. Vector pos;
  419. float pad1;
  420. Quaternion q;
  421. float start; // beginning of influence
  422. float peak; // start of full influence
  423. float tail; // end of full influence
  424. float end; // end of all influence
  425. float top;
  426. float drop;
  427. float commit; // frame footstep target should be committed
  428. float release; // frame ankle should end rotation from latched orientation
  429. float flWeight; // processed version of start-end cycle
  430. float flRuleWeight; // blending weight
  431. float latched; // does the IK rule use a latched value?
  432. char *szLabel;
  433. Vector kneeDir;
  434. float pad2;
  435. Vector kneePos;
  436. float pad3;
  437. ikcontextikrule_t_PS3() {}
  438. private:
  439. // No copy constructors allowed
  440. ikcontextikrule_t_PS3(const ikcontextikrule_t_PS3& vOther);
  441. };
  442. void Studio_AlignIKMatrix_PS3( matrix3x4a_t &mMat, const Vector &vAlignTo );
  443. bool Studio_SolveIK_PS3( int8 iThigh, int8 iKnee, int8 iFoot, Vector &targetFoot, matrix3x4a_t* pBoneToWorld );
  444. bool Studio_SolveIK_PS3( int8 iThigh, int8 iKnee, int8 iFoot, Vector &targetFoot, Vector &targetKneePos, Vector &targetKneeDir, matrix3x4a_t* pBoneToWorld );
  445. class CIKContext_PS3
  446. {
  447. public:
  448. CIKContext_PS3( );
  449. // void Init( const CStudioHdr *pStudioHdr, const QAngle &angles, const BoneVector &pos, float flTime, int iFramecounter, int boneMask );
  450. void Init( bonejob_SPU *pBonejobSPU, const QAngle &angles, const Vector &pos, float flTime, int iFramecounter, int boneMask );
  451. // void AddDependencies( mstudioseqdesc_t_PS3 &seqdesc, int iSequence, float flCycle, const float poseParameters[], float flWeight = 1.0f );
  452. void ClearTargets( void );
  453. // void UpdateTargets( Vector pos[], Quaternion q[], matrix3x4a_t boneToWorld[], CBoneBitList &boneComputed );
  454. // void AutoIKRelease( void );
  455. void AddAutoplayLocks( bonejob_SPU *pBonejob, BoneVector pos[], BoneQuaternion q[] );
  456. void SolveAutoplayLocks( bonejob_SPU *pBonejob, BoneVector pos[], BoneQuaternion q[] );
  457. // void AddSequenceLocks( mstudioseqdesc_t &SeqDesc, BoneVector pos[], BoneQuaternion q[] );
  458. void AddSequenceLocks( bonejob_SPU *pBonejob, accumposeentry_SPU* pPoseEntry, BoneVector pos[], BoneQuaternion q[] );
  459. void SolveSequenceLocks( bonejob_SPU *pBonejob, accumposeentry_SPU* pPoseEntry, BoneVector pos[], BoneQuaternion q[] );
  460. // void AddAllLocks( BoneVector pos[], BoneQuaternion q[] );
  461. // void SolveAllLocks( BoneVector pos[], BoneQuaternion q[] );
  462. void SolveLock( bonejob_SPU *pBonejob, const mstudioiklock_t_PS3 *plock, int i, BoneVector pos[], BoneQuaternion q[], matrix3x4a_t boneToWorld[], CBoneBitList_PS3 &boneComputed );
  463. // CUtlVectorFixed< CIKTarget, 12 > m_target;
  464. CIKTarget_PS3 m_target[ 12 ];
  465. int m_targetCount;
  466. int m_numTarget;
  467. private:
  468. // CStudioHdr const *m_pStudioHdr;
  469. //
  470. // bool Estimate( int iSequence, float flCycle, int iTarget, const float poseParameter[], float flWeight = 1.0f );
  471. void BuildBoneChain( const bonejob_SPU *pBonejob, const BoneVector pos[], const BoneQuaternion q[], int iBone, matrix3x4a_t *pBoneToWorld, CBoneBitList_PS3 &boneComputed );
  472. //
  473. // // virtual IK rules, filtered and combined from each sequence
  474. // CUtlVector< CUtlVector< ikcontextikrule_t_PS3 > > m_ikChainRule;
  475. // CUtlVector< ikcontextikrule_t_PS3 > m_ikLock;
  476. ikcontextikrule_t_PS3 m_ikLock[ MAX_IKLOCKS ];
  477. matrix3x4a_t m_rootxform;
  478. int m_iFramecounter;
  479. float m_flTime;
  480. int m_boneMask;
  481. };
  482. //-----------------------------------------------------------------------------
  483. // Purpose:
  484. //-----------------------------------------------------------------------------
  485. // replaces the bonetoworld transforms for all bones that are procedural
  486. // bool CalcProceduralBone_PS3(
  487. // const CStudioHdr_PS3 *pStudioHdr,
  488. // int iBone,
  489. // CBoneAccessor_PS3 &bonetoworld
  490. // );
  491. // void Studio_BuildMatrices(
  492. // const CStudioHdr_PS3 *pStudioHdr,
  493. // const QAngle& angles,
  494. // const BoneVector& origin,
  495. // const BoneVector pos[],
  496. // const BoneQuaternion q[],
  497. // int iBone,
  498. // float flScale,
  499. // matrix3x4a_t bonetoworld[MAXSTUDIOBONES],
  500. // int boneMask
  501. // );
  502. // Get a bone->bone relative transform
  503. //void Studio_CalcBoneToBoneTransform( const CStudioHdr *pStudioHdr, int inputBoneIndex, int outputBoneIndex, matrix3x4_t &matrixOut );
  504. // Given a bone rotation value, figures out the value you need to give to the controller
  505. // to have the bone at that value.
  506. // [in] flValue = the desired bone rotation value
  507. // [out] ctlValue = the (0-1) value to set the controller t.
  508. // return value = flValue, unwrapped to lie between the controller's start and end.
  509. //float Studio_SetController( const CStudioHdr *pStudioHdr, int iController, float flValue, float &ctlValue );
  510. // Given a 0-1 controller value, maps it into the controller's start and end and returns the bone rotation angle.
  511. // [in] ctlValue = value in controller space (0-1).
  512. // return value = value in bone space
  513. //float Studio_GetController( const CStudioHdr *pStudioHdr, int iController, float ctlValue );
  514. //void Studio_CalcDefaultPoseParameters( const CStudioHdr *pStudioHdr, float flPoseParameter[MAXSTUDIOPOSEPARAM], int nCount );
  515. //float Studio_GetPoseParameter( const CStudioHdr *pStudioHdr, int iParameter, float ctlValue );
  516. //float Studio_SetPoseParameter( const CStudioHdr *pStudioHdr, int iParameter, float flValue, float &ctlValue );
  517. // converts a global 0..1 pose parameter into the local sequences blending value
  518. //int Studio_LocalPoseParameter( const CStudioHdr *pStudioHdr, const float poseParameter[], mstudioseqdesc_t &seqdesc, int iSequence, int iLocalIndex, float &flSetting );
  519. //void Studio_SeqAnims( const CStudioHdr *pStudioHdr, mstudioseqdesc_t &seqdesc, int iSequence, const float poseParameter[], mstudioanimdesc_t *panim[4], float *weight );
  520. //int Studio_MaxFrame( const CStudioHdr *pStudioHdr, int iSequence, const float poseParameter[] );
  521. //float Studio_FPS( const CStudioHdr *pStudioHdr, int iSequence, const float poseParameter[] );
  522. //float Studio_CPS( const CStudioHdr *pStudioHdr, mstudioseqdesc_t &seqdesc, int iSequence, const float poseParameter[] );
  523. //float Studio_Duration( const CStudioHdr *pStudioHdr, int iSequence, const float poseParameter[] );
  524. //void Studio_MovementRate( const CStudioHdr *pStudioHdr, int iSequence, const float poseParameter[], Vector *pVec );
  525. //float Studio_SeqMovementAndDuration( const CStudioHdr *pStudioHdr, int iSequence, float flCycleFrom, float flCycleTo, const float poseParameter[], Vector &deltaPos );
  526. // void Studio_Movement( const CStudioHdr *pStudioHdr, int iSequence, const float poseParameter[], Vector *pVec );
  527. //void Studio_AnimPosition( mstudioanimdesc_t *panim, float flCycle, Vector &vecPos, Vector &vecAngle );
  528. //void Studio_AnimVelocity( mstudioanimdesc_t *panim, float flCycle, Vector &vecVelocity );
  529. //float Studio_FindAnimDistance( mstudioanimdesc_t *panim, float flDist );
  530. // bool Studio_AnimMovement( mstudioanimdesc_t *panim, float flCycleFrom, float flCycleTo, Vector &deltaPos, QAngle &deltaAngle );
  531. // bool Studio_SeqMovement( const CStudioHdr *pStudioHdr, int iSequence, float flCycleFrom, float flCycleTo, const float poseParameter[], Vector &deltaMovement, QAngle &deltaAngle );
  532. // bool Studio_SeqVelocity( const CStudioHdr *pStudioHdr, int iSequence, float flCycle, const float poseParameter[], Vector &vecVelocity );
  533. // float Studio_FindSeqDistance( const CStudioHdr *pStudioHdr, int iSequence, const float poseParameter[], float flDist );
  534. // float Studio_FindSeqVelocity( const CStudioHdr *pStudioHdr, int iSequence, const float poseParameter[], float flVelocity );
  535. // int Studio_FindAttachment( const CStudioHdr *pStudioHdr, const char *pAttachmentName );
  536. // int Studio_FindRandomAttachment( const CStudioHdr *pStudioHdr, const char *pAttachmentName );
  537. // int Studio_BoneIndexByName( const CStudioHdr *pStudioHdr, const char *pName );
  538. // const char *Studio_GetDefaultSurfaceProps( CStudioHdr *pstudiohdr );
  539. // float Studio_GetMass( CStudioHdr *pstudiohdr );
  540. // const char *Studio_GetKeyValueText( const CStudioHdr *pStudioHdr, int iSequence );
  541. // FORWARD_DECLARE_HANDLE( memhandle_t );
  542. // struct bonecacheparams_t
  543. // {
  544. // CStudioHdr *pStudioHdr;
  545. // matrix3x4a_t *pBoneToWorld;
  546. // float curtime;
  547. // int boneMask;
  548. // };
  549. //
  550. // class CBoneCache
  551. // {
  552. // public:
  553. //
  554. // // you must implement these static functions for the ResourceManager
  555. // // -----------------------------------------------------------
  556. // static CBoneCache *CreateResource( const bonecacheparams_t &params );
  557. // static unsigned int EstimatedSize( const bonecacheparams_t &params );
  558. // // -----------------------------------------------------------
  559. // // member functions that must be present for the ResourceManager
  560. // void DestroyResource();
  561. // CBoneCache *GetData() { return this; }
  562. // unsigned int Size() { return m_size; }
  563. // // -----------------------------------------------------------
  564. //
  565. // CBoneCache();
  566. //
  567. // // was constructor, but placement new is messy wrt memdebug - so cast & init instead
  568. // void Init( const bonecacheparams_t &params, unsigned int size, short *pStudioToCached, short *pCachedToStudio, int cachedBoneCount );
  569. //
  570. // void UpdateBones( const matrix3x4a_t *pBoneToWorld, int numbones, float curtime );
  571. // matrix3x4a_t *GetCachedBone( int studioIndex );
  572. // void ReadCachedBones( matrix3x4a_t *pBoneToWorld );
  573. // void ReadCachedBonePointers( matrix3x4_t **bones, int numbones );
  574. //
  575. // bool IsValid( float curtime, float dt = 0.1f );
  576. //
  577. // public:
  578. // float m_timeValid;
  579. // int m_boneMask;
  580. //
  581. // private:
  582. // matrix3x4a_t *BoneArray();
  583. // short *StudioToCached();
  584. // short *CachedToStudio();
  585. //
  586. // unsigned int m_size;
  587. // unsigned short m_cachedBoneCount;
  588. // unsigned short m_matrixOffset;
  589. // unsigned short m_cachedToStudioOffset;
  590. // unsigned short m_boneOutOffset;
  591. // };
  592. //
  593. // void Studio_LockBoneCache();
  594. // void Studio_UnlockBoneCache();
  595. //
  596. // CBoneCache *Studio_GetBoneCache( memhandle_t cacheHandle, bool bLock = false );
  597. // void Studio_ReleaseBoneCache( memhandle_t cacheHandle );
  598. // memhandle_t Studio_CreateBoneCache( bonecacheparams_t &params );
  599. // void Studio_DestroyBoneCache( memhandle_t cacheHandle );
  600. // void Studio_InvalidateBoneCacheIfNotMatching( memhandle_t cacheHandle, float flTimeValid );
  601. // Given a ray, trace for an intersection with this studiomodel. Get the array of bones from StudioSetupHitboxBones
  602. // bool TraceToStudio( class IPhysicsSurfaceProps *pProps, const Ray_t& ray, CStudioHdr *pStudioHdr, mstudiohitboxset_t *set, matrix3x4_t **hitboxbones, int fContentsMask, const Vector &vecOrigin, float flScale, trace_t &trace );
  603. // TERROR: TraceToStudio variant that prioritizes hitgroups, so bullets can pass through arms and chest to hit the head, for instance
  604. // bool TraceToStudioGrouped( IPhysicsSurfaceProps *pProps, const Ray_t& ray, CStudioHdr *pStudioHdr, mstudiohitboxset_t *set,
  605. // matrix3x4_t **hitboxbones, int fContentsMask, trace_t &tr, const CUtlVector< int > &sortedHitgroups );
  606. void QuaternionSM_PS3( float s, const Quaternion &p, const Quaternion &q, Quaternion &qt );
  607. void QuaternionMA_PS3( const Quaternion &p, float s, const Quaternion &q, Quaternion &qt );
  608. //
  609. // bool Studio_PrefetchSequence( const CStudioHdr *pStudioHdr, int iSequence );
  610. //
  611. // void Studio_RunBoneFlexDrivers( float *pFlexController, const CStudioHdr *pStudioHdr, const Vector *pPositions, const matrix3x4_t *pBoneToWorld, const matrix3x4_t &mRootToWorld );
  612. //-----------------------------------------------------------------------------
  613. // Computes a number of twist bones given a parent/child pair
  614. // pqTwists, pflWeights, pqTwistBinds must all have at least nCount elements
  615. //-----------------------------------------------------------------------------
  616. // void ComputeTwistBones(
  617. // Quaternion *pqTwists,
  618. // int nCount,
  619. // bool bInverse,
  620. // const Vector &vUp,
  621. // const Quaternion &qParent,
  622. // const matrix3x4_t &mChild,
  623. // const Quaternion &qBaseInv,
  624. // const float *pflWeights,
  625. // const Quaternion *pqTwistBinds );
  626. //-----------------------------------------------------------------------------
  627. //
  628. //-----------------------------------------------------------------------------
  629. // round up to next 16B boundary, then add 16B
  630. #define ROUNDUPTONEXT16B( a ) (0x10 + (a + (0x10 - (a%0x10))))
  631. //-----------------------------------------------------------------------------
  632. // Squeezing memory for SPU - manual float and int allocs
  633. //-----------------------------------------------------------------------------
  634. #define LS_FLOATSTACK_SIZE ((MAXSTUDIOBONES_PS3 + 32) * 4 * 3 * 3) // 24k
  635. #define LS_INTSTACK_SIZE ((MAXSTUDIOBONES_PS3 * 2) + 16) // 1k
  636. extern ALIGN16 byte g_ls_Stack[ (LS_FLOATSTACK_SIZE * sizeof(float)) + (LS_INTSTACK_SIZE * sizeof(int)) ];
  637. extern byte *g_ls_StackPtr;
  638. extern byte *g_ls_StackPtr_MAX;
  639. // init when starting Job
  640. FORCEINLINE void InitLSStack()
  641. {
  642. g_ls_StackPtr = g_ls_Stack;
  643. }
  644. // term when exiting Job
  645. FORCEINLINE void TermLSStack()
  646. {
  647. #if !defined( _CERT )
  648. // ensure pop'd to start
  649. if( g_ls_StackPtr != g_ls_Stack )
  650. {
  651. Msg("*** IMPROPER LS STACK ON TERM ***\n");
  652. Msg("*** IMPROPER LS STACK ON TERM ***\n");
  653. Msg("*** IMPROPER LS STACK ON TERM ***\n");
  654. Msg("*** IMPROPER LS STACK ON TERM ***\n");
  655. DebuggerBreak();
  656. }
  657. #endif
  658. // float watermark
  659. // Msg("LS stack - high: %d, max: %d\n", (int)(g_ls_StackPtr_MAX - g_ls_Stack), (int)sizeof(g_ls_Stack) );
  660. }
  661. // keep it simple, ensure allocation is multiple of 16B to keep vectors aligned
  662. // size is number of bytes
  663. FORCEINLINE byte *PushLSStack( int size )
  664. {
  665. byte *pStack = g_ls_StackPtr;
  666. g_ls_StackPtr += ROUNDUPTONEXT16B( size );
  667. #if !defined( _CERT )
  668. if( g_ls_StackPtr > (g_ls_Stack + sizeof(g_ls_Stack)) )
  669. {
  670. Msg("*** EXCEEDED LS STACK ***\n");
  671. Msg("*** EXCEEDED LS STACK ***\n");
  672. Msg("*** EXCEEDED LS STACK ***\n");
  673. Msg("*** EXCEEDED LS STACK ***\n");
  674. DebuggerBreak();
  675. }
  676. #endif
  677. // maintain watermark
  678. if( g_ls_StackPtr > g_ls_StackPtr_MAX )
  679. {
  680. g_ls_StackPtr_MAX = g_ls_StackPtr;
  681. }
  682. return pStack;
  683. }
  684. FORCEINLINE void PopLSStack( int size )
  685. {
  686. g_ls_StackPtr -= ROUNDUPTONEXT16B( size );
  687. #if !defined( _CERT )
  688. if( g_ls_StackPtr < g_ls_Stack )
  689. {
  690. Msg("*** EXCEEDED LS STACK - POP ***\n");
  691. Msg("*** EXCEEDED LS STACK - POP ***\n");
  692. Msg("*** EXCEEDED LS STACK - POP ***\n");
  693. Msg("*** EXCEEDED LS STACK - POP ***\n");
  694. DebuggerBreak();
  695. }
  696. #endif
  697. }
  698. // class CLSStack
  699. // {
  700. // public:
  701. // CLSStack( int size )
  702. // {
  703. // ;
  704. // }
  705. // ~CLSStack()
  706. // {
  707. // ;
  708. // }
  709. // };
  710. //
  711. // #define LSSTACK(size) CLSStack
  712. //-----------------------------------------------------------------------------
  713. //
  714. //-----------------------------------------------------------------------------
  715. #if defined(__SPU__)
  716. extern BoneVector *g_posInit;
  717. extern BoneQuaternion *g_qInit;
  718. extern ikcontextikrule_t_PS3 *g_addDep_IKRules;
  719. extern int g_addDep_numIKRules;
  720. #else
  721. extern BoneVector g_posInit[ MAXSTUDIOBONES_PS3 ];
  722. extern BoneQuaternion g_qInit[ MAXSTUDIOBONES_PS3 ];
  723. extern ikcontextikrule_t_PS3 g_addDep_IKRules[ MAX_IKRULES ] ALIGN16;
  724. extern int g_addDep_numIKRules;
  725. #endif
  726. #endif // _PS3
  727. #endif // BONE_SETUP_H