Commit c4c871d6 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[ADD] - shader animation callback now uses boost::posix time. According to...

[ADD] - shader animation callback now uses boost::posix time. According to boost doc, this is portable and works on windows too.
parent 2d93f1ed
......@@ -22,13 +22,19 @@
//
//---------------------------------------------------------------------------
#include <ctime>
#include <iostream>
#include "boost/date_time/posix_time/posix_time.hpp"
#include "WGEShaderAnimationCallback.h"
WGEShaderAnimationCallback::WGEShaderAnimationCallback( int ticksPerSecond ):
osg::Uniform::Callback(),
m_ticksPerSec( ticksPerSecond )
m_start( boost::posix_time::microsec_clock::local_time() ),
m_ticksPerSec( ticksPerSecond ),
m_tickMillisecRatio( static_cast< double >( ticksPerSecond ) / 1000.0 )
{
m_timer.restart();
}
WGEShaderAnimationCallback::~WGEShaderAnimationCallback()
......@@ -38,8 +44,15 @@ WGEShaderAnimationCallback::~WGEShaderAnimationCallback()
void WGEShaderAnimationCallback::operator() ( osg::Uniform* uniform, osg::NodeVisitor* /*nv*/ )
{
// boost::timer measures seconds ...
int ticks = static_cast< int >( m_timer.elapsed() * m_ticksPerSec );
// according to boost doc, this is available on windows too! From boost doc "Get the local time using a sub second resolution clock. On Unix
// systems this is implemented using GetTimeOfDay. On most Win32 platforms it is implemented using ftime. Win32 systems often do not achieve
// microsecond resolution via this API. If higher resolution is critical to your application test your platform to see the achieved resolution.
// -> fortunately, millisecond resolution is enough here.
boost::posix_time::ptime t = boost::posix_time::microsec_clock::local_time();
boost::posix_time::time_duration td = t - m_start;
int ticks = static_cast< int >( static_cast< double >( td.total_milliseconds() ) * m_tickMillisecRatio );
uniform->set( ticks );
}
......@@ -27,7 +27,8 @@
#include "stdint.h"
#include <boost/timer.hpp>
#include "boost/date_time/posix_time/posix_time.hpp"
#include <osg/Uniform>
#include "../WExportWGE.h"
......@@ -62,15 +63,20 @@ public:
protected:
/**
* Timer that stops the time hopefully OS independent
*/
boost::timer m_timer;
* Timer that stops the time hopefully OS independent
*/
boost::posix_time::ptime m_start;
/**
* Number of ticks to count per second.
*/
int m_ticksPerSec;
/**
* Ratio between milliseconds and m_ticksPerSec
*/
double m_tickMillisecRatio;
private:
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment