Sirikata
|
00001 /* Sirikata Graphical Object Host 00002 * Entity.hpp 00003 * 00004 * Copyright (c) 2009, Patrick Reiter Horn 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_OGRE_PROXY_ENTITY_HPP__ 00034 #define SIRIKATA_OGRE_PROXY_ENTITY_HPP__ 00035 00036 #include <sirikata/ogre/Entity.hpp> 00037 #include <sirikata/proxyobject/ProxyObject.hpp> 00038 #include <sirikata/core/network/IOTimer.hpp> 00039 00040 namespace Sirikata { 00041 namespace Graphics { 00042 00043 class OgreSystem; 00044 class ProxyEntity; 00045 00046 class ProxyEntityListener { 00047 public: 00048 virtual ~ProxyEntityListener(); 00049 virtual void proxyEntityDestroyed(ProxyEntity*) {}; 00050 }; 00051 00053 class ProxyEntity 00054 : public Sirikata::Graphics::Entity, 00055 public PositionListener, 00056 public ProxyObjectListener, 00057 public MeshListener, 00058 public Provider<ProxyEntityListener*> 00059 { 00060 protected: 00061 ProxyObjectPtr mProxy; 00062 bool mActive; // Whether we've added ourselves to the download planner 00063 Network::IOTimerPtr mDestroyTimer; 00064 // Indicates if the parent cares about this ProxyEntity anymore, 00065 // i.e. if it can self destruct if it determines it's no longer 00066 // needed for rendering. 00067 bool mCanDestroy; 00068 00069 void handleDestroyTimeout(); 00070 00071 // Invoked when some condition switches to making it possible that 00072 // deletion could occur. If all conditions are satisfied, this 00073 // causes self destruction. NOTE: This *must not* be followed by 00074 // any other operations since it may result in the destruction of 00075 // this object. 00076 void tryDelete(); 00077 public: 00083 ProxyEntity(OgreRenderer *scene, const ProxyObjectPtr &ppo); 00084 virtual ~ProxyEntity(); 00085 00086 void initializeToProxy(const ProxyObjectPtr &ppo); 00087 00088 // Entity Overrides 00089 virtual BoundingSphere3f bounds(); 00090 virtual void tick(const Time& t, const Duration& deltaTime); 00091 virtual bool isDynamic() const; 00092 virtual bool isMobile() const; 00093 00094 ProxyObject &getProxy() const { 00095 return *mProxy; 00096 } 00097 const ProxyObjectPtr &getProxyPtr() const { 00098 return mProxy; 00099 } 00100 00101 00102 static ProxyEntity *fromMovableObject(Ogre::MovableObject *obj); 00103 00104 // PositionListener 00105 virtual void updateLocation( 00106 ProxyObjectPtr proxy, const TimedMotionVector3f &newLocation, 00107 const TimedMotionQuaternion& newOrient, const AggregateBoundingInfo& newBounds, 00108 const SpaceObjectReference& sporef); 00109 00110 // ProxyObjectListener 00111 virtual void validated(ProxyObjectPtr proxy); 00112 virtual void invalidated(ProxyObjectPtr proxy, bool permanent); 00113 virtual void destroyed(ProxyObjectPtr proxy); 00114 00115 // interface from MeshListener 00116 virtual void onSetMesh (ProxyObjectPtr proxy, Transfer::URI const& newMesh,const SpaceObjectReference& sporef); 00117 virtual void onSetScale (ProxyObjectPtr proxy, float32 newScale ,const SpaceObjectReference& sporef); 00118 virtual void onSetIsAggregate (ProxyObjectPtr proxy, bool isAgg,const SpaceObjectReference& sporef); 00119 00120 void extrapolateLocation(TemporalValue<Location>::Time current); 00121 00122 private: 00123 00124 void iUpdateLocation( 00125 ProxyObjectPtr proxy, const TimedMotionVector3f &newLocation, 00126 const TimedMotionQuaternion& newOrient, 00127 const AggregateBoundingInfo& newBounds, 00128 const SpaceObjectReference& sporef, Liveness::Token lt); 00129 00130 // ProxyObjectListener 00131 void iValidated(ProxyObjectPtr proxy,Liveness::Token lt); 00132 void iInvalidated(ProxyObjectPtr proxy, bool permanent,Liveness::Token lt); 00133 void iDestroyed(ProxyObjectPtr proxy,Liveness::Token lt); 00134 00135 // interface from MeshListener 00136 void iOnSetMesh ( 00137 ProxyObjectPtr proxy, Transfer::URI const& newMesh, 00138 const SpaceObjectReference& sporef,Liveness::Token lt); 00139 00140 void iOnSetScale ( 00141 ProxyObjectPtr proxy, float32 newScale, 00142 const SpaceObjectReference& sporef,Liveness::Token lt); 00143 00144 void iOnSetIsAggregate ( 00145 ProxyObjectPtr proxy, bool isAgg, 00146 const SpaceObjectReference& sporef, Liveness::Token lt); 00147 00148 void iHandleDestroyTimeout(Liveness::Token lt); 00149 00150 }; 00151 typedef std::tr1::shared_ptr<Entity> EntityPtr; 00152 00153 } 00154 } 00155 00156 #endif //SIRIKATA_OGRE_PROXY_ENTITY_HPP__