GteOnIdleTimer.cpp
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #include <GTEnginePCH.h>
10 #include <chrono>
11 #include <cmath>
12 #include <sstream>
13 using namespace gte;
14 
15 
16 OnIdleTimer::OnIdleTimer(int64_t frequency)
17  :
18  mFrequency(frequency > 0 ? frequency : 1)
19 {
20  Reset();
21 }
22 
24 {
26  mFrameCount = 0;
28  mAccumulatedTime = 0;
29  mTime0 = std::chrono::high_resolution_clock::now();
30  mTime1 = mTime0;
31 }
32 
34 {
35  if (--mCallCount == 0)
36  {
37  mTime1 = std::chrono::high_resolution_clock::now();
38  int64_t delta = std::chrono::duration_cast<std::chrono::milliseconds>(
39  mTime1 - mTime0).count();
40  mTime0 = mTime1;
42  mAccumulatedTime += delta;
43  mFrameCount = 0;
45  }
46 }
47 
49 {
50  if (mAccumulatedTime > 0)
51  {
52  double numFrames = static_cast<double>(mAccumulatedFrameCount);
53  double numMilliseconds = static_cast<double>(mAccumulatedTime);
54  return 1000.0 * numFrames / numMilliseconds;
55  }
56  else
57  {
58  return 0.0;
59  }
60 }
61 
63 {
64  if (mAccumulatedFrameCount > 0)
65  {
66  double numFrames = static_cast<double>(mAccumulatedFrameCount);
67  double numMilliseconds = static_cast<double>(mAccumulatedTime);
68  return 1000.0 * numMilliseconds / numFrames;
69  }
70  else
71  {
72  return 0.0;
73  }
74 }
75 
77 {
78  if (mAccumulatedFrameCount > 0)
79  {
80  double numFrames = static_cast<double>(mAccumulatedFrameCount);
81  double numMilliseconds = static_cast<double>(mAccumulatedTime);
82  double rate = numMilliseconds / numFrames;
83  return static_cast<int64_t>(std::round(rate));
84  }
85  else
86  {
87  return 0;
88  }
89 }
90 
92 {
93  std::ostringstream stream;
94  stream.setf(std::ios::fixed | std::ios::showpoint);
95  stream.precision(1);
96  stream << "fps: " << GetFramesPerSecond();
97  return stream.str();
98 }
99 
int64_t mAccumulatedFrameCount
std::chrono::high_resolution_clock::time_point mTime1
GLuint GLuint stream
Definition: glcorearb.h:1827
int64_t GetMillisecondsPerFrame() const
int64_t mAccumulatedTime
std::string GetFPS() const
std::chrono::high_resolution_clock::time_point mTime0
double GetSecondsPerFrame() const
GLsizei const GLchar *const * string
Definition: glcorearb.h:809
GLint GLsizei count
Definition: glcorearb.h:400
OnIdleTimer(int64_t frequency=30)
double GetFramesPerSecond() const


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:01