Skip to content

Commit d99b6fe

Browse files
authoredMay 26, 2017
Time: Change old u32 timestamps to 64-bit (#5818)
MacOSX build fix + cleanups
1 parent 4d5ce84 commit d99b6fe

18 files changed

+75
-96
lines changed
 

Diff for: ‎src/clientiface.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -590,9 +590,9 @@ void RemoteClient::notifyEvent(ClientStateEvent event)
590590
}
591591
}
592592

593-
u32 RemoteClient::uptime() const
593+
u64 RemoteClient::uptime() const
594594
{
595-
return porting::getTime(PRECISION_SECONDS) - m_connection_time;
595+
return porting::getTimeS() - m_connection_time;
596596
}
597597

598598
ClientInterface::ClientInterface(con::Connection* con)

Diff for: ‎src/clientiface.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ class RemoteClient
266266
m_version_patch(0),
267267
m_full_version("unknown"),
268268
m_deployed_compression(0),
269-
m_connection_time(porting::getTime(PRECISION_SECONDS))
269+
m_connection_time(porting::getTimeS())
270270
{
271271
}
272272
~RemoteClient()
@@ -345,7 +345,7 @@ class RemoteClient
345345
{ serialization_version = m_pending_serialization_version; }
346346

347347
/* get uptime */
348-
u32 uptime() const;
348+
u64 uptime() const;
349349

350350
/* set version information */
351351
void setVersionInfo(u8 major, u8 minor, u8 patch, const std::string &full)
@@ -432,7 +432,7 @@ class RemoteClient
432432
/*
433433
time this client was created
434434
*/
435-
const u32 m_connection_time;
435+
const u64 m_connection_time;
436436
};
437437

