// Timer Test #define _WIN32_WINNT 0x0601 // OSG includes #include #include #include #include using namespace std; class timed_class { public: timed_class(boost::asio::io_service& io_service) : _timer(io_service), i(0), timer(*osg::Timer::instance()) { last_tick = timer.tick(); // now schedule the first timer. _timer.expires_from_now(boost::posix_time::milliseconds(1000/60)); // runs with 60Hz _timer.async_wait(boost::bind(&timed_class::handle_timeout, this, boost::asio::placeholders::error)); } void handle_timeout(boost::system::error_code const& cError) { if (cError.value() == boost::asio::error::operation_aborted) return; if (cError && cError.value() != boost::asio::error::operation_aborted) return; // throw an exception? // Schedule the timer again... _timer.expires_from_now(boost::posix_time::milliseconds(1000/60)); // runs with 60Hz _timer.async_wait(boost::bind(&timed_class::handle_timeout, this, boost::asio::placeholders::error)); // Payload osg::Timer_t currentTick = timer.tick(); cout << timer.delta_m(last_tick,currentTick) << " msec ("<<(1000/60)<<")" << endl; last_tick = timer.tick(); } private: boost::asio::deadline_timer _timer; boost::asio::basic_deadline_timer<> _timer; int i; const osg::Timer& timer; osg::Timer_t last_tick; }; int main( int argc, char **argv ) { boost::asio::io_service io_service; timed_class t(io_service); //io_service.run(); // Start ioService in this thread( blocking // Start Timer in another thread to continue this thread boost::thread thread(boost::bind(&boost::asio::io_service::run, &io_service)); // OUtput stuff to show th thread is working while(1) //OSG_ALWAYS<<"Main Thread:"<