Example #1
0
			bool add(std::shared_ptr<ObjectT> obj) {
        // Already has obj?
        if (has(obj->id()))
          return false;
				_objects[obj->id()] = obj;
        return true;
			}
Example #2
0
void MidiRouter::addDevice(std::shared_ptr<MidiDevice> device) {
  _deviceNameToId[device->name()] = device->id();
  _devices[device->id()] = device;
  device->messageReceived += [&](MidiReceivedEventArgs& event) {
    onInputMessage(event);
  };
}
void SlamSystem::createNewCurrentKeyframe(std::shared_ptr<Frame> newKeyframeCandidate)
{
	if(enablePrintDebugInfo && printThreadingInfo)
		printf("CREATE NEW KF %d from %d\n", newKeyframeCandidate->id(), currentKeyFrame->id());


	if(SLAMEnabled)
	{
		// add NEW keyframe to id-lookup
		keyFrameGraph->idToKeyFrameMutex.lock();
		keyFrameGraph->idToKeyFrame.insert(std::make_pair(newKeyframeCandidate->id(), newKeyframeCandidate));
		keyFrameGraph->idToKeyFrameMutex.unlock();
	}

	// propagate & make new.
	map->createKeyFrame(newKeyframeCandidate.get());

	if(printPropagationStatistics)
	{

		Eigen::Matrix<float, 20, 1> data;
		data.setZero();
		data[0] = runningStats.num_prop_attempts / ((float)width*height);
		data[1] = (runningStats.num_prop_created + runningStats.num_prop_merged) / (float)runningStats.num_prop_attempts;
		data[2] = runningStats.num_prop_removed_colorDiff / (float)runningStats.num_prop_attempts;

        //outputWrapper->publishDebugInfo(data);
	}

    currentKeyFrameMutex.lock();
	currentKeyFrame = newKeyframeCandidate;
	currentKeyFrameMutex.unlock();
}
Example #4
0
force::force(std::shared_ptr<particle> part1, std::shared_ptr<particle> part2, unsigned int fileId, Eigen::Vector3d pos1, Eigen::Vector3d pos2, Eigen::Vector3d val, double volWater, double distCurr, double distCrit) {
  _part1 = part1;
  _part2 = part2;
  
  _volWater = volWater;
  _distCurr = distCurr;
  _distCrit = distCrit;
  
  if (fabs(pos1.norm()/part1->c().norm() - 1.0) > 0.0001 or fabs(pos2.norm()/part2->c().norm() -1.0 ) > 0.0001 ) {
    std::cerr<<"Particle positions in force and particle files are not the same!"<<std::endl;
    std::cerr<<"pid1 "<<part1->id()<<": ("<<pos1[0]<<" "<<pos1[1]<<" "<<pos1[2]<< ") != (" << part1->c()[0]<<" "<<part1->c()[1]<<" "<<part1->c()[2];
    std::cerr<<"pid2 "<<part2->id()<<": ("<<pos2[0]<<" "<<pos2[1]<<" "<<pos2[2]<< ") != (" << part2->c()[0]<<" "<<part2->c()[1]<<" "<<part2->c()[2]<<");   "<<std::endl;
    
    std::cerr<<"dif1 "<<pos1.norm()/part1->c().norm()<<"; dif2 "<<pos2.norm()/part2->c().norm()<<std::endl<<std::endl;
  }
  
  //Updating particle positions as they are more accurate in fstat
  _part1->c(pos1);
  _part2->c(pos2);
  
  
  _cPZ = Eigen::Vector3d::Zero();
  _val = val;
  _fileId = fileId;
  _calculateStressTensor = false;
  _cP = (pos1-pos2)/2.0 + pos1;
  _axisMatrix = _axisMatrix.Zero();
};
Example #5
0
/** A peer has connected successfully
    This is called after the peer handshake has been completed and during
    peer activation. At this point, the peer address and the public key
    are known.
*/
void
OverlayImpl::activate (std::shared_ptr<PeerImp> const& peer)
{
    std::lock_guard <decltype(mutex_)> lock (mutex_);

    // Now track this peer
    {
        auto const result (m_shortIdMap.emplace (
            std::piecewise_construct,
                std::make_tuple (peer->id()),
                    std::make_tuple (peer)));
        assert(result.second);
        (void) result.second;
    }

    {
        auto const result (m_publicKeyMap.emplace(
            peer->getNodePublic(), peer));
        assert(result.second);
        (void) result.second;
    }

    journal_.debug <<
        "activated " << peer->getRemoteAddress() <<
        " (" << peer->id() <<
        ":" << peer->getNodePublic().toPublicKey() << ")";

    // We just accepted this peer so we have non-zero active peers
    assert(size() != 0);
}
Example #6
0
void World::addEntity(std::shared_ptr<Entity> entity)
{
    if(entity_tree.find(entity->id()) != entity_tree.end())
        return;
    entity_tree[entity->id()] = entity;
    if(entity->id() + 1 > next_entity_id)
        next_entity_id = entity->id() + 1;
}
Example #7
0
 auto addLast(const std::shared_ptr<Source<O>>& src) { 
   if (!src) return;
   auto id = src->id();
   if (_last.find(id) != std::end(_last)) return;
   _last.emplace(id, src);
   for (auto &it : _flnext) it.second->prev(src, it.second);  
 }
