void time_trial(int index, int count) { space = demos[index].initFunc(); double start_time = GetMilliseconds(); for(int i=0; i<count; i++) demos[index].updateFunc(i); double end_time = GetMilliseconds(); demos[index].destroyFunc(); printf("Time(%c) = %8.2f ms (%s)\n", index + 'a', end_time - start_time, demos[index].name); }
void GraphicsWindow::AnimateOnto(Quaternion quatf, Vector offsetf) { // Get our initial orientation and translation. Quaternion quat0 = Quaternion::From(projRight, projUp); Vector offset0 = offset; // Make sure we take the shorter of the two possible paths. double mp = (quatf.Minus(quat0)).Magnitude(); double mm = (quatf.Plus(quat0)).Magnitude(); if(mp > mm) { quatf = quatf.ScaledBy(-1); mp = mm; } double mo = (offset0.Minus(offsetf)).Magnitude()*scale; // Animate transition, unless it's a tiny move. int32_t dt = (mp < 0.01 && mo < 10) ? (-20) : (int32_t)(100 + 1000*mp + 0.4*mo); // Don't ever animate for longer than 2000 ms; we can get absurdly // long translations (as measured in pixels) if the user zooms out, moves, // and then zooms in again. if(dt > 2000) dt = 2000; int64_t tn, t0 = GetMilliseconds(); double s = 0; Quaternion dq = quatf.Times(quat0.Inverse()); do { offset = (offset0.ScaledBy(1 - s)).Plus(offsetf.ScaledBy(s)); Quaternion quat = (dq.ToThe(s)).Times(quat0); quat = quat.WithMagnitude(1); projRight = quat.RotationU(); projUp = quat.RotationV(); PaintGraphics(); tn = GetMilliseconds(); s = (tn - t0)/((double)dt); } while((tn - t0) < dt); projRight = quatf.RotationU(); projUp = quatf.RotationV(); offset = offsetf; InvalidateGraphics(); // If the view screen is open, then we need to refresh it. SS.ScheduleShowTW(); }
MString MTimeSpan::GetString(bool msec/* = true*/) const { TCHAR sz[256]; if (msec) { if (GetTotalDays() > 0) { ::wsprintf(sz, TEXT("%u days and %02u:%02u:%02u.%03u"), static_cast<UINT>(GetTotalDays()), static_cast<UINT>(GetHour()), static_cast<UINT>(GetMinute()), static_cast<UINT>(GetSecond()), static_cast<UINT>(GetMilliseconds())); } else { ::wsprintf(sz, TEXT("%02u:%02u:%02u.%03u"), static_cast<UINT>(GetHour()), static_cast<UINT>(GetMinute()), static_cast<UINT>(GetSecond()), static_cast<UINT>(GetMilliseconds())); } } else { if (GetTotalDays() > 0) { ::wsprintf(sz, TEXT("%u days and %02u:%02u:%02u"), static_cast<UINT>(GetTotalDays()), static_cast<UINT>(GetHour()), static_cast<UINT>(GetMinute()), static_cast<UINT>(GetSecond())); } else { ::wsprintf(sz, TEXT("%02u:%02u:%02u"), static_cast<UINT>(GetHour()), static_cast<UINT>(GetMinute()), static_cast<UINT>(GetSecond())); } } return MString(sz); }
void MainLoopTimer::Measure() { if (--m_CallCount == 0) { m_Time1 = GetMilliseconds (); int64_t delta = m_Time1 - m_Time0; m_Time0 = m_Time1; m_AccumulatedNumFrames += m_NumFrames; m_AccumulatedTime += delta; m_NumFrames = 0; m_CallCount = m_Frequency; } }
void PostProcess::SaveToPng() { assert(m_pOutputTexture != 0); long millis = ((long)(GetMilliseconds() * 0.001)); std::cout << "Saving effect to png.\n"; std::ostringstream oss; oss << GetEecutablePath() << millis << "_effect.png"; if (GetEecutablePath() != "null") m_pOutputTexture->SavePNG(oss.str().c_str()); else std::cout << "Saved image (" << millis << ") to: " << GetEecutablePath() << "\n"; }
//! Stop a chronometer void Stop( void ) { // Sanity check if( !running ) { return; } struct timeval tStop; gettimeofday( &tStop, NULL ); running = false; accTime += GetMilliseconds( tStart, tStop ); }
//! Returns the current accumulated time float GetTime( void ) const { float msecs; msecs = accTime; if( running ) { struct timeval now; gettimeofday( &now, NULL ); msecs += GetMilliseconds( tStart, now ); } return( msecs ); }
void MainLoopTimer::Reset() { m_CallCount = m_Frequency; m_NumFrames = 0; m_AccumulatedNumFrames = 0; m_AccumulatedTime = 0; LARGE_INTEGER counter = { 0 }, frequency = { 1 }; QueryPerformanceCounter(&counter); QueryPerformanceFrequency(&frequency); m_InitialTicks = static_cast<int64_t>(counter.QuadPart); m_InverseFrequency = 1.0 / static_cast<double>(m_Frequency); m_InversePerformanceFrequency = 1.0/static_cast<double>(frequency.QuadPart); m_Time0 = GetMilliseconds (); m_Time1 = m_Time0; }
void Camera::SaveToPng() { long millis = ((long)(GetMilliseconds() * 0.001)); std::cout << "Saving camera to png.\n"; std::ostringstream oss; oss << GetEecutablePath() << millis << "_color.png"; if (GetEecutablePath() != "null" && m_eRenderMode == COLOR_DEPTH) GetRenderTarget()->SavePNG(oss.str().c_str(), GetNear(), GetFar()); else std::cout << "Could not save image!\n"; if (GetEecutablePath() != "null") { oss.clear(); oss << GetEecutablePath() << millis << "_depth.png"; GetDepthTarget()->SavePNG(oss.str().c_str(), GetNear(), GetFar()); } else { std::cout << "Saved image (" << millis << ") to: " << GetEecutablePath() << "\n"; } }
void GraphicsWindow::MouseLeftUp(double mx, double my) { orig.mouseDown = false; hoverWasSelectedOnMousedown = false; switch(pending.operation) { case DRAGGING_POINTS: SS.extraLine.draw = false; // fall through case DRAGGING_CONSTRAINT: case DRAGGING_NORMAL: case DRAGGING_RADIUS: ClearPending(); InvalidateGraphics(); break; case DRAGGING_MARQUEE: SelectByMarquee(); ClearPending(); InvalidateGraphics(); break; case 0: // We need to clear the selection here, and not in the mouse down // event, since a mouse down without anything hovered could also // be the start of marquee selection. But don't do that on the // left click to cancel a context menu. The time delay is an ugly // hack. if(hover.IsEmpty() && (contextMenuCancelTime == 0 || (GetMilliseconds() - contextMenuCancelTime) > 200)) { ClearSelection(); } break; default: break; // do nothing } }
FString FTimespan::ToString( const TCHAR* Format ) const { FString Result; while (*Format != TCHAR('\0')) { if ((*Format == TCHAR('%')) && (*++Format != TCHAR('\0'))) { switch (*Format) { case TCHAR('n'): if (Ticks < 0) Result += TCHAR('-'); break; case TCHAR('N'): Result += (Ticks < 0) ? TCHAR('-') : TCHAR('+'); break; case TCHAR('d'): Result += FString::Printf(TEXT("%i"), FMath::Abs(GetDays())); break; case TCHAR('h'): Result += FString::Printf(TEXT("%02i"), FMath::Abs(GetHours())); break; case TCHAR('m'): Result += FString::Printf(TEXT("%02i"), FMath::Abs(GetMinutes())); break; case TCHAR('s'): Result += FString::Printf(TEXT("%02i"), FMath::Abs(GetSeconds())); break; case TCHAR('f'): Result += FString::Printf(TEXT("%03i"), FMath::Abs(GetMilliseconds())); break; case TCHAR('D'): Result += FString::Printf(TEXT("%f"), FMath::Abs(GetTotalDays())); break; case TCHAR('H'): Result += FString::Printf(TEXT("%f"), FMath::Abs(GetTotalHours())); break; case TCHAR('M'): Result += FString::Printf(TEXT("%f"), FMath::Abs(GetTotalMinutes())); break; case TCHAR('S'): Result += FString::Printf(TEXT("%f"), FMath::Abs(GetTotalSeconds())); break; case TCHAR('F'): Result += FString::Printf(TEXT("%f"), FMath::Abs(GetTotalMilliseconds())); break; default: Result += *Format; } } else { Result += *Format; } ++Format; } return Result; }
uint64_t Get() const { return GetMilliseconds(); } //milliseconds
bool Time::operator>(Time& rhs) { return GetMilliseconds() > rhs.GetMilliseconds(); }
void GraphicsWindow::SpaceNavigatorMoved(double tx, double ty, double tz, double rx, double ry, double rz, bool shiftDown) { if(!havePainted) return; Vector out = projRight.Cross(projUp); // rotation vector is axis of rotation, and its magnitude is angle Vector aa = Vector::From(rx, ry, rz); // but it's given with respect to screen projection frame aa = aa.ScaleOutOfCsys(projRight, projUp, out); double aam = aa.Magnitude(); if(aam > 0.0) aa = aa.WithMagnitude(1); // This can either transform our view, or transform an imported part. GroupSelection(); Entity *e = NULL; Group *g = NULL; if(gs.points == 1 && gs.n == 1) e = SK.GetEntity(gs.point [0]); if(gs.entities == 1 && gs.n == 1) e = SK.GetEntity(gs.entity[0]); if(e) g = SK.GetGroup(e->group); if(g && g->type == Group::IMPORTED && !shiftDown) { // Apply the transformation to an imported part. Gain down the Z // axis, since it's hard to see what you're doing on that one since // it's normal to the screen. Vector t = projRight.ScaledBy(tx/scale).Plus( projUp .ScaledBy(ty/scale).Plus( out .ScaledBy(0.1*tz/scale))); Quaternion q = Quaternion::From(aa, aam); // 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. int64_t now = GetMilliseconds(); if(now - lastSpaceNavigatorTime > 5000 || lastSpaceNavigatorGroup.v != g->h.v) { SS.UndoRemember(); } g->TransformImportedBy(t, q); lastSpaceNavigatorTime = now; lastSpaceNavigatorGroup = g->h; SS.MarkGroupDirty(g->h); SS.ScheduleGenerateAll(); } else { // Apply the transformation to the view of the everything. The // x and y components are translation; but z component is scale, // not translation, or else it would do nothing in a parallel // projection offset = offset.Plus(projRight.ScaledBy(tx/scale)); offset = offset.Plus(projUp.ScaledBy(ty/scale)); scale *= exp(0.001*tz); if(aam > 0.0) { projRight = projRight.RotatedAbout(aa, -aam); projUp = projUp. RotatedAbout(aa, -aam); NormalizeProjectionVectors(); } } havePainted = false; InvalidateGraphics(); }
void GraphicsWindow::MouseRightUp(double x, double y) { SS.extraLine.draw = false; InvalidateGraphics(); // Don't show a context menu if the user is right-clicking the toolbar, // or if they are finishing a pan. if(ToolbarMouseMoved((int)x, (int)y)) return; if(orig.startedMoving) return; if(context.active) return; if(pending.operation == DRAGGING_NEW_LINE_POINT || pending.operation == DRAGGING_NEW_CUBIC_POINT) { // Special case; use a right click to stop drawing lines, since // a left click would draw another one. This is quicker and more // intuitive than hitting escape. Likewise for new cubic segments. ClearPending(); return; } context.active = true; if(!hover.IsEmpty()) { MakeSelected(&hover); SS.ScheduleShowTW(); } GroupSelection(); bool itemsSelected = (gs.n > 0 || gs.constraints > 0); if(itemsSelected) { if(gs.stylables > 0) { ContextMenuListStyles(); AddContextMenuItem("Assign to Style", CONTEXT_SUBMENU); } if(gs.n + gs.constraints == 1) { AddContextMenuItem("Group Info", CMNU_GROUP_INFO); } if(gs.n + gs.constraints == 1 && gs.stylables == 1) { AddContextMenuItem("Style Info", CMNU_STYLE_INFO); } if(gs.withEndpoints > 0) { AddContextMenuItem("Select Edge Chain", CMNU_SELECT_CHAIN); } if(gs.constraints == 1 && gs.n == 0) { Constraint *c = SK.GetConstraint(gs.constraint[0]); if(c->HasLabel() && c->type != Constraint::COMMENT) { AddContextMenuItem("Toggle Reference Dimension", CMNU_REFERENCE_DIM); } if(c->type == Constraint::ANGLE || c->type == Constraint::EQUAL_ANGLE) { AddContextMenuItem("Other Supplementary Angle", CMNU_OTHER_ANGLE); } } if(gs.comments > 0 || gs.points > 0) { AddContextMenuItem("Snap to Grid", CMNU_SNAP_TO_GRID); } if(gs.points == 1) { Entity *p = SK.GetEntity(gs.point[0]); Constraint *c; IdList<Constraint,hConstraint> *lc = &(SK.constraint); for(c = lc->First(); c; c = lc->NextAfter(c)) { if(c->type != Constraint::POINTS_COINCIDENT) continue; if(c->ptA.v == p->h.v || c->ptB.v == p->h.v) { break; } } if(c) { AddContextMenuItem("Delete Point-Coincident Constraint", CMNU_DEL_COINCIDENT); } } AddContextMenuItem(NULL, CONTEXT_SEPARATOR); if(LockedInWorkplane()) { AddContextMenuItem("Cut", CMNU_CUT_SEL); AddContextMenuItem("Copy", CMNU_COPY_SEL); } } if(SS.clipboard.r.n > 0 && LockedInWorkplane()) { AddContextMenuItem("Paste", CMNU_PASTE_SEL); } if(itemsSelected) { AddContextMenuItem("Delete", CMNU_DELETE_SEL); AddContextMenuItem(NULL, CONTEXT_SEPARATOR); AddContextMenuItem("Unselect All", CMNU_UNSELECT_ALL); } // If only one item is selected, then it must be the one that we just // selected from the hovered item; in which case unselect all and hovered // are equivalent. if(!hover.IsEmpty() && selection.n > 1) { AddContextMenuItem("Unselect Hovered", CMNU_UNSELECT_HOVERED); } int ret = ShowContextMenu(); switch(ret) { case CMNU_UNSELECT_ALL: MenuEdit(MNU_UNSELECT_ALL); break; case CMNU_UNSELECT_HOVERED: if(!hover.IsEmpty()) { MakeUnselected(&hover, true); } break; case CMNU_SELECT_CHAIN: MenuEdit(MNU_SELECT_CHAIN); break; case CMNU_CUT_SEL: MenuClipboard(MNU_CUT); break; case CMNU_COPY_SEL: MenuClipboard(MNU_COPY); break; case CMNU_PASTE_SEL: MenuClipboard(MNU_PASTE); break; case CMNU_DELETE_SEL: MenuClipboard(MNU_DELETE); break; case CMNU_REFERENCE_DIM: Constraint::MenuConstrain(MNU_REFERENCE); break; case CMNU_OTHER_ANGLE: Constraint::MenuConstrain(MNU_OTHER_ANGLE); break; case CMNU_DEL_COINCIDENT: { SS.UndoRemember(); if(!gs.point[0].v) break; Entity *p = SK.GetEntity(gs.point[0]); if(!p->IsPoint()) break; SK.constraint.ClearTags(); Constraint *c; for(c = SK.constraint.First(); c; c = SK.constraint.NextAfter(c)) { if(c->type != Constraint::POINTS_COINCIDENT) continue; if(c->ptA.v == p->h.v || c->ptB.v == p->h.v) { c->tag = 1; } } SK.constraint.RemoveTagged(); ClearSelection(); break; } case CMNU_SNAP_TO_GRID: MenuEdit(MNU_SNAP_TO_GRID); break; case CMNU_GROUP_INFO: { hGroup hg; if(gs.entities == 1) { hg = SK.GetEntity(gs.entity[0])->group; } else if(gs.points == 1) { hg = SK.GetEntity(gs.point[0])->group; } else if(gs.constraints == 1) { hg = SK.GetConstraint(gs.constraint[0])->group; } else { break; } ClearSelection(); SS.TW.GoToScreen(TextWindow::SCREEN_GROUP_INFO); SS.TW.shown.group = hg; SS.ScheduleShowTW(); break; } case CMNU_STYLE_INFO: { hStyle hs; if(gs.entities == 1) { hs = Style::ForEntity(gs.entity[0]); } else if(gs.points == 1) { hs = Style::ForEntity(gs.point[0]); } else if(gs.constraints == 1) { hs = SK.GetConstraint(gs.constraint[0])->disp.style; if(!hs.v) hs.v = Style::CONSTRAINT; } else { break; } ClearSelection(); SS.TW.GoToScreen(TextWindow::SCREEN_STYLE_INFO); SS.TW.shown.style = hs; SS.ScheduleShowTW(); break; } case CMNU_NEW_CUSTOM_STYLE: { uint32_t v = Style::CreateCustomStyle(); Style::AssignSelectionToStyle(v); break; } case CMNU_NO_STYLE: Style::AssignSelectionToStyle(0); break; default: if(ret >= CMNU_FIRST_STYLE) { Style::AssignSelectionToStyle(ret - CMNU_FIRST_STYLE); } else { // otherwise it was cancelled, so do nothing contextMenuCancelTime = GetMilliseconds(); } break; } context.active = false; SS.ScheduleShowTW(); }
Time Time::operator-(Time& rhs) { double difference = GetMilliseconds() - rhs.GetMilliseconds(); return milliseconds(difference); }
void SPolygon::UvTriangulateInto(SMesh *m, SSurface *srf) { if(l.n <= 0) return; SDWORD in = GetMilliseconds(); normal = Vector::From(0, 0, 1); while(l.n > 0) { FixContourDirections(); l.ClearTags(); // Find a top-level contour, and start with that. Then build bridges // in order to merge all its islands into a single contour. SContour *top; for(top = l.First(); top; top = l.NextAfter(top)) { if(top->timesEnclosed == 0) { break; } } if(!top) { dbp("polygon has no top-level contours?"); return; } // Start with the outer contour SContour merged; ZERO(&merged); top->tag = 1; top->CopyInto(&merged); (merged.l.n)--; // List all of the edges, for testing whether bridges work. SEdgeList el; ZERO(&el); top->MakeEdgesInto(&el); List<Vector> vl; ZERO(&vl); // And now find all of its holes. Note that we will also find any // outer contours that lie entirely within this contour, and any // holes for those contours. But that's okay, because we can merge // those too. SContour *sc; for(sc = l.First(); sc; sc = l.NextAfter(sc)) { if(sc->timesEnclosed != 1) continue; if(sc->l.n < 2) continue; // Test the midpoint of an edge. Our polygon may not be self- // intersecting, but two contours may share a vertex; so a // vertex could be on the edge of another polygon, in which // case ContainsPointProjdToNormal returns indeterminate. Vector tp = sc->AnyEdgeMidpoint(); if(top->ContainsPointProjdToNormal(normal, tp)) { sc->tag = 2; sc->MakeEdgesInto(&el); sc->FindPointWithMinX(); } } // dbp("finished finding holes: %d ms", GetMilliseconds() - in); for(;;) { double xmin = 1e10; SContour *scmin = NULL; for(sc = l.First(); sc; sc = l.NextAfter(sc)) { if(sc->tag != 2) continue; if(sc->xminPt.x < xmin) { xmin = sc->xminPt.x; scmin = sc; } } if(!scmin) break; if(!merged.BridgeToContour(scmin, &el, &vl)) { dbp("couldn't merge our hole"); return; } // dbp(" bridged to contour: %d ms", GetMilliseconds() - in); scmin->tag = 3; } // dbp("finished merging holes: %d ms", GetMilliseconds() - in); merged.UvTriangulateInto(m, srf); // dbp("finished ear clippping: %d ms", GetMilliseconds() - in); merged.l.Clear(); el.Clear(); vl.Clear(); // Careful, need to free the points within the contours, and not just // the contours themselves. This was a tricky memory leak. for(sc = l.First(); sc; sc = l.NextAfter(sc)) { if(sc->tag) { sc->l.Clear(); } } l.RemoveTagged(); } }
Time Time::operator+=(Time& rhs) { double sum = GetMilliseconds() + rhs.GetMilliseconds(); m_impl->SetMilliseconds(sum); return milliseconds(sum); }
bool Time::operator==(const Time& rhs) const { return (GetMilliseconds() == rhs.GetMilliseconds()); }
bool Time::operator<=(Time& rhs) { return GetMilliseconds() <= rhs.GetMilliseconds(); }