future_status result::wait_until(time_point const& wait_timeout_time, boost::unique_lock<boost::mutex>& lock) const { if(ready(lock)) return future_status::ready; while(!expired() && !(clock_type::now() > wait_timeout_time)) { // note: don't set to wait for 0 ms, it might not timeout if(m_condition.wait_for(lock, boost::chrono::milliseconds(1), boost::bind(&result::ready, this, boost::ref(lock)))) { return future_status::ready; } if(expired() || (clock_type::now() > wait_timeout_time)) break; lock.unlock(); io_runner::poll_one(*m_io_service); lock.lock(); } if(clock_type::now() > wait_timeout_time) return future_status::timeout; BOOST_ASSERT(expired()); m_exception = boost::make_shared<remote_error> (remote_error::timeout, "remote call timeout"); m_ready = true; return future_status::ready; }
int keepalive (Client *c) { int rc = FAILURE; if (c->keepAliveInterval == 0) { rc = SUCCESS; goto exit; } if (expired(&c->ping_timer)) { if (!c->ping_outstanding) { Timer timer; InitTimer (&timer); countdown_ms (&timer, 1000); int len = MQTTSerialize_pingreq (c->buf, c->buf_size); if (len > 0 && (rc = sendPacket(c, len, &timer)) == SUCCESS) // send the ping packet c->ping_outstanding = 1; } } exit: return rc; }
//------------------------------------------------------------------------------ void BaseAssetMan::updateOrphanedAssets(std::chrono::milliseconds absTime) { // Check the first held asset and if it is less than the absolute time, // release it and continue. while (mHeldAssets.empty() == false) { if (mHeldAssets.top()->getAbsTimeHeld() < absTime) mHeldAssets.pop(); else break; } // Iterate over all of the assets and remove expired elements. auto it = mAssets.begin(); while (it != mAssets.end()) { if (it->expired()) { // Remove this element from the list since it has expired. it = mAssets.erase(it); } else { ++it; } } }
void SmartAttributeEditorManager::unbindObservers() { if (!expired(m_document)) { MapDocumentSPtr document = lock(m_document); document->selectionDidChangeNotifier.removeObserver(this, &SmartAttributeEditorManager::selectionDidChange); document->nodesDidChangeNotifier.removeObserver(this, &SmartAttributeEditorManager::nodesDidChange); } }
// STATIC: Removes every object except persistant objects void PhysicsEntityContainer::RemoveEverything() { // Was this initalized if(!PhysicsEntityContainer::verifyInstantiation()) return; // Check if container is already empty auto& objList = PhysicsEntityContainer::_instance->_listOfContainedObjects; if(objList.empty()) return; // Remove everything not flagged as persistant auto back_itr = objList.before_begin(); auto front_itr = objList.begin(); while(front_itr != objList.end()) { // Check for null ptr if(front_itr->expired()) { // Delete the pointer at front_itr front_itr = objList.erase_after(back_itr); } // Check if not persistant else if(!(*front_itr)._Get()->IsPersistant()) { // Delete the pointer at front_itr front_itr = objList.erase_after(back_itr); } // Iterate else { front_itr++; back_itr++; } } }
// Loads without clearing current scene bool GameOverScene::LoadAdditive() { // Load the desired GameObjects here // Find persistant ScoreKeeper and make un-persistant auto scoreKeeper = GameObjectContainer::GetByName("ScoreKeeper"); if(!scoreKeeper.expired()) { scoreKeeper._Get()->SetPersistance(false); } // Make a cube GameObject auto cube = GameObjectContainer::Create(); cube._Get()->AddComponent<ObjectRendererComponent>(); auto renderer = cube._Get()->GetComponent<ObjectRendererComponent>(); renderer._Get()->GetRenderer()._Get()->SetMaterial( MaterialRegistry::GetByName("GameOver") ); // Adjust the camera in front of the cube auto theCamera = Camera::GetInstance(); theCamera._Get()->SetPosition(Vector3(0.0f, 0.0f, 1.0f)); theCamera._Get()->LookAtPoint(Vector3(0.0f, 0.0f, 0.0f)); // Add the functionality for the Game Over screen auto gameOverCtrlr = GameObjectContainer::Create(); gameOverCtrlr._Get()->AddCustomComponent<component::ManageGameOver>(); auto scoreEvaluator = GameObjectContainer::Create(); scoreEvaluator._Get()->AddCustomComponent<component::ScoreEvaluator>(); auto scoreFontRenderer = scoreEvaluator._Get()->GetComponent<FontRendererComponent>()._Get()->GetRenderer(); scoreFontRenderer._Get()->SetPosition(190, 487); return true; }
void DrawableManager::updateBuffer(const std::string & type) { auto & objects = m_drawables[type].objects; std::vector<glm::mat4> modelVec; std::vector<glm::vec4> colorVec; std::vector<glm::vec4> miscVec; modelVec.reserve(objects.size()); colorVec.reserve(objects.size()); miscVec.reserve(objects.size()); auto it = objects.begin(); while (it != objects.end()) { if (it->expired()) { it = objects.erase(it); continue; } modelVec.emplace_back(it->lock()->getModelMatrix()); colorVec.emplace_back(it->lock()->color); miscVec.emplace_back(it->lock()->misc); ++it; } #ifdef LEGACY_MODE m_drawables[type].modelBuffer.bind(GL_UNIFORM_BUFFER); m_drawables[type].modelBuffer.setData( 0, k_modelTypeSize * static_cast<unsigned int>(modelVec.size()), modelVec.data()); m_drawables[type].modelBuffer.unbind(); if (!m_drawables[type].unicolored) { m_drawables[type].colorBuffer.bind(GL_UNIFORM_BUFFER); m_drawables[type].colorBuffer.setData( 0, k_colorTypeSize * static_cast<unsigned int>(colorVec.size()), colorVec.data()); m_drawables[type].colorBuffer.unbind(); } m_drawables[type].miscBuffer.bind(GL_UNIFORM_BUFFER); m_drawables[type].miscBuffer.setData( 0, k_miscTypeSize * static_cast<unsigned int>(miscVec.size()), miscVec.data()); m_drawables[type].miscBuffer.unbind(); #else m_drawables[type].modelBuffer.setData( 0, k_modelTypeSize * static_cast<unsigned int>(modelVec.size()), modelVec.data()); if (!m_drawables[type].unicolored) { m_drawables[type].colorBuffer.setData( 0, k_colorTypeSize * static_cast<unsigned int>(colorVec.size()), colorVec.data()); } m_drawables[type].miscBuffer.setData( 0, k_miscTypeSize * static_cast<unsigned int>(miscVec.size()), miscVec.data()); #endif }
void Ability_Active::apply_ability(Unit & target) { for(auto iter = effects.begin(); iter != effects.end(); ++iter) if(iter->expired(duration_counter)) iter->apply_effect(*ability_caster, target); ++duration_counter; }
bool Ability_Active::expired() { for(auto iter = effects.begin(); iter != effects.end(); ++iter) if(!iter->expired(duration_counter)) return false; return true; }
bool PhysicsEntityContainer::Update() { // Check if the list is empty if(_listOfContainedObjects.empty()) return true; // Loop through all objects in list for motion updating auto back_itr = _listOfContainedObjects.before_begin(); auto front_itr = _listOfContainedObjects.begin(); while(front_itr != _listOfContainedObjects.end()) { // Check for null ptr if(front_itr->expired()) { // Delete the pointer at front_itr front_itr = _listOfContainedObjects.erase_after(back_itr); } // Update and iterate else { (*front_itr)._Get()->Update(); front_itr++; back_itr++; } } // Loop again for collision detection for(auto& firstEntity : _listOfContainedObjects) { PhysicsCollisionGroups firstGroup = firstEntity._Get()->GetCollisionGroup(); for(auto& secondEntity : _listOfContainedObjects) { PhysicsCollisionGroups secondGroup = secondEntity._Get()->GetCollisionGroup(); // Skip if they are the same entity if(firstEntity._Get()->GetID() == secondEntity._Get()->GetID()) { continue; } // Skip if they are the same collision group else if(firstGroup == secondGroup) { continue; } // Skip if not colliding else if(!PhysicsEntityContainer::doEntitiesOverlap(firstEntity, secondEntity)) { continue; } // If you're here, there was a collision else { // Message first entity of collision only // A future loop will message the second entity about this collision. firstEntity._Get()->OnCollision(secondGroup, secondEntity); } } } return true; }
void FaceAttribsEditor::unbindObservers() { if (!expired(m_document)) { MapDocumentSPtr document = lock(m_document); document->documentWasNewedNotifier.removeObserver(this, &FaceAttribsEditor::documentWasNewed); document->documentWasLoadedNotifier.removeObserver(this, &FaceAttribsEditor::documentWasLoaded); document->brushFacesDidChangeNotifier.removeObserver(this, &FaceAttribsEditor::brushFacesDidChange); document->selectionDidChangeNotifier.removeObserver(this, &FaceAttribsEditor::selectionDidChange); document->textureCollectionsDidChangeNotifier.removeObserver(this, &FaceAttribsEditor::textureCollectionsDidChange); } }
void AbstractSocket::timerEvent(QTimerEvent * event) // TODO: each socket must self managed > done? { Q_D(AbstractSocket); if (event->timerId() == d->expirationDelayTimerId) { log("AbstractSocket::timerEvent: expired"); emit expired(socketDescriptor()); return; } QSslSocket::timerEvent(event); }
bool result::ready(boost::unique_lock<boost::mutex>&) const { if(!m_ready && expired()) { m_exception = boost::make_shared<remote_error> (remote_error::timeout, "remote call timeout"); m_ready = true; } return m_ready; }
timeout_t TQEvent::timeout(void) { timeout_t timeout = get(); if(is_active() && !timeout) { disarm(); expired(); timeout = get(); Timer::update(); } return timeout; }
int main() { auto w = bar(); if(w.expired()) { std::cout << "expired" << std::endl; } else { std::cout << "not expired" << std::endl; } }
timeout_t stack::call::getTimeout(void) { timeout_t current; Mutex::protect(this); current = timer.get(); if(current < 2) { timer = Timer::inf; expired(); } Mutex::release(this); return current; }
// only used in single-threaded mode where one command at a time is in process int waitfor (Client *c, int packet_type, Timer *timer) { int rc = FAILURE; do { if (expired(timer)) break; // we timed out - bail out } while ((rc = cycle(c, timer)) != packet_type); return rc; }
// only used in single-threaded mode where one command at a time is in process int waitfor(Client* c, int packet_type, Timer* timer) { int rc = FAILURE; do { if (expired(timer)) break; // we timed out } while ((rc = cycle(c, timer)) != packet_type); //STM: loop here if not the desired packet received return rc; }
bool particles_product::initialize() { // TODO: from xml + register user types passes_.initialize(3); auto link_clear = passes_.add_pass<rendering::effect::clear>(); if(link_clear.expired()) return false; auto link_positions = passes_.add_pass<pass_positions>(); if(link_positions.expired()) return false; auto link_particles = passes_.add_pass<pass_particles>(); if(link_particles.expired()) return false; passes_.add_dependency(link_particles, link_positions, rendering::pass_slot::slot_0); return true; }
int main() { Banana mushy; Banana expired(4,2); mushy = expired; std::cout << "Expired: " << expired.content() << std::endl; std::cout << "Expired: " << mushy.content() << std::endl; return 0; }
void Scene::AddGameObject(const std::shared_ptr<EntityNode> &node) { m_RootNode->AddChild(node); auto pWeakEntity = node->GetEntity(); if (!pWeakEntity.expired()) { auto pStrongEntity = std::shared_ptr<Entity>(pWeakEntity); m_EntityMap[pStrongEntity->GetEntityID()] = pStrongEntity; } }
void Observable::RemoveDeadObservers() { std::vector<ObserverList::iterator> observersToRemove; for (auto obsIter = mObservers.begin(); obsIter != mObservers.end(); ++obsIter) { if (obsIter->expired()) observersToRemove.push_back(obsIter); } for (auto obs : observersToRemove) mObservers.erase(obs); }
void ServerAllocation::print(std::ostream& os) const { os << "ServerAllocation[" << "\r\tTuple=" << _tuple << "\r\tUsername="******"\n\tBandwidth Limit=" << bandwidthLimit() << "\n\tBandwidth Used=" << bandwidthUsed() << "\n\tBandwidth Remaining=" << bandwidthRemaining() << "\n\tBase Time Remaining=" << IAllocation::timeRemaining() << "\n\tTime Remaining=" << timeRemaining() << "\n\tMax Time Remaining=" << maxTimeRemaining() << "\n\tDeletable=" << IAllocation::deleted() << "\n\tExpired=" << expired() << "]" << endl; }
IoT_Error_t subscribeToShadowActionAcks(const char *pThingName, ShadowActions_t action, bool isSticky) { IoT_Error_t ret_val = NONE_ERROR; MQTTSubscribeParams subParams = MQTTSubscribeParamsDefault; bool clearBothEntriesFromList = true; int16_t indexAcceptedSubList = 0; int16_t indexRejectedSubList = 0; indexAcceptedSubList = getNextFreeIndexOfSubscriptionList(); indexRejectedSubList = getNextFreeIndexOfSubscriptionList(); if (indexAcceptedSubList >= 0 && indexRejectedSubList >= 0) { topicNameFromThingAndAction(SubscriptionList[indexAcceptedSubList].Topic, pThingName, action, SHADOW_ACCEPTED); subParams.mHandler = AckStatusCallback; subParams.qos = QOS_0; subParams.pTopic = SubscriptionList[indexAcceptedSubList].Topic; ret_val = pMqttClient->subscribe(&subParams); if (ret_val == NONE_ERROR) { SubscriptionList[indexAcceptedSubList].count = 1; SubscriptionList[indexAcceptedSubList].isSticky = isSticky; topicNameFromThingAndAction(SubscriptionList[indexRejectedSubList].Topic, pThingName, action, SHADOW_REJECTED); subParams.pTopic = SubscriptionList[indexRejectedSubList].Topic; ret_val = pMqttClient->subscribe(&subParams); if (ret_val == NONE_ERROR) { SubscriptionList[indexRejectedSubList].count = 1; SubscriptionList[indexRejectedSubList].isSticky = isSticky; clearBothEntriesFromList = false; // wait for SUBSCRIBE_SETTLING_TIME seconds to let the subscription take effect Timer subSettlingtimer; InitTimer(&subSettlingtimer); countdown(&subSettlingtimer, SUBSCRIBE_SETTLING_TIME); while(!expired(&subSettlingtimer)); } } } if (clearBothEntriesFromList) { if (indexAcceptedSubList >= 0) { SubscriptionList[indexAcceptedSubList].isFree = true; } else if (indexRejectedSubList >= 0) { SubscriptionList[indexRejectedSubList].isFree = true; } if (SubscriptionList[indexAcceptedSubList].count == 1) { ret_val = pMqttClient->unsubscribe(SubscriptionList[indexAcceptedSubList].Topic); } } return ret_val; }
void spawn_more_kittens(KittenManager * litter, gboolean ** seen) { unsigned int i; if (litter->kitten_count < MAX_KITTENS && expired(litter->spawn_timer) && SDL_GetTicks() > 5000) { for (i = 0; i < MAX_KITTENS - litter->kitten_count; i++) { spawn_kitten(litter, seen); } } }
static json_object * get_cached(const char *url, const char *name) { char fname[PATH_MAX]; char full_url[500]; int rc = 0; const char *error; json_object *root; snprintf(fname, PATH_MAX-1, "%s%s.json", cache_path, name); if (expired(fname, 3600*24)) { get_full_url(url, full_url); rc = fetch(full_url, fname); } if (rc != 0) { provider->error_number = 1; return NULL; } root = json_object_from_file(fname); error = get_str(root, "error"); if (rc == 0 && root != NULL && error == NULL) return root; sleep(2); authorize(NULL); get_full_url(url, full_url); rc = fetch(url, fname); root = json_object_from_file(fname); error = get_str(root, "error"); if (rc != 0 || root == NULL) { sprintf(last_error, "cannot load %s. rc: %d", fname, rc); provider->error_number = 1; return NULL; } if (error != NULL) { remove(fname); sprintf(last_error, "api error: %s", error); provider->error_number = 1; return NULL; } return root; }
void ResourceManager::reloadAll() { auto iter = mReloadables.begin(); while(iter != mReloadables.end()) { if(!iter->expired()) { iter->lock()->reload(sInstance); iter++; }else{ iter = mReloadables.erase(iter); } } }
void Real::entry() { disable(); Time::Real now = Time::Real::now(); if(cancelled) { cancelled = 0; reschedule(now); } else { expired(now); } }
void HandleExpiredResponseCallbacks(void) { uint8_t i; for (i = 0; i < MAX_ACKS_TO_COMEIN_AT_ANY_GIVEN_TIME; i++) { if (!AckWaitList[i].isFree) { if (expired(&(AckWaitList[i].timer))) { if (AckWaitList[i].callback != NULL) { AckWaitList[i].callback(AckWaitList[i].thingName, AckWaitList[i].action, SHADOW_ACK_TIMEOUT, shadowRxBuf, AckWaitList[i].pCallbackContext); } AckWaitList[i].isFree = true; unsubscribeFromAcceptedAndRejected(i); } } } }
std::shared_ptr<Texture> MaterialManager::getTexture( const std::shared_ptr<Geometry3D>& geometry, int meshIndex, MaterialTexture textureType ) { int id = geometry->getID(); auto it = m_materials.find(id); if (it != m_materials.end()) { if (meshIndex >= 0 && meshIndex < (int)it->second.size()) { auto texPtr = it->second[meshIndex].textures[textureType]; if (!texPtr.expired()) return texPtr.lock(); } } return std::shared_ptr<Texture>(); }