Example #8
0
  auto addFirst(const std::shared_ptr<Dest<I>>& dest) { 
    if (!dest) return;
    auto id = dest->id();
    if (_first.find(id) != std::end(_first)) return;
    _first[id] = dest;
    for (auto &it : _flprev) it.second->next(dest, it.second);  
 }
float nrps::makeWeight(const std::shared_ptr<Domain> &lhs, const std::shared_ptr<Domain> &rhs, std::unordered_map<uint32_t, std::shared_ptr<Taxon>> *taxonCache,  std::unordered_map<std::pair<uint32_t, uint32_t>, float> *weightCache)
{
    uint32_t taxid1 = lhs->origin()->taxId(), taxid2 = rhs->origin()->taxId();
    if (taxid1 == 0 || taxid2 == 0)
        return std::numeric_limits<float>::infinity();
    std::pair<uint32_t, uint32_t> key(std::min(taxid1, taxid2), std::max(taxid1, taxid2));
    float weight;
    if (weightCache == nullptr || !weightCache->count(key)) {
        if (!taxonCache->count(taxid1))
            taxonCache->emplace(taxid1, TaxonBuilder::getInstance()->buildOne(taxid1));
        if (!taxonCache->count(taxid2))
            taxonCache->emplace(taxid2, TaxonBuilder::getInstance()->buildOne(taxid2));
        auto dist = *taxonCache->at(taxid1) - *taxonCache->at(taxid2);
        weight = dist[0] + dist[1];
        if (weightCache != nullptr)
            weightCache->emplace(key, weight);
    } else
        weight = weightCache->at(key);
    if (!weight) // TODO: there could be multiple pathways producing the same product in the same organism
        weight += (lhs->product()->id() != rhs->product()->id()) * 0.7;
    if (!weight) {
        int diff = lhs->module() - rhs->module();
        if (diff > 0)
            weight += 0.6;
        else if (std::abs(diff) > 1)
            weight += 0.5;
        else if (std::abs(diff) == 1)
            weight += (rhs->type() != DomainType::C) ? 0.4 : 0.1;
        else if (std::abs(diff) == 0 && rhs->type() == DomainType::C)
            weight += 0.2;
    }
    if (weight > 0.1 && lhs->worksWithNextDomain(rhs->id()))
        weight = 0.15;
    return weight;
}
Example #10
0
bool MessageMatcher::MatchAndExplain(
    std::shared_ptr<Message> msg,
    ::testing::MatchResultListener* listener) const {
  bool match = true;
  if (!msg) return false;
  if (msg->str() != goodmsg->str()) {
    *listener << "str mismatch ";
    match = false;
  }
  if ((!msg->value() && goodmsg->value()) ||
      (msg->value() && !goodmsg->value()) ||
      (msg->value() && goodmsg->value() &&
       *msg->value() != *goodmsg->value())) {
    *listener << "value mismatch ";
    match = false;
  }
  if (msg->id() != goodmsg->id()) {
    *listener << "id mismatch ";
    match = false;
  }
  if (msg->flags() != goodmsg->flags()) {
    *listener << "flags mismatch";
    match = false;
  }
  if (msg->seq_num_uid() != goodmsg->seq_num_uid()) {
    *listener << "seq_num_uid mismatch";
    match = false;
  }
  return match;
}
void FrameBufferObjectMultisample::blitDepth(const std::shared_ptr<FrameBufferObject> &fbo)
{
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo->id());
	glBindFramebuffer(GL_READ_FRAMEBUFFER, m_handle);
	glBlitFramebuffer(0, 0, m_target->width(), m_target->height(), 0, 0, m_target->width(), m_target->height(), GL_DEPTH_BUFFER_BIT, m_filtering);
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
Example #12
0
void AssetStore::updateAsset(const BitHordeIds& ids, const std::shared_ptr<StoredAsset>& asset)
{
	auto tigerId = findBithordeId(ids, bithorde::HashType::TREE_TIGER);

	auto assetId = asset->id();

	auto oldTiger = _index.lookupAsset(assetId);
	if (tigerId.empty()) {
		// Updates with empty TigerId won't overwrite.
		tigerId = oldTiger;
	} else if ((!oldTiger.empty()) && (oldTiger != tigerId)) {
		BOOST_LOG_SEV(bithorded::storeLog, warning) << "asset " << assetId << " were linked by the wrong tthsum " << oldTiger;
		unlink(_tigerFolder/oldTiger);
	}

	auto assetPath = _assetsFolder / assetId;
	_index.addAsset(assetId, tigerId, assetDiskUsage(assetPath), assetDiskAllocated(assetPath), fs::last_write_time(assetPath));

	if (!tigerId.empty()) {
		fs::path link = _tigerFolder / tigerId.base32();
		if (fs::exists(fs::symlink_status(link)))
			fs::remove(link);
		fs::create_relative_symlink(_assetsFolder / assetId, link);
	}
}
Example #13
0
 void flprev(std::shared_ptr<Source<I>> pr) {
   if (!pr) return;
   for(auto &it : _first) it.second->prev(pr, it.second);
   auto id = pr->id();
   if (_flprev.find(id) == std::end(_flprev)) {
     _flprev.emplace(id, pr);
   }
 }
