// Fire any weapons that are ready to fire. If an anti-missile is ready, // instead of firing here this function returns true and it can be fired if // collision detection finds a missile in range. bool Ship::Fire(list<Projectile> &projectiles, std::list<Effect> &effects) { isInSystem = true; forget = 0; // A ship that is about to die creates a special single-turn "projectile" // representing its death explosion. if(IsDestroyed() && explosionCount == explosionTotal && explosionWeapon) projectiles.emplace_back(position, explosionWeapon); if(CannotAct()) return false; bool hasAntiMissile = false; const vector<Armament::Weapon> &weapons = armament.Get(); for(unsigned i = 0; i < weapons.size(); ++i) { const Outfit *outfit = weapons[i].GetOutfit(); if(outfit && CanFire(outfit)) { if(outfit->AntiMissile()) hasAntiMissile = true; else if(commands.HasFire(i)) armament.Fire(i, *this, projectiles, effects); } } armament.Step(*this); return hasAntiMissile; }
void expand_stages(map<int, PipelineComponentBase*> &base_stages, int copies, list<map<int, PipelineComponentBase*>> &all_stages) { for (int i=0; i<copies; i++) { map<int, PipelineComponentBase*> cpy; for (pair<int, PipelineComponentBase*> pcb : base_stages) { // clone basic info PipelineComponentBase* pcb_cpy = pcb.second->clone(); // set name and id pcb_cpy->setName(pcb.second->getName()); pcb_cpy->setId(new_uid()); // copy input list for (int inp : pcb.second->getInputs()) pcb_cpy->addInput(inp); // copy output list for (int out : pcb.second->getOutputs()) pcb_cpy->addOutput(out); cpy[pcb_cpy->getId()] = pcb_cpy; } all_stages.emplace_back(cpy); } }
// returns by reference a list of copied outputs. void expand_arguments(map<int, ArgumentBase*> &ref_arguments, int copies, list<map<int, ArgumentBase*>> ©_arguments) { for (int i=0; i<copies; i++) { map<int, ArgumentBase*> cpy = cpy_ab_map(ref_arguments); copy_arguments.emplace_back(cpy); } }
void StreamSorter<Message>::open_all(const vector<string>& filenames, list<ifstream>& streams, list<cursor_t>& cursors) { // The open files need to live in a collection; the cursors don't own them. // They also can't be allowed to move since we reference them. // The cursors also need to live in a collection, because we don't want to be // moving/copying them and their internal buffers and streams. // And they can't move after creation either. // So everything lives in caller-passed lists. for (auto& filename : filenames) { // Open each file streams.emplace_back(); streams.back().open(filename); // Make a cursor for it cursors.emplace_back(streams.back()); } }
// This is called when a projectile "dies," either of natural causes or // because it hit its target. void Projectile::MakeSubmunitions(list<Projectile> &projectiles) const { // Only make submunitions if you did *not* hit a target. if(lifetime <= -100) return; for(const auto &it : weapon->Submunitions()) for(int i = 0; i < it.second; ++i) projectiles.emplace_back(*this, it.first); }
void do_sort(std::list<T>& chunk_data) { std::list<T> result; result.splice(result.begin(),chunk_data,chunk_data.begin()); T const& partition_val=*result.begin(); typename std::list<T>::iterator divide_point = std::partition(chunk_data.begin(),chunk_data.end(),[&](T const& val){return val<partition_val;}); chunk_to_sort new_lower_chunk; new_lower_chunk.data_m.splice(new_lower_chunk.data_m.end(), chunk_data,chunk_data.begin(),divide_point); chunks_m.emplace_back(std::move(new_lower_chunk)); }
void _gameData::addEnemyMaskPlus1(list<pos>& poses, pos rc){ float sqrtfar2=sqrt(ar2); for(int row=-4; row<=4; row++){ for(int col=-4; col<=4; col++){ float oedist=sqrt(euclideanDist2(0,0,row,col,rows,cols)); //if(sqrtfar2+1<oedist and oedist<=sqrtfar2+2){ if(oedist<=sqrtfar2+2) poses.emplace_back(pos(wrap(rc.row+row, rows), wrap(rc.col+col,cols))); } } };
int get_line(char** line, FILE* f) { char* nline; size_t length=0; if (line_buffer.empty()) { if (getline(&nline, &length, f) == -1) return -1; string sline(nline); size_t pos=string::npos; while ((pos = sline.find("><")) != string::npos) { line_buffer.emplace_back(sline.substr(0,pos+1)); sline = sline.substr(pos+1); } line_buffer.emplace_back(sline); } char* cline = (char*)malloc((line_buffer.front().length()+1)*sizeof(char*)); memcpy(cline, line_buffer.front().c_str(), line_buffer.front().length()+1); *line = cline; line_buffer.pop_front(); return strlen(*line); }
// Fire this weapon. If it is a turret, it automatically points toward // the given ship's target. If the weapon requires ammunition, it will // be subtracted from the given ship. void Armament::Weapon::Fire(Ship &ship, list<Projectile> &projectiles, list<Effect> &effects) { // Since this is only called internally by Armament (no one else has non- // const access), assume Armament checked that this is a valid call. Angle aim = ship.Facing(); // Get projectiles to start at the right position. They are drawn at an // offset of (.5 * velocity) and that velocity includes the velocity of the // ship that fired them. Point start = ship.Position() + aim.Rotate(point) - .5 * ship.Velocity(); shared_ptr<const Ship> target = ship.GetTargetShip(); // If you are boarding your target, do not fire on it. if(ship.IsBoarding() || ship.Commands().Has(Command::BOARD)) target.reset(); if(!isTurret || !target || target->GetSystem() != ship.GetSystem()) aim += angle; else { Point p = target->Position() - start + ship.GetPersonality().Confusion(); Point v = target->Velocity() - ship.Velocity(); double steps = RendezvousTime(p, v, outfit->Velocity()); // Special case: RendezvousTime() may return NaN. But in that case, this // comparison will return false. if(!(steps < outfit->TotalLifetime())) steps = outfit->TotalLifetime(); p += steps * v; aim = Angle(TO_DEG * atan2(p.X(), -p.Y())); } projectiles.emplace_back(ship, start, aim, outfit); if(outfit->WeaponSound()) Audio::Play(outfit->WeaponSound(), start); double force = outfit->FiringForce(); if(force) ship.ApplyForce(aim.Unit() * -force); for(const auto &eit : outfit->FireEffects()) for(int i = 0; i < eit.second; ++i) { effects.push_back(*eit.first); effects.back().Place(start, ship.Velocity(), aim); } Fire(ship); }
void operator()(GNode node, list<GNode>& workList) { Node &nData = graph.getData(node); for (Graph::edge_iterator ei = graph.edge_begin(node),ee=graph.edge_end(node); ei != ee; ei++) { GNode neigh = graph.getEdgeDst(ei); Node &neighData = graph.getData(neigh); if (neighData.component > nData.component) { neighData.component = nData.component; if (schedule == FIFO) { workList.emplace_back(neigh); } else { workList.emplace_front(neigh); } } } }
void get_workflow_arguments(FILE* workflow, list<ArgumentBase*> &output_arguments) { char *line = NULL; size_t len = 0; // initial ports section beginning and end string ie("<outputs>"); string iee("</outputs>"); // ports section beginning and end string e("<entry>"); string ee("</entry>"); // go to the initial entries beginning while (get_line(&line, workflow) != -1 && string(line).find(ie) == string::npos); // cout << "port init begin: " << line << endl; // keep getting ports until it reaches the end of initial ports while (get_line(&line, workflow) != -1 && string(line).find(iee) == string::npos) { // consumes the port beginning while (string(line).find(e) == string::npos && get_line(&line, workflow) != -1); // cout << "port begin: " << line << endl; // finds the name and field string name = get_workflow_field(workflow, "string"); // generate an argument string type = get_workflow_field(workflow, "path"); ArgumentBase* arg = new_typed_arg_base(type); arg->setName(name); arg->setId(new_uid()); output_arguments.emplace_back(arg); // consumes the port ending while (get_line(&line, workflow) != -1 && string(line).find(ee) == string::npos); // cout << "not port end: " << line << endl; // cout << "port end: " << line << endl; } // cout << "port init end: " << line << endl; }
void pcl::recognition::ObjRecRANSAC::filterGraphOfConflictingHypotheses (ORRGraph<Hypothesis*>& graph, list<ObjRecRANSAC::Output>& recognized_objects) const { #ifdef OBJ_REC_RANSAC_VERBOSE printf ("ObjRecRANSAC::%s(): filtering the conflict graph ... ", __func__); fflush (stdout); #endif vector<ORRGraph<Hypothesis*>::Node*> &nodes = graph.getNodes (); // Compute the penalty for each graph node for ( vector<ORRGraph<Hypothesis*>::Node*>::iterator it = nodes.begin () ; it != nodes.end () ; ++it ) { size_t num_of_explained = 0; // Accumulate the number of pixels the neighbors are explaining for ( set<ORRGraph<Hypothesis*>::Node*>::const_iterator neigh = (*it)->getNeighbors ().begin () ; neigh != (*it)->getNeighbors ().end () ; ++neigh ) num_of_explained += (*neigh)->getData ()->explained_pixels_.size (); // Now compute the fitness for the node (*it)->setFitness (static_cast<int> ((*it)->getData ()->explained_pixels_.size ()) - static_cast<int> (num_of_explained)); } // Leave the fitest leaves on, such that there are no neighboring ON nodes list<ORRGraph<Hypothesis*>::Node*> on_nodes, off_nodes; graph.computeMaximalOnOffPartition (on_nodes, off_nodes); // The ON nodes correspond to accepted solutions for ( list<ORRGraph<Hypothesis*>::Node*>::iterator it = on_nodes.begin () ; it != on_nodes.end () ; ++it ) { recognized_objects.emplace_back((*it)->getData ()->obj_model_->getObjectName (), (*it)->getData ()->rigid_transform_, (*it)->getData ()->match_confidence_, (*it)->getData ()->obj_model_->getUserData () ); } #ifdef OBJ_REC_RANSAC_VERBOSE printf ("done\n"); #endif }
int AddBlockMintsToAccumulator(const CoinDenomination den, const CBloomFilter filter, const CBlockIndex* pindex, libzerocoin::Accumulator* accumulator, bool isWitness, list<CBigNum>& notAddedCoins) { // if this block contains mints of the denomination that is being spent, then add them to the witness int nMintsAdded = 0; if (pindex->MintedDenomination(den)) { //add the mints to the witness for (const PublicCoin& pubcoin : GetPubcoinFromBlock(pindex)) { if (pubcoin.getDenomination() != den) { continue; } if (isWitness && filter.contains(pubcoin.getValue().getvch())) { notAddedCoins.emplace_back(pubcoin.getValue()); continue; } accumulator->increment(pubcoin.getValue()); ++nMintsAdded; } } return nMintsAdded; }
virtual void registerColleague(ColleagueInterface * colleague) { colleagueList.emplace_back(colleague); }
/** * split and trim comma-separated list of values (other delimiters can be used too, ie: semicolon). * * RFC 4180 difference: it does skip space-only lines and trim values unless it is " quoted ". * * @param[in] i_values source string of comma separated values. * @param[in,out] io_resultLst source string of comma separated values. * @param[in] i_delimiters list of delimiters, default: comma. * @param[in] i_isUnquote if true then do "unquote ""csv"" ", default: false. * @param[in] i_quote quote character, default: sql single ' quote. * @param[in] i_locale locale to trim space characters, defaut: user default locale. */ void openm::splitCsv( const string & i_values, list<string> & io_resultLst, const char * i_delimiters, bool i_isUnquote, char i_quote, const locale & i_locale) { // if source is empty then return empty result string::size_type nSrcLen = i_values.length(); if (nSrcLen <= 0) { io_resultLst.clear(); // source string is empty: return empty list return; } // no delimiters: return entire source string as first element of result list size_t nDelimLen = (i_delimiters != nullptr) ? strnlen(i_delimiters, OM_STRLEN_MAX) : 0; if (0 == nDelimLen) { io_resultLst.clear(); io_resultLst.push_back(trim(i_values)); return; } // position and size in already existing list to set new values size_t lstSize = io_resultLst.size(); size_t lstPos = 0; list<string>::iterator lstIt = io_resultLst.begin(); // find delimiter(s) and append values into output list string::size_type nStart = 0; bool isInside = false; bool isDelim = false; for (string::size_type nPos = 0; nPos < nSrcLen; nPos++) { char chNow = i_values[nPos]; // if unquote required and this is quote then toogle 'inside '' quote' status if (i_isUnquote && chNow == i_quote) { isInside = !isInside; } // if not 'inside' of quoted value then check for any of delimiters if (!isInside) { isDelim = any_of( i_delimiters, i_delimiters + nDelimLen, [chNow](const char i_delim) -> bool { return chNow == i_delim; } ); } // if this is delimiter or end of string then unquote value and append to the list if (isDelim || nPos == nSrcLen - 1) { // column size: until end of line or until next delimiter size_t nLen = (nPos == nSrcLen - 1 && !isDelim) ? nSrcLen - nStart : nPos - nStart; // if previous list had enough columns then use it else append new column // trim spaces and unquote value if required if (lstPos < lstSize) { lstIt->clear(); // clear previous value lstIt->append(( i_isUnquote ? toUnQuoted(i_values.substr(nStart, nLen), i_quote, i_locale) : trim(i_values.substr(nStart, nLen), i_locale) )); ++lstIt; // next column in existing list buffer } else { // append new column io_resultLst.emplace_back(( i_isUnquote ? toUnQuoted(i_values.substr(nStart, nLen), i_quote, i_locale) : trim(i_values.substr(nStart, nLen), i_locale) )); } ++lstPos; // column count in the current list // if this is like: a,b, where delimiter at the end of line then append empty "" value if (nPos == nSrcLen - 1 && isDelim) { if (lstPos < lstSize) { lstIt->clear(); // clear previous column value ++lstIt; } else { io_resultLst.emplace_back(""); // append new empty column } ++lstPos; } nStart = nPos + 1; // skip delimiter and continue isDelim = false; } } // if current line have less columns than previous buffer then trim extra columns from result if (lstPos < lstSize) { io_resultLst.resize(lstPos); } }
void pcl::recognition::ObjRecRANSAC::sampleOrientedPointPairs (int num_iterations, const vector<ORROctree::Node*>& full_scene_leaves, list<OrientedPointPair>& output) const { #ifdef OBJ_REC_RANSAC_VERBOSE printf ("ObjRecRANSAC::%s(): sampling oriented point pairs (opps) ... ", __func__); fflush (stdout); int num_of_opps = 0; #endif int num_full_leaves = static_cast<int> (full_scene_leaves.size ()); if ( !num_full_leaves ) { #ifdef OBJ_REC_RANSAC_VERBOSE cout << "done [" << num_of_opps << " opps].\n"; #endif return; } // The random generator UniformGenerator<int> randgen (0, num_full_leaves - 1, static_cast<uint32_t> (time (NULL))); // Init the vector with the ids vector<int> ids (num_full_leaves); for ( int i = 0 ; i < num_full_leaves ; ++i ) ids[i] = i; // Sample 'num_iterations' number of oriented point pairs for ( int i = 0 ; i < num_iterations ; ++i ) { // Choose a random position within the array of ids randgen.setParameters (0, static_cast<int> (ids.size ()) - 1); int rand_pos = randgen.run (); // Get the leaf at that random position ORROctree::Node *leaf1 = full_scene_leaves[ids[rand_pos]]; // Delete the selected id ids.erase (ids.begin() + rand_pos); // Get the leaf's point and normal const float *p1 = leaf1->getData ()->getPoint (); const float *n1 = leaf1->getData ()->getNormal (); // Randomly select a leaf at the right distance from 'leaf1' ORROctree::Node *leaf2 = scene_octree_.getRandomFullLeafOnSphere (p1, pair_width_); if ( !leaf2 ) continue; // Get the leaf's point and normal const float *p2 = leaf2->getData ()->getPoint (); const float *n2 = leaf2->getData ()->getNormal (); if ( ignore_coplanar_opps_ ) { if ( aux::pointsAreCoplanar (p1, n1, p2, n2, max_coplanarity_angle_) ) continue; } // Save the sampled point pair output.emplace_back(p1, n1, p2, n2); #ifdef OBJ_REC_RANSAC_VERBOSE ++num_of_opps; #endif } #ifdef OBJ_REC_RANSAC_VERBOSE cout << "done [" << num_of_opps << " opps].\n"; #endif }