質問編集履歴
2
文章を修正しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -259,3 +259,41 @@
|
|
259
259
|
}
|
260
260
|
|
261
261
|
```
|
262
|
+
|
263
|
+
```
|
264
|
+
|
265
|
+
//Main.cpp
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
while (true)
|
270
|
+
|
271
|
+
{
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
fps->Update();
|
276
|
+
|
277
|
+
entry->Update(); //更新
|
278
|
+
|
279
|
+
entry->Renderer(); //描画
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
if(entry->getChangeScene() == Scene::SceneType::Exit)
|
284
|
+
|
285
|
+
{
|
286
|
+
|
287
|
+
break;
|
288
|
+
|
289
|
+
}
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
fps->Wait();
|
294
|
+
|
295
|
+
}
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
```
|
1
提示コードを修正しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -52,10 +52,88 @@
|
|
52
52
|
|
53
53
|
```cpp
|
54
54
|
|
55
|
+
#ifndef ___FPS_H_
|
56
|
+
|
57
|
+
#define ___FPS_H_
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
55
63
|
#include <iostream>
|
56
64
|
|
57
65
|
#include <chrono>
|
58
66
|
|
67
|
+
#include <thread>
|
68
|
+
|
69
|
+
#include <time.h>
|
70
|
+
|
71
|
+
#include <fstream>
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
class Fps
|
80
|
+
|
81
|
+
{
|
82
|
+
|
83
|
+
public:
|
84
|
+
|
85
|
+
Fps();
|
86
|
+
|
87
|
+
~Fps();
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
void Wait();
|
92
|
+
|
93
|
+
void Update();
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
private:
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
long long getMilliSeconds();
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
long long count;
|
108
|
+
|
109
|
+
long long start;
|
110
|
+
|
111
|
+
long long wait;
|
112
|
+
|
113
|
+
long long fps = 60;
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
};
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
#endif
|
126
|
+
|
127
|
+
```
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
```
|
132
|
+
|
133
|
+
#include <iostream>
|
134
|
+
|
135
|
+
#include <chrono>
|
136
|
+
|
59
137
|
#include "../header/Fps.hpp"
|
60
138
|
|
61
139
|
#include "../lib/ncurses/include/curses.h"
|
@@ -88,8 +166,6 @@
|
|
88
166
|
|
89
167
|
{
|
90
168
|
|
91
|
-
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
92
|
-
|
93
169
|
std::chrono::system_clock::time_point time = std::chrono::system_clock::now();
|
94
170
|
|
95
171
|
std::chrono::milliseconds tp_msec = std::chrono::duration_cast<std::chrono::milliseconds>(time.time_since_epoch());
|
@@ -98,8 +174,6 @@
|
|
98
174
|
|
99
175
|
return all_msec;
|
100
176
|
|
101
|
-
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
102
|
-
|
103
177
|
}
|
104
178
|
|
105
179
|
|
@@ -112,22 +186,30 @@
|
|
112
186
|
|
113
187
|
long long t = getMilliSeconds() - start;
|
114
188
|
|
189
|
+
|
190
|
+
|
191
|
+
//Print("t %lld",t);
|
192
|
+
|
193
|
+
//Print("(count * 1000 / fps) %lld",(count * 1000 / fps));
|
194
|
+
|
195
|
+
|
196
|
+
|
115
197
|
wait = (count * 1000 / fps) - t;
|
116
198
|
|
117
|
-
//
|
199
|
+
//Print("%lld\n",wait);
|
200
|
+
|
201
|
+
|
118
202
|
|
119
203
|
if(wait > 0)
|
120
204
|
|
121
205
|
{
|
122
206
|
|
123
|
-
Print("%lld\n",wait);
|
207
|
+
//Print("%lld\n",wait);
|
124
|
-
|
208
|
+
|
125
|
-
|
209
|
+
std::this_thread::sleep_for(std::chrono::milliseconds(wait));
|
126
210
|
|
127
211
|
}
|
128
212
|
|
129
|
-
///////////////////////////////////////////////////////////////////////////////////////////////////
|
130
|
-
|
131
213
|
}
|
132
214
|
|
133
215
|
|
@@ -154,6 +236,8 @@
|
|
154
236
|
|
155
237
|
count = 0;
|
156
238
|
|
239
|
+
|
240
|
+
|
157
241
|
}
|
158
242
|
|
159
243
|
|