Leaked source code of windows server 2003
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.

214 lines
5.9 KiB

  1. #if !defined(MOTION__Action_inl__INCLUDED)
  2. #define MOTION__Action_inl__INCLUDED
  3. /***************************************************************************\
  4. *****************************************************************************
  5. *
  6. * Global Functions
  7. *
  8. *****************************************************************************
  9. \***************************************************************************/
  10. /*
  11. * ComputeTickDelta: PORTED FROM NT-USER
  12. *
  13. * ComputeTickDelta computes a time delta between two times. The
  14. * delta is defined as a 31-bit, signed value. It is best to think of time as
  15. * a clock that wraps around. The delta is the minimum distance on this circle
  16. * between two different places on the circle. If the delta goes
  17. * counter-clockwise, it is looking at a time in the PAST and is POSITIVE. If
  18. * the delta goes clockwise, it is looking at a time in the FUTURE and is
  19. * negative.
  20. *
  21. * It is IMPORTANT to realize that the (dwCurTime >= dwLastTime) comparison does
  22. * not determine the delta's sign, but only determines the operation to compute
  23. * the delta without an overflow occuring.
  24. */
  25. //---------------------------------------------------------------------------
  26. inline
  27. int ComputeTickDelta(
  28. IN DWORD dwCurTick,
  29. IN DWORD dwLastTick)
  30. {
  31. return (int) (dwCurTick - dwLastTick);
  32. }
  33. //---------------------------------------------------------------------------
  34. inline
  35. int ComputePastTickDelta(
  36. IN DWORD dwCurTick,
  37. IN DWORD dwLastTick)
  38. {
  39. int nDelta = ComputeTickDelta(dwCurTick, dwLastTick);
  40. AssertMsg(nDelta >= 0, "Ensure delta occurs in the past");
  41. return nDelta;
  42. }
  43. /***************************************************************************\
  44. *****************************************************************************
  45. *
  46. * class Action
  47. *
  48. *****************************************************************************
  49. \***************************************************************************/
  50. //------------------------------------------------------------------------------
  51. inline Action * CastAction(BaseObject * pbase)
  52. {
  53. if ((pbase != NULL) && (pbase->GetHandleType() == htAction)) {
  54. return (Action *) pbase;
  55. }
  56. return NULL;
  57. }
  58. //------------------------------------------------------------------------------
  59. inline bool IsPresentTime(float fl)
  60. {
  61. return (fl < 0.01f);
  62. }
  63. //------------------------------------------------------------------------------
  64. inline BOOL
  65. Action::IsPresent() const
  66. {
  67. AssertMsg((!m_fPresent) || IsPresentTime(m_ma.flDelay), "Ensure delay matches if present");
  68. return m_fPresent;
  69. }
  70. //------------------------------------------------------------------------------
  71. inline BOOL
  72. Action::IsComplete() const
  73. {
  74. return (m_ma.cRepeat == 0);
  75. }
  76. //------------------------------------------------------------------------------
  77. inline DWORD
  78. Action::GetStartTime() const
  79. {
  80. return m_dwStartTick;
  81. }
  82. //------------------------------------------------------------------------------
  83. inline float
  84. Action::GetStartDelay() const
  85. {
  86. float flDelay = m_ma.flPeriod - m_ma.flDuration;
  87. if (flDelay < 0.0f) {
  88. flDelay = 0.0f;
  89. }
  90. return flDelay;
  91. }
  92. //------------------------------------------------------------------------------
  93. inline Thread *
  94. Action::GetThread() const
  95. {
  96. return m_pThread;
  97. }
  98. //------------------------------------------------------------------------------
  99. inline void
  100. Action::SetPresent(BOOL fPresent)
  101. {
  102. m_fPresent = fPresent;
  103. if (fPresent) {
  104. m_ma.flDelay = 0.0f;
  105. }
  106. }
  107. //---------------------------------------------------------------------------
  108. inline void
  109. Action::SetParent(GList<Action> * plstParent)
  110. {
  111. m_plstParent = plstParent;
  112. }
  113. /***************************************************************************\
  114. *
  115. * Action::ResetPresent
  116. *
  117. * ResetPresent() resets the Action's counters to be called immediately.
  118. *
  119. \***************************************************************************/
  120. inline void
  121. Action::ResetPresent(DWORD dwCurTick)
  122. {
  123. m_dwStartTick = dwCurTick;
  124. }
  125. /***************************************************************************\
  126. *
  127. * Action::ResetFuture
  128. *
  129. * ResetFuture() resets the Action's counters into the future for the next
  130. * time the Action will be called.
  131. *
  132. \***************************************************************************/
  133. inline void
  134. Action::ResetFuture(DWORD dwCurTick, BOOL fInit)
  135. {
  136. float flDelay = GetStartDelay();
  137. if (fInit) {
  138. flDelay += m_ma.flDelay;
  139. }
  140. m_dwStartTick = dwCurTick + (int) (flDelay * 1000.0f);
  141. }
  142. //---------------------------------------------------------------------------
  143. inline DWORD
  144. Action::GetIdleTimeOut(DWORD dwCurTick) const
  145. {
  146. //
  147. // Return the amount of time needed before this Action starts to get
  148. // processed. The Future is the reverse of the normal ComputeTickDelta().
  149. // We also need to make sure that the time returned is never in the past.
  150. //
  151. int nFuture = -ComputeTickDelta(dwCurTick, m_dwStartTick);
  152. return nFuture >= 0 ? (DWORD) (nFuture) : 0;
  153. }
  154. //---------------------------------------------------------------------------
  155. inline DWORD
  156. Action::GetPauseTimeOut() const
  157. {
  158. //
  159. // Return the amount of time that the Action requests before its next
  160. // timeslice. This is used to keep long-lived Actions from taking all of
  161. // the CPU time, but is different than IdleTimeOut which is the amount of
  162. // time before the Action needs to execute again.
  163. //
  164. return m_ma.dwPause;
  165. }
  166. //---------------------------------------------------------------------------
  167. inline void
  168. Action::MarkDelete(BOOL fDelete)
  169. {
  170. AssertMsg(!m_fDeleteInFire, "Only should be marked to be deleted once");
  171. m_fDeleteInFire = fDelete;
  172. }
  173. #endif // MOTION__Action_inl__INCLUDED