Sirikata
|
00001 /* Sirikata 00002 * StandardLocationService.hpp 00003 * 00004 * Copyright (c) 2009, Ewen Cheslack-Postava 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions are 00009 * met: 00010 * * Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * * Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in 00014 * the documentation and/or other materials provided with the 00015 * distribution. 00016 * * Neither the name of Sirikata nor the names of its contributors may 00017 * be used to endorse or promote products derived from this software 00018 * without specific prior written permission. 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 00021 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 00022 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00023 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 00024 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00025 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00026 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00027 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00028 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00029 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00030 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 */ 00032 00033 #ifndef _SIRIKATA_STANDARD_LOCATION_SERVICE_HPP_ 00034 #define _SIRIKATA_STANDARD_LOCATION_SERVICE_HPP_ 00035 00036 #include <sirikata/space/LocationService.hpp> 00037 #include <sirikata/core/util/PresenceProperties.hpp> 00038 00039 namespace Sirikata { 00040 00044 class StandardLocationService : public LocationService { 00045 public: 00046 StandardLocationService(SpaceContext* ctx, LocationUpdatePolicy* update_policy); 00047 // FIXME add constructor which can add all the objects being simulated to mLocations 00048 00049 virtual bool contains(const UUID& uuid) const; 00050 bool isLocal(const UUID& uuid) const; 00051 bool isReplica(const UUID& uuid) const { return !isLocal(uuid); } 00052 00053 virtual void service(); 00054 00055 virtual uint64 epoch(const UUID& uuid); 00056 virtual TimedMotionVector3f location(const UUID& uuid); 00057 virtual Vector3f currentPosition(const UUID& uuid); 00058 virtual TimedMotionQuaternion orientation(const UUID& uuid); 00059 virtual Quaternion currentOrientation(const UUID& uuid); 00060 virtual AggregateBoundingInfo bounds(const UUID& uuid); 00061 virtual const String& mesh(const UUID& uuid); 00062 virtual const String& physics(const UUID& uuid); 00063 00064 virtual void addLocalObject(const UUID& uuid, const TimedMotionVector3f& loc, const TimedMotionQuaternion& orient, const AggregateBoundingInfo& bounds, const String& mesh, const String& physics, const String& zernike); 00065 virtual void removeLocalObject(const UUID& uuid); 00066 00067 virtual void addLocalAggregateObject(const UUID& uuid, const TimedMotionVector3f& loc, const TimedMotionQuaternion& orient, const AggregateBoundingInfo& bounds, const String& mesh, const String& physics); 00068 virtual void removeLocalAggregateObject(const UUID& uuid); 00069 virtual void updateLocalAggregateLocation(const UUID& uuid, const TimedMotionVector3f& newval); 00070 virtual void updateLocalAggregateOrientation(const UUID& uuid, const TimedMotionQuaternion& newval); 00071 virtual void updateLocalAggregateBounds(const UUID& uuid, const AggregateBoundingInfo& newval); 00072 virtual void updateLocalAggregateMesh(const UUID& uuid, const String& newval); 00073 virtual void updateLocalAggregatePhysics(const UUID& uuid, const String& newval); 00074 00075 virtual void addReplicaObject(const Time& t, const UUID& uuid, bool agg, const TimedMotionVector3f& loc, const TimedMotionQuaternion& orient, const AggregateBoundingInfo& bounds, const String& mesh, const String& physics, const String& zernike); 00076 virtual void removeReplicaObject(const Time& t, const UUID& uuid); 00077 00078 virtual void receiveMessage(Message* msg); 00079 00080 virtual bool locationUpdate(UUID source, void* buffer, uint32 length); 00081 00082 // Command handlers 00085 virtual void commandProperties(const Command::Command& cmd, Command::Commander* cmdr, Command::CommandID cmdid); 00087 virtual void commandObjectProperties(const Command::Command& cmd, Command::Commander* cmdr, Command::CommandID cmdid); 00088 00089 private: 00090 struct LocationInfo { 00091 // Regular location info that we need to maintain for all objects 00092 SequencedPresenceProperties props; 00093 // NOTE: This is a copy of props.mesh(), which *is not always valid*. It's 00094 // only used for the accessor, when returning by const& since we don't have 00095 // a String version within props. DO NOT use anywhere else. 00096 String mesh_copied_str; 00097 String physics_copied_str; 00098 00099 bool local; 00100 bool aggregate; 00101 }; 00102 typedef std::tr1::unordered_map<UUID, LocationInfo, UUID::Hasher> LocationMap; 00103 00104 LocationMap mLocations; 00105 }; // class StandardLocationService 00106 00107 } // namespace Sirikata 00108 00109 #endif //_SIRIKATA_STANDARD_LOCATION_SERVICE_HPP_