SDXFrameWork 0.10 SDXFrameWork

- Main Page
- Related Pages
- Classes

All Classes Namespaces Functions Variables Enumerations Enumerator Pages
Time.h
1 //Copyright © 2014 SDXFramework
2 //[License]GNU Affero General Public License, version 3
3 //[Contact]http://sourceforge.jp/projects/dxframework/
4 #pragma once
5 //#include <Multimedia/Color.h>
6 #include <chrono>
7
8 namespace SDX
9 {
13 class Time
14 {
15 private:
16 MONO_STATE(Time)
17
18 double fps;
19 std::chrono::system_clock::time_point reset;
20 std::chrono::system_clock::time_point fpsCounter;
21 std::chrono::system_clock::time_point watch;
22
23 static Time& Single()
24 {
25 static Time single;
26 return single;
27 }
28
29 public:
31 static void ResetCount()
32 {
33 Single().reset = std::chrono::system_clock::now();
34 }
35
37 static double GetNowCount()
38 {
39 auto diff = std::chrono::system_clock::now() - Single().reset;
40 return (double)std::chrono::duration_cast<std::chrono::microseconds>(diff).count() / 1000;
41 }
42
44 static void GetDate(tm *現在時刻)
45 {
46 time_t timer;
47
48 time(&timer);
49
50 localtime_s(現在時刻, &timer);
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
82 static void DrawWatch(const Point &座標, const char* 描画文字列)
83 {
84 std::string buf = 描画文字列;
85 buf += " = ";
86
87 auto diff = std::chrono::system_clock::now() - Single().watch;
88 double count = (double)std::chrono::duration_cast<std::chrono::milliseconds>(diff).count();
89 Drawing::String(座標, Color(255, 255, 255), { buf, count });
90 Single().watch = std::chrono::system_clock::now();
91 }
92 };
93 }
SDX::Time::GetFPS
static double GetFPS()
FPSを取得.
Definition: Time.h:54
SDX::Time::DrawWatch
static void DrawWatch(const Point &座標, const char *描画文字列)
処理時間計測終了.
Definition: Time.h:82
SDX::Point
点を表す図形クラス.
Definition: Point.h:22
SDX::Drawing::String
static void String(const Point &座標, const Color &色, const VariadicStream &描画する文字列)
文字を描画.
Definition: Drawing.h:444
SDX::Time::StartWatch
static void StartWatch()
処理時間計測開始.
Definition: Time.h:74
SDX::Time::GetNowCount
static double GetNowCount()
リセット後の経過時間のミリ秒で取得(小数点以下).
Definition: Time.h:37
SDX::Color
色を表すクラス.
Definition: Color.h:11
SDX::Time
時間と日付を取得する関数群.
Definition: Time.h:13
SDX::Time::CheckFPS
static void CheckFPS()
FPS計測を更新.
Definition: Time.h:66
SDX::Time::ResetCount
static void ResetCount()
時間の初期化.
Definition: Time.h:31
SDX::Time::ResetFPS
static void ResetFPS()
FPSの計測開始.
Definition: Time.h:60
SDX::Time::GetDate
static void GetDate(tm *現在時刻)
日付を取得.
Definition: Time.h:44