SDXFrameWork  0.04
SDXFrameWork
 全て クラス ネームスペース 関数 変数 ページ
Timer.h
1 #pragma once
2 #include <Multimedia/Color.h>
3 #include <chrono>
4 
5 namespace SDX
6 {
8 class Time
10 {
11 private:
12  double fps;
13  std::chrono::system_clock::time_point reset;
14  std::chrono::system_clock::time_point fpsCounter;
15  std::chrono::system_clock::time_point watch;
16 
17  Time(void)
18  {
19  this->ResetCount();
20  }
21 
22  ~Time(void){};
23 
24  static Time& Single()
25  {
26  static Time value;
27  return value;
28  }
29 
30 public:
32  static void ResetCount()
33  {
34  Single().reset = std::chrono::system_clock::now();
35  }
36 
38  static double GetNowCount()
39  {
40  auto diff = std::chrono::system_clock::now() - Single().reset;
41  return (double)std::chrono::duration_cast<std::chrono::microseconds>(diff).count()/ 1000;
42  }
43 
45  static tm GetDate()
46  {
47  time_t timer;
48  tm local;
49  localtime_s(&local, &timer);
50  return local;
51  }
52 
54  static double GetFPS()
55  {
56  return Single().fps;
57  }
58 
60  static void ResetFPS()
61  {
62  Single().fpsCounter = std::chrono::system_clock::now();
63  }
64 
66  static void CheckFPS()
67  {
68  auto diff = std::chrono::system_clock::now() - Single().fpsCounter;
69  Single().fps = 1000000.0 / (double)std::chrono::duration_cast<std::chrono::microseconds>(diff).count();
70  Single().fpsCounter = std::chrono::system_clock::now();
71  }
72 
74  static void StartWatch()
75  {
76  Single().watch = std::chrono::system_clock::now();
77  }
78 
80  static void DrawWatch(int X座標 , int Y座標 , const char* 描画文字列)
83  {
84  std::string buf = 描画文字列;
85  buf += " = %f";
86 
87  auto diff = std::chrono::system_clock::now() - Single().watch;
88  Drawing::String(X座標, Y座標, Color(255,255,255), buf.c_str(), (double)std::chrono::duration_cast<std::chrono::microseconds>(diff).count() / 1000);
89  Single().watch = std::chrono::system_clock::now();
90  }
91 };
92 
93 }
static double GetFPS()
FPSを取得.
Definition: Timer.h:54
static void StartWatch()
処理時間計測開始.
Definition: Timer.h:74
static double GetNowCount()
リセット後の経過時間のミリ秒で取得(小数点以下).
Definition: Timer.h:38
色を表すクラス.
Definition: Color.h:7
static void CheckFPS()
FPS計測を更新.
Definition: Timer.h:66
static tm GetDate()
日付を取得.
Definition: Timer.h:45
static void ResetCount()
時間の初期化.
Definition: Timer.h:32
static void ResetFPS()
FPSの計測開始.
Definition: Timer.h:60
static void String(int X座標, int Y座標, Color 色, const char *文字列,...)
書式付きで文字を描画.
Definition: Drawing.h:149
static void DrawWatch(int X座標, int Y座標, const char *描画文字列)
処理時間計測終了.
Definition: Timer.h:82