Example #14
0
 void flnext(std::shared_ptr<Dest<O>> nx) {
   if (!nx) return;
   for (auto &it : _last) it.second->next(nx, it.second);
   auto id = nx->id();
   if (_flnext.find(id) == std::end(_flnext)) {
     _flnext.emplace(id, nx);
   }
 }
Example #15
0
void JobScheduler::handleIndexDataMessage(const std::shared_ptr<IndexDataMessage> &message)
{
    auto node = mActiveById.take(message->id());
    if (!node) {
        debug() << "Got IndexDataMessage for unknown job";
        return;
    }
    debug() << "job got index data message" << node->job->id << node->job->source.key() << node->job.get();
    jobFinished(node->job, message);
}
Example #16
0
int PropertyFS::compare(const std::shared_ptr<base::IProperty> &other) const {
    int cmp = 0;
    if (!name().empty() && !other->name().empty()) {
        cmp = (name()).compare(other->name());
    }
    if (cmp == 0) {
        cmp = id().compare(other->id());
    }
    return cmp;
}
 void StdChoreographer::unmanageCircle(const std::shared_ptr<Circle>& circle)
 {
     for(auto it = _circles.begin(); it != _circles.end(); ++it)
     {
         if((*it)->id() == circle->id())
         {
             _circles.erase(it);
             return;
         }
     }
 }
 void StdChoreographer::unmanagePolygon(const std::shared_ptr<Polygon>& polygon)
 {
     for(auto it = _polygons.begin(); it != _polygons.end(); ++it)
     {
         if((*it)->id() == polygon->id())
         {
             _polygons.erase(it);
             return;
         }
     }
 }
Example #19
0
// Adds a peer that is already handshaked and active
void
OverlayImpl::add_active (std::shared_ptr<PeerImp> const& peer)
{
    std::lock_guard <decltype(mutex_)> lock (mutex_);

    {
        auto const result =
            m_peers.emplace (peer->slot(), peer);
        assert (result.second);
        (void) result.second;
    }

    // Now track this peer
    {
        auto const result (m_shortIdMap.emplace (
            std::piecewise_construct,
                std::make_tuple (peer->id()),
                    std::make_tuple (peer)));
        assert(result.second);
        (void) result.second;
    }

    {
        auto const result (m_publicKeyMap.emplace(
            peer->getNodePublic(), peer));
        assert(result.second);
        (void) result.second;
    }

    list_.emplace(peer.get(), peer);

    journal_.debug <<
        "activated " << peer->getRemoteAddress() <<
        " (" << peer->id() <<
        ":" << peer->getNodePublic().toPublicKey() << ")";

    // As we are not on the strand, run() must be called
    // while holding the lock, otherwise new I/O can be
    // queued after a call to stop().
    peer->run();
}
Example #20
0
    bool Play::addView(const std::shared_ptr<View>& view)
    {
        for(auto& v : _views)
        {
            if(v->id() == view->id())
                return false;
        }

        _views.push_back(view);

        return true;
    }
