Skip to content

Commit

Permalink
Make Viewer::advanceToNextFrame() more customizable
Browse files Browse the repository at this point in the history
To prevent applications from reimplementing this method, which can lead to
major problems, it is made more customizable. It is now possible to change
the time source by overwriting `Viewer::advanceToNextTimePoint()` and to
add special stuff with `Viewer::advanceToNextFrameHook()`.

See vsg-dev#1132.
  • Loading branch information
rhabacker committed Mar 20, 2024
1 parent ccf1df6 commit 93c1a58
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
8 changes: 8 additions & 0 deletions include/vsg/app/Viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ namespace vsg
/// hint for setting the FrameStamp::simulationTime to time since start_point()
static constexpr double UseTimeSinceStartPoint = std::numeric_limits<double>::max();

/// get next time point in Viewer::advanceToNextFrame()
/// The standard implemnentation advances to the actual time by using vsg::clock::now()
virtual clock::time_point advanceToNextTimePoint();

/// hook for Viewer::advanceToNextFrame() for advancing to next tasks, layers etc.
/// The default implementation advances to the next tasks
virtual void advanceToNextFrameHook();

/// Convenience method for advancing to the next frame.
/// Check active status, return false if viewer no longer active.
/// If still active, poll for pending events and place them in the Events list and advance to the next frame, generate updated FrameStamp to signify the advancement to a new frame and return true.
Expand Down
20 changes: 15 additions & 5 deletions src/vsg/app/Viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,19 @@ bool Viewer::pollEvents(bool discardPreviousEvents)
return result;
}

clock::time_point Viewer::advanceToNextTimePoint()
{
return vsg::clock::now();
}

void Viewer::advanceToNextFrameHook()
{
for (auto& task : recordAndSubmitTasks)
{
task->advance();
}
}

bool Viewer::advanceToNextFrame(double simulationTime)
{
static constexpr SourceLocation s_frame_source_location{"Viewer advanceToNextFrame", VsgFunctionName, __FILE__, __LINE__, COLOR_VIEWER, 1};
Expand All @@ -168,7 +181,7 @@ bool Viewer::advanceToNextFrame(double simulationTime)
if (!acquireNextFrame()) return false;

// create FrameStamp for frame
auto time = vsg::clock::now();
auto time = advanceToNextTimePoint();
if (!_frameStamp)
{
_start_point = time;
Expand All @@ -192,10 +205,7 @@ bool Viewer::advanceToNextFrame(double simulationTime)
// signal to instrumentation the start of frame
if (instrumentation) instrumentation->enterFrame(&s_frame_source_location, frameReference, *_frameStamp);

for (auto& task : recordAndSubmitTasks)
{
task->advance();
}
advanceToNextFrameHook();

// create an event for the new frame.
_events.emplace_back(new FrameEvent(_frameStamp));
Expand Down

0 comments on commit 93c1a58

Please sign in to comment.