|
|
|
@ -5,9 +5,9 @@ Window::Window() { |
|
|
|
|
timer = new QTimer(this); |
|
|
|
|
timer->setInterval(17); |
|
|
|
|
connect(timer, &QTimer::timeout, this, [this]{ |
|
|
|
|
update(); |
|
|
|
|
game.update(17.f / 1000); |
|
|
|
|
}); |
|
|
|
|
game.window = this; |
|
|
|
|
timer->start(); |
|
|
|
|
label = new QLabel(this); |
|
|
|
|
label->resize(size()); |
|
|
|
@ -18,6 +18,12 @@ void Window::paintEvent(QPaintEvent *event) { |
|
|
|
|
output.fill(Qt::white); |
|
|
|
|
game.draw(output); |
|
|
|
|
label->setPixmap(output.scaled(label->size())); |
|
|
|
|
update(); |
|
|
|
|
auto now = std::chrono::high_resolution_clock::now(); |
|
|
|
|
auto diff = duration_cast<std::chrono::nanoseconds>((now - tp)); |
|
|
|
|
double seconds = double(diff.count()) / 1000. / 1000. / 1000. ; |
|
|
|
|
currentFPS = 1 / seconds; |
|
|
|
|
tp = now; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Window::resizeEvent(QResizeEvent *e) { |
|
|
|
|