Example #21
0
File: vgl.cpp Project: bkentel/Vox
void
gl::Program::detachShader(std::shared_ptr<Shader> shader)
{
	auto it = shaders_.find(shader);

	//if shader hasn't been attached, do nothing
	if (it == shaders_.end()) {
		return;
	}

	shaders_.erase(it);
	detail::detachShader(id(), shader->id());
}
Example #22
0
void SessionManager::HandleMessage(std::shared_ptr<RawMessage> spMsg)
{
    switch (spMsg->id()) {
        case MSG_CHECK_VERSION:
            HandleVersionCheck(spMsg);
            break;
        case MSG_REQ_LOGIN:
            HandleReqLogin(spMsg);
            break;
        default:
            assert(false);
    }
}
Example #23
0
File: vgl.cpp Project: bkentel/Vox
void
gl::Program::attachShader(std::shared_ptr<Shader> shader)
{
	auto it = shaders_.find(shader);
		
	//if shader is already attached, don't attach it again 
	if (it != shaders_.end()) {
		return;
	}

	shaders_.insert(shader);
	detail::attachShader(id(), shader->id());
}
Example #24
0
bool Artist::setThumbnail( std::shared_ptr<Thumbnail> thumbnail )
{
    assert( thumbnail != nullptr );

    if ( m_thumbnailId != 0 )
    {
        if ( m_thumbnail == nullptr )
        {
            auto m_thumbnail = Thumbnail::fetch( m_ml, m_thumbnailId );
            if ( m_thumbnail == nullptr )
                return false;
        }
        if ( m_thumbnail->origin() == Thumbnail::Origin::Artist ||
             m_thumbnail->origin() == Thumbnail::Origin::UserProvided ||
             m_thumbnail->origin() == Thumbnail::Origin::Empty )
            return m_thumbnail->update( thumbnail->mrl(),
                                        thumbnail->origin(),
                                        thumbnail->isOwned() );
    }
    std::unique_ptr<sqlite::Transaction> t;
    if ( sqlite::Transaction::transactionInProgress() == false )
        t = m_ml->getConn()->newTransaction();
    if ( thumbnail->id() == 0 )
    {
        if ( thumbnail->insert() == 0 )
            return false;
    }
    static const std::string req = "UPDATE " + Artist::Table::Name +
            " SET thumbnail_id = ? WHERE id_artist = ?";
    if ( sqlite::Tools::executeUpdate( m_ml->getConn(), req, thumbnail->id(),
                                       m_id ) == false )
        return false;
    if ( t != nullptr )
        t->commit();
    m_thumbnailId = thumbnail->id();
    m_thumbnail = std::move( thumbnail );
    return true;
}
Example #25
0
void dispatcher::add_window( const std::shared_ptr<window> &w )
{
	_windows[w->id()] = w;
	xcb_change_property( _connection, XCB_PROP_MODE_REPLACE, w->id(), _atom_wm_protocols, XCB_ATOM_ATOM, 32, 1, &_atom_delete_window );
}
Example #26
0
void NetworkConnection::QueueOutgoing(std::shared_ptr<Message> msg) {
  std::lock_guard<std::mutex> lock(m_pending_mutex);

  // Merge with previous.  One case we don't combine: delete/assign loop.
  switch (msg->type()) {
    case Message::kEntryAssign:
    case Message::kEntryUpdate: {
      // don't do this for unassigned id's
      unsigned int id = msg->id();
      if (id == 0xffff) {
        m_pending_outgoing.push_back(msg);
        break;
      }
      if (id < m_pending_update.size() && m_pending_update[id].first != 0) {
        // overwrite the previous one for this id
        auto& oldmsg = m_pending_outgoing[m_pending_update[id].first - 1];
        if (oldmsg && oldmsg->Is(Message::kEntryAssign) &&
            msg->Is(Message::kEntryUpdate)) {
          // need to update assignment with new seq_num and value
          oldmsg = Message::EntryAssign(oldmsg->str(), id, msg->seq_num_uid(),
                                        msg->value(), oldmsg->flags());
        } else
          oldmsg = msg;  // easy update
      } else {
        // new, but remember it
        std::size_t pos = m_pending_outgoing.size();
        m_pending_outgoing.push_back(msg);
        if (id >= m_pending_update.size()) m_pending_update.resize(id + 1);
        m_pending_update[id].first = pos + 1;
      }
      break;
    }
    case Message::kEntryDelete: {
      // don't do this for unassigned id's
      unsigned int id = msg->id();
      if (id == 0xffff) {
        m_pending_outgoing.push_back(msg);
        break;
      }

      // clear previous updates
      if (id < m_pending_update.size()) {
        if (m_pending_update[id].first != 0) {
          m_pending_outgoing[m_pending_update[id].first - 1].reset();
          m_pending_update[id].first = 0;
        }
        if (m_pending_update[id].second != 0) {
          m_pending_outgoing[m_pending_update[id].second - 1].reset();
          m_pending_update[id].second = 0;
        }
      }

      // add deletion
      m_pending_outgoing.push_back(msg);
      break;
    }
    case Message::kFlagsUpdate: {
      // don't do this for unassigned id's
      unsigned int id = msg->id();
      if (id == 0xffff) {
        m_pending_outgoing.push_back(msg);
        break;
      }
      if (id < m_pending_update.size() && m_pending_update[id].second != 0) {
        // overwrite the previous one for this id
        m_pending_outgoing[m_pending_update[id].second - 1] = msg;
      } else {
        // new, but remember it
        std::size_t pos = m_pending_outgoing.size();
        m_pending_outgoing.push_back(msg);
        if (id >= m_pending_update.size()) m_pending_update.resize(id + 1);
        m_pending_update[id].second = pos + 1;
      }
      break;
    }
    case Message::kClearEntries: {
      // knock out all previous assigns/updates!
      for (auto& i : m_pending_outgoing) {
        if (!i) continue;
        auto t = i->type();
        if (t == Message::kEntryAssign || t == Message::kEntryUpdate ||
            t == Message::kFlagsUpdate || t == Message::kEntryDelete ||
            t == Message::kClearEntries)
          i.reset();
      }
      m_pending_update.resize(0);
      m_pending_outgoing.push_back(msg);
      break;
    }
    default:
      m_pending_outgoing.push_back(msg);
      break;
  }
}
Example #27
0
bool Poller<T>::register_connection(std::shared_ptr<Connection<T>> connection)
{
    return m_poller_tasks[connection->id() % m_poller_task_num]->register_connection(connection);
}
Example #28
0
/**
 * Entity save function, based on engine lua scripts;
 */
void Save_Entity(FILE **f, std::shared_ptr<Entity> ent)
{
    if(ent == NULL)
    {
        return;
    }

    if(ent->m_typeFlags & ENTITY_TYPE_SPAWNED)
    {
        uint32_t room_id = (ent->m_self->room)?(ent->m_self->room->id):(0xFFFFFFFF);
        fprintf(*f, "\nspawnEntity(%d, 0x%X, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d);", ent->m_bf.animations.model->id, room_id,
                ent->m_transform.getOrigin()[0], ent->m_transform.getOrigin()[1], ent->m_transform.getOrigin()[2],
                ent->m_angles[0], ent->m_angles[1], ent->m_angles[2], ent->id());
    }
    else
    {
        fprintf(*f, "\nsetEntityPos(%d, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f);", ent->id(),
                ent->m_transform.getOrigin()[0], ent->m_transform.getOrigin()[1], ent->m_transform.getOrigin()[2],
                ent->m_angles[0], ent->m_angles[1], ent->m_angles[2]);
    }

    fprintf(*f, "\nsetEntitySpeed(%d, %.2f, %.2f, %.2f);", ent->id(), ent->m_speed[0], ent->m_speed[1], ent->m_speed[2]);
    fprintf(*f, "\nsetEntityAnim(%d, %d, %d);", ent->id(), ent->m_bf.animations.current_animation, ent->m_bf.animations.current_frame);
    fprintf(*f, "\nsetEntityState(%d, %d, %d);", ent->id(), ent->m_bf.animations.next_state, ent->m_bf.animations.last_state);
    fprintf(*f, "\nsetEntityCollisionFlags(%d, %d, %d);", ent->id(), ent->m_self->collision_type, ent->m_self->collision_shape);

    if(ent->m_enabled)
    {
        fprintf(*f, "\nenableEntity(%d);", ent->id());
    }
    else
    {
        fprintf(*f, "\ndisableEntity(%d);", ent->id());
    }

    fprintf(*f, "\nsetEntityFlags(%d, %d, %d, %d, 0x%.4X, 0x%.8X);", ent->id(), ent->m_active, ent->m_enabled, ent->m_visible, ent->m_typeFlags, ent->m_callbackFlags);

    fprintf(*f, "\nsetEntityTriggerLayout(%d, 0x%.2X);", ent->id(), ent->m_triggerLayout);
    //setEntityMeshswap()

    if(ent->m_self->room != NULL)
    {
        fprintf(*f, "\nsetEntityRoomMove(%d, %d, %d, %d);", ent->id(), ent->m_self->room->id, ent->m_moveType, ent->m_dirFlag);
    }
    else
    {
        fprintf(*f, "\nsetEntityRoomMove(%d, nil, %d, %d);", ent->id(), ent->m_moveType, ent->m_dirFlag);
    }

    if(auto ch = std::dynamic_pointer_cast<Character>(ent))
    {
        fprintf(*f, "\nremoveAllItems(%d);", ent->id());
        for(const InventoryNode& i : ch->m_inventory)
        {
            fprintf(*f, "\naddItem(%d, %d, %d);", ent->id(), i.id, i.count);
        }

        for(int i=0;i<PARAM_SENTINEL;i++)
        {
            fprintf(*f, "\nsetCharacterParam(%d, %d, %.2f, %.2f);", ent->id(), i, ch->m_parameters.param[i], ch->m_parameters.maximum[i]);
        }
    }
}
Example #29
0
void Parser::register_connection(std::shared_ptr<Connection> connection)
{
    static auto num = m_parser_tasks.size();
    connection->m_parser_task = m_parser_tasks[connection->id() % num];
}
Example #30
0
void
FlowScene::
deleteConnection(std::shared_ptr<Connection> connection)
{
  _connections.erase(connection->id());
}