void ProxyObject::setParent(const ProxyObjectPtr &parent, TemporalValue<Location>::Time timeStamp, const Location &absLocation, const Location &relLocation) { if (!parent) { unsetParent(timeStamp, absLocation); return; } ProxyObjectPtr oldParent (getParentProxy()); if (oldParent) { oldParent->ProxyObjectProvider::removeListener(this); } parent->ProxyObjectProvider::addListener(this); // Using now() should best allow a linear extrapolation to work. Location lastPosition(globalLocation(timeStamp)); mParentId = parent->getObjectReference(); Location newparentLastGlobal(parent->globalLocation(timeStamp)); /* std::cout<<" Last parent global "<<std::endl<<newparentLastGlobal<<std::endl<< "global loc = "<<std::endl<<lastPosition<< std::endl<<"local loc = "<<std::endl<<lastPosition.toLocal(newparentLastGlobal)<<std::endl; */ mLocation.resetValue(timeStamp, lastPosition.toLocal(newparentLastGlobal)); mLocation.updateValue(timeStamp, relLocation); PositionProvider::notify(&PositionListener::setParent, parent, timeStamp, absLocation, relLocation); }
void JSAggregateVisibleData::updateFrom(ProxyObjectPtr proxy) { Mutex::scoped_lock locker (childMutex); if (mChildren.find(proxy->getObjectReference()) == mChildren.end()) { // Note that we currently pass in NULL so we don't get // notifications. We'd only get them upon clearing our children list in // the destructor anyway. mChildren[proxy->getObjectReference()] = JSVisibleDataPtr(new JSProxyVisibleData(NULL, proxy)); } mBest = proxy->getObjectReference(); }
void ProxyManager::resetAllProxies() { PROXYMAN_SERIALIZED(); for (ProxyMap::const_iterator iter = mProxyMap.begin(); iter != mProxyMap.end(); ++iter) { // Just try locking the weak pointer, if that doesn't work nothing // will. Note that we want to catch *everything*, even ones we don't // keep a strong ref to. This ensures that we if we reuse a proxy later // via the weak reference, we won't forget to reset it. Since resetting // only affects seqnos, this shouldn't have any adverse affects on those // still holding a reference. ProxyObjectPtr proxy = iter->second.wptr.lock(); if (proxy) proxy->reset(); } }
double SAngleDownloadPlanner::calculatePriority(ProxyObjectPtr proxy) { if (camera == NULL || !proxy) return 0; float radius = proxy->bounds().radius(); Vector3d objLoc(proxy->location().position()); Vector3d cameraLoc = camera->getPosition(); if (withinBound(radius, objLoc, cameraLoc)) return 0.99; Vector3d diff = cameraLoc - objLoc; SolidAngle sa = SolidAngle::fromCenterRadius((Vector3f)diff, radius); float priority = (sa.asFloat())/(SolidAngle::Max.asFloat()); return (double)priority; }
void ProxyEntity::iValidated(ProxyObjectPtr ptr,Liveness::Token lt) { if (!lt) return; assert(ptr == mProxy); SILOG(ogre, detailed, "Validating ProxyEntity " << ptr->getObjectReference().toString()); mCanDestroy = false; mDestroyTimer->cancel(); // Because this could be a new ProxyEntity, created after a bunch // of updates have been received by the ProxyObject, we need to // refresh its important data iUpdateLocation( mProxy, mProxy->location(), mProxy->orientation(), mProxy->bounds(), SpaceObjectReference::null(),lt ); if (!mActive) { getScene()->downloadPlanner()->addNewObject(mProxy, this); mActive = true; } }
void ObjectHostProxyManager::createViewedObject(const ProxyObjectPtr &newObj, QueryTracker*viewer) { std::pair<ProxyMap::iterator, bool> result = mProxyMap.insert( ProxyMap::value_type(newObj->getObjectReference().object(), newObj)); if (result.second==true) { notify(&ProxyCreationListener::onCreateProxy,newObj); } result.first->second.viewers.insert(viewer); }
ProxyEntity::ProxyEntity(OgreRenderer *scene, const ProxyObjectPtr &ppo) : Entity(scene, ppo->getObjectReference().toString()), mProxy() { mDestroyTimer = Network::IOTimer::create( mScene->context()->ioService, std::tr1::bind(&ProxyEntity::handleDestroyTimeout, this) ); }
void ProxyEntity::initializeToProxy(const ProxyObjectPtr &ppo) { assert( ppo ); assert( !mProxy || (mProxy->getObjectReference() == ppo->getObjectReference()) ); setIsAggregate(ppo->isAggregate()); /** FIXME: ADDING AND REMOVING LISTENERS COULD INVALIDATE ITERATORS */ if (mProxy) { mProxy->ProxyObjectProvider::removeListener(this); mProxy->PositionProvider::removeListener(this); mProxy->MeshProvider::removeListener(this); } mProxy = ppo; mProxy->ProxyObjectProvider::addListener(this); mProxy->PositionProvider::addListener(this); mProxy->MeshProvider::addListener(this); checkDynamic(); }
void Entity::setParent(const ProxyObjectPtr &parent, Time ti, const Location &absLocation, const Location &relLocation) { Entity *parentEntity = mScene->getEntity(parent); if (!parentEntity) { SILOG(ogre,fatal,"No Entity has been created for proxy " << parent->getObjectReference() << " which is to become parent of "<<getProxy().getObjectReference()); return; } addToScene(parentEntity->mSceneNode); }
void HostedObject::processLocationUpdate( const SpaceID& space, ProxyObjectPtr proxy_obj, bool predictive, TimedMotionVector3f* loc, uint64 loc_seqno, TimedMotionQuaternion* orient, uint64 orient_seqno, BoundingSphere3f* bounds, uint64 bounds_seqno, String* mesh, uint64 mesh_seqno, String* phy, uint64 phy_seqno ) { if (loc) proxy_obj->setLocation(*loc, loc_seqno); if (orient) proxy_obj->setOrientation(*orient, orient_seqno); if (bounds) proxy_obj->setBounds(*bounds, bounds_seqno); if (mesh) proxy_obj->setMesh(Transfer::URI(*mesh), mesh_seqno); if (phy && *phy != "") proxy_obj->setPhysics(*phy, phy_seqno); }
void ProxyEntity::initializeToProxy(const ProxyObjectPtr &ppo) { assert( ppo ); assert( !mProxy || (mProxy->getObjectReference() == ppo->getObjectReference()) ); if (mProxy) { mProxy->ProxyObjectProvider::removeListener(this); mProxy->PositionProvider::removeListener(this); mProxy->MeshProvider::removeListener(this); } mProxy = ppo; mProxy->ProxyObjectProvider::addListener(this); mProxy->PositionProvider::addListener(this); mProxy->MeshProvider::addListener(this); checkDynamic(); }
void ProxyManager::destroyObject(const ProxyObjectPtr &delObj) { PROXYMAN_SERIALIZED(); ProxyMap::iterator iter = mProxyMap.find(delObj->getObjectReference().object()); if (iter != mProxyMap.end()) { iter->second.ptr->destroy(); notify(&ProxyCreationListener::onDestroyProxy,iter->second.ptr); // Here we only erase the strong reference, keeping the weak one so we // can recover it if its still in use and we get a re-addition. Be // careful not to use the iterator after this since this may trigger // destruction of the object which will call proxyDeleted and invalidate // it! iter->second.ptr.reset(); } }
void ProxyObject::setParent(const ProxyObjectPtr &parent, TemporalValue<Location>::Time timeStamp) { if (!parent) { unsetParent(timeStamp); return; } Location globalParent (parent->globalLocation(timeStamp)); Location globalLoc (globalLocation(timeStamp)); // std::cout << "Extrapolated = "<<extrapolateLocation(timeStamp)<<std::endl; Location localLoc (globalLoc.toLocal(globalParent)); /* std::cout<<" Setting parent "<<std::endl<<globalParent<<std::endl<< "global loc = "<<std::endl<<globalLoc<< std::endl<<"local loc = "<<std::endl<<localLoc<<std::endl; */ setParent(parent, timeStamp, globalLoc, localLoc); }
void ProxyEntity::iInvalidated(ProxyObjectPtr ptr, bool permanent,Liveness::Token lt) { if (!lt) return; assert(ptr == mProxy); SILOG(ogre, detailed, "Invalidating ProxyEntity " << ptr->getObjectReference().toString()); if (!mActive) return; // If the the object really disconnected, it'll be marked as a permanent // removal. If it just left the result set then it should still be in the // world and shouldn't hurt to leave it around for awhile, and we'll get // less flickering if we try to mask an removal/addition pair due to quick // changes/data structure rearrangement by the space server. if (permanent) iHandleDestroyTimeout(lt); else mDestroyTimer->wait(Duration::seconds(15)); }
ProxyObjectPtr ProxyManager::createObject( const SpaceObjectReference& id, const TimedMotionVector3f& tmv, const TimedMotionQuaternion& tmq, const AggregateBoundingInfo& bs, const Transfer::URI& meshuri, const String& phy, bool isAggregate, uint64 seqNo ) { PROXYMAN_SERIALIZED(); ProxyObjectPtr newObj; // Try to reuse an existing object, even if we only have a valid // weak pointer to it. assert(id.space() == mID.space()); ProxyMap::iterator iter = mProxyMap.find(id.object()); if (iter != mProxyMap.end()) { // From strong ref newObj = iter->second.ptr; if (!newObj) { // From weak ref newObj = iter->second.wptr.lock(); // And either update the strong ref or clear out the entry // if its not even valid anymore. if (newObj) iter->second.ptr = newObj; else mProxyMap.erase(iter); } } // If we couldn't get a valid existing copy, create and insert a // new one. if (!newObj) { newObj = ProxyObject::construct(getSharedPtr(), id); std::pair<ProxyMap::iterator, bool> result = mProxyMap.insert( ProxyMap::value_type( newObj->getObjectReference().object(), ProxyData(newObj) ) ); iter = result.first; } assert(newObj); assert(newObj->getObjectReference() == id); assert(newObj->getOwner().get() == this); // This makes things simpler elsewhere: For new objects, we ensure // all the values are set properly so that when the notification // happens below, the proxy passed to listeners (for // onCreateProxy) will be completely setup, making it valid for // use. We don't need this for old ProxyObjects since they were // already initialized. The seqNo of 0 only updates something if it wasn't // set yet. newObj->setLocation(tmv, 0); newObj->setOrientation(tmq, 0); newObj->setBounds(bs, 0); if(meshuri) newObj->setMesh(meshuri, 0); if(phy.size() > 0) newObj->setPhysics(phy, 0); newObj->setIsAggregate(isAggregate, 0); // Notification of the proxy will have already occured, but // updates via, e.g., PositionListener or MeshListener, will go // out here, so the potentially invalid initial data automatically // filled when the object was created by createObject() shouldn't // matter. newObj->setLocation(tmv, seqNo); newObj->setOrientation(tmq, seqNo); newObj->setBounds(bs, seqNo); if(meshuri) newObj->setMesh(meshuri, seqNo); if(phy.size() > 0) newObj->setPhysics(phy, seqNo); newObj->setIsAggregate(isAggregate, seqNo); // Notification has to happen either way notify(&ProxyCreationListener::onCreateProxy, newObj); return newObj; }
void OrphanLocUpdateManager::addUpdateFromExisting(ProxyObjectPtr proxyPtr) { addUpdateFromExisting( proxyPtr->getObjectReference(), *(dynamic_cast<SequencedPresenceProperties*>(proxyPtr.get())) ); }
void ObjectHostProxyManager::destroyObject(const ProxyObjectPtr &newObj) { destroyViewedObject(newObj->getObjectReference(), 0); }
void PerPresenceData::initializeAs(ProxyObjectPtr proxyobj) { object = proxyobj->getObjectReference().object(); mProxyObject = proxyobj; }
const SpaceObjectReference& id() const { return mProxy->getObjectReference(); }