Simplify
This commit is contained in:
parent
890d061a92
commit
ee3c7c61db
2 changed files with 2 additions and 11 deletions
11
lib/Game.cpp
11
lib/Game.cpp
|
@ -14,22 +14,16 @@ Game::Game() {
|
||||||
score.lives = DEFAULT_LIVES;
|
score.lives = DEFAULT_LIVES;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Game::now() {
|
|
||||||
return std::chrono::system_clock::now();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Game::run() {
|
void Game::run() {
|
||||||
|
|
||||||
const std::chrono::milliseconds delta_time(1000 / 60);
|
const std::chrono::milliseconds delta_time(1000 / 60);
|
||||||
|
|
||||||
std::chrono::milliseconds t(0);
|
|
||||||
std::chrono::milliseconds accumulator(0);
|
std::chrono::milliseconds accumulator(0);
|
||||||
auto current_time = now();
|
auto current_time = std::chrono::system_clock::now();
|
||||||
|
|
||||||
InputState inputState;
|
InputState inputState;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
auto newTime = now();
|
auto newTime = std::chrono::system_clock::now();
|
||||||
auto frameTime = std::chrono::duration_cast<std::chrono::milliseconds>(newTime - current_time);
|
auto frameTime = std::chrono::duration_cast<std::chrono::milliseconds>(newTime - current_time);
|
||||||
current_time = newTime;
|
current_time = newTime;
|
||||||
accumulator += frameTime;
|
accumulator += frameTime;
|
||||||
|
@ -39,7 +33,6 @@ void Game::run() {
|
||||||
while (accumulator >= delta_time) {
|
while (accumulator >= delta_time) {
|
||||||
step(delta_time, inputState);
|
step(delta_time, inputState);
|
||||||
accumulator -= delta_time;
|
accumulator -= delta_time;
|
||||||
t += delta_time;
|
|
||||||
}
|
}
|
||||||
canvas.update(gameState, score);
|
canvas.update(gameState, score);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,6 @@ private:
|
||||||
void eatPellets();
|
void eatPellets();
|
||||||
void processEvents(InputState & inputState);
|
void processEvents(InputState & inputState);
|
||||||
void checkCollision(Ghost & ghost);
|
void checkCollision(Ghost & ghost);
|
||||||
|
|
||||||
[[nodiscard]] static auto now();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace pacman
|
} // namespace pacman
|
||||||
|
|
Loading…
Reference in a new issue