-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOxsyClock.cpp
More file actions
141 lines (118 loc) · 4.77 KB
/
OxsyClock.cpp
File metadata and controls
141 lines (118 loc) · 4.77 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include "OxsyLibrary.h"
#include "OxsyClock.h"
#include "OxsyClassPointers.h"
#include "OxsyLogger.h"
#include "OxsyTime.h"
COxsyClock::COxsyClock(COxsyClassPointers *pClassPointers)
{
m_pClassPointers = pClassPointers;
// m_dCorrectionFactor = 1.0;
m_dElapsedTime = 0.0;
#ifdef WIN32
m_nClockStartValue.QuadPart = 0;
m_nClockStopValue.QuadPart = 0;
// m_nClockFrequency.QuadPart = 0;
QueryPerformanceFrequency(&m_nClockFrequency);
#else // _LINUX
m_nClockStartValue.tv_sec = 0;
m_nClockStartValue.tv_usec = 0;
m_nClockStopValue.tv_sec = 0;
m_nClockStopValue.tv_usec = 0;
// m_nClockFrequency.tv_sec = 0;
// m_nClockFrequency.tv_usec = 0;
gettimeofday(&m_nClockFrequency, NULL);
#endif
}
COxsyClock::~COxsyClock()
{
}
//--------------------------------- Define variable for log -----------------------------------
#define LOG_CLOCK_START_CLOCK
//---------------------------------------------------------------------------------------------
void COxsyClock::start_clock()
{
#ifdef CREATE_GAME_LOG_FILE
#ifdef LOG_CLOCK_START_CLOCK
COxsyLogger *pLogger = m_pClassPointers->GetLoggerPointer();
COxsyTime *pTime = m_pClassPointers->GetTimePointer();
#endif
#endif
#ifdef WIN32
// if (QueryPerformanceFrequency(&m_nClockFrequency))
if (QueryPerformanceCounter(&m_nClockStartValue))
{
#ifdef CREATE_GAME_LOG_FILE
#ifdef LOG_CLOCK_START_CLOCK
if (pLogger->GetFileHandler()) fprintf(pLogger->GetFileHandler(), "%d ____________________ START CLOCK = %.0lf ____________________\n\n", pTime->get_time(), (double)m_nClockStartValue.QuadPart);
#endif
#endif
}
#else // _LINUX
// if (gettimeofday(&m_nClockFrequency, NULL))
// if (gettimeofday(&m_nClockStartValue, NULL))
// {
gettimeofday(&m_nClockStartValue, NULL);
#ifdef CREATE_GAME_LOG_FILE
#ifdef LOG_CLOCK_START_CLOCK
if (pLogger->GetFileHandler()) fprintf(pLogger->GetFileHandler(), "%d ____________________ START CLOCK = %.0lf ____________________\n\n", pTime->get_time(), (double)(m_nClockStartValue.tv_sec * 1000000 + m_nClockStartValue.tv_usec));
#endif
#endif
// }
#endif
}
//--------------------------------- Define variable for log -----------------------------------
#define LOG_CLOCK_STOP_CLOCK
//---------------------------------------------------------------------------------------------
void COxsyClock::stop_clock()
{
#ifdef CREATE_GAME_LOG_FILE
#ifdef LOG_CLOCK_STOP_CLOCK
COxsyLogger *pLogger = m_pClassPointers->GetLoggerPointer();
COxsyTime *pTime = m_pClassPointers->GetTimePointer();
#endif
#endif
#ifdef WIN32
// if (QueryPerformanceFrequency(&m_nClockFrequency))
if(QueryPerformanceCounter(&m_nClockStopValue))
{
m_dElapsedTime = TIME_DIF_TO_MS(m_nClockStartValue, m_nClockStopValue, m_nClockFrequency);
#ifdef CREATE_GAME_LOG_FILE
#ifdef LOG_CLOCK_STOP_CLOCK
if (pLogger->GetFileHandler()) fprintf(pLogger->GetFileHandler(), "%d ____________________ STOP CLOCK = %.0lf ____________________\n\n", pTime->get_time(), (double)m_nClockStopValue.QuadPart);
if (pLogger->GetFileHandler()) fprintf(pLogger->GetFileHandler(), "%d ____________________ ELAPSED TIME = %lf ____________________\n\n", pTime->get_time(), m_dElapsedTime);
#endif
#endif
}
#else // _LINUX
// if (gettimeofday(&m_nClockFrequency, NULL))
// if (gettimeofday(&m_nClockStopValue, NULL))
// {
gettimeofday(&m_nClockStopValue, NULL);
m_dElapsedTime = TIME_DIF_TO_MS(m_nClockStartValue, m_nClockStopValue); // / m_dCorrectionFactor;
#ifdef CREATE_GAME_LOG_FILE
#ifdef LOG_CLOCK_STOP_CLOCK
if (pLogger->GetFileHandler()) fprintf(pLogger->GetFileHandler(), "%d ____________________ STOP CLOCK = %.0lf ____________________\n\n", pTime->get_time(), (double)(m_nClockStopValue.tv_sec * 1000000 + m_nClockStopValue.tv_usec));
if (pLogger->GetFileHandler()) fprintf(pLogger->GetFileHandler(), "%d ____________________ ELAPSED TIME = %lf ____________________\n\n", pTime->get_time(), m_dElapsedTime);
#endif
#endif
// }
#endif
}
//--------------------------------- Define variable for log -----------------------------------
#define LOG_CLOCK_GET_ELAPSED_TIME
//---------------------------------------------------------------------------------------------
double COxsyClock::get_elapsed_time()
{
#ifdef CREATE_GAME_LOG_FILE
#ifdef LOG_CLOCK_GET_ELAPSED_TIME
COxsyLogger *pLogger = m_pClassPointers->GetLoggerPointer();
COxsyTime *pTime = m_pClassPointers->GetTimePointer();
#endif
#endif
#ifdef CREATE_GAME_LOG_FILE
#ifdef LOG_CLOCK_GET_ELAPSED_TIME
if (pLogger->GetFileHandler()) fprintf(pLogger->GetFileHandler(), "%d ____________________ ELAPSED TIME = %lf ____________________\n\n", pTime->get_time(), m_dElapsedTime);
#endif
#endif
return m_dElapsedTime;
}