string AIHints::constraintsNotFulfilled(AIAction * action, AIHint * hint, ManaCost * potentialMana) { std::stringstream out; if (!action) { if (hint->mCombatAttackTip.size()) { out << "to see if this can attack[" << hint->mCombatAttackTip << "]"; return out.str(); } if (hint->mSourceId && !findSource(hint->mSourceId)) { out << "needcardinplay[" << hint->mSourceId << "]"; return out.str(); } out << "needability[" << hint->mAction << "]"; return out.str(); } MTGAbility * a = action->ability; if (!a) return "not supported"; MTGCardInstance * card = action->click; if (!card) return "not supported"; //dummy test: would the ability work if we were sure to fulfill its mana requirements? if (!a->isReactingToClick(card, a->getCost())) { DebugTrace("This shouldn't happen, this AIAction doesn't seem like a good choice"); return "not supported"; } if (!a->isReactingToClick(card, potentialMana)) { //Not enough Mana, try to find which mana we should get in priority ManaCost * diff = potentialMana->Diff(a->getCost()); for (int i = 0; i < Constants::NB_Colors; i++) { if(diff->getCost(i) < 0) { out << "needmana[" << Constants::MTGColorChars[i] << "]"; if (Constants::MTGColorChars[i] == 'r') DebugTrace("Got it"); SAFE_DELETE(diff); return out.str(); } } //TODO, handle more cases where the cost cannot be paid return "not supported, can't afford cost for some reason"; } //No problem found, we believe this is a good action to perform return ""; }
void Pool::resume(Source *source) { thread::Lock lock(mutex); ALuint out; if (findSource(source, out)) source->resumeAtomic(); }
// get weight short ImageMix::getWeight(const char *id) { // find source ImageSourceList::iterator src = findSource(id); // if found, return its weight return src != m_sources.end() ? getImageSourceMix(*src)->getWeight() : 0; }
// get source object PyImage * ImageBase::getSource (const char * id) { // find source ImageSourceList::iterator src = findSource(id); // return it, if found return src != m_sources.end() ? (*src)->getSource() : NULL; }
// set source object bool ImageBase::setSource (const char * id, PyImage *source) { // find source ImageSourceList::iterator src = findSource(id); // check source loop if (source != NULL && source->m_image->loopDetect(this)) return false; // if found, set new object if (src != m_sources.end()) // if new object is not empty or sources are static if (source != NULL || m_staticSources) // replace previous source (*src)->setSource(source); // otherwise delete source else m_sources.erase(src); // if source is not found and adding is allowed else if (!m_staticSources) { // create new source ImageSource * newSrc = newSource(id); newSrc->setSource(source); // if source was created, add it to source list if (newSrc != NULL) m_sources.push_back(newSrc); } // otherwise source wasn't set else return false; // source was set return true; }
void Pool::rewind(Source * source) { LOCK(mutex); ALuint out; if(findSource(source, out)) source->rewindAtomic(); UNLOCK(mutex); }
void Pool::pause(Source * source) { LOCK(mutex); ALuint out; if(findSource(source, out)) source->pauseAtomic(); UNLOCK(mutex); }
// set weight bool ImageMix::setWeight(const char *id, short weight) { // find source ImageSourceList::iterator src = findSource(id); // if source isn't found, report it if (src == m_sources.end()) return false; // set its weight getImageSourceMix(*src)->setWeight(weight); return true; }
void RealtimeMediaSourceCenterQt5WebRTC::createMediaStream(MediaStreamCreationClient* client, const String& audioDeviceID, const String& videoDeviceID) { ASSERT(client); RefPtr<RealtimeMediaSourceQt5WebRTC> audioSource = findSource(audioDeviceID, RealtimeMediaSource::Audio); RefPtr<RealtimeMediaSourceQt5WebRTC> videoSource = findSource(videoDeviceID, RealtimeMediaSource::Video); m_sourceMap.clear(); if (!audioSource && !videoSource) { client->failedToCreateStreamWithPermissionError(); return; } String audioSourceName = audioSource ? audioSource->name() : String(); String videoSourceName = videoSource ? videoSource->name() : String(); std::shared_ptr<WRTCInt::RTCMediaStream> rtcStream( getRTCMediaSourceCenter().createMediaStream( audioSourceName.utf8().data(), videoSourceName.utf8().data())); Vector<RefPtr<RealtimeMediaSource>> audioSources; Vector<RefPtr<RealtimeMediaSource>> videoSources; if (audioSource) { audioSource->setRTCStream(rtcStream); audioSources.append(audioSource.release()); } if (videoSource) { videoSource->setRTCStream(rtcStream); videoSources.append(videoSource.release()); } String id = rtcStream->id().c_str(); client->didCreateStream(MediaStreamPrivate::create(id, audioSources, videoSources)); }
bool Pool::releaseSource(Source *source, bool stop) { ALuint s; if (findSource(source, s)) { if (stop) source->stopAtomic(); source->release(); available.push(s); playing.erase(source); return true; } return false; }
static int parseNoSource(rpmSpec spec, const char * field, rpmTagVal tag) { const char *f, *fe; const char *name; int flag; uint32_t num; if (tag == RPMTAG_NOSOURCE) { flag = RPMBUILD_ISSOURCE; name = "source"; } else { flag = RPMBUILD_ISPATCH; name = "patch"; } fe = field; for (f = fe; *f != '\0'; f = fe) { struct Source *p; SKIPWHITE(f); if (*f == '\0') break; fe = f; SKIPNONWHITE(fe); if (*fe != '\0') fe++; if (parseUnsignedNum(f, &num)) { rpmlog(RPMLOG_ERR, _("line %d: Bad number: %s\n"), spec->lineNum, f); return RPMRC_FAIL; } if (! (p = findSource(spec, num, flag))) { rpmlog(RPMLOG_ERR, _("line %d: Bad no%s number: %u\n"), spec->lineNum, name, num); return RPMRC_FAIL; } p->flags |= RPMBUILD_ISNO; } return 0; }
bool Pool::assignSource(Source *source, ALuint &out, char &wasPlaying) { out = 0; if (findSource(source, out)) return wasPlaying = true; wasPlaying = false; if (available.empty()) return false; out = available.front(); available.pop(); playing.insert(std::make_pair(source, out)); source->retain(); return true; }
bool Pool::play(Source * source, ALuint & out) { bool ok; out = 0; LOCK(mutex); bool alreadyPlaying = findSource(source, out); if(!alreadyPlaying) { // Try to play. if(!available.empty()) { // Get the first available source. out = available.front(); // Remove it. available.pop(); // Insert into map of playing sources. playing.insert(std::pair<Source *, ALuint>(source, out)); source->retain(); source->playAtomic(); ok = true; } else { ok = false; } } else { ok = true; } UNLOCK(mutex); return ok; }
int parseNoSource(Spec spec, const char * field, rpmTag tag) { const char *f, *fe; const char *name; rpmuint32_t num, flag; if (tag == RPMTAG_NOSOURCE) { flag = RPMFILE_SOURCE; name = "source"; } else { flag = RPMFILE_PATCH; name = "patch"; } fe = field; for (f = fe; *f != '\0'; f = fe) { struct Source *p; SKIPWHITE(f); if (*f == '\0') break; fe = f; SKIPNONWHITE(fe); if (*fe != '\0') fe++; if (parseNum(f, &num)) { rpmlog(RPMLOG_ERR, _("line %d: Bad number: %s\n"), spec->lineNum, f); return RPMRC_FAIL; } if (! (p = findSource(spec, num, flag))) { rpmlog(RPMLOG_ERR, _("line %d: Bad no%s number: %d\n"), spec->lineNum, name, num); return RPMRC_FAIL; } p->flags |= RPMFILE_GHOST; } return RPMRC_OK; }
void Foam::equationReader::createMap ( const label index, const tokenList& tl, PtrList<equationOperation>& map, labelList& opLvl, labelList& pl ) const { // equation * eqn(&this->operator[](index)); // current parenthesis level - note, a negative parenthesis value indicates // that this is the root level of a function, and therefore ',' is allowed label p(0); forAll(tl, i) { if (tl[i].isNumber()) { // Internal constant. Save to internalScalars and record source opLvl[i] = 0; pl[i] = p; map.set ( i, new equationOperation ( equationOperation::stinternalScalar, addInternalScalar(tl[i].number()) + 1, 0, 0, equationOperation::otnone ) ); } else if (tl[i].isWord()) { // could be a variable name, function or mathematical constant // - check for function first - function is [word][punctuation '('] if ( (i < (tl.size() - 1)) && (tl[i + 1].isPunctuation()) && (tl[i + 1].pToken() == token::BEGIN_LIST) ) { // Function detected; function brackets are negative opLvl[i] = 4; p = -mag(p) - 1; pl[i] = p; map.set ( i, new equationOperation ( equationOperation::stnone, 0, 0, 0, equationOperation::findOp(tl[i].wordToken()) ) ); if (map[i].operation() == equationOperation::otnone) { OStringStream description; description << tl[i].wordToken() << " is not a recognized " << "function."; fatalParseError ( index, tl, i, i, "equationReader::parse", description ); } // Set next token as well (function opening parenthesis) i++; opLvl[i] = 4; pl[i] = p; map.set ( i, new equationOperation ( equationOperation::stnone, 0, 0, 0, equationOperation::otnone ) ); } else if ( (tl[i].wordToken() == "e_") || (tl[i].wordToken() == "pi_") || (tl[i].wordToken() == "twoPi_") || (tl[i].wordToken() == "piByTwo_") || (tl[i].wordToken() == "GREAT_") || (tl[i].wordToken() == "VGREAT_") || (tl[i].wordToken() == "ROOTVGREAT_") || (tl[i].wordToken() == "SMALL_") || (tl[i].wordToken() == "VSMALL_") || (tl[i].wordToken() == "ROOTVSMALL_") ) { // Mathematical constant if ( findSource(tl[i].wordToken()).sourceType() != equationOperation::stnone ) { // Found a possible conflicting variable name - warn WarningIn("equationReader::createMap") << "Equation for " << operator[](index).name() << ", given by:" << token::NL << token::TAB << operator[](index).rawText() << token:: NL << "refers " << "to '" << tl[i].wordToken() << "'. Although " << "variable " << tl[i].wordToken() << "was found in " << "the data sources, " << tl[i].wordToken() << " is a" << " mathematical constant. The mathematical constant " << "will be used." << endl; } opLvl[i] = 0; pl[i] = p; label internalIndex(0); if (tl[i].wordToken() == "e_") { // MathConstantScope is a hack that allows equationReader // to work in multiple versions of OpenFOAM. See // include/versionSpecific.H internalIndex = addInternalScalar(MathConstantScope::e) + 1; } else if (tl[i].wordToken() == "pi_") { internalIndex = addInternalScalar(MathConstantScope::pi) + 1; } else if (tl[i].wordToken() == "twoPi_") { internalIndex = addInternalScalar(MathConstantScope::twoPi) + 1; } else if (tl[i].wordToken() == "piByTwo_") { internalIndex = addInternalScalar(MathConstantScope::piByTwo) + 1; } else if (tl[i].wordToken() == "GREAT_") { internalIndex = addInternalScalar(GREAT) + 1; } else if (tl[i].wordToken() == "VGREAT_") { internalIndex = addInternalScalar(VGREAT) + 1; } else if (tl[i].wordToken() == "ROOTVGREAT_") { internalIndex = addInternalScalar(ROOTVGREAT) + 1; } else if (tl[i].wordToken() == "SMALL_") { internalIndex = addInternalScalar(SMALL) + 1; } else if (tl[i].wordToken() == "VSMALL_") { internalIndex = addInternalScalar(VSMALL) + 1; } else // tl[i].wordToken() == "ROOTVSMALL_" { internalIndex = addInternalScalar(ROOTVSMALL) + 1; } map.set ( i, new equationOperation ( equationOperation::stinternalScalar, internalIndex, 0, 0, equationOperation::otnone ) ); } else { // Variable name opLvl[i] = 0; pl[i] = p; map.set ( i, new equationOperation(findSource(tl[i].wordToken())) ); if (map[i].sourceIndex() == 0) { OStringStream description; description << "Variable name " << tl[i].wordToken() << " not found in any available sources."; fatalParseError ( index, tl, i, i, "equationReader::parse", description ); } if (map[i].componentIndex() < 0) { OStringStream description; description << "Variable name " << tl[i].wordToken() << " is interpretted as variablePart.componentPart, " << "and the componentPart is not valid, or is " << "required, but is missing."; fatalParseError ( index, tl, i, i, "equationReader::parse", description ); } } } else if (tl[i].isPunctuation()) { switch (tl[i].pToken()) { case token::BEGIN_LIST: // ( opLvl[i] = 4; p = mag(p) + 1; pl[i] = p; map.set ( i, new equationOperation ( equationOperation::stnone, 0, 0, 0, equationOperation::otnone ) ); break; case token::END_LIST: // ) { opLvl[i] = -4; pl[i] = p; p = mag(p) - 1; if (p < 0) { OStringStream description; description << "Too many ')'."; fatalParseError ( index, tl, i, i, "equationReader::parse", description ); } // Look for preceding parenthesis change - was it negative? for (label j(i - 1); j >= 0; j--) { if (mag(pl[j]) == p) { if (pl[j] < 0) { p = -p; } break; } } map.set ( i, new equationOperation ( equationOperation::stnone, 0, 0, 0, equationOperation::otnone ) ); break; } case token::COMMA: // , // , is only accepted in a function level parenthesis if (p < 0) { opLvl[i] = 5; pl[i] = p; map.set ( i, new equationOperation ( equationOperation::stnone, 0, 0, 0, equationOperation::otnone ) ); } else { OStringStream description; description << "The comma, ',' does not make sense " << "here. Only permitted in the root parenthesis " << "level of a function."; fatalParseError ( index, tl, i, i, "equationReader::parse", description ); } break; case token::ADD: // + opLvl[i] = 1; pl[i] = p; map.set ( i, new equationOperation ( equationOperation::stnone, 0, 0, 0, equationOperation::otplus ) ); break; case token::SUBTRACT: // - opLvl[i] = 1; pl[i] = p; map.set ( i, new equationOperation ( equationOperation::stnone, 0, 0, 0, equationOperation::otminus ) ); break; case token::MULTIPLY: // * opLvl[i] = 2; pl[i] = p; map.set ( i, new equationOperation ( equationOperation::stnone, 0, 0, 0, equationOperation::ottimes ) ); break; case token::DIVIDE: // / opLvl[i] = 2; pl[i] = p; map.set ( i, new equationOperation ( equationOperation::stnone, 0, 0, 0, equationOperation::otdivide ) ); break; case token::COLON: // :, means ^ { OStringStream description; description << "The '^' operator is not currently " << "supported. Use pow(a,b) instead."; fatalParseError ( index, tl, i, i, "equationReader::parse", description ); break; } /* opLvl[i] = 3; pl[i] = p; map.set ( i, new equationOperation ( equationOperation::stnone, 0, 0, 0, equationOperation::otpow ) ); break; */ default: { OStringStream description; description << "Punctuation character '" << tl[i].pToken() << "' is prohibitted."; fatalParseError ( index, tl, i, i, "equationReader::parse", description ); break; } } // end punctuation switch } // end if punctuation else { OStringStream description; description << "Unrecognized token: [" << tl[i] << "]."; fatalParseError ( index, tl, i, i, "equationReader::parse", description ); } } // mapping loop if (p) { OStringStream description; description << "Parentheses do not match. Expecting " << mag(p) << " additional ')'s."; fatalParseError ( index, tl, 0, tl.size() - 1, "equationReader::parse", description ); } // Assign negatives (distinguish these from subtraction) // The difference is characterized by the preceding character: // -preceeded by an operator = negative '+' '-' '*' '/' '^' // -preceeded by an open bracket = negative '(' // -preceeded by a comma = negative ',' // -preceeded by a variable = subtract 'word' or 'number' // -preceeded by a close bracket = subtract ')' // Negatives are identified by a negative dictLookupIndex if (map[0].operation() == equationOperation::otminus) { opLvl[0] = 2; map[0].dictLookupIndex() = -1; } for (label i(1); i < map.size(); i++) { if (map[i].operation() == equationOperation::otminus) { if (opLvl[i-1] > 0) { opLvl[i] = 2; map[i].dictLookupIndex() = -1; } } } }
void Foam::equationReader::removePowExponents ( const label index, tokenList& tl, PtrList<equationOperation>& map, labelList& opLvl, labelList& pl ) const { // Remove pow(a,b) exponent part 'b' from an equation and create a sub- // equation. label tokenI(0); while (tokenI < map.size()) { if (map[tokenI].operation() == equationOperation::otpow) { // Found a 'pow('. Look for ','; fail on ')', or end of list // pl checks ensure the ',' or ')' relate to the 'pow(', and not // another function / parethesis const label powFoundAt(tokenI); const label pLvl(pl[tokenI]); while ((opLvl[tokenI] != 5) || (pl[tokenI] != pLvl)) { if ( ((opLvl[tokenI] == -4) && (pl[tokenI] == pLvl)) || (tokenI == (map.size() - 1)) ) { OStringStream description; description << "pow() function takes two arguments."; fatalParseError ( index, tl, powFoundAt, tokenI, "equationReader::removePowExponents", description ); } tokenI++; } // Found 'pow( ... ,' look for ')', fail on list end const label commaFoundAt(tokenI); while ((opLvl[tokenI] != -4) || (pl[tokenI] != pLvl)) { if (tokenI == (map.size() - 1)) { OStringStream description; description << "Can't find closing parenthesis for " << "pow() function."; fatalParseError ( index, tl, powFoundAt, tokenI, "equationReader::removePowExponents", description ); } tokenI++; } const label closeFoundAt(tokenI); // Ignore if the exponent is only 1 token if ((closeFoundAt - commaFoundAt) > 2) { // Now create sub-equation OStringStream subEqnStream; for ( label subTokenI(commaFoundAt + 1); subTokenI < closeFoundAt; subTokenI++ ) { if ( tl[subTokenI].isPunctuation() && (tl[subTokenI].pToken() == token::COLON)) { subEqnStream << "^"; } else { subEqnStream << tl[subTokenI]; } } string subEqnRawText(subEqnStream.str()); const equation& eqn(operator[](index)); equation subEqn ( eqn.name() + "_powExponent_" + name(powFoundAt), subEqnRawText, eqn.overrideDimensions(), eqn.changeDimensions() ); bool eqnCreated(false); for (label eqnI(0); eqnI < size(); eqnI++) { const equation& eqnTest(operator[](eqnI)); if (eqnTest.name() == subEqn.name()) { clearEquation(eqnI); eqnTest.setRawText(subEqn.rawText()); eqnTest.setOverrideDimensions ( subEqn.overrideDimensions() ); eqnTest.setChangeDimensions ( eqnTest.changeDimensions() ); eqnCreated = true; } } if (!eqnCreated) { createEquation(subEqn); } // Change commaFoundAt + 1 entry to reflect new subEquation // reference tl[commaFoundAt + 1] = token(subEqn.name()); map.set ( commaFoundAt + 1, new equationOperation(findSource(subEqn.name())) ); opLvl[commaFoundAt + 1] = 0; pl[commaFoundAt + 1] = pl[commaFoundAt]; // Remove the subEquation from tl, map, opLvl and pl label tokensRemoved(closeFoundAt - (commaFoundAt + 2)); label newSize(map.size() - tokensRemoved); for ( label subTokenI(commaFoundAt + 2); subTokenI < newSize; subTokenI++ ) { tl[subTokenI] = tl[subTokenI + tokensRemoved]; map[subTokenI] = map[subTokenI + tokensRemoved]; opLvl[subTokenI] = opLvl[subTokenI + tokensRemoved]; pl[subTokenI] = pl[subTokenI + tokensRemoved]; } tl.setSize(newSize); map.setSize(newSize); opLvl.setSize(newSize); pl.setSize(newSize); } } tokenI++; } }
void DreamWebEngine::convIcons() { uint8 index = _character & 127; uint16 frame = getPersFrame(index); const GraphicsFile *base = findSource(frame); showFrame(*base, 234, 2, frame, 0); }
///////////////////////////////////////////////////////////////////////////////////////// // DefaultUnfoundedCheck - Finding & propagating unfounded sets ///////////////////////////////////////////////////////////////////////////////////////// bool DefaultUnfoundedCheck::findUnfoundedSet() { // first: remove all sources that were recently falsified VarVec::size_type unpick = invalid_.size(); for (VarVec::size_type i = 0; i != invalidExt_.size(); ++i) { uint32 id = invalidExt_[i] >> 1; ExtWatch::Type t = static_cast<ExtWatch::Type>(invalidExt_[i] & 1u); if (t == ExtWatch::watch_choice_false) { if (atoms_[id].hasSource() && !solver_->isFalse(graph_->getBodyNode(atoms_[id].watch()).lit)) { atoms_[id].markSourceInvalid(); sourceQ_.push_back(id); propagateSource(true); } } else if (t == ExtWatch::watch_body_goal_false) { typedef DependencyGraph::BodyNode BodyNode; const ExtWatch& w = watches_[id]; BodyData& b = bodies_[w.bodyId]; ExtData* ext = extended_[b.lower_or_ext]; const BodyNode& B = graph_->getBodyNode(w.bodyId); NodeId pred = w.data >> 1; ext->removeFromWs(pred, B.pred_weight(pred, test_bit(w.data, 0) != 0)); if (ext->lower > 0 && b.watches && b.picked == 0 && !solver_->isFalse(B.lit)) { invalid_.push_back(w.bodyId); b.picked = 1; } } } for (VarVec::size_type i = 0; i != invalid_.size(); ++i) { removeSource(invalid_[i]); } for (VarVec::size_type i = unpick; i != invalid_.size(); ++i) { bodies_[invalid_[i]].picked = 0; } invalid_.clear(); invalidExt_.clear(); assert(sourceQ_.empty() && unfounded_.empty()); // second: try to re-establish sources. while (!todo_.empty()) { NodeId head = dequeueTodo(); if (!atoms_[head].hasSource() && !solver_->isFalse(graph_->getAtomNode(head).lit) && !findSource(head)) { return true; // found an unfounded set - contained in unfounded_ } assert(sourceQ_.empty()); } todo_.clear(); return false; // no unfounded sets }