Sirikata
|
00001 // Copyright (c) 2011 Sirikata Authors. All rights reserved. 00002 // Use of this source code is governed by a BSD-style license that can 00003 // be found in the LICENSE file. 00004 00005 #ifndef _SIRIKATA_LIBCORE_PRESENCE_PROPERTIES_HPP_ 00006 #define _SIRIKATA_LIBCORE_PRESENCE_PROPERTIES_HPP_ 00007 00008 #include <sirikata/core/util/Platform.hpp> 00009 #include <sirikata/core/util/MotionVector.hpp> 00010 #include <sirikata/core/util/MotionQuaternion.hpp> 00011 #include <sirikata/core/transfer/URI.hpp> 00012 #include <sirikata/core/util/ObjectReference.hpp> 00013 #include <sirikata/core/util/AggregateBoundingInfo.hpp> 00014 00015 namespace Sirikata { 00016 00021 class IPresencePropertiesRead { 00022 public: 00023 virtual ~IPresencePropertiesRead() {} 00024 00025 virtual TimedMotionVector3f location() const = 0; 00026 virtual TimedMotionQuaternion orientation() const = 0; 00027 virtual AggregateBoundingInfo bounds() const = 0; 00028 virtual Transfer::URI mesh() const = 0; 00029 virtual String physics() const = 0; 00030 virtual bool isAggregate() const = 0; 00031 virtual ObjectReference parent() const = 0; 00032 }; 00033 typedef std::tr1::shared_ptr<IPresencePropertiesRead> IPresencePropertiesReadPtr; 00034 00039 class PresenceProperties : public virtual IPresencePropertiesRead { 00040 public: 00041 PresenceProperties() 00042 : mLoc(Time::null(), MotionVector3f(Vector3f::zero(), Vector3f::zero())), 00043 mOrientation(Time::null(), MotionQuaternion(Quaternion::identity(), Quaternion::identity())), 00044 mBounds(Vector3f::zero(), 0), 00045 mMesh(), 00046 mPhysics(), 00047 mIsAggregate(false), 00048 mParent(ObjectReference::null()) 00049 {} 00050 PresenceProperties( 00051 const TimedMotionVector3f& loc, const TimedMotionQuaternion& orient, 00052 const AggregateBoundingInfo& bnds, const Transfer::URI& msh, const String& phy 00053 ) 00054 : mLoc(loc), 00055 mOrientation(orient), 00056 mBounds(bnds), 00057 mMesh(msh), 00058 mPhysics(phy) 00059 {} 00060 virtual ~PresenceProperties() {} 00061 00062 virtual TimedMotionVector3f location() const { return mLoc; } 00063 virtual bool setLocation(const TimedMotionVector3f& l) { mLoc = l; return true; } 00064 00065 virtual TimedMotionQuaternion orientation() const { return mOrientation; } 00066 virtual bool setOrientation(const TimedMotionQuaternion& o) { mOrientation = o; return true; } 00067 00068 virtual AggregateBoundingInfo bounds() const { return mBounds; } 00069 virtual bool setBounds(const AggregateBoundingInfo& b) { mBounds = b; return true; } 00070 00071 virtual Transfer::URI mesh() const { return mMesh; } 00072 virtual bool setMesh(const Transfer::URI& m) { mMesh = m; return true; } 00073 00074 virtual String physics() const { return mPhysics; } 00075 virtual bool setPhysics(const String& p) { mPhysics = p; return true; } 00076 00077 virtual bool setIsAggregate(bool isAgg) { mIsAggregate = isAgg; return true; } 00078 virtual bool isAggregate() const { return mIsAggregate; } 00079 00080 virtual bool setParent(const ObjectReference& par) { mParent = par; return true; } 00081 virtual ObjectReference parent() const { return mParent; } 00082 protected: 00083 TimedMotionVector3f mLoc; 00084 TimedMotionQuaternion mOrientation; 00085 AggregateBoundingInfo mBounds; 00086 Transfer::URI mMesh; 00087 String mPhysics; 00088 bool mIsAggregate; 00089 ObjectReference mParent; 00090 }; 00091 typedef std::tr1::shared_ptr<PresenceProperties> PresencePropertiesPtr; 00092 00097 class SequencedPresenceProperties : public PresenceProperties { 00098 public: 00099 enum LOC_PARTS { 00100 LOC_POS_PART = 0, 00101 LOC_ORIENT_PART = 1, 00102 LOC_BOUNDS_PART = 2, 00103 LOC_MESH_PART = 3, 00104 LOC_PHYSICS_PART = 4, 00105 LOC_IS_AGG_PART = 5, 00106 LOC_PARENT_PART = 6, 00107 LOC_NUM_PART = 7 00108 }; 00109 00110 SequencedPresenceProperties() 00111 { 00112 reset(); 00113 } 00114 virtual ~SequencedPresenceProperties() {} 00115 00116 uint64 getUpdateSeqNo(LOC_PARTS whichPart) const { 00117 if (whichPart >= LOC_NUM_PART) 00118 { 00119 SILOG(proxyobject, error, "Error in getUpdateSeqNo of proxy. Requesting an update sequence number for a field that does not exist. Returning 0"); 00120 return 0; 00121 } 00122 return mUpdateSeqno[whichPart]; 00123 } 00124 00125 bool setLocation(const TimedMotionVector3f& reqloc, uint64 seqno) { 00126 if (seqno < mUpdateSeqno[LOC_POS_PART]) 00127 return false; 00128 00129 mUpdateSeqno[LOC_POS_PART] = seqno; 00130 mLoc = reqloc; 00131 return true; 00132 } 00133 bool setLocation(const TimedMotionVector3f& l) { return PresenceProperties::setLocation(l); } 00134 00135 bool setOrientation(const TimedMotionQuaternion& reqorient, uint64 seqno) { 00136 if (seqno < mUpdateSeqno[LOC_ORIENT_PART]) return false; 00137 00138 mUpdateSeqno[LOC_ORIENT_PART] = seqno; 00139 mOrientation = reqorient; 00140 return true; 00141 } 00142 bool setOrientation(const TimedMotionQuaternion& o) { return PresenceProperties::setOrientation(o); } 00143 00144 bool setBounds(const AggregateBoundingInfo& b, uint64 seqno) { 00145 if (seqno < mUpdateSeqno[LOC_BOUNDS_PART]) 00146 return false; 00147 00148 mUpdateSeqno[LOC_BOUNDS_PART] = seqno; 00149 mBounds = b; 00150 return true; 00151 } 00152 bool setBounds(const AggregateBoundingInfo& b) { return PresenceProperties::setBounds(b); } 00153 00154 bool setMesh(const Transfer::URI& m, uint64 seqno) { 00155 if (seqno < mUpdateSeqno[LOC_MESH_PART]) 00156 return false; 00157 00158 mUpdateSeqno[LOC_MESH_PART] = seqno; 00159 mMesh = m; 00160 return true; 00161 } 00162 bool setMesh(const Transfer::URI& m) { return PresenceProperties::setMesh(m); } 00163 00164 bool setPhysics(const String& p, uint64 seqno) { 00165 if (seqno < mUpdateSeqno[LOC_PHYSICS_PART]) 00166 return false; 00167 00168 mUpdateSeqno[LOC_PHYSICS_PART] = seqno; 00169 mPhysics = p; 00170 return true; 00171 } 00172 bool setPhysics(const String& p) { return PresenceProperties::setPhysics(p); } 00173 00174 bool setIsAggregate(bool isAgg, uint64 seqno) { 00175 if (seqno < mUpdateSeqno[LOC_IS_AGG_PART]) 00176 return false; 00177 00178 mUpdateSeqno[LOC_IS_AGG_PART] = seqno; 00179 mIsAggregate = isAgg; 00180 return true; 00181 } 00182 bool setIsAggregate(bool isAgg) { return PresenceProperties::setIsAggregate(isAgg); } 00183 00184 00185 bool setParent(const ObjectReference& parent, uint64 seqno) { 00186 if (seqno < mUpdateSeqno[LOC_PARENT_PART]) 00187 return false; 00188 00189 mUpdateSeqno[LOC_PARENT_PART] = seqno; 00190 mParent = parent; 00191 return true; 00192 } 00193 bool setParent(const ObjectReference& parent) { return PresenceProperties::setParent(parent); } 00194 00195 00196 void reset() { 00197 memset(mUpdateSeqno, 0, LOC_NUM_PART * sizeof(uint64)); 00198 } 00199 00200 uint64 maxSeqNo() const { 00201 uint64 maxseqno = mUpdateSeqno[0]; 00202 for(uint32 i = 1; i < LOC_NUM_PART; i++) 00203 maxseqno = std::max(maxseqno, mUpdateSeqno[i]); 00204 return maxseqno; 00205 } 00206 private: 00207 uint64 mUpdateSeqno[LOC_NUM_PART]; 00208 }; 00209 typedef std::tr1::shared_ptr<SequencedPresenceProperties> SequencedPresencePropertiesPtr; 00210 00211 } // namespace Sirikata 00212 00213 #endif //_SIRIKATA_LIBCORE_PRESENCE_PROPERTIES_HPP_