BVB Source Codes

CRYENGINE Show CalculationStopper.cpp Source code

Return Download CRYENGINE: download CalculationStopper.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #include "StdAfx.h"
  4. #include "CalculationStopper.h"
  5.  
  6. #ifdef DEBUG_STOPPER
  7. bool CCalculationStopper::m_neverStop = false;
  8. #endif
  9.  
  10. #ifdef STOPPER_CAN_USE_COUNTER
  11. bool CCalculationStopper::m_useCounter;
  12. #endif
  13.  
  14. #ifdef CALIBRATE_STOPPER
  15. std::map<string, std::pair<unsigned, float>> CCalculationStopper::m_mapCallRate;
  16. #endif
  17.  
  18. //===================================================================
  19. // CCalculationStopper
  20. //===================================================================
  21. CCalculationStopper::CCalculationStopper(const char* szName, float fCalculationTime, float fCallsPerSecond)
  22.  
  23. #ifdef STOPPER_CAN_USE_COUNTER
  24.         : m_stopCounter(0), m_fCallsPerSecond(fCallsPerSecond)
  25. #endif
  26. {
  27.         m_endTime = gEnv->pTimer->GetAsyncTime() + CTimeValue(fCalculationTime);
  28.  
  29. #ifdef STOPPER_CAN_USE_COUNTER
  30.         if (m_useCounter)
  31.         {
  32.                 m_stopCounter = (unsigned)(dt * fCallsPerSecond);
  33.                 if (m_stopCounter < 1)
  34.                         m_stopCounter = 1;
  35.         }
  36. #endif
  37.  
  38. #ifdef CALIBRATE_STOPPER
  39.         m_name = name;
  40.         m_calls = 0;
  41.         m_dt = dt;
  42. #endif
  43. }
  44.  
  45. bool CCalculationStopper::ShouldCalculationStop() const
  46. {
  47. #ifdef DEBUG_STOPPER
  48.         if (m_neverStop)
  49.                 return false;
  50. #endif
  51.  
  52. #ifdef STOPPER_CAN_USE_COUNTER
  53.         if (m_useCounter)
  54.         {
  55.                 if (m_stopCounter > 0)
  56.                 {
  57.                         --m_stopCounter;
  58.                 }
  59.                 return m_stopCounter == 0;
  60.         }
  61.         else
  62. #endif
  63.  
  64.         {
  65. #ifdef CALIBRATE_STOPPER
  66.                 ++m_calls;
  67.                 if (gEnv->pTimer->GetAsyncTime() > m_endTime)
  68.                 {
  69.                         std::pair<unsigned, float>& record = m_mapCallRate[m_name];
  70.                         record.first += m_calls;
  71.                         record.second += m_dt;
  72.                         return true;
  73.                 }
  74.                 else
  75.                 {
  76.                         return false;
  77.                 }
  78. #else
  79.                 return gEnv->pTimer->GetAsyncTime() > m_endTime;
  80. #endif
  81.         }
  82. }
  83.  
  84. float CCalculationStopper::GetSecondsRemaining() const
  85. {
  86. #ifdef STOPPER_CAN_USE_COUNTER
  87.         if (m_useCounter)
  88.         {
  89.                 return m_stopCounter / m_fCallsPerSecond;
  90.         }
  91.         else
  92. #endif
  93.         {
  94.                 return (m_endTime - gEnv->pTimer->GetAsyncTime()).GetSeconds();
  95.         }
  96. }
  97.  
downloadCalculationStopper.cpp Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top