00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00025
00026 #ifndef RemoteSync_H
00027 #define RemoteSync_H
00028
00029 #include "H3DNetworkingUtils/Config.h"
00030 #include <H3D/Group.h>
00031 #include <H3D/TimeSensor.h>
00032 #include "H3DNetworkingUtils/TimePacket.h"
00033 #include "H3DNetworkingUtils/RemoteTimePacket.h"
00034 #include "H3DNetworkingUtils/PacketSequenceChecker.h"
00035 #include <vector>
00036
00037 namespace H3DNetworkingUtils {
00038
00041
00042 class H3D_NETWORKING_UTILS_DLL_SPEC RemoteSync : public H3D::Group {
00043 public:
00044
00045
00046 class ClockOffset;
00047 struct TimePacketCollector;
00048 typedef H3D::TypedSFNode<RemoteTimePacket> SFRemoteTimePacket;
00049
00051 RemoteSync( H3D::Inst<ClockOffset > _clockOffset = 0,
00052 H3D::Inst< TimePacketCollector > _timePacketReceived = 0,
00053 H3D::Inst< SFRemoteTimePacket> _remoteTimePacket = 0);
00054
00056 static H3D::H3DNodeDatabase database;
00057
00059 virtual void initialize();
00060
00061 struct H3D_NETWORKING_UTILS_DLL_SPEC TimePacker :
00062 public H3D::TypedField< H3D::SField< TimePacket >,
00063 H3D::SFTime > {
00064 virtual void update();
00065 };
00066
00067
00068 struct H3D_NETWORKING_UTILS_DLL_SPEC TimePacketCollector : public H3D::AutoUpdate <
00069 H3D::TypedField<H3D::Field, H3D::SField<TimePacket> > > {
00070 TimePacketCollector() : remote_syncP (0) {}
00071 virtual void update() {
00072 H3D::SField<TimePacket> * packet = static_cast<H3D::SField<TimePacket> *>(event.ptr);
00073 remote_syncP->appendResult(packet->getValue());
00074 }
00075 RemoteSync * remote_syncP;
00076 };
00077
00078 class H3D_NETWORKING_UTILS_DLL_SPEC ClockOffset : public H3D::PeriodicUpdate< H3D::SFTime > {
00079 public:
00080 ClockOffset(): rs( 0 ) {
00081 startup = true;
00082 }
00083 virtual void update();
00084 RemoteSync *rs;
00085 private:
00086 bool startup;
00087 };
00088
00089
00090
00091
00095 auto_ptr< ClockOffset > clockOffset;
00096
00100 auto_ptr< TimePacketCollector > timePacketReceived;
00101
00105 auto_ptr< SFRemoteTimePacket > remoteTimePacket;
00106
00107 H3D::AutoRef< H3D::TimeSensor > timer;
00108 std::vector< TimePacket > results;
00109
00110 protected:
00111 virtual void appendResult(TimePacket const & packet) {
00112 if (packet.state)
00113 results.push_back(packet);
00114 }
00115
00116 auto_ptr< TimePacker > time_packer;
00117
00118 };
00119
00120 }
00121
00122 #endif