SDXFrameWork 0.13 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 std::string GetDateString()
55 {
56 tm time;
57 GetDate( &time );
58 VariadicStream str = { time.tm_year+1900, "_" , time.tm_mon , "_" , time.tm_mday , "_" , time.tm_hour , "_" , time.tm_min , "_" , time.tm_sec};
59 return str.StringS[0];
60 }
61
63 static double GetFPS()
64 {
65 return Single().fps;
66 }
67
69 static void ResetFPS()
70 {
71 Single().fpsCounter = std::chrono::system_clock::now();
72 }
73
75 static void CheckFPS()
76 {
77 auto diff = std::chrono::system_clock::now() - Single().fpsCounter;
78 Single().fps = 1000000.0 / (double)std::chrono::duration_cast<std::chrono::microseconds>(diff).count();
79 Single().fpsCounter = std::chrono::system_clock::now();
80 }
81
83 static void StartWatch()
84 {
85 Single().watch = std::chrono::system_clock::now();
86 }
87
91 static void DrawWatch(const Point &座標, const char* 描画文字列)
92 {
93 std::string buf = 描画文字列;
94 buf += " = ";
95
96 auto diff = std::chrono::system_clock::now() - Single().watch;
97 double count = (double)std::chrono::duration_cast<std::chrono::milliseconds>(diff).count();
98 Drawing::String(座標, Color(255, 255, 255), { buf, count });
99 Single().watch = std::chrono::system_clock::now();
100 }
101 };
102 }
SDX::Time::GetFPS
static double GetFPS()
FPSを取得.
Definition: Time.h:63
SDX::Time::DrawWatch
static void DrawWatch(const Point &座標, const char *描画文字列)
処理時間計測終了.
Definition: Time.h:91
SDX::Time::GetDateString
static std::string GetDateString()
現在の日付、時刻を文字列にして返す.
Definition: Time.h:54
SDX::Point
点を表す図形クラス.
Definition: Point.h:22
SDX::Drawing::String
static void String(const Point &座標, const Color &色, const VariadicStream &描画する文字列)
文字を描画.
Definition: Drawing.h:463
SDX::VariadicStream::StringS
std::vector< std::string > StringS
一行ずつの文字列.
Definition: VariadicStream.h:53
SDX::Time::StartWatch
static void StartWatch()
処理時間計測開始.
Definition: Time.h:83
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:75
SDX::Time::ResetCount
static void ResetCount()
時間の初期化.
Definition: Time.h:31
SDX::Time::ResetFPS
static void ResetFPS()
FPSの計測開始.
Definition: Time.h:69
SDX::VariadicStream
可変数引数な文字列を処理するクラス.
Definition: VariadicStream.h:25
SDX::Time::GetDate
static void GetDate(tm *現在時刻)
日付を取得.
Definition: Time.h:44