-
Notifications
You must be signed in to change notification settings - Fork 0
/
Temporizador.cpp
40 lines (35 loc) · 931 Bytes
/
Temporizador.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
// ControlaTempo.cpp
// Imagens
//
// Created by Márcio Sarroglia Pinho on 23/03/20.
// Copyright © 2020 rmd. All rights reserved.
//
#include "Temporizador.h"
// Inicializa o temporizador
Temporizador::Temporizador()
{
#ifdef _WIN32
start_time = GetTickCount();
#else
// Figure out time elapsed since last call to idle function
gettimeofday(&start_time, NULL);
#endif
}
// Retorna o tempo decorrido desde a última chamada desta mesma função
double Temporizador::getDeltaT()
{
double dt;
#ifdef _WIN32
DWORD end_time;
end_time = GetTickCount();
dt = (float) (end_time - start_time) / 1000.0;
#else
// Figure out time elapsed since last call to idle function
struct timeval end_time;
gettimeofday(&end_time, NULL);
dt = (float)(end_time.tv_sec - start_time.tv_sec) + 1.0e-6*(end_time.tv_usec - start_time.tv_usec);
#endif
start_time = end_time;
return dt;
}