Exemplo n.º 1
0
			MovementCommand &AllocateMovementCommand( void ) {
				//FIXME: calculate ~1s worth of input?
				if ( movementCmds.size() >= 10 ) {
					movementCmds.pop_front();
					//FIXME: does this call destructor on pointer elements?
				}

				MovementCommand newCmd = {};
				movementCmds.push_back( newCmd );

				return movementCmds.back();
			}
Exemplo n.º 2
0
TSRTexture* TSRTextureManager::Aquire( const char* _pResourceName, eDefaultTextureType _typeHint, bool _bLoadImmediately )
{
	string Key = _pResourceName;

    if ( m_ResourcesMap.find( Key ) != m_ResourcesMap.end() )
	{
		sResourceEntry& entry = m_ResourcesMap[ Key ];
    	entry.m_NumUsers++;
	    return entry.m_pResource;
	}

	/// unlock this line to stream textures
	_bLoadImmediately = true;

	if ( _bLoadImmediately )
	{
		// if not found..create a new entry
		sResourceEntry newEntry;
		newEntry.m_pResource = new TSRTexture( _pResourceName );
		newEntry.m_NumUsers  = 1;

		m_ResourcesMap[ Key ] = newEntry;
		return newEntry.m_pResource;
	}
	else
	{
		// if not found..create a new entry
		sResourceEntry newEntry;
		newEntry.m_pResource = new TSRTexture();
		newEntry.m_NumUsers  = 1;

		switch ( _typeHint )
		{
		case DefaultTexture_Black:
			newEntry.m_pResource->m_pWrapped = m_pBlackTexture->m_pWrapped;
			break;
		case DefaultTexture_Normal:
			newEntry.m_pResource->m_pWrapped = m_pDefaultNormalTexture->m_pWrapped;
			break;
		default:
			newEntry.m_pResource->m_pWrapped = m_pWhiteTexture->m_pWrapped;
			break;
		}
		m_ResourcesMap[ Key ] = newEntry;

		/// add a new request to the queue
		sTextureLoadRequest newRequest;
		newRequest.m_pTextureToLoad = newEntry.m_pResource;
		newRequest.m_strFileName = _pResourceName;
		g_TextureLoadRequests.push_back( newRequest );
		return newEntry.m_pResource;
	}
}
Exemplo n.º 3
0
bool TorControlConnection::Command(const std::string &cmd, const ReplyHandlerCB& reply_handler)
{
    if (!b_conn)
        return false;
    struct evbuffer *buf = bufferevent_get_output(b_conn);
    if (!buf)
        return false;
    evbuffer_add(buf, cmd.data(), cmd.size());
    evbuffer_add(buf, "\r\n", 2);
    reply_handlers.push_back(reply_handler);
    return true;
}
Exemplo n.º 4
0
void loadCaptureInfo(std::deque<Capture> &captures,
                      const std::string &capturesFileName)
{
    std::ifstream capturesFile(capturesFileName);
    
    if (capturesFile) {
        int actionType;
        sf::Int32 captureTime;
        while (capturesFile >> actionType >> captureTime) {
            captures.push_back(std::make_pair(actionType, captureTime));
        }
    } else {
Exemplo n.º 5
0
                        void enque(value_type const q)
                        {
                        	{
	                        	libmaus2::parallel::ScopePosixSpinLock llock(lock);
        	                        Q.push_back(q);
				}

                                semaphore.post();
                                
                                if ( parent )
	                                parent->enque(q);
                        }
Exemplo n.º 6
0
void gputask_Kick()
{
	if(!g_gpuTasks.empty())
	{
		auto ptr = g_gpuTasks.front();
		g_gpuTasks.pop_front();

		if(ptr->m_submit) ptr->m_submit();
		if(ptr->m_complete)
			g_kickedTasks.push_back(ptr);
	}
}
Exemplo n.º 7
0
				void setup()
				{
					while ( next < V.size() && freemem >= V[next]->directSortSpace() )
					{
						freemem -= V[next]->directSortSpace();
						pending.push_back(next);
						next += 1;
					}
					uint64_t const p = pending.size();
					for ( uint64_t i = 0; i < p; ++i )
						P.post();
				}
Exemplo n.º 8
0
	void FrameStart()
	{
		ProcessFrames();

		SFrame frame;
		frame.num = m_Profiler.GetFrameNumber();
		frame.timeStart = m_Profiler.GetTime();

		m_Frames.push_back(frame);

		RegionEnter("frame");
	}
Exemplo n.º 9
0
static void	load_ia(std::deque<AObject*> &map, std::vector<int> &m_vector)
{
  std::deque<AObject*>::iterator it;

  map.push_back(new Aintelligence(m_vector[POSX], m_vector[POSY], IA));
  it = map.end();
  --it;
  dynamic_cast<Player*>(*it)->setNbBomb((int)m_vector[BOMB_NB]);
  dynamic_cast<Player*>(*it)->setTotBomb((int)m_vector[BOMB_MAX]);
  dynamic_cast<Player*>(*it)->setSpeed((int)m_vector[SPEED]);
  dynamic_cast<Player*>(*it)->setRange((int)m_vector[RANGE]);
}
Exemplo n.º 10
0
void SDCFsiSolver::getVariablesInfo(
    std::deque<int> & dof,
    std::deque<bool> & enabled,
    std::deque<std::string> & names
    )
{
    std::deque<int> dofFluid, dofSolid;
    std::deque<bool> enabledFluid, enabledSolid;
    std::deque<std::string> namesFluid, namesSolid;
    fluid->getVariablesInfo( dofFluid, enabledFluid, namesFluid );
    solid->getVariablesInfo( dofSolid, enabledSolid, namesSolid );

    assert( dofFluid.size() == enabledFluid.size() );
    assert( dofFluid.size() == namesFluid.size() );
    assert( dofSolid.size() == enabledSolid.size() );
    assert( dofSolid.size() == namesSolid.size() );

    for ( unsigned int i = 0; i < dofFluid.size(); i++ )
    {
        dof.push_back( dofFluid.at( i ) );
        enabled.push_back( enabledFluid.at( i ) );
        names.push_back( namesFluid.at( i ) );
    }

    for ( unsigned int i = 0; i < dofSolid.size(); i++ )
    {
        dof.push_back( dofSolid.at( i ) );
        enabled.push_back( enabledSolid.at( i ) );
        names.push_back( namesSolid.at( i ) );
    }
}
Exemplo n.º 11
0
  void LoadData(std::deque<mitk::ContourModelSet::Pointer> &r)
  {
    std::vector<itk::SmartPointer<mitk::BaseData> > readerOutput;

    readerOutput = mitk::IOUtil::Load(GetTestDataFilePath("RT/StructureSet/BODY.cnt_set"));
    mitk::ContourModelSet::Pointer cnt_set = dynamic_cast<mitk::ContourModelSet*>(readerOutput.at(0).GetPointer());
    cnt_set->SetProperty("name", mitk::StringProperty::New("BODY"));
    r.push_back(cnt_set);

    readerOutput = mitk::IOUtil::Load(GetTestDataFilePath("RT/StructureSet/Bladder.cnt_set"));
    cnt_set = dynamic_cast<mitk::ContourModelSet*>(readerOutput.at(0).GetPointer());
    cnt_set->SetProperty("name", mitk::StringProperty::New("Bladder"));
    r.push_back(cnt_set);

    readerOutput = mitk::IOUtil::Load(GetTestDataFilePath("RT/StructureSet/Femoral Head Lt.cnt_set"));
    cnt_set = dynamic_cast<mitk::ContourModelSet*>(readerOutput.at(0).GetPointer());
    cnt_set->SetProperty("name", mitk::StringProperty::New("Femoral Head Lt"));
    r.push_back(cnt_set);

    readerOutput = mitk::IOUtil::Load(GetTestDataFilePath("RT/StructureSet/Femoral Head RT.cnt_set"));
    cnt_set = dynamic_cast<mitk::ContourModelSet*>(readerOutput.at(0).GetPointer());
    cnt_set->SetProperty("name", mitk::StringProperty::New("Femoral Head RT"));
    r.push_back(cnt_set);

    readerOutput = mitk::IOUtil::Load(GetTestDataFilePath("RT/StructureSet/PTV.cnt_set"));
    cnt_set = dynamic_cast<mitk::ContourModelSet*>(readerOutput.at(0).GetPointer());
    cnt_set->SetProperty("name", mitk::StringProperty::New("PTV"));
    r.push_back(cnt_set);

    readerOutput = mitk::IOUtil::Load(GetTestDataFilePath("RT/StructureSet/Rectum.cnt_set"));
    cnt_set = dynamic_cast<mitk::ContourModelSet*>(readerOutput.at(0).GetPointer());
    cnt_set->SetProperty("name", mitk::StringProperty::New("Rectum"));
    r.push_back(cnt_set);
  }
Exemplo n.º 12
0
void run_sim(void)
{
	BondMap::iterator weakest;
	Bond hypocenter;

	counter = 0;

	for (i=0; i<N;)
	{
		weakest = accessibleBonds.begin();
		already_invaded = invade_bond(weakest->second, weakest->first);
		if(!already_invaded)
		{
			if(weakest->first < cutoff)
			{
				if(counter == 0)
				{
					hypocenter = weakest->second;
				}
				counter +=1;
			}
			else
			{
				if(counter != 0)
				{
					if(burst_counts.count(counter) > 0)
					{
						burst_counts[counter] += 1;
					}
					else
					{
						burst_counts.insert(std::make_pair(counter,1));
					}
					burst_list.push_back(boost::make_tuple(hypocenter.first.first, hypocenter.first.second, counter));
					counter = 0;
				}
			}

			if(chem_level_list.count(weakest->second.first ) > 0)
			{
				chem_level_list.insert(std::make_pair(weakest->second.second, chem_level_list[weakest->second.first]+1));
			}
			else
			{
				chem_level_list.insert(std::make_pair(weakest->second.second, 1));
			}

			i++;
		}
		accessibleBonds.erase(weakest);
	}
}
Exemplo n.º 13
0
void AdminClient::internal_write(message msg) {

    bool writing = !write_queue_.empty();

    //std::cout << "Adding message \"" << msg.data() << "\" to queue\n";
    write_queue_.push_back(msg);

    if (!writing){
        boost::asio::async_write(sock_, boost::asio::buffer(write_queue_.front().data()), 
                boost::bind(&AdminClient::write_handler, this, 
                    boost::asio::placeholders::error));
    }
}
Exemplo n.º 14
0
	void push(const TaskPtr& task) {
		if (!_running) {
			return;
		}
		boost::unique_lock<boost::mutex> lock(_mutex);
		std::cout << "push A" << std::endl;
		_tasks.push_back(task);
		if (_tasks.size() >= 1) {
			std::cout << "push B" << std::endl;
			_no_task.notify_one();
			std::cout << "push C" << std::endl;
		}
	}
Exemplo n.º 15
0
void recurDir(const std::string &pathName, std::deque<std::string> &queue) {
    DIR *dir = opendir(pathName.c_str());
    if (!dir) {
        std::cerr << pathName << ": " << strerror(errno) << std::endl;
        return;
    }
    while (dirent *aFile = readdir(dir)) {
        if (aFile->d_name[0] == '.') continue;
        std::string path = pathName + "/" + aFile->d_name;
        queue.push_back(path);
    }
    closedir(dir);
}
Exemplo n.º 16
0
void genSprites3d(float size,int across, int depth, std::deque<sparky::graphics::Renderable3D*>& queue, sparky::graphics::Window& window){
	sparky::maths::vec3 s(size * 0.9f,0.01f, size * 0.9f);
	for (float y = size * 0.05; y < 50; y += size){
		for (float x = size * 0.05; x < 10; x += size){
			queue.push_back(new
				sparky::graphics::Renderable3D
				(sparky::maths::vec3(x - (WINDOW_WIDTH/2), -0.5, y-1),
				s,
				sparky::maths::vec4(rand() % 1000 / 1000.0f, rand() % 1000 / 1000.0f, rand() % 1000 / 1000.0f, 1)
				));
		}
	}
}
Exemplo n.º 17
0
void visualizerShowCamera(const Matrix3f& R, const Vector3f& _t, float r, float g, float b, double s = 0.01 /*downscale factor*/, const std::string& name = "") {
	std::string name_ = name,line_name = name + "line";
	if (name.length() <= 0) {
		stringstream ss; ss<<"camera"<<iCamCounter++;
		name_ = ss.str();
		ss << "line";
		line_name = ss.str();
	}
	
	Vector3f t = -R.transpose() * _t;

	Vector3f vright = R.row(0).normalized() * s;
	Vector3f vup = -R.row(1).normalized() * s;
	Vector3f vforward = R.row(2).normalized() * s;

	Vector3f rgb(r,g,b);

	pcl::PointCloud<pcl::PointXYZRGB> mesh_cld;
	mesh_cld.push_back(Eigen2PointXYZRGB(t,rgb));
	mesh_cld.push_back(Eigen2PointXYZRGB(t + vforward + vright/2.0 + vup/2.0,rgb));
	mesh_cld.push_back(Eigen2PointXYZRGB(t + vforward + vright/2.0 - vup/2.0,rgb));
	mesh_cld.push_back(Eigen2PointXYZRGB(t + vforward - vright/2.0 + vup/2.0,rgb));
	mesh_cld.push_back(Eigen2PointXYZRGB(t + vforward - vright/2.0 - vup/2.0,rgb));

	//TODO Mutex acquire
	pcl::PolygonMesh pm;
	pm.polygons.resize(6); 
	for(int i=0;i<6;i++)
		for(int _v=0;_v<3;_v++)
			pm.polygons[i].vertices.push_back(ipolygon[i*3 + _v]);
	pcl::toROSMsg(mesh_cld,pm.cloud);
	bShowCam = true;
	cam_meshes.push_back(std::make_pair(name_,pm));
	//TODO mutex release

	linesToShow.push_back(std::make_pair(line_name,
		AsVector(Eigen2Eigen(t,rgb),Eigen2Eigen(t + vforward*3.0,rgb))
		));
}
 std::future<void> async(_Function&& work, _Args&&... args) {
     auto promise_ptr = std::make_shared<std::promise<void>>();
     do {
         if (std::this_thread::get_id() != thread_.get_id()) {
             std::lock_guard<std::recursive_mutex> api_lock(api_mutex_);
             if (!is_running_) {
                 throw std::runtime_error("Not running");
             }
             std::lock_guard<std::mutex> lock(works_mutex_);
             works_.push_back([=]() {
                 try {
                     work(args...);
                     promise_ptr->set_value();
                 }
                 catch (...) {
                     promise_ptr->set_exception(std::current_exception());
                 }
             });
             workable_.notify_all();
         }
         else {
             if (!is_running_) {
                 throw std::runtime_error("Not running");
             }
             std::lock_guard<std::mutex> lock(works_mutex_);
             works_.push_back([=]() {
                 try {
                     work(args...);
                     promise_ptr->set_value();
                 }
                 catch (...) {
                     promise_ptr->set_exception(std::current_exception());
                 }
             });
             workable_.notify_all();
         }
     } while (0);
     return promise_ptr->get_future();
 }
Exemplo n.º 19
0
/**
**  Send chat message. (Message is sent with low priority)
**
**  @param msg  Text message to send.
*/
void NetworkSendChatMessage(const std::string &msg)
{
	if (!IsNetworkGame()) {
		return;
	}
	CNetworkChat nc;
	nc.Text = msg;
	CNetworkCommandQueue ncq;
	ncq.Type = MessageChat;
	ncq.Data.resize(nc.Size());
	nc.Serialize(&ncq.Data[0]);
	MsgCommandsIn.push_back(ncq);
}
Exemplo n.º 20
0
    void AppendData(double mass)
    {
        wxLongLong_t now = ::wxGetUTCTimeMillis().GetValue();
        wxLongLong_t oldest = now - m_timeWindow;

        while (m_data.size() > 0 && m_data.front().time < oldest)
            m_data.pop_front();

        Entry entry;
        entry.time = now;
        entry.mass = mass;
        m_data.push_back(entry);
    }
Exemplo n.º 21
0
 int write(char *bf,long long len)
   {
   pthread_mutex_lock(&mutex);
   int writeCnt = 0;
   while(len > 0)
     {
     data.push_back(*bf++);
     len--;
     writeCnt++;
     }
   pthread_mutex_unlock(&mutex);
   return writeCnt;
   }
Exemplo n.º 22
0
 value_type* push_anywhere(T& dat) {
   if (!freelist.empty()) {
    value_type* ret = freelist.front();
    ret->first = dat;
    ret->second = false;
    freelist.pop_front();
    return ret;
   }
   else {
     data.push_back(std::make_pair(dat, false));
     return &(data.back());
   }
 }
Exemplo n.º 23
0
			void put(T &&x, std::chrono::milliseconds time_out = INFINITE)
			{
				{
					auto_lock lock(mutex_);
					while(queue_.size() == max_size_ )
						not_full_.wait_for(mutex_, time_out);

					assert(queue_.size() != max_size_);
					queue_.push_back(std::forward<T>(x));
				}

				not_empty_.notify_one();
			}
Exemplo n.º 24
0
    bool
    Handle( std::shared_ptr<BlurryRoots::Yanecos::IEvent> someEvent )
    {
        if( someEvent->GetType() == typeid( ActorMoveRequestEvent ) )
        {
            auto event =
                std::static_pointer_cast<ActorMoveRequestEvent>(
                    someEvent
                );

            _moveRequests.push_back( event );
        }
    }
Exemplo n.º 25
0
bool RegionWellsReader::loadRegion(std::deque<int> &wellX, std::deque<int> &wellY, std::deque<std::vector<float> > &wellMeasurements,
    int regionX, int regionY, Mask *mask)
{
  if ((regionX >= numRegionsX) || (regionY >= numRegionsY))
    return false;

  wellX.clear();
  wellY.clear();
  wellMeasurements.clear();
  pthread_mutex_lock(read_mutex);
  int Y = std::min(regionY*sizeRegionY,(int)wells->NumRows());
  int X = std::min(regionX*sizeRegionX,(int)wells->NumCols());
  int nY = ((regionY+1)*sizeRegionY);
  int nX = ((regionX+1)*sizeRegionX);
  wells->SetChunk(Y, std::min(nY-Y,(int)wells->NumRows() - Y),
                  X, std::min(nX-X,(int)wells->NumCols() - X),
                  0, wells->NumFlows());
  wells->ReadWells();
  for (int nextY = regionY * sizeRegionY; (nextY < (regionY + 1) * sizeRegionY) && (nextY < sizeY); nextY++) {
    for (int nextX = regionX * sizeRegionX; (nextX < (regionX + 1) * sizeRegionX) && (nextX < sizeX); nextX++) {

      if (!mask->Match(nextX, nextY, MaskTF) && !mask->Match(nextX, nextY, MaskLib))
        continue;

      wellX.push_back(nextX);
      wellY.push_back(nextY);
      wellMeasurements.push_back(std::vector<float>());
      wellMeasurements.back().resize(numFlows);


      const WellData *w = wells->ReadXY(nextX, nextY);
      copy(w->flowValues, w->flowValues + numFlows, wellMeasurements.back().begin());

    }
  }
  pthread_mutex_unlock(read_mutex);
  return true; // Region reading successful

}
Exemplo n.º 26
0
std::shared_ptr<WalletRequest> WalletTransactionSender::doSendTransaction(std::shared_ptr<SendTransactionContext> context, std::deque<std::shared_ptr<WalletEvent> >& events) {
  if (m_isStoping) {
    events.push_back(std::make_shared<WalletSendTransactionCompletedEvent>(context->transactionId, make_error_code(cryptonote::error::TX_CANCELLED)));
    return std::shared_ptr<WalletRequest>();
  }

  try
  {
    Transaction& transaction = m_transactionsCache.getTransaction(context->transactionId);

    std::vector<cryptonote::tx_source_entry> sources;
    prepareInputs(context->selectedTransfers, context->outs, sources, context->mixIn);

    cryptonote::tx_destination_entry changeDts = AUTO_VAL_INIT(changeDts);
    createChangeDestinations(m_keys.m_account_address, transaction.totalAmount, context->foundMoney, changeDts);

    std::vector<cryptonote::tx_destination_entry> splittedDests;
    splitDestinations(transaction.firstTransferId, transaction.transferCount, changeDts, context->dustPolicy, splittedDests);

    cryptonote::transaction tx;
    constructTx(m_keys, sources, splittedDests, transaction.extra, context->unlockTimestamp, m_upperTransactionSizeLimit, tx);

    fillTransactionHash(tx, transaction.hash);

    m_unconfirmedTransactions.add(tx, context->transactionId, changeDts.amount);
    notifyBalanceChanged(events);

    return std::make_shared<WalletRelayTransactionRequest>(tx, std::bind(&WalletTransactionSender::relayTransactionCallback, this, context->transactionId,
          std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
  }
  catch(std::system_error& ec) {
    events.push_back(std::make_shared<WalletSendTransactionCompletedEvent>(context->transactionId, ec.code()));
  }
  catch(std::exception&) {
    events.push_back(std::make_shared<WalletSendTransactionCompletedEvent>(context->transactionId, make_error_code(cryptonote::error::INTERNAL_WALLET_ERROR)));
  }

  return std::shared_ptr<WalletRequest>();
}
Exemplo n.º 27
0
 // process a match
 // node, a matched node
 // command, next command to process
 void match_found(variant* node, std::vector<vtpath_command>::iterator inext_command)
 {
     if( inext_command == commands.end() ) {
         TINFRA_TRACE(vtpath_exec_tracer, "vpath_visit: matched result: " << node << ": " << *node);
         // if we're at end of pattern, i.e no rules
         // that means that we've been matched "directly"
         // so mark CURRENT as a result
         result_queue.push_back(node);
         return;
     } else {
         push_container(node, inext_command);
     }
 }
Exemplo n.º 28
0
void processCmdLine(int32_t aCount, char ** anArgList) {

  if (aCount < 4) {
    usage();
    std::exit(-1);
  }

  int64_t start_insn = boost::lexical_cast<int64_t>( anArgList[1] );
  int64_t end_insn   = boost::lexical_cast<int64_t>( anArgList[2] );
  if (start_insn >= end_insn) {
    std::cout << "Start instruction must exceed end instruction\n";
    std::exit(-1);
  }
  std::string input_file = anArgList[3];
  std::string output_file = anArgList[4];

  theCommands.push_back(  ll::bind( &loadDatabase, input_file ) );
  theCommands.push_back(  ll::bind( &computeRegions, start_insn, end_insn ) );
  theCommands.push_back(  ll::bind( &reduceSum, ll::var(region_string) ) );
  theCommands.push_back(  ll::bind( &save, output_file, "selection" ) );

}
Exemplo n.º 29
0
void WalletTransactionSender::sendTransactionRandomOutsByAmount(std::shared_ptr<SendTransactionContext> context, std::deque<std::shared_ptr<WalletEvent> >& events,
    boost::optional<std::shared_ptr<WalletRequest> >& nextRequest, std::error_code ec) {
  if (m_isStoping) {
    events.push_back(std::make_shared<WalletSendTransactionCompletedEvent>(context->transactionId, make_error_code(cryptonote::error::TX_CANCELLED)));
    return;
  }

  if (ec) {
    events.push_back(std::make_shared<WalletSendTransactionCompletedEvent>(context->transactionId, ec));
    return;
  }

  auto scanty_it = std::find_if(context->outs.begin(), context->outs.end(), [&] (cryptonote::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::outs_for_amount& out) {return out.outs.size() < context->mixIn;});

  if (scanty_it != context->outs.end()) {
    events.push_back(std::make_shared<WalletSendTransactionCompletedEvent>(context->transactionId, make_error_code(cryptonote::error::MIXIN_COUNT_TOO_BIG)));
    return;
  }

  std::shared_ptr<WalletRequest> req = doSendTransaction(context, events);
  if (req)
    nextRequest = req;
}
Exemplo n.º 30
0
void NewObjInGlobal()
{
    int percent = RandomRange(1, 100);
    if (percent <= 20)
    {
        g_globalTable.push_back(g_gc.NewTable(luna::GCGen2));
    }
    else if (percent <= 50)
    {
        g_globalString.push_back(g_gc.NewString(luna::GCGen2));
    }
    else if (percent <= 60)
    {
        if (!g_globalFunction.empty())
        {
            auto index = RandomNum(g_globalFunction.size());
            auto proto = g_globalFunction[index];
            auto c = g_gc.NewClosure(luna::GCGen1);
            c->SetPrototype(proto);
            g_globalClosure.push_back(c);
        }
    }
}