質問編集履歴
2
文章を修正しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -128,4 +128,23 @@
|
|
128
128
|
{
|
129
129
|
|
130
130
|
}
|
131
|
+
```
|
132
|
+
```
|
133
|
+
//Main.cpp
|
134
|
+
|
135
|
+
while (true)
|
136
|
+
{
|
137
|
+
|
138
|
+
fps->Update();
|
139
|
+
entry->Update(); //更新
|
140
|
+
entry->Renderer(); //描画
|
141
|
+
|
142
|
+
if(entry->getChangeScene() == Scene::SceneType::Exit)
|
143
|
+
{
|
144
|
+
break;
|
145
|
+
}
|
146
|
+
|
147
|
+
fps->Wait();
|
148
|
+
}
|
149
|
+
|
131
150
|
```
|
1
提示コードを修正しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -25,8 +25,47 @@
|
|
25
25
|
```
|
26
26
|
|
27
27
|
```cpp
|
28
|
+
#ifndef ___FPS_H_
|
29
|
+
#define ___FPS_H_
|
30
|
+
|
31
|
+
|
28
32
|
#include <iostream>
|
29
33
|
#include <chrono>
|
34
|
+
#include <thread>
|
35
|
+
#include <time.h>
|
36
|
+
#include <fstream>
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
class Fps
|
41
|
+
{
|
42
|
+
public:
|
43
|
+
Fps();
|
44
|
+
~Fps();
|
45
|
+
|
46
|
+
void Wait();
|
47
|
+
void Update();
|
48
|
+
|
49
|
+
private:
|
50
|
+
|
51
|
+
long long getMilliSeconds();
|
52
|
+
|
53
|
+
|
54
|
+
long long count;
|
55
|
+
long long start;
|
56
|
+
long long wait;
|
57
|
+
long long fps = 60;
|
58
|
+
|
59
|
+
};
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
#endif
|
64
|
+
```
|
65
|
+
|
66
|
+
```
|
67
|
+
#include <iostream>
|
68
|
+
#include <chrono>
|
30
69
|
#include "../header/Fps.hpp"
|
31
70
|
#include "../lib/ncurses/include/curses.h"
|
32
71
|
#include "../header/Log.hpp"
|
@@ -43,26 +82,28 @@
|
|
43
82
|
//ミリ秒を取得
|
44
83
|
long long Fps::getMilliSeconds()
|
45
84
|
{
|
46
|
-
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
47
85
|
std::chrono::system_clock::time_point time = std::chrono::system_clock::now();
|
48
86
|
std::chrono::milliseconds tp_msec = std::chrono::duration_cast<std::chrono::milliseconds>(time.time_since_epoch());
|
49
87
|
long long all_msec = tp_msec.count();//経過時間を総ミリ秒(整数値)に変換
|
50
88
|
return all_msec;
|
51
|
-
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
52
89
|
}
|
53
90
|
|
54
91
|
|
55
92
|
void Fps::Wait()
|
56
93
|
{
|
57
94
|
long long t = getMilliSeconds() - start;
|
95
|
+
|
96
|
+
//Print("t %lld",t);
|
97
|
+
//Print("(count * 1000 / fps) %lld",(count * 1000 / fps));
|
98
|
+
|
58
99
|
wait = (count * 1000 / fps) - t;
|
59
|
-
//
|
100
|
+
//Print("%lld\n",wait);
|
101
|
+
|
60
102
|
if(wait > 0)
|
61
103
|
{
|
62
|
-
Print("%lld\n",wait);
|
104
|
+
//Print("%lld\n",wait);
|
63
|
-
|
105
|
+
std::this_thread::sleep_for(std::chrono::milliseconds(wait));
|
64
106
|
}
|
65
|
-
///////////////////////////////////////////////////////////////////////////////////////////////////
|
66
107
|
}
|
67
108
|
|
68
109
|
|
@@ -76,6 +117,7 @@
|
|
76
117
|
{
|
77
118
|
start = getMilliSeconds();
|
78
119
|
count = 0;
|
120
|
+
|
79
121
|
}
|
80
122
|
|
81
123
|
count++;
|