/** * Returns this 2D pose relative to the global (null) coordinate system. */ self getGlobalPose() const { if(!Parent.expired()) { self result = Parent.lock()->getGlobalPose(); result.Position += result.Rotation * Position; result.Rotation *= Rotation; return result; } else return *this; };
static CDisplayPtr GetGlobalDisplay() { static weak_ptr<CDisplay> display_global; CDisplayPtr display(display_global.lock()); if(display) { if(display->lost()) { CLog::Log(LOGERROR, "VAAPI - vaapi display is in lost state"); display.reset(); } return display; } VADisplay disp; disp = vaGetDisplayGLX(g_Windowing.GetDisplay()); int major_version, minor_version; VAStatus res = vaInitialize(disp, &major_version, &minor_version); CLog::Log(LOGDEBUG, "VAAPI - initialize version %d.%d", major_version, minor_version); if(res != VA_STATUS_SUCCESS) { CLog::Log(LOGERROR, "VAAPI - unable to initialize display %d - %s", res, vaErrorStr(res)); return display; } const char* vendor = vaQueryVendorString(disp); CLog::Log(LOGDEBUG, "VAAPI - vendor: %s", vendor); bool deinterlace = true; int major, minor, micro; bool support_4k = true; if(sscanf(vendor, "Intel i965 driver - %d.%d.%d", &major, &minor, µ) == 3) { /* older version will crash and burn */ if(compare_version(major, minor, micro, 1, 0, 17) < 0) { CLog::Log(LOGDEBUG, "VAAPI - deinterlace not support on this intel driver version"); deinterlace = false; } // do the same check for 4K decoding: version < 1.2.0 (stable) and 1.0.21 (staging) // cannot decode 4K and will crash the GPU if((compare_version(major, minor, micro, 1, 2, 0) < 0) && (compare_version(major, minor, micro, 1, 0, 21) < 0)) { support_4k = false; } } display = CDisplayPtr(new CDisplay(disp, deinterlace)); display->support_4k(support_4k); display_global = display; return display; }
//check if it's the right place to set square if so ,set it void Tetris::SquareSetCheck(const TETRIS_TYPE t_type,weak_ptr<Square> t_wsquare) { if(!t_wsquare.expired()){ shared_ptr<Square> t_ssquare = t_wsquare.lock(); if(t_ssquare->ConflictCheck(t_type) == true) { t_ssquare->SetSquare(t_type); } }else{ LogWriter::me->WriteLog("square expired in SquareSetCheck"); } }
static bool __cdecl alphabeticalG3DLast(weak_ptr<Texture> const& elem1, weak_ptr<Texture> const& elem2) { const shared_ptr<Texture>& elem1Locked = elem1.lock(); const shared_ptr<Texture>& elem2Locked = elem2.lock(); if (isNull(elem1Locked)) { return true; } else if (isNull(elem2Locked)) { return false; } else { return alphabeticalIgnoringCaseG3DLastLessThan(elem1Locked->name(), elem2Locked->name()); } }
static bool __cdecl alphabeticalTextureLT(weak_ptr<Texture> const& elem1, weak_ptr<Texture> const& elem2) { const shared_ptr<Texture>& elem1Locked = elem1.lock(); const shared_ptr<Texture>& elem2Locked = elem2.lock(); if (isNull(elem1Locked)) { return true; } else if (isNull(elem2Locked)) { return false; } else { return elem1Locked->name() < elem2Locked->name(); } }
/** * Returns true if P is part of the parent chain from this pose. */ bool isParentPose(const shared_ptr< const self >& P) const { if(Parent.expired()) { if(P) return true; else return false; } else { if(P) return false; else if(P == Parent.lock()) return true; else return Parent.lock()->isParentPose(P); }; };
/** * Returns this 2D pose relative to pose P. */ self getPoseRelativeTo(const shared_ptr< const self >& P) const { if(!P) return getGlobalPose(); if(isParentPose(P)) { if(Parent.lock() == P) return *this; else return Parent.lock()->getPoseRelativeTo(P) * (*this); } else if(P->isParentPose( rtti::rk_static_ptr_cast< const self >(mThis))) return ~(P->getPoseRelativeTo( rtti::rk_static_ptr_cast< const self >(mThis))); else if(Parent.expired()) return (~(P->getGlobalPose())) * (*this); else return Parent.lock()->getPoseRelativeTo(P) * (*this); };
void VRPhysicsManager::updatePhysics( weak_ptr<VRThread> wthread) { if (dynamicsWorld == 0) return; long long dt,t0,t1,t2,t3; auto thread = wthread.lock(); if (thread == 0) return; t0 = thread->t_last; t1 = getTime(); thread->t_last = t1; dt = t1-t0; { MLock lock(mtx); prepareObjects(); for (auto f : updateFktsPre) (*f)(0); dynamicsWorld->stepSimulation(1e-6*dt, 30); for (auto f : updateFktsPost) (*f)(0); } t2 = getTime(); dt = t2-t1; //sleep up to 500 fps if (dt < PHYSICS_THREAD_TIMESTEP_MS * 1000) this_thread::sleep_for(chrono::microseconds(PHYSICS_THREAD_TIMESTEP_MS * 1000 -dt)); t3 = getTime(); MLock lock(mtx); fps = 1e6/(t3-t1); }
shared_ptr<Type> MakeStrongPtr(weak_ptr<Type> pWeakPtr) { if (!pWeakPtr.expired()) return shared_ptr<Type>(pWeakPtr); else return shared_ptr<Type>(); }
void PropertyList::Init(weak_ptr<Leaf> leaf, wxListCtrl* ctrList) { mLeaf.reset(); mCtrList = 0; if ( (leaf.expired()) || (ctrList == 0) ) { return; } mLeaf = leaf; mCtrList = ctrList; shared_ptr<Property> property = wxGetApp().GetProperty(); if (property.get() != 0) { property->GetClassList(mLeaf.lock(), mClassList); } mCtrList->ClearAll(); mCtrList->InsertColumn(0, _T("name"), wxLIST_FORMAT_LEFT, 120); mCtrList->InsertColumn(1, _T("value"), wxLIST_FORMAT_LEFT, 600); }
void MyFather() { auto father = father_.lock(); if (father) cout << father->name_ << " is MyFather\n"; else cout << "father is gone\n"; }
uint32_t BusinessPool::DelTermSession(weak_ptr<TermSession> ts) { shared_ptr<TermSession> sp_ts(ts.lock()); if (!sp_ts) { logger_.Warn("[删除终端会话]******对应的终端会话不存在******"); return 0; } CASession *cs = sp_ts->ca_session_; if (cs == NULL) { logger_.Warn("[删除终端会话]******对应的CA会话不存在******"); return 0; } cs->Remove(sp_ts->Id()); logger_.Warn("[删除终端会话][CAId:" SFMT64U "][TSId:0x" SFMT64X "]", cs->Id(), sp_ts->Id()); CASessionMgr *cs_mgr = pool_relation_ca_session_mgr_[getIdByTermSessionId(sp_ts->Id())]; cs_mgr->DetachTermSessionInfo(sp_ts->Id()); uint32_t ret = cs->termCnt(); //if no terminal session in ca session, // remove ca session. if (cs->termCnt() == 0) { logger_.Warn("[删除终端会话][CAId:" SFMT64U "][TSId:0x" SFMT64X "],CA会话中无终端,删除CA会话", cs->Id(), sp_ts->Id()); CASessionMgr *cs_mgr = pool_relation_ca_session_mgr_[getIdByTermSessionId(sp_ts->Id())]; cs_mgr->Detach(cs->Id()); cs_mgr->Destory(cs); } return ret; }
void RemoveFromParent() { if( auto p = Parent.lock() ) { p->RemoveChild( shared_from_this() ); } }
//read input key to move square void Tetris::SquareCtrl(const TETRIS_TYPE t_type,weak_ptr<Square> t_wsquare) { if(!t_wsquare.expired()){ shared_ptr<Square> t_ssquare = t_wsquare.lock(); KeyboardUpdate(); //down button is pressed if(((KeyboardGet(KEY_INPUT_DOWN) > 0)&&(t_type == TETRIS_UP))|| ((KeyboardGet(KEY_INPUT_UP) > 0)&&(t_type == TETRIS_DOWN))|| ((KeyboardGet(KEY_INPUT_RIGHT) > 0)&&(t_type == TETRIS_RIGHT))|| ((KeyboardGet(KEY_INPUT_LEFT) > 0)&&(t_type == TETRIS_LEFT)) ){ t_ssquare->Move(kGODOWN,t_type); } //left button is pressed else if(((KeyboardGet(KEY_INPUT_LEFT) > 0)&&(t_type == TETRIS_UP))|| ((KeyboardGet(KEY_INPUT_RIGHT) > 0)&&(t_type == TETRIS_DOWN))|| ((KeyboardGet(KEY_INPUT_DOWN) > 0)&&(t_type == TETRIS_LEFT))|| ((KeyboardGet(KEY_INPUT_UP) > 0)&&(t_type == TETRIS_RIGHT)) ){ t_ssquare->Move(kGOLEFT,t_type); } //right button is pressed else if(((KeyboardGet(KEY_INPUT_RIGHT) > 0)&&(t_type == TETRIS_UP))|| ((KeyboardGet(KEY_INPUT_LEFT) > 0)&&(t_type == TETRIS_DOWN))|| ((KeyboardGet(KEY_INPUT_UP) > 0)&&(t_type == TETRIS_LEFT))|| ((KeyboardGet(KEY_INPUT_DOWN) > 0)&&(t_type == TETRIS_RIGHT)) ){ t_ssquare->Move(kGORIGHT,t_type); } else if(((KeyboardGet(KEY_INPUT_UP) > 0)&&(t_type == TETRIS_UP))|| ((KeyboardGet(KEY_INPUT_DOWN) > 0)&&(t_type == TETRIS_DOWN))|| ((KeyboardGet(KEY_INPUT_RIGHT) > 0)&&(t_type == TETRIS_LEFT))|| ((KeyboardGet(KEY_INPUT_LEFT) > 0)&&(t_type == TETRIS_RIGHT)) ){ t_ssquare->Turn(t_type); }else if(KeyboardGet(KEY_INPUT_SPACE ) > 0){ CtrlBoardChangine(t_type); } else if (KeyboardGet(KEY_INPUT_Z) == 1){ SpeedUp(); } else if (KeyboardGet(KEY_INPUT_X) == 1){ SpeedDown(); } } }
void load( Archive& archive, int mode, const char* name, weak_ptr<Type>& object ) { SWEET_ASSERT( mode == MODE_REFERENCE ); SWEET_ASSERT( object.lock() == ptr<Type>() ); ObjectGuard<Archive> guard( archive, name, 0, MODE_REFERENCE ); archive.reference( archive.get_address(), reinterpret_cast<void**>(&object), &resolver<weak_ptr<Type> >::resolve ); }
void TimeOutTimer::Add(weak_ptr<TermSession> ts) { shared_ptr<TermSession> sp_ts(ts.lock()); if (sp_ts) { MutexLock lock(mutex_); termsession_list_[sp_ts->Id()] = sp_ts; } }
void DirectusMaterial::Reflect(weak_ptr<GameObject> gameobject) { m_inspectedMaterial = weak_ptr<Material>(); // Catch the evil case if (gameobject.expired()) { this->hide(); return; } MeshRenderer* meshRenderer = gameobject.lock()->GetComponent<MeshRenderer>().lock().get(); if (!meshRenderer) { this->hide(); return; } m_inspectedMaterial = meshRenderer->GetMaterial(); if (m_inspectedMaterial.expired()) { this->hide(); return; } // Do the actual reflection ReflectName(); ReflectShader(); ReflectAlbedo(); ReflectRoughness(); ReflectMetallic(); ReflectNormal(); ReflectHeight(); ReflectOcclusion(); ReflectEmission(); ReflectMask(); ReflectTiling(); ReflectOffset(); SetPropertiesVisible(m_inspectedMaterial.lock()->IsEditable() ? true : false); // Make this widget visible this->show(); }
inline shared_ptr<vector<string>> StrBlobPtr::check(size_t i, const string &msg) const { auto ret = wptr.lock(); if (!ret) throw runtime_error("unbound StrBlobPtr"); if (i >= ret->size()) throw out_of_range(msg); return ret; }
shared_ptr<vector<string>> const_str_blob_ptr::check(vector<string>::size_type i,const string &msg)const { shared_ptr<vector<string>> ret = wptr.lock(); if(!ret) throw runtime_error("unbound const_str_blob_ptr"); if(i > ret->size()) throw out_of_range(msg); return ret; }
void useResource(weak_ptr<Simple>& weakSimple) { auto resource = weakSimple.lock(); if (resource) { cout << "Resource still alive." << endl; } else { cout << "Resource has been freed!" << endl; } }
void show() { shared_ptr<Team> t = team.lock(); if (!t) { cout << "Team not found" << endl; return; } cout << name << " in " << t->name << endl; }
static void decrease(weak_ptr<Battalion>& battalion, Soldier *soldier) { shared_ptr<Battalion> sp = battalion.lock(); if (sp) { cout << soldier->getName() << "已经壮烈牺牲了!" << endl; sp->reduce(); } }
/** * Extracts the next timestamp from a Timer. * * Note: Caller must hold l_Mutex. * * @param wtimer Weak pointer to the timer. * @returns The next timestamp */ double operator()(const weak_ptr<Timer>& wtimer) { Timer::Ptr timer = wtimer.lock(); if (!timer) return 0; return timer->m_Next; }
void AccessStrategy::afterRtoTimeout(weak_ptr<pit::Entry> pitWeak, weak_ptr<fib::Entry> fibWeak, FaceId inFace, FaceId firstOutFace) { shared_ptr<pit::Entry> pitEntry = pitWeak.lock(); BOOST_ASSERT(pitEntry != nullptr); // pitEntry can't become nullptr, because RTO timer should be cancelled upon pitEntry destruction shared_ptr<fib::Entry> fibEntry = fibWeak.lock(); if (fibEntry == nullptr) { NFD_LOG_DEBUG(pitEntry->getInterest() << " timeoutFrom " << firstOutFace << " fib-gone"); return; } NFD_LOG_DEBUG(pitEntry->getInterest() << " timeoutFrom " << firstOutFace << " multicast-except " << inFace << ',' << firstOutFace); this->multicast(pitEntry, fibEntry, {inFace, firstOutFace}); }
/** * The entry point of the thread that handles the client connection. */ void threadMain(const weak_ptr<Client> self) { vector<string> args; try { while (!this_thread::interruption_requested()) { try { if (!channel.read(args)) { // Client closed connection. break; } } catch (const SystemException &e) { P_TRACE(2, "Exception in ApplicationPoolServer client thread during " "reading of a message: " << e.what()); break; } P_TRACE(4, "Client " << this << ": received message: " << toString(args)); if (args[0] == "get" && args.size() == 7) { processGet(args); } else if (args[0] == "close" && args.size() == 2) { processClose(args); } else if (args[0] == "clear" && args.size() == 1) { processClear(args); } else if (args[0] == "setMaxIdleTime" && args.size() == 2) { processSetMaxIdleTime(args); } else if (args[0] == "setMax" && args.size() == 2) { processSetMax(args); } else if (args[0] == "getActive" && args.size() == 1) { processGetActive(args); } else if (args[0] == "getCount" && args.size() == 1) { processGetCount(args); } else if (args[0] == "setMaxPerApp" && args.size() == 2) { processSetMaxPerApp(atoi(args[1])); } else if (args[0] == "getSpawnServerPid" && args.size() == 1) { processGetSpawnServerPid(args); } else { processUnknownMessage(args); break; } args.clear(); } } catch (const boost::thread_interrupted &) { P_TRACE(2, "Client thread " << this << " interrupted."); } catch (const exception &e) { P_TRACE(2, "Uncaught exception in ApplicationPoolServer client thread:\n" << " message: " << toString(args) << "\n" << " exception: " << e.what()); } mutex::scoped_lock l(server.lock); ClientPtr myself(self.lock()); if (myself != NULL) { server.clients.erase(myself); } }
void ofxWidget::setFocus(bool focus_) { if (focus_ == isActivated()) return; // callback previous widget telling it that it // loses focus if (auto previousElementInFocus = sFocusedWidget.lock()) if (previousElementInFocus->onFocusLeave) previousElementInFocus->onFocusLeave(); sFocusedWidget = mThis; // callback this widget telling it that it // receives focus if (auto nextFocusedWidget = sFocusedWidget.lock()) if (nextFocusedWidget->onFocusEnter) nextFocusedWidget->onFocusEnter(); }
void choice::set_selected(weak_ptr<choice_item> value) { auto old_selected = m_selected.lock(); auto new_selected = value.lock(); if (value.lock() != old_selected) { if (old_selected) old_selected->set_pressed(false); m_selected = value; if (new_selected) new_selected->set_pressed(true); auto s = sink().lock(); if (s) s->action(selected()); } }
// ---------------------------------------------------------------------- // static method - called once on the widget having the focus bool ofxWidget::keyEvent(ofKeyEventArgs& args_) { if (sAllWidgets.empty()) return false; if (auto w = sFocusedWidget.lock()) { if (w->onKey) w->onKey(args_); } return false; }
void kinematicFrame::SetParent(weak_ptr<Leaf> parent) { shared_ptr<SimSpark> spark = wxGetApp().GetSpark(); if (spark.get() == 0) { return; } if (parent.expired()) { mParent = Leaf::CachedPath<zeitgeist::Leaf>(); } else { std::string path = parent.lock()->GetFullPath(); mParent.SetKey(Core::CacheKey(spark->GetCore()->GetRoot(), path)); } UpdateCached(); }
weak_ptr<TTrieNode> TStaticTemplateMatcher::suf_link_move(weak_ptr<TTrieNode> node) { if (node.lock()->suf_link_.lock()) return node.lock()->suf_link_; weak_ptr<TTrieNode> prev = node.lock()->parentnode_; while (prev.lock() != getroot() && !suf_link_move(prev).lock()->isEdge(node.lock()->parentsymbol_)) prev = suf_link_move(prev); node.lock()->suf_link_ = moveto(suf_link_move(prev),node.lock()->parentsymbol_); return node.lock()->suf_link_; }