438438
class ClientInterface {

Diff for: ‎src/guiFormSpecMenu.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2658,7 +2658,7 @@ void GUIFormSpecMenu::drawMenu()
26582658
if (hovered != NULL) {
26592659
s32 id = hovered->getID();
26602660

2661-
u32 delta = 0;
2661+
u64 delta = 0;
26622662
if (id == -1) {
26632663
m_old_tooltip_id = id;
26642664
m_old_tooltip = L"";
@@ -3247,7 +3247,7 @@ bool GUIFormSpecMenu::DoubleClickDetection(const SEvent event)
32473247
m_doubleclickdetect[1].time = porting::getTimeMs();
32483248
}
32493249
else if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP) {
3250-
u32 delta = porting::getDeltaMs(m_doubleclickdetect[0].time, porting::getTimeMs());
3250+
u64 delta = porting::getDeltaMs(m_doubleclickdetect[0].time, porting::getTimeMs());
32513251
if (delta > 400) {
32523252
return false;
32533253
}

Diff for: ‎src/guiFormSpecMenu.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,8 @@ class GUIFormSpecMenu : public GUIModalMenu
420420
v2s32 m_old_pointer; // Mouse position after previous mouse event
421421
gui::IGUIStaticText *m_tooltip_element;
422422

423-
u32 m_tooltip_show_delay;
424-
s64 m_hovered_time;
423+
u64 m_tooltip_show_delay;
424+
u64 m_hovered_time;
425425
s32 m_old_tooltip_id;
426426
std::wstring m_old_tooltip;
427427

Diff for: ‎src/hud.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ void Hud::resizeHotbar() {
626626
}
627627

628628
struct MeshTimeInfo {
629-
s64 time;
629+
u64 time;
630630
scene::IMesh *mesh;
631631
};
632632

Diff for: ‎src/intlGUIEditBox.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ namespace gui
155155
gui::IGUIFont *OverrideFont, *LastBreakFont;
156156
IOSOperator* Operator;
157157

158-
u32 BlinkStartTime;
158+
u64 BlinkStartTime;
159159
s32 CursorPos;
160160
s32 HScrollPos, VScrollPos; // scroll position in characters
161161
u32 Max;

Diff for: ‎src/map.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ void Map::transformLiquids(std::map<v3s16, MapBlock*> &modified_blocks,
981981

982982
time_until_purge *= 1000; // seconds -> milliseconds
983983

984-
u32 curr_time = porting::getTime(PRECISION_MILLI);
984+
u64 curr_time = porting::getTimeMs();
985985
u32 prev_unprocessed = m_unprocessed_count;
986986
m_unprocessed_count = m_transforming_liquid.size();
987987

Diff for: ‎src/map.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ class Map /*: public NodeContainer*/
343343
private:
344344
f32 m_transforming_liquid_loop_count_multiplier;
345345
u32 m_unprocessed_count;
346-
u32 m_inc_trending_up_start_time; // milliseconds
346+
u64 m_inc_trending_up_start_time; // milliseconds
347347
bool m_queue_size_timer_started;
348348

349349
DISABLE_CLASS_COPY(Map);

Diff for: ‎src/network/connection.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ class Peer {
769769
// Seconds from last receive
770770
float m_timeout_counter;
771771

772-
u32 m_last_timeout_check;
772+
u64 m_last_timeout_check;
773773
};
774774

775775
class UDPPeer : public Peer

Diff for: ‎src/profiler.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,33 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2121

2222
static Profiler main_profiler;
2323
Profiler *g_profiler = &main_profiler;
24+
ScopeProfiler::ScopeProfiler(
25+
Profiler *profiler, const std::string &name, ScopeProfilerType type)
26+
: m_profiler(profiler), m_name(name), m_timer(NULL), m_type(type)
27+
{
28+
if (m_profiler)
29+
m_timer = new TimeTaker(m_name);
30+
}
31+
32+
ScopeProfiler::~ScopeProfiler()
33+
{
34+
if (!m_timer)
35+
return;
36+
37+
float duration_ms = m_timer->stop(true);
38+
float duration = duration_ms / 1000.0;
39+
if (m_profiler) {
40+
switch (m_type) {
41+
case SPT_ADD:
42+
m_profiler->add(m_name, duration);
43+
break;
44+
case SPT_AVG:
45+
m_profiler->avg(m_name, duration);
46+
break;
47+
case SPT_GRAPH_ADD:
48+
m_profiler->graphAdd(m_name, duration);
49+
break;
50+
}
51+
}
52+
delete m_timer;
53+
}

Diff for: ‎src/profiler.h

+2-42
Original file line numberDiff line numberDiff line change
@@ -193,48 +193,8 @@ class ScopeProfiler
193193
{
194194
public:
195195
ScopeProfiler(Profiler *profiler, const std::string &name,
196-
enum ScopeProfilerType type = SPT_ADD):
197-
m_profiler(profiler),
198-
m_name(name),
199-
m_timer(NULL),
200-
m_type(type)
201-
{
202-
if(m_profiler)
203-
m_timer = new TimeTaker(m_name.c_str());
204-
}
205-
// name is copied
206-
ScopeProfiler(Profiler *profiler, const char *name,
207-
enum ScopeProfilerType type = SPT_ADD):
208-
m_profiler(profiler),
209-
m_name(name),
210-
m_timer(NULL),
211-
m_type(type)
212-
{
213-
if(m_profiler)
214-
m_timer = new TimeTaker(m_name.c_str());
215-
}
216-
~ScopeProfiler()
217-
{
218-
if(m_timer)
219-
{
220-
float duration_ms = m_timer->stop(true);
221-
float duration = duration_ms / 1000.0;
222-
if(m_profiler){
223-
switch(m_type){
224-
case SPT_ADD:
225-
m_profiler->add(m_name, duration);
226-
break;
227-
case SPT_AVG:
228-
m_profiler->avg(m_name, duration);
229-
break;
230-
case SPT_GRAPH_ADD:
231-
m_profiler->graphAdd(m_name, duration);
232-
break;
233-
}
234-
}
235-
delete m_timer;
236-
}
237-
}
196+
ScopeProfilerType type = SPT_ADD);
197+
~ScopeProfiler();
238198
private:
239199
Profiler *m_profiler;
240200
std::string m_name;

Diff for: ‎src/touchscreengui.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ bool TouchScreenGUI::doubleTapDetection()
922922
m_key_events[1].x = m_move_downlocation.X;
923923
m_key_events[1].y = m_move_downlocation.Y;
924924

925-
u32 delta = porting::getDeltaMs(m_key_events[0].down_time, porting::getTimeMs());
925+
u64 delta = porting::getDeltaMs(m_key_events[0].down_time, porting::getTimeMs());
926926
if (delta > 400)
927927
return false;
928928

@@ -1006,7 +1006,7 @@ void TouchScreenGUI::step(float dtime)
10061006
(!m_move_has_really_moved) &&
10071007
(!m_move_sent_as_mouse_event)) {
10081008

1009-
u32 delta = porting::getDeltaMs(m_move_downtime, porting::getTimeMs());
1009+
u64 delta = porting::getDeltaMs(m_move_downtime, porting::getTimeMs());
10101010

10111011
if (delta > MIN_DIG_TIME_MS) {
10121012
m_shootline = m_device

Diff for: ‎src/unittest/test.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ bool run_tests()
229229
{
230230
DSTACK(FUNCTION_NAME);
231231

232-
u32 t1 = porting::getTime(PRECISION_MILLI);
232+
u64 t1 = porting::getTimeMs();
233233
TestGameDef gamedef;
234234

235235
g_logger.setLevelSilenced(LL_ERROR, true);
@@ -246,7 +246,7 @@ bool run_tests()
246246
num_total_tests_run += testmods[i]->num_tests_run;
247247
}
248248

249-
u32 tdiff = porting::getTime(PRECISION_MILLI) - t1;
249+
u64 tdiff = porting::getTimeMs() - t1;
250250

251251
g_logger.setLevelSilenced(LL_ERROR, false);
252252

@@ -273,12 +273,12 @@ bool run_tests()
273273
bool TestBase::testModule(IGameDef *gamedef)
274274
{
275275
rawstream << "======== Testing module " << getName() << std::endl;
276-
u32 t1 = porting::getTime(PRECISION_MILLI);
276+
u64 t1 = porting::getTimeMs();
277277

278278

279279
runTests(gamedef);
280280

281-
u32 tdiff = porting::getTime(PRECISION_MILLI) - t1;
281+
u64 tdiff = porting::getTimeMs() - t1;
282282
rawstream << "======== Module " << getName() << " "
283283
<< (num_tests_failed ? "failed" : "passed") << " (" << num_tests_failed
284284
<< " failures / " << num_tests_run << " tests) - " << tdiff

Diff for: ‎src/unittest/test.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class TestFailedException : public std::exception {
3333

3434
// Runs a unit test and reports results
3535
#define TEST(fxn, ...) do { \
36-
u32 t1 = porting::getTime(PRECISION_MILLI); \
36+
u64 t1 = porting::getTimeMs(); \
3737
try { \
3838
fxn(__VA_ARGS__); \
3939
rawstream << "[PASS] "; \
@@ -46,7 +46,7 @@ class TestFailedException : public std::exception {
4646
num_tests_failed++; \
4747
} \
4848
num_tests_run++; \
49-
u32 tdiff = porting::getTime(PRECISION_MILLI) - t1; \
49+
u64 tdiff = porting::getTimeMs() - t1; \
5050
rawstream << #fxn << " - " << tdiff << "ms" << std::endl; \
5151
} while (0)
5252

Diff for: ‎src/util/timetaker.cpp

+8-15
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2323
#include "../log.h"
2424
#include <ostream>
2525

26-
TimeTaker::TimeTaker(const char *name, u32 *result, TimePrecision prec)
26+
TimeTaker::TimeTaker(const std::string &name, u64 *result, TimePrecision prec)
2727
{
2828
m_name = name;
2929
m_result = result;
@@ -32,18 +32,13 @@ TimeTaker::TimeTaker(const char *name, u32 *result, TimePrecision prec)
3232
m_time1 = porting::getTime(prec);
3333
}
3434

35-
u32 TimeTaker::stop(bool quiet)
35+
u64 TimeTaker::stop(bool quiet)
3636
{
37-
if(m_running)
38-
{
39-
u32 time2 = porting::getTime(m_precision);
40-
u32 dtime = time2 - m_time1;
41-
if(m_result != NULL)
42-
{
37+
if (m_running) {
38+
u64 dtime = porting::getTime(m_precision) - m_time1;
39+
if (m_result != NULL) {
4340
(*m_result) += dtime;
44-
}
45-
else
46-
{
41+
} else {
4742
if (!quiet) {
4843
static const char* const units[] = {
4944
"s" /* PRECISION_SECONDS */,
@@ -62,10 +57,8 @@ u32 TimeTaker::stop(bool quiet)
6257
return 0;
6358
}
6459

65-
u32 TimeTaker::getTimerTime()
60+
u64 TimeTaker::getTimerTime()
6661
{
67-
u32 time2 = porting::getTime(m_precision);
68-
u32 dtime = time2 - m_time1;
69-
return dtime;
62+
return porting::getTime(m_precision) - m_time1;
7063
}
7164

Diff for: ‎src/util/timetaker.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,24 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3030
class TimeTaker
3131
{
3232
public:
33-
TimeTaker(const char *name, u32 *result=NULL,
34-
TimePrecision=PRECISION_MILLI);
33+
TimeTaker(const std::string &name, u64 *result=NULL,
34+
TimePrecision prec=PRECISION_MILLI);
3535

3636
~TimeTaker()
3737
{
3838
stop();
3939
}
4040

41-
u32 stop(bool quiet=false);
41+
u64 stop(bool quiet=false);
4242

43-
u32 getTimerTime();
43+
u64 getTimerTime();
4444

4545
private:
46-
const char *m_name;
47-
u32 m_time1;
46+
std::string m_name;
47+
u64 m_time1;
4848
bool m_running;
4949
TimePrecision m_precision;
50-
u32 *m_result;
50+
u64 *m_result;
5151
};
5252

5353
#endif

Diff for: ‎src/voxel.cpp

+4-8
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2727
/*
2828
Debug stuff
2929
*/
30-
u32 addarea_time = 0;
31-
u32 emerge_time = 0;
32-
u32 emerge_load_time = 0;
33-
u32 clearflag_time = 0;
34-
//u32 getwaterpressure_time = 0;
35-
//u32 spreadwaterpressure_time = 0;
36-
u32 updateareawaterpressure_time = 0;
37-
u32 flowwater_pre_time = 0;
30+
u64 addarea_time = 0;
31+
u64 emerge_time = 0;
32+
u64 emerge_load_time = 0;
33+
u64 clearflag_time = 0;
3834

3935

4036
VoxelManipulator::VoxelManipulator():

Diff for: ‎src/voxel.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ class INodeDefManager;
4949
/*
5050
Debug stuff
5151
*/
52-
extern u32 emerge_time;
53-
extern u32 emerge_load_time;
52+
extern u64 emerge_time;
53+
extern u64 emerge_load_time;
5454

5555
/*
5656
This class resembles aabbox3d<s16> a lot, but has inclusive

0 commit comments

Comments
 (0)
Please sign in to comment.