std::vector< CoinTriple<AlpsNodeDesc*, AlpsNodeStatus, double> > KnapTreeNode::branch() { KnapNodeDesc* desc = dynamic_cast<KnapNodeDesc*>(desc_); const int oldCap = desc->getUsedCapacity(); const int oldVal = desc->getUsedValue(); const KnapModel* m = dynamic_cast<KnapModel*>(desc->model()); const int n = m->getNumItems(); const KnapVarStatus* oldStati = desc->getVarStati(); KnapVarStatus* newStati = new KnapVarStatus[n]; std::copy(oldStati, oldStati+n, newStati); newStati[branchedOn_] = KnapVarFixedToZero; std::vector< CoinTriple<AlpsNodeDesc*, AlpsNodeStatus, double> > newNodes; int cap = oldCap; int val = oldVal; AlpsNodeDesc* child; child = new KnapNodeDesc(const_cast<KnapModel*>(m), newStati, cap, val); newNodes.push_back(CoinMakeTriple(child, AlpsNodeStatusCandidate, getQuality())); newStati = new KnapVarStatus[n]; std::copy(oldStati, oldStati+n, newStati); newStati[branchedOn_] = KnapVarFixedToOne; cap = oldCap + m->getItem(branchedOn_).first; val = oldVal + m->getItem(branchedOn_).second; // *FIXME* : we could figure out if it's fathomed...// DONE, // if used capacity is not larger than the knap capacity, then add // it newNodes... if ( cap <= m->getCapacity() ) { child = new KnapNodeDesc(const_cast<KnapModel* >(m), newStati, cap, val); newNodes.push_back(CoinMakeTriple(child, AlpsNodeStatusCandidate, getQuality())); } else { // Need this child = new KnapNodeDesc(const_cast<KnapModel* >(m), newStati, cap, val); newNodes.push_back(CoinMakeTriple(child, AlpsNodeStatusFathomed, getQuality())); } return newNodes; }
void CDisplaySettingsDetailsWidget::load() { CSystem &s = CSystem::GetInstance(); landscapeSlider->setValue( getQuality( qualityToLandscapeThreshold, s.config.getFloat( "LandscapeThreshold" ) ) ); landscapeSlider->setValue( std::min( landscapeSlider->value(), getQuality( qualityToZFar, s.config.getFloat( "Vision" ) ) ) ); landscapeSlider->setValue( std::min( landscapeSlider->value(), getQuality( qualityToLandscapeTileNear, s.config.getFloat( "LandscapeTileNear" ) ) ) ); landscapeSlider->setValue( std::min( landscapeSlider->value(), getQuality( qualityToMicrovegetDensity, s.config.getFloat( "MicroVegetDensity" ) ) ) ); charactersSlider->setValue( getQuality( qualityToSkinNbMaxPoly, s.config.getInt( "SkinNbMaxPoly" ) ) ); charactersSlider->setValue( std::min( charactersSlider->value(), getQuality( qualityToNbMaxSkeletonNotCLod, s.config.getInt( "NbMaxSkeletonNotCLod" ) ) ) ); charactersSlider->setValue( std::min( charactersSlider->value(), getQuality( qualityToCharacterFarClip, s.config.getFloat( "CharacterFarClip" ) ) ) ); fxSlider->setValue( getQuality( qualityToFxNbMaxPoly, s.config.getInt( "FxNbMaxPoly" ) ) ); int hdTextureInstalled = s.config.getInt( "HDTextureInstalled" ); if( hdTextureInstalled == 1 ) texturesSlider->setMaximum( QUALITY_NORMAL ); else texturesSlider->setMaximum( QUALITY_MEDIUM ); // Comment taken from the original config tool: // NB: if the player changes its client.cfg, mixing HDEntityTexture=1 and DivideTextureSizeBy2=1, it will // result to a low quality! if( s.config.getInt( "DivideTextureSizeBy2" ) ) texturesSlider->setValue( QUALITY_LOW ); else if( s.config.getInt( "HDEntityTexture" ) && ( hdTextureInstalled == 1 ) ) texturesSlider->setValue( QUALITY_NORMAL ); else texturesSlider->setValue( QUALITY_MEDIUM ); }
virtual WriteResult writeImage(const osg::Image& img,std::ostream& fout,const osgDB::ReaderWriter::Options *options) const { osg::ref_ptr<osg::Image> tmp_img = new osg::Image(img); tmp_img->flipVertical(); WriteResult::WriteStatus ws = write_JPEG_file(fout, *(tmp_img.get()), getQuality(options)); return ws; }
//SIM800 initialization procedure for simple SMS and call features void AGS::SIM800Init() { while (Serial.available() > 0) Serial.read(); Serial.println F("****************************************"); while (sendATcommand("AT", "OK", 2000) == 0); Serial.println F("SIM800 available!"); delay(2000); //otestuj registraci do site while ((sendATcommand("AT+CREG?", "+CREG: 0,1", 1000) || sendATcommand("AT+CREG?", "+CREG: 0,5", 1000)) == 0); while (Serial.available() > 0) Serial.read(); Serial.println F("SIM800 registered to GSM!"); //parameters to obtain time stamp from GSM network while (sendATcommand("AT+CLTS=1", "OK", 500) == 0); while (sendATcommand("AT+CENG=3", "OK", 500) == 0); while (Serial.available() > 0) Serial.read(); Serial.println("Time stamp from GSM:" + timeStamp()); Serial.println("GSM signal quality:" + getQuality()); Serial.println("GSM provider:" + getProviderName()); sendATcommand("AT+CMGF=1", "OK", 500); //zakaz indikace SMS sendATcommand("AT+CNMI=0,0", "OK", 500); //CLIP enabled sendATcommand("AT+CLIP=1", "OK", 1000); //smaz vsechny SMSky sendATcommand("AT+CMGD=1,4", "OK", 2000); sendATcommand("AT+CMGD=1", "OK", 2000); Serial.println F("SIM800 has been configured!"); Serial.println F("****************************************"); }
TilesRenderParameters* PlanetRendererBuilder::createPlanetRendererParameters() { return new TilesRenderParameters(getRenderDebug(), getUseTilesSplitBudget(), getForceFirstLevelTilesRenderOnStart(), getIncrementalTileQuality(), getQuality()); }
JPEGCodec::JPEGCodec(const Header &header, const ChannelList &channels) : VideoCodec(header, channels), _descriptor(header.frameRate(), header.width(), header.height(), MoxMxf::VideoDescriptor::VideoCodecJPEG) { setWindows(_descriptor, header); assert(channels.size() == 3); const Channel *r_channel = channels.findChannel("R"); if(r_channel) { assert(r_channel->type == UINT8); } else assert(false); MoxMxf::RGBADescriptor::RGBALayout layout; layout.push_back(MoxMxf::RGBADescriptor::RGBALayoutItem('R', 8)); layout.push_back(MoxMxf::RGBADescriptor::RGBALayoutItem('G', 8)); layout.push_back(MoxMxf::RGBADescriptor::RGBALayoutItem('B', 8)); _descriptor.setPixelLayout(layout); _quality = (isLossless(header) ? 100 : getQuality(header)); }
void SMSClient::quality(unsigned quality) { if (quality != getQuality()){ setQuality(quality); Event e(EventClientChanged, this); e.process(); } }
void TurbulenceModule::write (utils::OutStream &s) const { s.writeDouble (mPower); s.writeInt (getRoughness()); s.writeInt (getSeed()); s.writeDouble (getFrequency()); s.writeInt (getQuality()); }
std::vector<float> DestinNetworkAlt::getLayersQualities() { std::vector<float> qualities(destin->nLayers); for (int i = 0; i < destin->nLayers; i++) { qualities[i] = getQuality(i); } return qualities; }
void LightsaberCrystalComponentImplementation::fillAttributeList(AttributeListMessage* alm, CreatureObject* object) { TangibleObjectImplementation::fillAttributeList(alm, object); PlayerObject* player = object->getPlayerObject(); if (object->hasSkill("force_title_jedi_rank_01") || player->isPrivileged()) { if (ownerID == 0) { StringBuffer str; str << "\\#pcontrast2 UNTUNED"; alm->insertAttribute("crystal_owner", str); } else { alm->insertAttribute("crystal_owner", ownerName); } if (getColor() != 31) { StringBuffer str3; str3 << "@jedi_spam:saber_color_" << getColor(); alm->insertAttribute("color", str3); } else { if (ownerID != 0 || player->isPrivileged()) { alm->insertAttribute("mindamage", damage); alm->insertAttribute("maxdamage", damage); alm->insertAttribute("wpn_attack_speed", attackSpeed); alm->insertAttribute("wpn_wound_chance", woundChance); alm->insertAttribute("wpn_attack_cost_health", sacHealth); alm->insertAttribute("wpn_attack_cost_action", sacAction); alm->insertAttribute("wpn_attack_cost_mind", sacMind); alm->insertAttribute("forcecost", (int)getForceCost()); // For debugging if (player->isPrivileged()) { StringBuffer str; str << "@jedi_spam:crystal_quality_" << getQuality(); alm->insertAttribute("challenge_level", itemLevel); alm->insertAttribute("crystal_quality", str); } } else { StringBuffer str; str << "@jedi_spam:crystal_quality_" << getQuality(); alm->insertAttribute("crystal_quality", str); } } } }
std::string EpisodeTorrent::to_string() { std::ostringstream ss; ss << "Title: '" << title << "', " << "Season: '" << season << "', " << "Episode: '" << episode << "', " << "Quality: '" << getQuality() << "'"; return ss.str(); }
bool BookTip::step (beast::Journal j) { if (m_valid) { if (m_entry) { offerDelete (view_, m_entry, j); m_entry = nullptr; } } for(;;) { // See if there's an entry at or worse than current quality. Notice // that the quality is encoded only in the index of the first page // of a directory. auto const first_page = view_.succ (m_book, m_end); if (! first_page) return false; unsigned int di = 0; std::shared_ptr<SLE> dir; if (dirFirst (view_, *first_page, dir, di, m_index, j)) { m_dir = dir->key(); m_entry = view_.peek(keylet::offer(m_index)); m_quality = Quality (getQuality (*first_page)); m_valid = true; // Next query should start before this directory m_book = *first_page; // The quality immediately before the next quality --m_book; break; } // There should never be an empty directory but just in case, // we handle that case by advancing to the next directory. m_book = *first_page; } return true; }
static void toggleQuality() { char *text; Widget *w = menu.widgets[menu.index]; game.audioQuality = game.audioQuality == 22050 ? 44100 : 22050; changeSoundQuality(); text = getQuality(); updateLabelText(w->label, text); free(text); }
void VideoPicture :: fillAVFrame(AVFrame *frame) { if (!mBuffer || mBuffer->getBufferSize() < getSize()) allocInternalFrameBuffer(); unsigned char* buffer = (unsigned char*)mBuffer->getBytes(0, getSize()); // This is an inherently unsafe operation; it copies over all the bits in the AVFrame memcpy(frame, mFrame, sizeof(AVFrame)); //*frame = *mFrame; // and then relies on avpicture_fill to overwrite any areas in frame that // are pointed to the wrong place. avpicture_fill((AVPicture*)frame, buffer, (enum PixelFormat) frame->format, frame->width, frame->height); frame->quality = getQuality(); frame->type = FF_BUFFER_TYPE_USER; }
void LightsaberCrystalComponentImplementation::fillAttributeList(AttributeListMessage* alm, CreatureObject* object) { TangibleObjectImplementation::fillAttributeList(alm, object); PlayerObject* player = object->getPlayerObject(); if (player->getJediState() > 1 || player->isPrivileged()){ if (owner == ""){ StringBuffer str; str << "\\#FF6600" << "UNTUNED" ; alm->insertAttribute("crystal_owner", str); } else { alm->insertAttribute("crystal_owner", owner); } } if (getColor() != 31){ if (owner == ""){ StringBuffer str2; str2 << "@jedi_spam:saber_color_" << getColor(); alm->insertAttribute("color", str2); } else { StringBuffer str3; str3 << "@jedi_spam:saber_color_" << getColor(); alm->insertAttribute("color", str3); } } if (player->getJediState() > 1 || player->isPrivileged()){ if (getColor() == 31){ if (owner != ""){ alm->insertAttribute("mindamage", minimumDamage); alm->insertAttribute("maxdamage", maximumDamage); alm->insertAttribute("wpn_attack_speed", attackSpeed); alm->insertAttribute("wpn_wound_chance", woundChance); alm->insertAttribute("wpn_attack_cost_health", sacHealth); alm->insertAttribute("wpn_attack_cost_action", sacAction); alm->insertAttribute("wpn_attack_cost_mind", sacMind); alm->insertAttribute("forcecost", forceCost); } else { StringBuffer str; str << "@jedi_spam:crystal_quality_" << getQuality(); alm->insertAttribute("quality", str); } } } }
int corpsExplore::refresh(std::string& name, int& quality, int& secs, float& fac) { boost::mt19937& gen = muduo::ThreadLocalSingleton<boost::mt19937>::instance(); boost::random::discrete_distribution<> dist(m_gailvs); quality = dist(gen) + 1; int type = my_random(1, m_names.size()); //cout<<"corpsExplore::refresh - type "<<type<<", quality "<<quality<<endl; name = m_names[type-1]; secs = 600; fac = 1; baseCorpsExploreData* q = getQuality(quality); if (q) { secs = q->mins * 60; fac = q->fac; } return type; }
std::string SingleParticle2dx::DataStructures::Particle::getDataString() { std::string result = SingleParticle2dx::Utilities::StringFunctions::TtoString(getParticleNumber()); result += "\t" + getGlobalParticleInformation().getDataString(); result += "\t" + SingleParticle2dx::Utilities::StringFunctions::TtoString(getUseForReconstruction()); result += "\t" + SingleParticle2dx::Utilities::StringFunctions::TtoString(getLastAngularChange()); result += "\t" + getParticleShift().getDataString(); result += "\t" + getInitialOrientation().getDataString(); result += "\t" + getOldOrientation().getDataString(); result += "\t" + getNewOrientation().getDataString(); result += "\t" + SingleParticle2dx::Utilities::StringFunctions::TtoString(getSimMeasure()); result += "\t" + SingleParticle2dx::Utilities::StringFunctions::TtoString(getQuality()); result += "\t" + SingleParticle2dx::Utilities::StringFunctions::TtoString(getConsistency()); result += "\t" + SingleParticle2dx::Utilities::StringFunctions::TtoString(getWeight()); result += "\t" + SingleParticle2dx::Utilities::StringFunctions::TtoString(getContainerNumber()); result += "\t" + SingleParticle2dx::Utilities::StringFunctions::TtoString(getIsCMParticle()); result += "\t" + SingleParticle2dx::Utilities::StringFunctions::TtoString(calculateDensity()); result += "\t" + getClassInformation().getDataString(); return result; }
void MainWindow::start() { leFilePath->setDisabled( true ); bSelectFile->setDisabled( true ); bStart->setDisabled( true ); slider->setDisabled( true ); QString newFilePath; Resolutions * resolutions = new Resolutions(); QList<Resolution *> * lRes = new QList<Resolution *>; *lRes << new Resolution( 2560, 1440 ); *lRes << new Resolution( 1920, 1440 ); *lRes << new Resolution( 1920, 1200 ); *lRes << new Resolution( 1920, 1080 ); *lRes << new Resolution( 1680, 1200 ); *lRes << new Resolution( 1680, 1050 ); *lRes << new Resolution( 1600, 1200 ); *lRes << new Resolution( 1440, 900 ); *lRes << new Resolution( 1440, 1050 ); *lRes << new Resolution( 1280, 1024 ); *lRes << new Resolution( 1280, 960 ); *lRes << new Resolution( 1280, 800 ); *lRes << new Resolution( 1280, 720 ); *lRes << new Resolution( 1152, 864 ); *lRes << new Resolution( 1024, 1024 ); *lRes << new Resolution( 1024, 768 ); *lRes << new Resolution( 800, 600 ); *lRes << new Resolution( 800, 480 ); *lRes << new Resolution( 640, 480 ); *lRes << new Resolution( 320, 480 ); progressBar->setMaximum( lRes->size() ); progressBar->setValue( 0 ); QImage qImg, qImg2; Geometry geometry; Geometry resGeometry; Geometry * cropGeometry = 0; try { //qDebug() << "img.read:" << leFilePath->text(); qImg.load( leFilePath->text() ); } catch( std::exception &error_ ) { //qDebug() << error_.what(); return; } geometry.width( qImg.size().width() ); geometry.height( qImg.size().height() ); for(int i = 0; i < lRes->size(); i++) { qImg2 = qImg; newFilePath = leFilePath->text(); newFilePath.insert( (newFilePath.size() - 4), '-' ); newFilePath.insert( (newFilePath.size() - 4), QString::number( lRes->at(i)->getWidth() ) ); newFilePath.insert( (newFilePath.size() - 4), 'x' ); newFilePath.insert( (newFilePath.size() - 4), QString::number( lRes->at(i)->getHeight() ) ); //qDebug() << "-----------------"; //qDebug() << newFilePath; resGeometry.width( lRes->at(i)->getWidth() ); resGeometry.height( lRes->at(i)->getHeight() ); cropGeometry = resolutions->needCrop( geometry.width(), geometry.height(), resGeometry.width(), resGeometry.height() ); if( cropGeometry ) { qImg2 = qImg.copy(cropGeometry->xOff(), cropGeometry->yOff(), cropGeometry->width(), cropGeometry->height()); delete( cropGeometry ); } qImg2 = qImg2.scaled( resGeometry.width(), resGeometry.height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation ); qImg2.save( newFilePath, 0, getQuality() ); progressBar->setValue( progressBar->value() + 1 ); } delete( resolutions ); delete( lRes ); leFilePath->setDisabled( false ); bSelectFile->setDisabled( false ); bStart->setDisabled( false ); slider->setDisabled( false ); }
void AudioResamplerDyn<TC, TI, TO>::setSampleRate(int32_t inSampleRate) { if (mInSampleRate == inSampleRate) { return; } int32_t oldSampleRate = mInSampleRate; int32_t oldHalfNumCoefs = mConstants.mHalfNumCoefs; uint32_t oldPhaseWrapLimit = mConstants.mL << mConstants.mShift; bool useS32 = false; mInSampleRate = inSampleRate; // TODO: Add precalculated Equiripple filters if (mFilterQuality != getQuality() || !isClose(inSampleRate, oldSampleRate, mFilterSampleRate, mSampleRate)) { mFilterSampleRate = inSampleRate; mFilterQuality = getQuality(); // Begin Kaiser Filter computation // // The quantization floor for S16 is about 96db - 10*log_10(#length) + 3dB. // Keep the stop band attenuation no greater than 84-85dB for 32 length S16 filters // // For s32 we keep the stop band attenuation at the same as 16b resolution, about // 96-98dB // double stopBandAtten; double tbwCheat = 1.; // how much we "cheat" into aliasing int halfLength; if (mFilterQuality == DYN_HIGH_QUALITY) { // 32b coefficients, 64 length useS32 = true; stopBandAtten = 98.; if (inSampleRate >= mSampleRate * 4) { halfLength = 48; } else if (inSampleRate >= mSampleRate * 2) { halfLength = 40; } else { halfLength = 32; } } else if (mFilterQuality == DYN_LOW_QUALITY) { // 16b coefficients, 16-32 length useS32 = false; stopBandAtten = 80.; if (inSampleRate >= mSampleRate * 4) { halfLength = 24; } else if (inSampleRate >= mSampleRate * 2) { halfLength = 16; } else { halfLength = 8; } if (inSampleRate <= mSampleRate) { tbwCheat = 1.05; } else { tbwCheat = 1.03; } } else { // DYN_MED_QUALITY // 16b coefficients, 32-64 length // note: > 64 length filters with 16b coefs can have quantization noise problems useS32 = false; stopBandAtten = 84.; if (inSampleRate >= mSampleRate * 4) { halfLength = 32; } else if (inSampleRate >= mSampleRate * 2) { halfLength = 24; } else { halfLength = 16; } if (inSampleRate <= mSampleRate) { tbwCheat = 1.03; } else { tbwCheat = 1.01; } } // determine the number of polyphases in the filterbank. // for 16b, it is desirable to have 2^(16/2) = 256 phases. // https://ccrma.stanford.edu/~jos/resample/Relation_Interpolation_Error_Quantization.html // // We are a bit more lax on this. int phases = mSampleRate / gcd(mSampleRate, inSampleRate); // TODO: Once dynamic sample rate change is an option, the code below // should be modified to execute only when dynamic sample rate change is enabled. // // as above, #phases less than 63 is too few phases for accurate linear interpolation. // we increase the phases to compensate, but more phases means more memory per // filter and more time to compute the filter. // // if we know that the filter will be used for dynamic sample rate changes, // that would allow us skip this part for fixed sample rate resamplers. // while (phases<63) { phases *= 2; // this code only needed to support dynamic rate changes } if (phases>=256) { // too many phases, always interpolate phases = 127; } // create the filter mConstants.set(phases, halfLength, inSampleRate, mSampleRate); createKaiserFir(mConstants, stopBandAtten, inSampleRate, mSampleRate, tbwCheat); } // End Kaiser filter // update phase and state based on the new filter. const Constants& c(mConstants); mInBuffer.resize(mChannelCount, c.mHalfNumCoefs); const uint32_t phaseWrapLimit = c.mL << c.mShift; // try to preserve as much of the phase fraction as possible for on-the-fly changes mPhaseFraction = static_cast<unsigned long long>(mPhaseFraction) * phaseWrapLimit / oldPhaseWrapLimit; mPhaseFraction %= phaseWrapLimit; // should not do anything, but just in case. mPhaseIncrement = static_cast<uint32_t>(static_cast<uint64_t>(phaseWrapLimit) * inSampleRate / mSampleRate); // determine which resampler to use // check if locked phase (works only if mPhaseIncrement has no "fractional phase bits") int locked = (mPhaseIncrement << (sizeof(mPhaseIncrement)*8 - c.mShift)) == 0; if (locked) { mPhaseFraction = mPhaseFraction >> c.mShift << c.mShift; // remove fractional phase } // stride is the minimum number of filter coefficients processed per loop iteration. // We currently only allow a stride of 16 to match with SIMD processing. // This means that the filter length must be a multiple of 16, // or half the filter length (mHalfNumCoefs) must be a multiple of 8. // // Note: A stride of 2 is achieved with non-SIMD processing. int stride = ((c.mHalfNumCoefs & 7) == 0) ? 16 : 2; LOG_ALWAYS_FATAL_IF(stride < 16, "Resampler stride must be 16 or more"); LOG_ALWAYS_FATAL_IF(mChannelCount < 1 || mChannelCount > 8, "Resampler channels(%d) must be between 1 to 8", mChannelCount); // stride 16 (falls back to stride 2 for machines that do not support NEON) if (locked) { switch (mChannelCount) { case 1: mResampleFunc = &AudioResamplerDyn<TC, TI, TO>::resample<1, true, 16>; break; case 2: mResampleFunc = &AudioResamplerDyn<TC, TI, TO>::resample<2, true, 16>; break; case 3: mResampleFunc = &AudioResamplerDyn<TC, TI, TO>::resample<3, true, 16>; break; case 4: mResampleFunc = &AudioResamplerDyn<TC, TI, TO>::resample<4, true, 16>; break; case 5: mResampleFunc = &AudioResamplerDyn<TC, TI, TO>::resample<5, true, 16>; break; case 6: mResampleFunc = &AudioResamplerDyn<TC, TI, TO>::resample<6, true, 16>; break; case 7: mResampleFunc = &AudioResamplerDyn<TC, TI, TO>::resample<7, true, 16>; break; case 8: mResampleFunc = &AudioResamplerDyn<TC, TI, TO>::resample<8, true, 16>; break; } } else { switch (mChannelCount) { case 1: mResampleFunc = &AudioResamplerDyn<TC, TI, TO>::resample<1, false, 16>; break; case 2: mResampleFunc = &AudioResamplerDyn<TC, TI, TO>::resample<2, false, 16>; break; case 3: mResampleFunc = &AudioResamplerDyn<TC, TI, TO>::resample<3, false, 16>; break; case 4: mResampleFunc = &AudioResamplerDyn<TC, TI, TO>::resample<4, false, 16>; break; case 5: mResampleFunc = &AudioResamplerDyn<TC, TI, TO>::resample<5, false, 16>; break; case 6: mResampleFunc = &AudioResamplerDyn<TC, TI, TO>::resample<6, false, 16>; break; case 7: mResampleFunc = &AudioResamplerDyn<TC, TI, TO>::resample<7, false, 16>; break; case 8: mResampleFunc = &AudioResamplerDyn<TC, TI, TO>::resample<8, false, 16>; break; } } #ifdef DEBUG_RESAMPLER printf("channels:%d %s stride:%d %s coef:%d shift:%d\n", mChannelCount, locked ? "locked" : "interpolated", stride, useS32 ? "S32" : "S16", 2*c.mHalfNumCoefs, c.mShift); #endif }
// OPTIMIZE: When calculating path increment, note if increment consumes all // liquidity. No need to revisit path in the future if all liquidity is used. // TER PathCursor::advanceNode (bool const bReverse) const { TER resultCode = tesSUCCESS; // Taker is the active party against an offer in the ledger - the entity // that is taking advantage of an offer in the order book. WriteLog (lsTRACE, RippleCalc) << "advanceNode: TakerPays:" << node().saTakerPays << " TakerGets:" << node().saTakerGets; int loopCount = 0; do { // VFALCO NOTE Why not use a for() loop? // VFALCO TODO The limit on loop iterations puts an // upper limit on the number of different quality // levels (ratio of pay:get) that will be considered for one path. // Changing this value has repercusssions on validation and consensus. // if (++loopCount > NODE_ADVANCE_MAX_LOOPS) { WriteLog (lsWARNING, RippleCalc) << "Loop count exceeded"; return tefEXCEPTION; } bool bDirectDirDirty = node().directory.initialize ( { previousNode().issue_, node().issue_}, view()); if (auto advance = node().directory.advance (view())) { bDirectDirDirty = true; if (advance == NodeDirectory::NEW_QUALITY) { // We didn't run off the end of this order book and found // another quality directory. WriteLog (lsTRACE, RippleCalc) << "advanceNode: Quality advance: node.directory.current=" << node().directory.current; } else if (bReverse) { WriteLog (lsTRACE, RippleCalc) << "advanceNode: No more offers."; node().offerIndex_ = 0; break; } else { // No more offers. Should be done rather than fall off end of // book. WriteLog (lsWARNING, RippleCalc) << "advanceNode: Unreachable: " << "Fell off end of order book."; // FIXME: why? return telFAILED_PROCESSING; } } if (bDirectDirDirty) { // Our quality changed since last iteration. // Use the rate from the directory. node().saOfrRate = amountFromQuality ( getQuality (node().directory.current)); // For correct ratio node().uEntry = 0; node().bEntryAdvance = true; WriteLog (lsTRACE, RippleCalc) << "advanceNode: directory dirty: node.saOfrRate=" << node().saOfrRate; } if (!node().bEntryAdvance) { if (node().bFundsDirty) { // We were called again probably merely to update structure // variables. node().saTakerPays = node().sleOffer->getFieldAmount (sfTakerPays); node().saTakerGets = node().sleOffer->getFieldAmount (sfTakerGets); // Funds left. node().saOfferFunds = accountFunds(view(), node().offerOwnerAccount_, node().saTakerGets, fhZERO_IF_FROZEN, getConfig()); node().bFundsDirty = false; WriteLog (lsTRACE, RippleCalc) << "advanceNode: funds dirty: node().saOfrRate=" << node().saOfrRate; } else { WriteLog (lsTRACE, RippleCalc) << "advanceNode: as is"; } } else if (!dirNext (view(), node().directory.current, node().directory.ledgerEntry, node().uEntry, node().offerIndex_)) // This is the only place that offerIndex_ changes. { // Failed to find an entry in directory. // Do another cur directory iff multiQuality_ if (multiQuality_) { // We are allowed to process multiple qualities if this is the // only path. WriteLog (lsTRACE, RippleCalc) << "advanceNode: next quality"; node().directory.advanceNeeded = true; // Process next quality. } else if (!bReverse) { // We didn't run dry going backwards - why are we running dry // going forwards - this should be impossible! // TODO(tom): these warnings occur in production! They // shouldn't. WriteLog (lsWARNING, RippleCalc) << "advanceNode: unreachable: ran out of offers"; return telFAILED_PROCESSING; } else { // Ran off end of offers. node().bEntryAdvance = false; // Done. node().offerIndex_ = 0; // Report no more entries. } } else { // Got a new offer. node().sleOffer = view().peek (keylet::offer(node().offerIndex_)); if (!node().sleOffer) { // Corrupt directory that points to an entry that doesn't exist. // This has happened in production. WriteLog (lsWARNING, RippleCalc) << "Missing offer in directory"; node().bEntryAdvance = true; } else { node().offerOwnerAccount_ = node().sleOffer->getAccountID (sfAccount); node().saTakerPays = node().sleOffer->getFieldAmount (sfTakerPays); node().saTakerGets = node().sleOffer->getFieldAmount (sfTakerGets); AccountIssue const accountIssue ( node().offerOwnerAccount_, node().issue_); WriteLog (lsTRACE, RippleCalc) << "advanceNode: offerOwnerAccount_=" << to_string (node().offerOwnerAccount_) << " node.saTakerPays=" << node().saTakerPays << " node.saTakerGets=" << node().saTakerGets << " node.offerIndex_=" << node().offerIndex_; if (node().sleOffer->isFieldPresent (sfExpiration) && (node().sleOffer->getFieldU32 (sfExpiration) <= view().parentCloseTime())) { // Offer is expired. WriteLog (lsTRACE, RippleCalc) << "advanceNode: expired offer"; rippleCalc_.permanentlyUnfundedOffers_.insert( node().offerIndex_); continue; } if (node().saTakerPays <= zero || node().saTakerGets <= zero) { // Offer has bad amounts. Offers should never have a bad // amounts. auto const index = node().offerIndex_; if (bReverse) { // Past internal error, offer had bad amounts. // This has occurred in production. WriteLog (lsWARNING, RippleCalc) << "advanceNode: PAST INTERNAL ERROR" << " REVERSE: OFFER NON-POSITIVE:" << " node.saTakerPays=" << node().saTakerPays << " node.saTakerGets=" << node().saTakerGets; // Mark offer for always deletion. rippleCalc_.permanentlyUnfundedOffers_.insert ( node().offerIndex_); } else if (rippleCalc_.permanentlyUnfundedOffers_.find (index) != rippleCalc_.permanentlyUnfundedOffers_.end ()) { // Past internal error, offer was found failed to place // this in permanentlyUnfundedOffers_. // Just skip it. It will be deleted. WriteLog (lsDEBUG, RippleCalc) << "advanceNode: PAST INTERNAL ERROR " << " FORWARD CONFIRM: OFFER NON-POSITIVE:" << " node.saTakerPays=" << node().saTakerPays << " node.saTakerGets=" << node().saTakerGets; } else { // Reverse should have previously put bad offer in list. // An internal error previously left a bad offer. WriteLog (lsWARNING, RippleCalc) << "advanceNode: INTERNAL ERROR" <<" FORWARD NEWLY FOUND: OFFER NON-POSITIVE:" << " node.saTakerPays=" << node().saTakerPays << " node.saTakerGets=" << node().saTakerGets; // Don't process at all, things are in an unexpected // state for this transactions. resultCode = tefEXCEPTION; } continue; } // Allowed to access source from this node? // // XXX This can get called multiple times for same source in a // row, caching result would be nice. // // XXX Going forward could we fund something with a worse // quality which was previously skipped? Might need to check // quality. auto itForward = pathState_.forward().find (accountIssue); const bool bFoundForward = itForward != pathState_.forward().end (); // Only allow a source to be used once, in the first node // encountered from initial path scan. This prevents // conflicting uses of the same balance when going reverse vs // forward. if (bFoundForward && itForward->second != nodeIndex_ && node().offerOwnerAccount_ != node().issue_.account) { // Temporarily unfunded. Another node uses this source, // ignore in this offer. WriteLog (lsTRACE, RippleCalc) << "advanceNode: temporarily unfunded offer" << " (forward)"; continue; } // This is overly strict. For contributions to past. We should // only count source if actually used. auto itReverse = pathState_.reverse().find (accountIssue); bool bFoundReverse = itReverse != pathState_.reverse().end (); // For this quality increment, only allow a source to be used // from a single node, in the first node encountered from // applying offers in reverse. if (bFoundReverse && itReverse->second != nodeIndex_ && node().offerOwnerAccount_ != node().issue_.account) { // Temporarily unfunded. Another node uses this source, // ignore in this offer. WriteLog (lsTRACE, RippleCalc) << "advanceNode: temporarily unfunded offer" <<" (reverse)"; continue; } // Determine if used in past. // We only need to know if it might need to be marked unfunded. auto itPast = rippleCalc_.mumSource_.find (accountIssue); bool bFoundPast = (itPast != rippleCalc_.mumSource_.end ()); // Only the current node is allowed to use the source. node().saOfferFunds = accountFunds(view(), node().offerOwnerAccount_, node().saTakerGets, fhZERO_IF_FROZEN, getConfig()); // Funds held. if (node().saOfferFunds <= zero) { // Offer is unfunded. WriteLog (lsTRACE, RippleCalc) << "advanceNode: unfunded offer"; if (bReverse && !bFoundReverse && !bFoundPast) { // Never mentioned before, clearly just: found unfunded. // That is, even if this offer fails due to fill or kill // still do deletions. // Mark offer for always deletion. rippleCalc_.permanentlyUnfundedOffers_.insert (node().offerIndex_); } else { // Moving forward, don't need to insert again // Or, already found it. } // YYY Could verify offer is correct place for unfundeds. continue; } if (bReverse // Need to remember reverse mention. && !bFoundPast // Not mentioned in previous passes. && !bFoundReverse) // New to pass. { // Consider source mentioned by current path state. WriteLog (lsTRACE, RippleCalc) << "advanceNode: remember=" << node().offerOwnerAccount_ << "/" << node().issue_; pathState_.insertReverse (accountIssue, nodeIndex_); } node().bFundsDirty = false; node().bEntryAdvance = false; } } } while (resultCode == tesSUCCESS && (node().bEntryAdvance || node().directory.advanceNeeded)); if (resultCode == tesSUCCESS) { WriteLog (lsTRACE, RippleCalc) << "advanceNode: node.offerIndex_=" << node().offerIndex_; } else { WriteLog (lsDEBUG, RippleCalc) << "advanceNode: resultCode=" << transToken (resultCode); } return resultCode; }
std::uint64_t BookDirIterator::getRate () const { return getQuality(mIndex); }
static void loadMenuLayout() { char *text; int x, y, w, maxWidth, i; menu.widgetCount = 5; menu.widgets = malloc(sizeof(Widget *) * menu.widgetCount); if (menu.widgets == NULL) { showErrorAndExit("Ran out of memory when creating Control Menu"); } x = y = 0; menu.widgets[0] = createWidget(_("Sound"), &control.button[CONTROL_UP], &toggleSound, &toggleSound, &toggleSound, x, y, TRUE, 255, 255, 255); menu.widgets[0]->label = createLabel(game.audio == TRUE || game.audioDisabled == TRUE ? _("Yes") : _("No"), menu.widgets[0]->x + menu.widgets[0]->normalState->w + 10, y); menu.widgets[1] = createWidget(_("SFX Volume"), &game.sfxDefaultVolume, &lowerSFXVolume, &raiseSFXVolume, NULL, x, y, TRUE, 255, 255, 255); text = getVolumePercent(game.sfxDefaultVolume); menu.widgets[1]->label = createLabel(_(text), menu.widgets[1]->x + menu.widgets[1]->normalState->w + 10, y); free(text); menu.widgets[2] = createWidget(_("Music Volume"), &game.musicDefaultVolume, &lowerMusicVolume, &raiseMusicVolume, NULL, x, y, TRUE, 255, 255, 255); text = getVolumePercent(game.musicDefaultVolume); menu.widgets[2]->label = createLabel(_(text), menu.widgets[2]->x + menu.widgets[2]->normalState->w + 10, y); free(text); menu.widgets[3] = createWidget(_("Audio Quality"), &game.audioQuality, &toggleQuality, &toggleQuality, &toggleQuality, x, y, TRUE, 255, 255, 255); text = getQuality(); menu.widgets[3]->label = createLabel(text, menu.widgets[3]->x + menu.widgets[3]->normalState->w + 10, y); free(text); menu.widgets[4] = createWidget(_("Back"), NULL, NULL, NULL, &showOptionsMenu, -1, y, TRUE, 255, 255, 255); y = BUTTON_PADDING + BORDER_PADDING; maxWidth = w = 0; for (i=0;i<menu.widgetCount;i++) { if (menu.widgets[i]->label != NULL && menu.widgets[i]->normalState->w > maxWidth) { maxWidth = menu.widgets[i]->normalState->w; } } for (i=0;i<menu.widgetCount;i++) { menu.widgets[i]->y = y; if (menu.widgets[i]->x != -1) { menu.widgets[i]->x = BUTTON_PADDING + BORDER_PADDING; } if (menu.widgets[i]->label != NULL) { menu.widgets[i]->label->y = y; menu.widgets[i]->label->x = menu.widgets[i]->x + maxWidth + 10; if (menu.widgets[i]->label->x + menu.widgets[i]->label->text->w > w) { w = menu.widgets[i]->label->x + menu.widgets[i]->label->text->w; } } else { if (menu.widgets[i]->x + menu.widgets[i]->selectedState->w > w) { w = menu.widgets[i]->x + menu.widgets[i]->selectedState->w; } } y += menu.widgets[i]->selectedState->h + BUTTON_PADDING; } menu.w = w + BUTTON_PADDING; menu.h = y - BORDER_PADDING; menu.background = addBorder(createSurface(menu.w, menu.h, FALSE), 255, 255, 255, 0, 0, 0); menu.x = (SCREEN_WIDTH - menu.background->w) / 2; menu.y = (SCREEN_HEIGHT - menu.background->h) / 2; }