// Tell emacs -*- c++ -*- /* Copyright (c) 2002 Data Visualization Research Lab, // Center for Coastal and Ocean Mapping, // University of New Hampshire. All rights reserved. // http://www.ccom.unh.edu/vislab // Not to be copied or distributed without written agreement. // Permission to use with UNH CS770/870 assignments // granted by Colin Ware 7/2008 // Contact: colinw@cisunix.unh.edu or roland@ccom.unh.edu // Based on TimeControl class, adapted fro CS770/870 by mdp 11/23/2008 */ /*---------------------------------------------------------------------------*/ /// \file /// \brief Class for managing animation time cross-platform /*---------------------------------------------------------------------------*/ // AnimationTimer.h /*---------------------------------------------------------------------------*/ class AnimationTimer; #ifndef ANIMATIONTIMER_H #define ANIMATIONTIMER_H class AnimationTimer { public: AnimationTimer(); //---main interface--- //Key method for keeping up with time void updateCurrentTime(bool frameFlag = false); //Set the length of time for an animation frame in milliseconds void setTargetFrameTime(int milliseconds = -1); //Set the passed simulation time to correspond with the current system time void setSimulationTime(double time); //---convenience functions--- double getCurrentSysTime(); //get actual system time double getFrameTime() {return frameTime;} //get length of last frame void getSysTimeStr(char * tstr); static void getTimeStr(char * tstr,double tm); void sleep(int milliseconds); //relinquish control for passed # of msecs //---basic accessors--- double getRecentSysTime() {return currentSysTime;} double getSimulationTime() {return currentSimTime;} double getScale() {return scale;} double getOffset() {return offset;} int isPaused(){return paused;} //---handy items that might map to animation controls--- void stop(); void play(); void rev(); void setScale(double scale); void setTimeAndScale(double time, double scale); void setOffsetAndScale(double offset, double scale); void repeat() {loopAtEnd = 1;} void dontRepeat() {loopAtEnd = 0;} void loop(); void dontLoop() {looping = 0;} void setLoopStart(); void setLoopEnd(); private: double currentSysTime; // system time in seconds double lastSysTime; // time of previous frame static double currentSimTime; // transformed sys time double lastSimTime; // simulation time of last frame double scale; // how to scale sys time to sim time double offset; // offset from sys time to sim time double frameTime; int targetFrameMS; double targetTime; // time to which we are translating // Looping double loopStart; double loopEnd; bool looping, loopAtEnd; int paused; }; #endif