From 7ca137f5fe0368ccb1c1e46e89d855d099af15c6 Mon Sep 17 00:00:00 2001 From: Daniel Richard G Date: Mon, 28 Oct 2013 00:28:39 -0400 Subject: [PATCH] Changed GetMilliseconds() to return a 64-bit value This function previously returned an int32_t. Presuming that it measures the length of time since the application was started, the 32-bit type would cause the returned value to wrap from 2^31-1 to -2^31 after a little less than twenty-five days. --- generate.cpp | 4 ++-- graphicswin.cpp | 2 +- mouse.cpp | 2 +- solvespace.h | 2 +- srf/triangulate.cpp | 10 +++++----- ui.h | 4 ++-- win32/w32main.cpp | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/generate.cpp b/generate.cpp index 11c6eb6..92ef72c 100644 --- a/generate.cpp +++ b/generate.cpp @@ -179,13 +179,13 @@ void SolveSpace::GenerateAll(int first, int last, bool andFindFree) { SK.param.MoveSelfInto(&prev); SK.entity.Clear(); - int32_t inTime = GetMilliseconds(); + int64_t inTime = GetMilliseconds(); bool displayedStatusMessage = false; for(i = 0; i < SK.group.n; i++) { Group *g = &(SK.group.elem[i]); - int32_t now = GetMilliseconds(); + int64_t now = GetMilliseconds(); // Display the status message if we've taken more than 400 ms, or // if we've taken 200 ms but we're not even halfway done, or if // we've already started displaying the status message. diff --git a/graphicswin.cpp b/graphicswin.cpp index 8a3805a..d65e696 100644 --- a/graphicswin.cpp +++ b/graphicswin.cpp @@ -263,7 +263,7 @@ void GraphicsWindow::AnimateOnto(Quaternion quatf, Vector offsetf) { // long translations (as measured in pixels) if the user zooms out, moves, // and then zooms in again. if(dt > 2000) dt = 2000; - int32_t tn, t0 = GetMilliseconds(); + int64_t tn, t0 = GetMilliseconds(); double s = 0; Quaternion dq = quatf.Times(quat0.Inverse()); do { diff --git a/mouse.cpp b/mouse.cpp index 97a8f56..ca9e90f 100644 --- a/mouse.cpp +++ b/mouse.cpp @@ -1291,7 +1291,7 @@ void GraphicsWindow::SpaceNavigatorMoved(double tx, double ty, double tz, // If we go five seconds without SpaceNavigator input, or if we've // switched groups, then consider that a new action and save an undo // point. - int32_t now = GetMilliseconds(); + int64_t now = GetMilliseconds(); if(now - lastSpaceNavigatorTime > 5000 || lastSpaceNavigatorGroup.v != g->h.v) { diff --git a/solvespace.h b/solvespace.h index 308eee1..67248a5 100644 --- a/solvespace.h +++ b/solvespace.h @@ -208,7 +208,7 @@ void ToggleFullScreen(void); bool FullScreenIsActive(void); void GetGraphicsWindowSize(int *w, int *h); void GetTextWindowSize(int *w, int *h); -int32_t GetMilliseconds(void); +int64_t GetMilliseconds(void); int64_t GetUnixTime(void); void dbp(const char *str, ...); diff --git a/srf/triangulate.cpp b/srf/triangulate.cpp index 3a51161..0c39451 100644 --- a/srf/triangulate.cpp +++ b/srf/triangulate.cpp @@ -11,7 +11,7 @@ void SPolygon::UvTriangulateInto(SMesh *m, SSurface *srf) { if(l.n <= 0) return; - int32_t in = GetMilliseconds(); + //int64_t in = GetMilliseconds(); normal = Vector::From(0, 0, 1); @@ -67,7 +67,7 @@ void SPolygon::UvTriangulateInto(SMesh *m, SSurface *srf) { } } -// dbp("finished finding holes: %d ms", GetMilliseconds() - in); +// dbp("finished finding holes: %d ms", (int)(GetMilliseconds() - in)); for(;;) { double xmin = 1e10; SContour *scmin = NULL; @@ -86,13 +86,13 @@ void SPolygon::UvTriangulateInto(SMesh *m, SSurface *srf) { dbp("couldn't merge our hole"); return; } -// dbp(" bridged to contour: %d ms", GetMilliseconds() - in); +// dbp(" bridged to contour: %d ms", (int)(GetMilliseconds() - in)); scmin->tag = 3; } -// dbp("finished merging holes: %d ms", GetMilliseconds() - in); +// dbp("finished merging holes: %d ms", (int)(GetMilliseconds() - in)); merged.UvTriangulateInto(m, srf); -// dbp("finished ear clippping: %d ms", GetMilliseconds() - in); +// dbp("finished ear clippping: %d ms", (int)(GetMilliseconds() - in)); merged.l.Clear(); el.Clear(); vl.Clear(); diff --git a/ui.h b/ui.h index c3a1d32..3cdee15 100644 --- a/ui.h +++ b/ui.h @@ -636,7 +636,7 @@ public: CMNU_FIRST_STYLE = 0x40000000 }; void ContextMenuListStyles(void); - int32_t contextMenuCancelTime; + int64_t contextMenuCancelTime; // The toolbar, in toolbar.cpp bool ToolbarDrawOrHitTest(int x, int y, bool paint, int *menuHit); @@ -683,7 +683,7 @@ public: bool KeyDown(int c); void EditControlDone(const char *s); - int32_t lastSpaceNavigatorTime; + int64_t lastSpaceNavigatorTime; hGroup lastSpaceNavigatorGroup; void SpaceNavigatorMoved(double tx, double ty, double tz, double rx, double ry, double rz, bool shiftDown); diff --git a/win32/w32main.cpp b/win32/w32main.cpp index 0d103b1..3946b6d 100644 --- a/win32/w32main.cpp +++ b/win32/w32main.cpp @@ -660,13 +660,13 @@ bool FullScreenIsActive(void) return false; } -int32_t GetMilliseconds(void) +int64_t GetMilliseconds(void) { LARGE_INTEGER t, f; QueryPerformanceCounter(&t); QueryPerformanceFrequency(&f); LONGLONG d = t.QuadPart/(f.QuadPart/1000); - return (int32_t)d; + return (int64_t)d; } int64_t GetUnixTime(void)