animphysagent.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #ifdef FEATURE_NETWORK_RECONCILIATION
  2. /**
  3. * The replay system only replays outputs from animation. It does not replay animations and does not replay actual inputs.
  4. * This means very often when a desync is detected, multiple corrections have to be sent before the simulation is stable.
  5. * This is why we only ever actually use this system for when a player is in HumanCommandMove and HumanCommandFall.
  6. *
  7. * For some situations, such as swimming, it is not possible to ever correct as the water alignment heavily depends on re-simulaton of
  8. * animations, which is not happening. With this, we use MINIMAL correction mode. This minimal correction mode is something similiar
  9. * to how the old correction system used to work and could lead to situations such as being stuck behind doors.
  10. * This is not a problem for swimming.
  11. */
  12. enum AnimPhysCorrectionType
  13. {
  14. //! Additively apply the correction based on the delta and sends very minimal data, uses 'NetworkCompareResult.FORCE_CORRECT'
  15. MINIMAL,
  16. //! No correction is performed
  17. DROP,
  18. //! Rewind the player physics and replay the moves
  19. FULL
  20. };
  21. class AnimPhysOwnerState : PawnOwnerState
  22. {
  23. proto native void SetCorrectionType(int value);
  24. proto native int GetCorrectionType();
  25. proto native void SetPosition(vector value);
  26. proto native void GetPosition(out vector value);
  27. proto native void SetRotation(float value[4]);
  28. proto native void GetRotation(out float value[4]);
  29. //! If parent entity doesn't exist for the owner then the correction is dropped
  30. proto native void SetParent(Object value);
  31. proto native Object GetParent();
  32. //! If linked entity doesn't exist for the owner then the correction is dropped
  33. proto native void SetLinked(Object value);
  34. proto native Object GetLinked();
  35. proto native bool IsLinked();
  36. proto native bool IsParented();
  37. proto native void SetSpeed(vector value);
  38. proto native void GetSpeed(out vector value);
  39. proto native void SetCollisionLayer(int value);
  40. proto native int GetCollisionLayer();
  41. proto native void SetFlags(int value);
  42. proto native int GetFlags();
  43. proto native void SetCollisionOffset(vector value);
  44. proto native int GetCollisionOffset(out vector value);
  45. proto native void SetStance(int value);
  46. proto native int GetStance();
  47. #ifdef DIAG_DEVELOPER
  48. override event void GetTransform(inout vector transform[4])
  49. {
  50. float rotation[4];
  51. GetRotation(rotation);
  52. Math3D.QuatToMatrix(rotation, transform);
  53. vector position;
  54. GetPosition(position);
  55. transform[3] = position;
  56. Object parent = GetParent();
  57. if (parent)
  58. {
  59. vector parentTransform[4];
  60. parent.GetTransform(parentTransform);
  61. Math3D.MatrixMultiply4(parentTransform, transform, transform);
  62. }
  63. }
  64. #endif
  65. };
  66. class AnimPhysMove : PawnMove
  67. {
  68. proto native void SetCorrectionType(int value);
  69. proto native int GetCorrectionType();
  70. proto native void SetPosition(vector value);
  71. proto native void GetPosition(out vector value);
  72. proto native void SetRotation(float value[4]);
  73. proto native void GetRotation(out float value[4]);
  74. proto native void SetParent(Object value);
  75. proto native void SetLinked(Object value);
  76. proto native Object GetParentOrLinked();
  77. proto native Object GetParent();
  78. proto native bool HasParent();
  79. proto native bool IsParented();
  80. proto native bool IsLinked();
  81. //! Parent (or linked) entity could've been deleted, store the necessary values so we have something to work with
  82. proto native void SetParentTransform(vector transform[4]);
  83. proto native void GetParentTransform(out vector transform[4]);
  84. #ifdef DIAG_DEVELOPER
  85. override event void GetTransform(inout vector transform[4])
  86. {
  87. float rotation[4];
  88. GetRotation(rotation);
  89. Math3D.QuatToMatrix(rotation, transform);
  90. vector position;
  91. GetPosition(position);
  92. transform[3] = position;
  93. if (HasParent())
  94. {
  95. vector parentTransform[4];
  96. GetParentTransform(parentTransform);
  97. Math3D.MatrixMultiply4(parentTransform, transform, transform);
  98. }
  99. }
  100. #endif
  101. };
  102. #endif