WheelBox::WheelBox( Qt::Orientation orientation, int type, QWidget *parent ): QWidget( parent ) { QWidget *box = createBox( orientation, type ); d_label = new QLabel( this ); d_label->setAlignment( Qt::AlignHCenter | Qt::AlignTop ); QBoxLayout *layout = new QVBoxLayout( this ); layout->addWidget( box ); layout->addWidget( d_label ); setNum( d_wheel->value() ); connect( d_wheel, SIGNAL( valueChanged( double ) ), this, SLOT( setNum( double ) ) ); }
void PokeEdit::moveEntered(const QModelIndex &index) { int num = index.data(CustomModel::MovenumRole).toInt(); if (num == Move::SecretSword && poke().num() == Pokemon::Keldeo && PokemonInfo::Released(Pokemon::Keldeo_R, poke().gen())) { setNum(Pokemon::Keldeo_R); return; } for (int i = 0; i < 4; i++) { if (poke().move(i) == Move::NoMove) { setMove(i, num); return; } } QMessageBox::information(NULL, tr("Impossible to add move"), tr("No more free moves!")); }
void rList<type>::insert(const int index, const type &val) { if(!list) setSize(granularity); if(index < 0) index = 0; else if(index > num) append(val); else { setNum(num + 1); for(int i = num; i > index; i--) list[i + 1] = list[i]; list[index] = val; } }
bool NumberLabel::init(Texture2D *texture, const int number) { if(!Node::init()) return false; _texture = texture; CC_SAFE_RETAIN(_texture); if (_texture) { _numWidth = _texture->getContentSize().width/10; setContentSize(Size(0,_texture->getContentSize().height)); } _node = Layer::create(); addChild(_node); setNum(number); return true; }
void PokeEdit::setMove(int slot, int move) { try { poke().setMove(move, slot, !hackMons); m_moves[slot]->setText(MoveInfo::Name(move)); if (move == Move::Return) { ui->happiness->setValue(255); } else if (move == Move::Frustration) { ui->happiness->setValue(0); } if (poke().num().pokenum == Pokemon::Keldeo) { if (!poke().hasMove(Move::SecretSword)) { setNum(Pokemon::Keldeo); } } } catch (const QString &s) { QMessageBox::information(NULL, tr("Invalid moveset"), s); m_moves[slot]->clear(); } }
bool NumberTube::init(Size tubeSize, Vec2 tubePosition) { if (!Sprite::init()) { return false; } //NumberTube自身布局 setContentSize(tubeSize); setPosition(tubePosition); //添加背景 background = LayerColor::create(Color4B(255, 100, 100, 255)); background -> setContentSize(tubeSize); addChild(background); //添加数字label numLabel = Label::createWithSystemFont("0", "Arial", 50); numLabel -> setTextColor(Color4B(255, 255, 255, 255)); numLabel -> setPosition(Vec2(tubeSize.width / 2, tubeSize.height / 2)); setNum(0); addChild(numLabel); return true; }
void rList<type>::insert(const int index, const int length, const type &val) { if(!list) setSize(granularity); if(index < 0) index = 0; else if(index > num) index = num; else { setNum(num + length); //From end until length for(int i = num; i > index + length; i--) list[i + length] = list[i]; for(int i = index; i < index + length; i++) list[i] = val; } }
// Documented in superclass. void SoComposeMatrix::evaluate() { int numTranslation = this->translation.getNum(); int numRotation = this->rotation.getNum(); int numScaleFactor = this->scaleFactor.getNum(); int numScaleOrientation = this->scaleOrientation.getNum(); int numCenter = this->center.getNum(); int numOut = numTranslation > numRotation? numTranslation:numRotation; int numOut2 = numScaleFactor>numScaleOrientation?numScaleFactor:numScaleOrientation; numOut2 = numOut2>numCenter?numOut2:numCenter; numOut = numOut>numOut2?numOut:numOut2; SO_ENGINE_OUTPUT(matrix,SoMFMatrix,setNum(numOut)); int i; for (i=0;i<numOut;i++) { const SbVec3f translationVal= i<numTranslation?this->translation[i]:this->translation[numTranslation-1]; const SbVec3f scaleFactorVal= i<numScaleFactor?this->scaleFactor[i]:this->scaleFactor[numScaleFactor-1]; const SbVec3f centerVal=i<numCenter?this->center[i]:this->center[numCenter-1]; const SbRotation rotationVal= i<numRotation?this->rotation[i]:this->rotation[numRotation-1]; const SbRotation scaleOrientationVal= i<numScaleOrientation? this->scaleOrientation[i]:this->scaleOrientation[numScaleOrientation-1]; SbMatrix mat; mat.setTransform(translationVal,rotationVal,scaleFactorVal, scaleOrientationVal,centerVal); SO_ENGINE_OUTPUT(matrix,SoMFMatrix,set1Value(i,mat)); } }
void Buttongrid::printName(unsigned char id){ const char* name = names[id]; // Calculate characters in name int n; for(n=0;n<8;n++){ if(name[n] == 0) break; } Serial.print(n); Serial.print(" characters for id: "); Serial.print(id); Serial.print(" "); Serial.println(names[id]); // If name is empty draw the id, else draw the name if(n==0){ setNum(id); }else{ //i++; int boundX1, boundX2, boundY1, boundY2; int btnWidth = w/columns; int btnHeight = h/rows; unsigned char colIndex = getColumn(id)-1; unsigned char rowIndex = getRow(id)-1; int xPos = btnWidth/2 - (n*FONT_X*font_size)/2; int yPos = btnHeight/(2) - 8; xPos = x+(colIndex*btnWidth)+xPos+3*borderWidth; yPos = y+yPos+(rowIndex*btnHeight); Tft.drawString((char*)names[id],xPos, yPos, font_size, fgColor); } return; }
void TB_PokemonBody::setNum(Pokemon::uniqueId pokenum) { setNum(pokenum, true); }
void TB_PokemonBody::changeForme(Pokemon::uniqueId pokenum) { setNum(pokenum, false); }
// // uint8_t f2s(char* buffer, double value, uint8_t decimal, uint8_t width, uint8_t padMode, char padChar) // // Convert the value into string with give format, and return the length of string // - decimal: decimal place // - width: size of the string (the buffer must have size not less than width + 1 ) // - padMode: 0 - fit value '1.0', 1 - Right align ' 1.0', 2 - Left align '1.0 ' // - padChar: character used to fill the empty space, will be ignored if padMode = 0 // // uint8_t myUtil::f2s(char* buffer, double value, uint8_t decimal, uint8_t width, uint8_t padMode, char padChar) { if (width == 0) return false; double absValue, adjValue; // for safety, don't use unsigned int here, as the length (e.g. len_rem) can be negative after calculation int len_ne, len_int, len_dec, len_rem, data_len; if (value < 0) { len_ne = 1; absValue = - value; } else { len_ne = 0; absValue = value; } len_int = getLen(absValue); if (len_ne + len_int > width) { return fillError(buffer, width); } len_dec = (decimal > 0 ? 1 : 0); if (decimal) { len_rem = width - (len_ne + len_int + len_dec); if (len_rem > decimal) { len_rem = decimal; } else { if (len_rem <= 0) { len_rem = 0; len_dec = 0; // no need to display decimal place } } } else { len_rem = 0; } data_len = len_ne + len_int + len_dec + len_rem; adjValue = absValue + 0.5 / getFactor(len_rem); // check if addition digits after round up (e.g. 999.5 -> 1000.0) if (getLen(adjValue) > len_int) { len_int++; if (len_ne + len_int > width) { return fillError(buffer, width); } if ((width > 0) && (data_len >= width)) { // try to reduce decimal to fit the display if (len_rem > 0) { len_rem--; adjValue = absValue + 0.5 / getFactor(len_rem); if (len_rem == 0) len_dec = 0; } } data_len = len_ne + len_int + len_dec + len_rem; } // Fill buffer with 0 as terminator anywhere, * size = width + 1 for (int idx = 0; idx <= width; idx++) buffer[idx] = 0; if (len_rem == 0) len_dec = 0; data_len = len_ne + len_int + len_dec + len_rem; uint8_t ptr = 0; // pad left if (padMode == _F2S_PAD_LEFT) while (ptr < width - data_len) buffer[ptr++] = padChar; if (len_ne) buffer[ptr++] = '-'; unsigned long adjInt = (unsigned long) adjValue; setNum(buffer, ptr, adjInt, len_int); ptr += len_int; if (len_rem > 0) { buffer[ptr++] = '.'; unsigned long adjRem = getFactor(len_rem) * (adjValue - adjInt); setNum(buffer, ptr, adjRem, len_rem); ptr += len_rem; } // pad right if (padMode == _F2S_PAD_RIGHT) while (ptr < width) buffer[ptr++] = padChar; // Just for safety, should already filled with 0 before buffer[ptr] = 0; return ptr; }
void PokeTeam::loadFromXml(const QDomElement &poke, int version) { if (poke.hasAttribute("Gen")) { setGen(Pokemon::gen(poke.attribute("Gen", QString::number(GenInfo::GenMax())).toInt(), poke.attribute("SubGen", QString::number(GenInfo::NumberOfSubgens(poke.attribute("Gen", QString::number(GenInfo::GenMax())).toInt())-1)).toInt())); } reset(); /* Code to import old teams which had different formes registered as different pokemon numbers */ int num = poke.attribute("Num").toInt(); int forme = poke.attribute("Forme").toInt(); if (gen().num == 4 && num > 493 && forme == 0 && !PokemonInfo::Exists(Pokemon::uniqueId(num, 0), 4)) { //Old way int indexes[] = { 479,479,479,479,479,386,386,386,413,413,492,487 }; int formes[] = { 1,2,3,4,5,1,2,3,1,2,1,1 }; int i = num - 494; setNum(Pokemon::uniqueId(indexes[i], formes[i])); } else { setNum(Pokemon::uniqueId(num, forme)); } bool outdated = gen() < 5 && version < 1; load(); nickname() = poke.attribute("Nickname"); item() = poke.attribute("Item").toInt(); ability() = poke.attribute("Ability").toInt(); if (outdated) { ability() = AbilityInfo::ConvertFromOldAbility(ability()); } nature() = poke.attribute("Nature").toInt(); gender() = poke.attribute("Gender").toInt(); shiny() = QVariant(poke.attribute("Shiny")).toBool(); happiness() = poke.attribute("Happiness").toInt(); level() = poke.attribute("Lvl").toInt(); int cptMove=0; QDomElement moveElement = poke.firstChildElement("Move"); while(!moveElement.isNull()) { int movenum = moveElement.text().toInt(); if (outdated) { movenum = MoveInfo::ConvertFromOldMove(movenum); } setMove(movenum,cptMove,false); cptMove++; moveElement = moveElement.nextSiblingElement("Move"); } int cptDV=0; QDomElement DVElement = poke.firstChildElement("DV"); while(!DVElement.isNull()) { setDV(outdated ? NatureInfo::ConvertToStat(cptDV) : cptDV,DVElement.text().toInt()); cptDV++; DVElement = DVElement.nextSiblingElement("DV"); } int cptEV=0; QDomElement EVElement = poke.firstChildElement("EV"); while(!EVElement.isNull()) { setEV(outdated ? NatureInfo::ConvertToStat(cptEV) : cptEV,EVElement.text().toInt()); cptEV++; EVElement = EVElement.nextSiblingElement("EV"); } }
void Fraction::setNumDen(int newNum, int newDen) { setNum(newNum); setDen(newDen); }
void PokeEdit::setNum(const QString &num) { setNum(PokemonInfo::Number(num)); }
PokeEdit::PokeEdit(TeamBuilderWidget *master, PokeTeam *poke, QAbstractItemModel *pokeModel, QAbstractItemModel *itemsModel, QAbstractItemModel *natureModel) : ui(new Ui::PokeEdit), pokemonModel(pokeModel), m_poke(poke), master(master) { ui->setupUi(this); ui->itemSprite->raise(); ui->item->setModel(itemsModel); ui->nature->setModel(natureModel); ui->levelSettings->setPoke(poke); ui->evbox->setPoke(poke); ui->ivbox->setPoke(poke); if (0) { master->getDock(EVDock)->setWidget(ui->evbox); master->getDock(IVDock)->setWidget(ui->ivbox); master->getDock(LevelDock)->setWidget(ui->levelSettings); master->getDock(MoveDock)->setWidget(ui->moveContainer); } else { QCloseDockWidget *hi = new QCloseDockWidget(tr("Advanced"), this); hi->setObjectName("AdvancedTab"); hi->setWidget(ui->ivbox); hi->setFeatures(QDockWidget::DockWidgetClosable|QDockWidget::DockWidgetMovable); ui->horizontalMove->addWidget(hi); if (advancedWindowClosed) { hi->close(); } connect(hi, SIGNAL(closed()), SIGNAL(closeAdvanced())); // QDockWidget *hi2 = new QDockWidget(tr("Level"), this); // hi2->setWidget(ui->levelSettings); // hi2->setFeatures(QDockWidget::DockWidgetClosable|QDockWidget::DockWidgetMovable); // ui->horizontalPoke->addWidget(hi2); } QSortFilterProxyModel *pokeFilter = new QSortFilterProxyModel(this); pokeFilter->setFilterRegExp("."); pokeFilter->setSourceModel(pokemonModel); QCompleter *completer = new QCompleter(pokeFilter, ui->nickname); completer->setCompletionColumn(1); completer->setCompletionRole(Qt::DisplayRole); completer->setCaseSensitivity(Qt::CaseInsensitive); completer->setCompletionMode(QCompleter::PopupCompletion); ui->nickname->setCompleter(completer); connect(completer, SIGNAL(activated(QString)), SLOT(setNum(QString))); /* 20 characters for the name. Longest name: Vivillon-Archipelago = 20 characters */ ui->nickname->setValidator(new QNickValidator(ui->nickname, 20)); fillMoves(); connect(ui->levelSettings, SIGNAL(levelUpdated()), this, SLOT(updateStats())); connect(ui->levelSettings, SIGNAL(levelUpdated()), ui->ivbox, SLOT(updateStats())); connect(ui->levelSettings, SIGNAL(genderUpdated()), this, SLOT(updatePicture())); connect(ui->levelSettings, SIGNAL(genderUpdated()), this, SLOT(updateGender())); connect(ui->ivbox, SIGNAL(genderUpdated()), SLOT(updateGender())); connect(ui->ivbox, SIGNAL(genderUpdated()), ui->levelSettings, SLOT(updateGender())); connect(ui->ivbox, SIGNAL(shinyUpdated()), SLOT(updatePicture())); connect(ui->happiness, SIGNAL(valueChanged(int)), this, SLOT(changeHappiness(int))); connect(ui->nature, SIGNAL(currentIndexChanged(int)), this, SLOT(changeNature(int))); connect(ui->item, SIGNAL(currentIndexChanged(QString)), this, SLOT(changeItem(QString))); connect(ui->evbox, SIGNAL(natureChanged(int)), this, SLOT(setNature(int))); connect(ui->evbox, SIGNAL(natureBoostChanged()), ui->ivbox, SLOT(updateStats())); connect(ui->ivbox, SIGNAL(statsUpdated()), ui->evbox, SLOT(updateEVs())); updateAll(); }
void MoveProxy::adaptTo(const BattleMove *move) { setNum(move->num()); changePP(move->PP()); }
void PokeSelection::setPokemon(const QModelIndex &p) { setNum(p.data(CustomModel::PokenumRole).toInt()); }
bool ShopPanel::init() { /*for(auto node:_buttons->getChildren()) { auto button = static_cast<Button*>(node); button->addTouchEventListener(CC_CALLBACK_2(ShopPanel::onButtonClicked, this)); }*/ //_container->setTouchEnabled(true); _container->setAnchorPoint(Vec2(0,0)); _listView = static_cast<ListView*>(Helper::seekWidgetByName(_root, "ListView_content")); _goodPan = static_cast<Layout*>(Helper::seekWidgetByName(_root, "Panel_good")); _goodPan->retain(); _goodPan->removeFromParent(); _listView->addEventListener((ui::ListView::ccListViewCallback)CC_CALLBACK_2(ShopPanel::selectedItemEvent, this)); _listView->addEventListener((ui::ListView::ccScrollViewCallback)CC_CALLBACK_2(ShopPanel::selectedItemEventScrollView,this)); //_title = Label::create("","Arial",20); //_title->setColor(Color3B::BLACK); //_title->setPosition(0, _container->getSize().height / 2 - 30); //_container->addChild(_title); //_label = Label::create("","Arial",17); //_label->setColor(Color3B::BLACK); //_label->setLineBreakWithoutSpace(true); //_label->setAnchorPoint(Vec2(0,0)); //_label->setDimensions(_scrollView->getSize().width,0); ////_label->setPositionY(_scrollView->getSize().height / 2); ////_label->setPositionX(_scrollView->getSize().width / 2); //_scrollView->addChild(_label); //auto clipper = ClippingNode::create(); //clipper->setContentSize(_scrollView->getSize()); ////clipper->setPositionY(_scrollView->getSize().height / 2 + _scrollView->getPosition().y); ////clipper->setAnchorPoint(Vec2(0.5, 0.5)); //_container->addChild(clipper); //auto stencil = DrawNode::create(); //Vec2 rectangle[4]; //rectangle[0] = Vec2(-clipper->getContentSize().width / 2, -clipper->getContentSize().height / 2); //rectangle[1] = Vec2(-clipper->getContentSize().width / 2, clipper->getContentSize().height / 2); //rectangle[2] = Vec2(clipper->getContentSize().width / 2, clipper->getContentSize().height / 2); //rectangle[3] = Vec2(clipper->getContentSize().width / 2, -clipper->getContentSize().height / 2); //Color4F white(1, 1, 1, 1); //stencil->drawPolygon(rectangle, 4, white, 1, white); //clipper->setStencil(stencil); //_scrollView->retain(); //_scrollView->removeFromParent(); //clipper->addChild(_scrollView); //_scrollView->release(); auto goodNum = cocos2d::Value(PlotScript::sharedHD()->getLuaVarString("script/Test.lua", "goodsNum")).asInt(); for(int i = 1; i <= goodNum; i++) { auto goodName = "good" + cocos2d::Value(i).asString(); auto content = PlotScript::sharedHD()->getLuaVarString("script/Test.lua", goodName.c_str()); ValueMap valueMap; stringToValueMap(std::string(content), valueMap); int lock = valueMap["lock"].asInt(); if(conditions[goodName+"_unlock"].intValue() == 1) lock = 0; if(lock == 0) { auto goodPan = _goodPan->clone(); auto goodUnit = GoodUnit::create(i); ValueMap model; model["typeId"] = valueMap["typeId"]; auto good = CellFactory::getInstance()->createCell(model); goodUnit->setGood(good); goodUnit->setPrice(valueMap["price"].asInt()); goodUnit->setNum(valueMap["num"].asInt()); goodUnit->setView(goodPan); _goodsUnit.pushBack(goodUnit); goodPan->setTag(i); _listView->pushBackCustomItem(goodPan); } } _container->setScale(0.85f); _container->setOpacity(200); _container->runAction(FadeIn::create(0.2)); _container->runAction(ScaleTo::create(0.2,1.0f,1.0f,1.0f)); _root->setTouchEnabled(true); _container->setTouchEnabled(false); _root->addTouchEventListener(CC_CALLBACK_2(ShopPanel::onButtonClicked, this)); setKeyboardEnabled(true); return true; }
void SoXipComposeVec6::evaluate() { SO_ENGINE_OUTPUT(outVOI, SoMFInt32, setNum(6)); // intersection of plane and volume SO_ENGINE_OUTPUT(outVOI, SoMFInt32, set1Value(0, xmin.getValue()) ); SO_ENGINE_OUTPUT(outVOI, SoMFInt32, set1Value(1, xmax.getValue()) ); SO_ENGINE_OUTPUT(outVOI, SoMFInt32, set1Value(2, ymin.getValue()) ); SO_ENGINE_OUTPUT(outVOI, SoMFInt32, set1Value(3, ymax.getValue()) ); SO_ENGINE_OUTPUT(outVOI, SoMFInt32, set1Value(4, zmin.getValue()) ); SO_ENGINE_OUTPUT(outVOI, SoMFInt32, set1Value(5, zmax.getValue()) ); // Reset outputs SO_ENGINE_OUTPUT( numSlices, SoSFShort, setValue(0) ); SO_ENGINE_OUTPUT( output, SoXipSFDataImage, setValue(0) ); SoXipDataImage* imageData = image.getValue(); if( mImageData != imageData ) { mImageData = image.getValue(); // Reset previous outputs mOutputs.setNum(0); if( mImageData ) { SbXipImage* image = mImageData->get(); if( !image ) return ; // Initialize outputs unsigned int numSlices = image->getDimStored()[2]; mOutputs.setNum( numSlices ); for( unsigned int i = 0; i < numSlices; ++ i ) mOutputs.set1Value( i, 0 ); } } if( imageData ) { SbXipImage* image = mImageData->get(); if( !image ) return ; SbXipImageDimensions dimensions = image->getDimStored(); SbXipImageDimensions sliceDimensions = dimensions; sliceDimensions[2] = 1; int sliceIndex = this->sliceIndex.getValue(); if( sliceIndex < 0 || sliceIndex >= dimensions[2] ) return ; if( mOutputs[sliceIndex] == 0 ) { // Compute the model matrix of the selected frame SbMatrix sliceModelMatrix = image->getModelMatrix(); sliceModelMatrix[2][0] /= dimensions[2]; sliceModelMatrix[2][1] /= dimensions[2]; sliceModelMatrix[2][2] /= dimensions[2]; sliceModelMatrix[3][0] += sliceIndex * sliceModelMatrix[2][0]; sliceModelMatrix[3][1] += sliceIndex * sliceModelMatrix[2][1]; sliceModelMatrix[3][2] += sliceIndex * sliceModelMatrix[2][2]; // Pointer to the selected slice char* imagePtr = (char *) image->refBufferPtr(); unsigned int cellSize; switch( image->getType() ) { case SbXipImage::UNSIGNED_BYTE: cellSize = sizeof(unsigned char); break ; case SbXipImage::BYTE: cellSize = sizeof(char); break ; case SbXipImage::UNSIGNED_SHORT: cellSize = sizeof(unsigned short); break ; case SbXipImage::SHORT: cellSize = sizeof(short); break ; case SbXipImage::UNSIGNED_INT: cellSize = sizeof(unsigned int); break ; case SbXipImage::INT: cellSize = sizeof(int); break ; case SbXipImage::FLOAT: cellSize = sizeof(float); break ; case SbXipImage::DOUBLE: cellSize = sizeof(double); break ; } void* slicePtr = imagePtr + cellSize * image->getComponents() * dimensions[0] * dimensions[1] * sliceIndex; SbXipImage* slice = new SbXipImage( sliceDimensions, image->getType(), image->getBitsStored(), slicePtr, image->getComponents(), image->getComponentType(), image->getComponentLayoutType(), sliceModelMatrix, image->getLineAlignment() ); image->unrefBufferPtr(); SoXipDataImage* output = new SoXipDataImage(); output->ref(); output->set( slice ); output->addRef( imageData ); mOutputs.set1Value( sliceIndex, output ); } SO_ENGINE_OUTPUT( output, SoXipSFDataImage, setValue(mOutputs[sliceIndex]) ); } }
PokeTeam::PokeTeam() { setNum(Pokemon::uniqueId(Pokemon::NoPoke)); setGen(GEN_MAX); }
int FluidSynthMidiDriver::open() { if (!stereo) { perr << "FluidSynth only works with Stereo output" << std::endl; return -1; } std::string sfsetting = "fluidsynth_soundfont"; std::vector<std::string> soundfonts; std::string soundfont; for (size_t i = 0; i < 10; i++) { std::string settingkey = sfsetting + static_cast<char>(i + '0'); soundfont = getConfigSetting(settingkey, ""); if (!soundfont.empty()) soundfonts.push_back(soundfont); } soundfont = getConfigSetting(sfsetting, ""); if (!soundfont.empty()) soundfonts.push_back(soundfont); if (soundfonts.empty()) { perr << "FluidSynth requires a 'fluidsynth_soundfont' setting" << std::endl; return -2; } _settings = new_fluid_settings(); // The default gain setting is ridiculously low, but we can't set it // too high either or sound will be clipped. This may need tuning... setNum("synth.gain", 2.1); setNum("synth.sample-rate", sample_rate); _synth = new_fluid_synth(_settings); // In theory, this ought to reduce CPU load... but it doesn't make any // noticeable difference for me, so disable it for now. // fluid_synth_set_interp_method(_synth, -1, FLUID_INTERP_LINEAR); // fluid_synth_set_reverb_on(_synth, 0); // fluid_synth_set_chorus_on(_synth, 0); int numloaded = 0; for (std::vector<std::string>::const_iterator it = soundfonts.begin(); it != soundfonts.end(); ++it) { int soundFont = fluid_synth_sfload(_synth, it->c_str(), 1); if (soundFont == -1) { perr << "Failed loading custom sound font '" << *it << "'" << std::endl; } else { perr << "Loaded custom sound font '" << *it << "'" << std::endl; _soundFont.push(soundFont); numloaded++; } } if (numloaded == 0) { perr << "Failed to load any custom sound fonts; giving up." << std::endl; return -3; } return 0; }
Card::Card(char n){ setNum(n); count++; }
int MidiDriver_FluidSynth::open() { if (_isOpen) return MERR_ALREADY_OPEN; if (!ConfMan.hasKey("soundfont")) error("FluidSynth requires a 'soundfont' setting"); _settings = new_fluid_settings(); // The default gain setting is ridiculously low - at least for me. This // cannot be fixed by ScummVM's volume settings because they can only // soften the sound, not amplify it, so instead we add an option to // adjust the gain of FluidSynth itself. double gain = (double)ConfMan.getInt("midi_gain") / 100.0; setNum("synth.gain", gain); setNum("synth.sample-rate", _outputRate); _synth = new_fluid_synth(_settings); if (ConfMan.getBool("fluidsynth_chorus_activate")) { fluid_synth_set_chorus_on(_synth, 1); int chorusNr = ConfMan.getInt("fluidsynth_chorus_nr"); double chorusLevel = (double)ConfMan.getInt("fluidsynth_chorus_level") / 100.0; double chorusSpeed = (double)ConfMan.getInt("fluidsynth_chorus_speed") / 100.0; double chorusDepthMs = (double)ConfMan.getInt("fluidsynth_chorus_depth") / 10.0; Common::String chorusWaveForm = ConfMan.get("fluidsynth_chorus_waveform"); int chorusType = FLUID_CHORUS_MOD_SINE; if (chorusWaveForm == "sine") { chorusType = FLUID_CHORUS_MOD_SINE; } else { chorusType = FLUID_CHORUS_MOD_TRIANGLE; } fluid_synth_set_chorus(_synth, chorusNr, chorusLevel, chorusSpeed, chorusDepthMs, chorusType); } else { fluid_synth_set_chorus_on(_synth, 0); } if (ConfMan.getBool("fluidsynth_reverb_activate")) { fluid_synth_set_reverb_on(_synth, 1); double reverbRoomSize = (double)ConfMan.getInt("fluidsynth_reverb_roomsize") / 100.0; double reverbDamping = (double)ConfMan.getInt("fluidsynth_reverb_damping") / 100.0; int reverbWidth = ConfMan.getInt("fluidsynth_reverb_width"); double reverbLevel = (double)ConfMan.getInt("fluidsynth_reverb_level") / 100.0; fluid_synth_set_reverb(_synth, reverbRoomSize, reverbDamping, reverbWidth, reverbLevel); } else { fluid_synth_set_reverb_on(_synth, 0); } Common::String interpolation = ConfMan.get("fluidsynth_misc_interpolation"); int interpMethod = FLUID_INTERP_4THORDER; if (interpolation == "none") { interpMethod = FLUID_INTERP_NONE; } else if (interpolation == "linear") { interpMethod = FLUID_INTERP_LINEAR; } else if (interpolation == "4th") { interpMethod = FLUID_INTERP_4THORDER; } else if (interpolation == "7th") { interpMethod = FLUID_INTERP_7THORDER; } fluid_synth_set_interp_method(_synth, -1, interpMethod); const char *soundfont = ConfMan.get("soundfont").c_str(); _soundFont = fluid_synth_sfload(_synth, soundfont, 1); if (_soundFont == -1) error("Failed loading custom sound font '%s'", soundfont); MidiDriver_Emulated::open(); _mixer->playStream(Audio::Mixer::kPlainSoundType, &_mixerSoundHandle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true); return 0; }
int checkSquare(int fin) { int i,j,k,l,t,value,square; int I,J; int numbers; //flag mask of completed numbers int unique; //flag mask to find unique flags int unique_plus; //flag mask to exclude not-unique flags int finished; //counter of completed numbers in this square int *linCol=(int *) calloc(n,sizeof(int)); //to find allineated flags allineatios int *linRow=(int *) calloc(n,sizeof(int)); //to find allineated flags allineatios int *totCol=(int *) calloc(n,sizeof(int)); //to eliminate doubled flags int *totRow=(int *) calloc(n,sizeof(int)); //to eliminate doubled flags if(linCol==NULL || linRow==NULL || totCol==NULL || totRow==NULL) { fprintf(stderr,"Allocation error (3)\n"); exit(ERR_ALLOC); } i=0; j=0; do { finished=0; square=(i/n)*n + (j/n); //position of this square in array q and index in fin if((fin & (1<<square)) ==0) //if this square is not completed { unique=0; unique_plus=0; //set the flag mask of completed numbers numbers=mask | (mask-1); //numbers = 1....1 (n2+1 ones) I=i; //coordinates of the 0 point of this square J=j; do { if((m[i][j] & mask) ==0) //if it's a number numbers=numbers & (numbers^(1<<m[i][j])); //set to 0 its flag in numbers mask else { //otherwise, if it's an int of flags unique_plus=unique_plus | (unique & m[i][j]); //detect duplicated flags unique=unique^m[i][j]; //set to 0 flags that are not uniques } } while(getCoord(&i,&j)==0); unique=unique ^ (unique & unique_plus); if((unique & mask)==0) //make sure it has flags's flag unique+=mask; i=I; //restart from the beginning of this square j=J; do { if(m[i][j] & mask) //if it's a flag { m[i][j]= m[i][j] & numbers; //use the mask if((unique & m[i][j])>mask && chkEnabled[LV2]) //check if it has a unique flag { if(DEBUG1) printf("%d uniS: (%d,%d)=%d >>>>%d \n",cycleCounter,i,j,m[i][j],m[i][j] & unique);////////////////// m[i][j]=unique & m[i][j]; //set the other flags to 0 } value=checkOneValue(i,j); if(value!=0) { if(value==-1) return -1; //error in the sudoku if(DEBUG1) printf("NEW: (%d,%d)=%d >>>>%d \n",i,j,m[i][j],value);////////////////// setNum(i,j,value); finished++; numbers=numbers | (1<<value); //add new number to the mask } } else { finished++; } } while(getCoord(&i,&j)==0); if(cycleCounter>CHECK_START) //Since it's an expensive check, it won't start at the beginning { if(chkEnabled[LV3]) { /* LV3: this part will check if there's a flags allineation if a flags allineation if found for a number, a function will set to 0 the number's flags in that line. */ //save the possible numbers of the rows and columns for(k=0; k<n; k++) { linCol[k]=0; linRow[k]=0; for(l=0; l<n; l++) { if(m[I+l][J+k] & mask) linCol[k]=linCol[k] | m[I+l][J+k]; if(m[I+k][J+l] & mask) linRow[k]=linRow[k] | m[I+k][J+l]; } } //compare the flags to exclude common numbers for(k=0; k<n; k++) { totCol[k]=0; totRow[k]=0; for(l=0; l<n; l++) { if(l!=k) { totCol[k]= totCol[k] | linCol[l]; totRow[k]= totRow[k] | linRow[l]; } } } //check of allineations for(k=0; k<n; k++) { linCol[k]=linCol[k] & (linCol[k] ^ totCol[k]); linRow[k]=linRow[k] & (linRow[k] ^ totRow[k]); if((linCol[k] & mask)) //make sure it has NOT flags's flag linCol[k]-=mask; if((linRow[k] & mask)) //make sure it has NOT flags's flag linRow[k]-=mask; if(linCol[k]>1) { if(DEBUG2) printf("column allineation: %d*,%d, =%d [cycler=%d]\n",I,J+k,linCol[k],cycleCounter);//////// warnCol(I,J,k,linCol[k]); if(DEBUG2) printMatrix(stdout,0); } if(linRow[k]>1) { if(DEBUG2) printf("row allineation: %d,%d*, =%d [cycler=%d]\n",I+k,J,linRow[k],cycleCounter);//////// warnRow(I,J,k,linRow[k]); if(DEBUG2) printMatrix(stdout,0); } } } /* Cicla sulle caselle di uno square cerca un gruppo di celle con flag identici se lo trovo ed il numero di caselle è == al numero di numeri possibili semplifico quei numeri dal resto dello square */ //LV4 if(chkEnabled[LV4]) { i=I; //restart from the beginning of this square j=J; do { if(m[i][j] & mask) //if it's a flag { //find groups of cells with identical flags k=0; t=i; l=j; do { if(m[t][l] & mask) //if it's a flag if(areEquals(m[i][j],m[t][l])) k++; } while(getCoord(&t,&l)==0); if(k==countValues(i,j)) { //i found a group of identical flags, //now i can semplify them from the cells that are not in the group t=I; l=J; do { if(m[t][l] & mask) //if it's a flag if(areEquals(m[i][j],m[t][l])==0) { square=(i/n)*n + (l/n); //position of this square in array q m[t][l]=( (m[t][l] ^ m[i][j]) & m[t][l] ) | mask; } } while(getCoord(&t,&l)==0); } } } while(getCoord(&i,&j)==0); //*/ } } if(finished==n2) fin=fin | (1<<square); //set the flag for this square as completed } else { while(getCoord(&i,&j)==0); //select next square } } while(i<n2 && j<n2); free(linCol); free(linRow); free(totCol); free(totRow); return fin; }
void SoItkImageFileReader::evaluate() { if( mOutput ) { mOutput->unref(); mOutput = 0; SO_ENGINE_OUTPUT( Output, SoItkSFDataImage, setValue( 0 ) ); SO_ENGINE_OUTPUT( Dimensions, SoMFShort, setNum( 0 ) ); } if( File.getValue().getLength() <= 0 ) return ; try { #define DO_IT( Type, ComponentLayoutFlag, TypeFlag, Dimension ) \ { \ typedef itk::Image< Type, Dimension > OutputImageType; \ typedef itk::ImageFileReader< OutputImageType > ReaderType; \ \ ReaderType::Pointer reader = ReaderType::New(); \ reader->SetFileName( File.getValue().getString() ); \ reader->Update(); \ \ /* Since Itk objects are reference-counted, we need to manually */ \ /* increment the reference count of the resulting image, to avoid */ \ /* the importFilter instance to destroy it. */ \ \ reader->GetOutput()->Register(); \ \ mOutput = new SoItkDataImage( TypeFlag, ComponentLayoutFlag, Dimension ); \ mOutput->ref(); \ mOutput->setPointer( reader->GetOutput() ); \ \ short dims[2]; \ dims[0] = mOutput->getDimension( 0 ); \ dims[1] = mOutput->getDimension( 1 ); \ SO_ENGINE_OUTPUT( Dimensions, SoMFShort, setNum(2) ); \ SO_ENGINE_OUTPUT( Dimensions, SoMFShort, setValues( 0, 2, dims ) ); \ } #define CASE( Type, ItkTypeFlag, Dimension, TypeFlag, ComponentLayoutFlag ) \ { \ case ItkTypeFlag: \ DO_IT( Type, ComponentLayoutFlag, TypeFlag, Dimension ) \ break ; \ } switch( Dimension.getValue() ) { case SoItkImageFileReader::TWO : { switch( ComponentLayout.getValue() ) { case SoItkImageFileReader::LUMINANCE : { switch( Type.getValue() ) { CASE( unsigned short, SoItkImageFileReader::UNSIGNED_SHORT, 2, SoItkDataImage::UNSIGNED_SHORT, SoItkDataImage::LUMINANCE); CASE( float, SoItkImageFileReader::FLOAT, 2, SoItkDataImage::FLOAT, SoItkDataImage::LUMINANCE); CASE( unsigned char, SoItkImageFileReader::UNSIGNED_CHAR, 2, SoItkDataImage::UNSIGNED_CHAR, SoItkDataImage::LUMINANCE ); CASE( short, SoItkImageFileReader::SHORT, 2, SoItkDataImage::SHORT, SoItkDataImage::LUMINANCE ); } } break; case SoItkImageFileReader::RGB : { switch( Type.getValue() ) { CASE( itk::RGBPixel<unsigned short>, SoItkImageFileReader::UNSIGNED_SHORT, 2, SoItkDataImage::UNSIGNED_SHORT, SoItkDataImage::RGB); CASE( itk::RGBPixel<float>, SoItkImageFileReader::FLOAT, 2, SoItkDataImage::FLOAT, SoItkDataImage::RGB ); CASE( itk::RGBPixel<unsigned char>, SoItkImageFileReader::UNSIGNED_CHAR, 2, SoItkDataImage::UNSIGNED_CHAR, SoItkDataImage::RGB ); CASE( itk::RGBPixel<short>, SoItkImageFileReader::SHORT, 2, SoItkDataImage::SHORT, SoItkDataImage::RGB ); } } break; case SoItkImageFileReader::RGBA : { switch( Type.getValue() ) { CASE( itk::RGBAPixel<unsigned short>, SoItkImageFileReader::UNSIGNED_SHORT, 2, SoItkDataImage::UNSIGNED_SHORT, SoItkDataImage::RGBA); CASE( itk::RGBAPixel<float>, SoItkImageFileReader::FLOAT, 2, SoItkDataImage::FLOAT, SoItkDataImage::RGBA ); CASE( itk::RGBAPixel<unsigned char>, SoItkImageFileReader::UNSIGNED_CHAR, 2, SoItkDataImage::UNSIGNED_CHAR, SoItkDataImage::RGBA ); CASE( itk::RGBAPixel<short>, SoItkImageFileReader::SHORT, 2, SoItkDataImage::SHORT, SoItkDataImage::RGBA ); } } break; } } break; case SoItkImageFileReader::THREE : { switch( ComponentLayout.getValue() ) { case SoItkImageFileReader::LUMINANCE : { switch( Type.getValue() ) { CASE( unsigned short, SoItkImageFileReader::UNSIGNED_SHORT, 3, SoItkDataImage::UNSIGNED_SHORT, SoItkDataImage::LUMINANCE); CASE( float, SoItkImageFileReader::FLOAT, 3, SoItkDataImage::FLOAT, SoItkDataImage::LUMINANCE); CASE( unsigned char, SoItkImageFileReader::UNSIGNED_CHAR, 3, SoItkDataImage::UNSIGNED_CHAR, SoItkDataImage::LUMINANCE ); CASE( short, SoItkImageFileReader::SHORT, 3, SoItkDataImage::SHORT, SoItkDataImage::LUMINANCE ); } } break; case SoItkImageFileReader::RGB : { switch( Type.getValue() ) { CASE( itk::RGBPixel<unsigned short>, SoItkImageFileReader::UNSIGNED_SHORT, 3, SoItkDataImage::UNSIGNED_SHORT, SoItkDataImage::RGB); CASE( itk::RGBPixel<float>, SoItkImageFileReader::FLOAT, 3, SoItkDataImage::FLOAT, SoItkDataImage::RGB ); CASE( itk::RGBPixel<unsigned char>, SoItkImageFileReader::UNSIGNED_CHAR, 3, SoItkDataImage::UNSIGNED_CHAR, SoItkDataImage::RGB ); CASE( itk::RGBPixel<short>, SoItkImageFileReader::SHORT, 3, SoItkDataImage::SHORT, SoItkDataImage::RGB ); } } break; case SoItkImageFileReader::RGBA : { switch( Type.getValue() ) { CASE( itk::RGBAPixel<unsigned short>, SoItkImageFileReader::UNSIGNED_SHORT, 3, SoItkDataImage::UNSIGNED_SHORT, SoItkDataImage::RGBA); CASE( itk::RGBAPixel<float>, SoItkImageFileReader::FLOAT, 3, SoItkDataImage::FLOAT, SoItkDataImage::RGBA ); CASE( itk::RGBAPixel<unsigned char>, SoItkImageFileReader::UNSIGNED_CHAR, 3, SoItkDataImage::UNSIGNED_CHAR, SoItkDataImage::RGBA ); CASE( itk::RGBAPixel<short>, SoItkImageFileReader::SHORT, 3, SoItkDataImage::SHORT, SoItkDataImage::RGBA ); } } break; } } break; } #undef CASE #undef DO_IT } catch( itk::ExceptionObject& e ) { SoDebugError::post( e.GetFile(), " line %d: %s", e.GetLine(), e.GetDescription() ); return ; } catch(...) { SoDebugError::post( __FILE__, "Unknown Exception" ); return ; } SO_ENGINE_OUTPUT( Output, SoItkSFDataImage, setValue( mOutput ) ); }
/* copy constructor */ BigInt::BigInt(const BigInt &orig) { setNum(orig.getNum()); setSign(orig.getSign()); }
PokeTeam::PokeTeam() { setNum(Pokemon::uniqueId(Pokemon::NoPoke)); setGen(Pokemon::gen(GenInfo::GenMax(), GenInfo::NumberOfSubgens(GenInfo::GenMax())-1)); }
void SoDoubleCalculator::evaluate() // //////////////////////////////////////////////////////////////////////// { if (reparse) { parser->clear(); SbBool OK = TRUE; int i; for (i=0; i<expression.getNum(); i++) { if (!parser->parse(expression[i].getString())) { OK = FALSE; break; } } if (! OK) { #ifdef DEBUG SoDebugError::post("SoDoubleCalculator::evaluate", "Invalid expression '%s'", expression[i].getString()); #endif /* DEBUG */ expression.setValue(""); parser->clear(); } reparse = FALSE; } int max = 0; int na = a.getNum(); if (na > max) max = na; int nb = b.getNum(); if (nb > max) max = nb; int nc = c.getNum(); if (nc > max) max = nc; int nd = d.getNum(); if (nd > max) max = nd; int ne = e.getNum(); if (ne > max) max = ne; int nf = f.getNum(); if (nf > max) max = nf; int ng = g.getNum(); if (ng > max) max = ng; int nh = h.getNum(); if (nh > max) max = nh; int nA = A.getNum(); if (nA > max) max = nA; int nB = B.getNum(); if (nB > max) max = nB; int nC = C.getNum(); if (nC > max) max = nC; int nD = D.getNum(); if (nD > max) max = nD; int nE = E.getNum(); if (nE > max) max = nE; int nF = F.getNum(); if (nF > max) max = nF; int nG = G.getNum(); if (nG > max) max = nG; int nH = H.getNum(); if (nG > max) max = nH; int nout = max; SO_ENGINE_OUTPUT(oa, SoMFDouble, setNum(nout)); SO_ENGINE_OUTPUT(ob, SoMFDouble, setNum(nout)); SO_ENGINE_OUTPUT(oc, SoMFDouble, setNum(nout)); SO_ENGINE_OUTPUT(od, SoMFDouble, setNum(nout)); SO_ENGINE_OUTPUT(oA, SoMFDouble, setNum(nout)); SO_ENGINE_OUTPUT(oB, SoMFDouble, setNum(nout)); SO_ENGINE_OUTPUT(oC, SoMFDouble, setNum(nout)); SO_ENGINE_OUTPUT(oD, SoMFDouble, setNum(nout)); for (int i=0; i<nout; i++) { va = a[clamp(i,na)]; vb = b[clamp(i,nb)]; vc = c[clamp(i,nc)]; vd = d[clamp(i,nd)]; ve = e[clamp(i,ne)]; vf = f[clamp(i,nf)]; vg = g[clamp(i,ng)]; vh = h[clamp(i,nh)]; vA = A[clamp(i,nA)]; vB = B[clamp(i,nB)]; vC = C[clamp(i,nC)]; vD = D[clamp(i,nD)]; vE = E[clamp(i,nE)]; vF = F[clamp(i,nF)]; vG = G[clamp(i,nG)]; vH = H[clamp(i,nH)]; ova = 0; ovb = 0; ovc = 0; ovd = 0; ovA = SbVec3f(0,0,0); ovB = SbVec3f(0,0,0); ovC = SbVec3f(0,0,0); ovD = SbVec3f(0,0,0); parser->eval(); SO_ENGINE_OUTPUT(oa, SoMFDouble, set1Value(i, ova)); SO_ENGINE_OUTPUT(ob, SoMFDouble, set1Value(i, ovb)); SO_ENGINE_OUTPUT(oc, SoMFDouble, set1Value(i, ovc)); SO_ENGINE_OUTPUT(od, SoMFDouble, set1Value(i, ovd)); SO_ENGINE_OUTPUT(oA, SoMFVec3f, set1Value(i, ovA)); SO_ENGINE_OUTPUT(oB, SoMFVec3f, set1Value(i, ovB)); SO_ENGINE_OUTPUT(oC, SoMFVec3f, set1Value(i, ovC)); SO_ENGINE_OUTPUT(oD, SoMFVec3f, set1Value(i, ovD)); } }
void Fraction::reduce() { int num = getNum(); int den = getDen(); int greater; int lesser; int remainder; int gcd; if (num < 0 && den < 0) // if both terms are negative, the fraction is positive { num = abs(num); den = abs(den); } if (num == 0) { setDen(1); // ensure that Fraction is reduced to 0/1 } else if (abs(num) > abs(den)) { greater = num; lesser = den; // the following +-20 lines implement Euclid's algorithm for finding the GCD of two numbers remainder = greater % lesser; if (remainder != 0) { do { remainder = greater % lesser; greater = lesser; lesser = remainder; } while (greater % lesser != 0); } else if (remainder == 0) // if the remainder is 0, either the numerator can be divided into the denominator or vice versa { if (abs(den) > abs(num)) { den = den / num; num = 1; } else if (abs(den) < abs(num)) { num = num / den; den = 1; } remainder = 1; } gcd = abs(remainder); // take the absolute value of the remainder to prevent negative errors since remainders are never < 0 setNum(num / gcd); setDen(den / gcd); } else if (abs(den) > abs(num)) { greater = den; lesser = num; remainder = greater % lesser; if (remainder != 0 && num % remainder != 0) { do { remainder = greater % lesser; greater = lesser; lesser = remainder; } while (greater % lesser != 0); } else if (remainder == 0) // fraction is already in reduced form { if (abs(den) > abs(num)) { den = den / num; num = 1; } else { } // if the fraction is a whole number, do nothing remainder = 1; } setNum(num / abs(remainder)); setDen(den / abs(remainder)); } else if (abs(num) == abs(den)) { if (num < den) // numerator is negative { setNum(-1); } else { setNum(1); } setDen(1); } }