FrameStamp 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
  2. *
  3. * This library is open source and may be redistributed and/or modified under
  4. * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
  5. * (at your option) any later version. The full license is in LICENSE file
  6. * included with this distribution, and on the openscenegraph.org website.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * OpenSceneGraph Public License for more details.
  12. */
  13. #ifndef OSG_FRAMESTAMP
  14. #define OSG_FRAMESTAMP 1
  15. #include <osg/Referenced>
  16. #if defined(__sgi) || (defined(WIN32) && !defined(__MWERKS__))
  17. #include <time.h>
  18. #else
  19. #include <ctime>
  20. using std::tm;
  21. #endif
  22. namespace osg
  23. {
  24. /** Class which encapsulates the frame number, reference time and calendar
  25. * time of specific frame, used to synchronize operations on the scene graph
  26. * and other machines when using a graphics cluster. Note the calendar
  27. * time can be an artificial simulation time or capture the real time
  28. * of day etc.*/
  29. class OSG_EXPORT FrameStamp : public Referenced
  30. {
  31. public:
  32. FrameStamp();
  33. FrameStamp(const FrameStamp& fs);
  34. FrameStamp& operator = (const FrameStamp& fs);
  35. void setFrameNumber(unsigned int fnum) { _frameNumber = fnum; }
  36. unsigned int getFrameNumber() const { return _frameNumber; }
  37. void setReferenceTime(double refTime) { _referenceTime = refTime; }
  38. double getReferenceTime() const { return _referenceTime; }
  39. void setSimulationTime(double refTime) { _simulationTime = refTime; }
  40. double getSimulationTime() const { return _simulationTime; }
  41. void setCalendarTime(const tm& calendarTime);
  42. void getCalendarTime(tm& calendarTime) const;
  43. // keep public to allow it to be permit allocation which is
  44. // not on the heap used osgcluster
  45. virtual ~FrameStamp();
  46. protected:
  47. // note no dynamic memory is used so that data can be passed
  48. // via a simple memory copy or within a data packet across
  49. // the network.
  50. unsigned int _frameNumber;
  51. double _referenceTime;
  52. double _simulationTime;
  53. // member variables of time.h's tm structure, copied here to
  54. // ensure that all data is not dynamic. The tm structure itself
  55. // is not completely consistent between implementations, which
  56. // could be a problem when sending the FrameStamp across a network
  57. // with different versions of tm (i.e mixing Unix and Windows.)
  58. int tm_sec; /* Seconds. [0-60] (1 leap second) */
  59. int tm_min; /* Minutes. [0-59] */
  60. int tm_hour; /* Hours. [0-23] */
  61. int tm_mday; /* Day. [1-31] */
  62. int tm_mon; /* Month. [0-11] */
  63. int tm_year; /* Year - 1900. */
  64. int tm_wday; /* Day of week. [0-6] */
  65. int tm_yday; /* Days in year. [0-365] */
  66. int tm_isdst; /* DST. [-1/0/1]*/
  67. };
  68. }
  69. #endif