void InputManager::retrieve() { for (int i = 0; i < InputAction::TOTAL; i++) { #ifdef USE_SDL2 const std::string cf = std::string("sdl2") + inputActionData[i].configField; #else const std::string cf = inputActionData[i].configField; #endif if (!cf.empty()) { mNameMap[cf] = i; InputFunction &kf = mKey[i]; const std::string keyStr = config.getValue(cf, ""); const size_t keyStrSize = keyStr.size(); if (keyStr.empty()) continue; StringVect keys; splitToStringVector(keys, keyStr, ','); unsigned int i2 = 0; for (StringVectCIter it = keys.begin(), it_end = keys.end(); it != it_end && i2 < inputFunctionSize; ++ it) { std::string keyStr2 = *it; if (keyStrSize < 2) continue; int type = InputType::KEYBOARD; if ((keyStr2[0] < '0' || keyStr2[0] > '9') && keyStr2[0] != '-') { switch (keyStr2[0]) { case 'm': type = InputType::MOUSE; break; case 'j': type = InputType::JOYSTICK; break; default: break; } keyStr2 = keyStr2.substr(1); } const int key = atoi(keyStr2.c_str()); if (key >= -255 && key < SDLK_LAST) { kf.values[i2] = InputItem(type, key); i2 ++; } } } } }
void ModeListModel::addCustomMode(std::string mode) { StringVectCIter it = mVideoModes.begin(); StringVectCIter it_end = mVideoModes.end(); while (it != it_end) { if (*it == mode) return; ++ it; } mVideoModes.push_back(mode); }
int main(int argc, char * argv[]) { bool pass = true; { StringVect perms = permutation_str_no_dup(""); pass = pass && perms.empty(); } { StringVect perms = permutation_str_no_dup("a"); pass = pass && (perms.size() == 1) && (std::find(perms.begin(), perms.end(), "a") != perms.end()) ; } { StringVect perms = permutation_str_no_dup("ab"); pass = pass && (perms.size() == 2) && (std::find(perms.begin(), perms.end(), "ab") != perms.end()) && (std::find(perms.begin(), perms.end(), "ba") != perms.end()) ; } { StringVect perms = permutation_str_no_dup("abc"); pass = pass && (perms.size() == 6) && (std::find(perms.begin(), perms.end(), "abc") != perms.end()) && (std::find(perms.begin(), perms.end(), "acb") != perms.end()) && (std::find(perms.begin(), perms.end(), "bac") != perms.end()) && (std::find(perms.begin(), perms.end(), "bca") != perms.end()) && (std::find(perms.begin(), perms.end(), "cab") != perms.end()) && (std::find(perms.begin(), perms.end(), "cba") != perms.end()) ; } return (pass ? 0 : -1); }
void InputManager::retrieve() { for (int i = 0; i < Input::KEY_TOTAL; i++) { if (*keyData[i].configField) { KeyFunction &kf = mKey[i]; std::string keyStr = config.getValue(keyData[i].configField, ""); if (keyStr.empty()) continue; StringVect keys; splitToStringVector(keys, keyStr, ','); int i2 = 0; for (StringVectCIter it = keys.begin(), it_end = keys.end(); it != it_end && i2 < KeyFunctionSize; ++ it) { std::string keyStr2 = *it; if (keyStr.size() < 2) continue; int type = INPUT_KEYBOARD; if ((keyStr2[0] < '0' || keyStr2[0] > '9') && keyStr2[0] != '-') { switch (keyStr2[0]) { case 'm': type = INPUT_MOUSE; break; case 'j': type = INPUT_JOYSTICK; break; default: break; } keyStr2 = keyStr2.substr(1); } int key = atoi(keyStr2.c_str()); if (key >= -255 && key < SDLK_LAST) { kf.values[i2] = KeyItem(type, key); i2 ++; } } } } }
Setup_Perfomance::Setup_Perfomance(const Widget2 *const widget) : SetupTabScroll(widget), #ifdef USE_SDL2 mSdlDriversList(new NamesModel), #endif // USE_SDL2 mTexturesList(new NamesModel) { // TRANSLATORS: settings tab name setName(_("Performance")); // Do the layout LayoutHelper h(this); ContainerPlacer place = h.getPlacer(0, 0); place(0, 0, mScroll, 10, 10); #ifdef USE_SDL2 StringVect sdlDriversList; SDL::getRenderers(sdlDriversList, config.getStringValue("sdlDriver")); sdlDriversList.insert(sdlDriversList.begin(), // TRANSLATORS: sdl driver name N_("default")); #endif // USE_SDL2 // TRANSLATORS: settings option new SetupItemLabel(_("Better performance (enable for better performance)"), "", this, Separator_true); // TRANSLATORS: settings option new SetupItemCheckBox(_("Auto adjust performance"), "", "adjustPerfomance", this, "adjustPerfomanceEvent", MainConfig_true); // TRANSLATORS: settings option new SetupItemCheckBox(_("Hw acceleration"), "", "hwaccel", this, "hwaccelEvent", MainConfig_true); // TRANSLATORS: settings option new SetupItemCheckBox(_("Enable opacity cache (Software, can " "use much memory)"), "", "alphaCache", this, "alphaCacheEvent", MainConfig_true); #ifndef USE_SDL2 // TRANSLATORS: settings option new SetupItemCheckBox(_("Enable map reduce (Software)"), "", "enableMapReduce", this, "enableMapReduceEvent", MainConfig_true); #endif // USE_SDL2 // TRANSLATORS: settings option new SetupItemCheckBox(_("Enable compound sprite delay (Software)"), "", "enableCompoundSpriteDelay", this, "enableCompoundSpriteDelayEvent", MainConfig_true); // TRANSLATORS: settings option new SetupItemCheckBox(_("Enable delayed images load (OpenGL)"), "", "enableDelayedAnimations", this, "enableDelayedAnimationsEvent", MainConfig_true); // TRANSLATORS: settings option new SetupItemCheckBox(_("Enable texture sampler (OpenGL)"), "", "useTextureSampler", this, "useTextureSamplerEvent", MainConfig_true); // TRANSLATORS: settings option new SetupItemCheckBox(_("Enable OpenGL context creation"), "", "openglContext", this, "openglContextEvent", MainConfig_true); // TRANSLATORS: settings option new SetupItemCheckBox(_("Enable OpenGL direct state access"), "", "enableDSA", this, "enableDSAEvent", MainConfig_true); // TRANSLATORS: settings option new SetupItemLabel(_("Better quality (disable for better performance)"), "", this, Separator_true); // TRANSLATORS: settings option new SetupItemCheckBox(_("Enable alpha channel fix (Software, can " "be very slow)"), "Can slow down drawing", "enableAlphaFix", this, "enableAlphaFixEvent", MainConfig_true); // TRANSLATORS: settings option new SetupItemCheckBox(_("Show beings transparency"), "", "beingopacity", this, "beingopacityEvent", MainConfig_true); // TRANSLATORS: settings option new SetupItemCheckBox(_("Enable reorder sprites (need for mods support)."), "", "enableReorderSprites", this, "enableReorderSpritesEvent", MainConfig_true); #ifndef USE_SDL2 // TRANSLATORS: settings option new SetupItemLabel(_("Small memory (enable for lower memory usage)"), "", this, Separator_true); // TRANSLATORS: settings option new SetupItemCheckBox(_("Disable advanced beings caching (Software)"), "", "disableAdvBeingCaching", this, "disableAdvBeingCachingEvent", MainConfig_true); // TRANSLATORS: settings option new SetupItemCheckBox(_("Disable beings caching (Software)"), "", "disableBeingCaching", this, "disableBeingCachingEvent", MainConfig_true); #endif // USE_SDL2 // TRANSLATORS: settings group new SetupItemLabel(_("Different options (enable or disable can " "improve performance)"), "", this, Separator_true); #ifdef USE_SDL2 mSdlDriversList->fillFromVector(sdlDriversList); new SetupItemDropDownStr( // TRANSLATORS: settings option _("Try first sdl driver (only for SDL2 default mode)"), "", "sdlDriver", this, "sdlDriverEvent", mSdlDriversList, 100, MainConfig_true); #endif // USE_SDL2 mTexturesList->fillFromArray(&texturesList[0], texturesListSize); // TRANSLATORS: settings option new SetupItemDropDown(_("Enable texture compression (OpenGL)"), "", "compresstextures", this, "compresstexturesEvent", mTexturesList, 100, MainConfig_true); // TRANSLATORS: settings option new SetupItemCheckBox(_("Enable rectangular texture extension (OpenGL)"), "", "rectangulartextures", this, "rectangulartexturesEvent", MainConfig_true); // TRANSLATORS: settings option new SetupItemCheckBox(_("Use new texture internal format (OpenGL)"), "", "newtextures", this, "newtexturesEvent", MainConfig_true); // TRANSLATORS: settings option new SetupItemCheckBox(_("Enable texture atlases (OpenGL)"), "", "useAtlases", this, "useAtlasesEvent", MainConfig_true); // TRANSLATORS: settings option new SetupItemCheckBox(_("Cache all sprites per map (can use " "additional memory)"), "", "uselonglivesprites", this, "uselonglivespritesEvent", MainConfig_true); // TRANSLATORS: settings option new SetupItemCheckBox(_("Cache all sounds (can use additional memory)"), "", "uselonglivesounds", this, "uselonglivesoundsEvent", MainConfig_true); // TRANSLATORS: settings group new SetupItemLabel(_("Critical options (DO NOT change if you don't " "know what you're doing)"), "", this, Separator_true); // TRANSLATORS: settings option new SetupItemCheckBox(_("Disable logging in game (do not enable)"), "", "disableLoggingInGame", this, "disableLoggingInGameEvent", MainConfig_true); setDimension(Rect(0, 0, 550, 350)); }
/*---------------------------------------------------------------------------------------------------------------------- | Saves simulated data stored in `sim_pattern_map' to a file named `filename'. If the file already exists, it will be | overwritten without warning. If the file does not yet exist, it will be created. The file written will be a valid | NEXUS data file suitable for executing in phylogenetic analysis software that reads the NEXUS file format. The | supplied `taxon_names' will be used in the matrix command of the NEXUS file to specify the names of the taxa. | Assumes that the number of elements in `taxon_names' equals `pattern_length'. The `datatype' argument should be the | correct NEXUS datatype (e.g. "dna", "standard") for the data simulated. The symbols used for the states are | supplied in the `state_symbols' vector. Each element of this vector should be a single-character string. Assumes | that no state in any pattern stored in `sim_pattern_map' is greater than or equal to the length of the | `state_symbols' vector (because states are used as indices into `state_symbols'). */ void SimData::saveToNexusFile( const std::string filename, /**< is the name of the file to create containing the simulated data stored in this object */ const StringVect & taxon_names, /**< is a vector containing the taxon names to use in the saved file */ const std::string datatype, /**< is a string to be used as the NEXUS datatype (e.g. "dna" or "standard") */ const StringVect & state_symbols) /**< is a vector of strings representing states (e.g. {"A", "C", "G", "T"}). Note that each state symbol should be a string of length 1 (i.e. a single character) */ { std::cerr << "taxon_names size = " << taxon_names.size() << std::endl; std::cerr << "pattern_length = " << pattern_length << std::endl; std::cerr << "taxon_names: |"; std::copy(taxon_names.begin(), taxon_names.end(), std::ostream_iterator<std::string>(std::cerr, "|")); PHYCAS_ASSERT(state_symbols.size() > 0); PHYCAS_ASSERT(taxon_names.size() == pattern_length); // Find length of longest string in taxon_names vector; this is used later for formatting purposes // The 2 is included in case apostrophes are needed when taxon names are output in the matrix command unsigned length_of_longest_name = 2 + (unsigned)std::max_element(taxon_names.begin(), taxon_names.end(), StringLengthLess())->length(); std::ofstream outf(filename.c_str()); outf << "#nexus" << "\n\n"; outf << "begin data;" << "\n"; outf << str(boost::format(" dimensions ntax=%d nchar=%d;") % pattern_length % (unsigned)total_count) << "\n"; outf << " format datatype=" << datatype << ";" << "\n"; outf << " matrix" << "\n"; // Create a format string to use with boost::format that left-justifies (the "-" flag) the // taxon names in a field of width length_of_longest_name std::string fmtstr = str(boost::format(" %%-%ds") % length_of_longest_name); for (unsigned i = 0; i < pattern_length; ++i) { if (taxon_names[i].find(' ') != std::string::npos) { std::string s = "'"; s += taxon_names[i]; s += "'"; outf << str(boost::format(fmtstr) % s) << " "; } else { outf << str(boost::format(fmtstr) % taxon_names[i]) << " "; } #if 1 // Spit out characters in the order in which they were simulated. While this is a nice feature, // it currently requires storing the data twice (patternVect and sim_pattern_map) unsigned nchar = (unsigned)patternVect.size(); for (unsigned k = 0; k < nchar; ++k) { unsigned j = (unsigned)patternVect[k][i]; char s = state_symbols[j][0]; outf << s; } #else for (pattern_map_t::iterator it = sim_pattern_map.begin(); it != sim_pattern_map.end(); ++it) { // The first member of it is the state, which must be converted from its coded form // to the standard symbol for this data type (e.g. A, C, G or T for DNA characters) int8_t j = (*it).first[i]; PHYCAS_ASSERT(j < (int8_t)state_symbols.size()); char s = state_symbols[j][0]; // use the first (and hopefully only) character in the string at position j // The second member of it is the pattern count unsigned n = (unsigned)it->second; //@POL assuming counts not fractional for (unsigned k = 0; k < n; ++k) { outf << s; } } #endif outf << "\n"; } outf << " ;" << "\n"; outf << "end;" << "\n"; outf.close(); }
void SpriteDef::loadAnimation(XmlNodePtr animationNode, Action *action, ImageSet *imageSet, int variant_offset) { if (!action || !imageSet) return; const std::string directionName = XML::getProperty(animationNode, "direction", ""); const SpriteDirection directionType = makeSpriteDirection(directionName); if (directionType == DIRECTION_INVALID) { logger->log("Warning: Unknown direction \"%s\" used in %s", directionName.c_str(), getIdPath().c_str()); return; } Animation *animation = new Animation; action->setAnimation(directionType, animation); // Get animation frames for_each_xml_child_node(frameNode, animationNode) { const int delay = XML::getIntProperty( frameNode, "delay", 0, 0, 100000); int offsetX = XML::getProperty(frameNode, "offsetX", 0) + imageSet->getOffsetX(); int offsetY = XML::getProperty(frameNode, "offsetY", 0) + imageSet->getOffsetY(); int rand = XML::getIntProperty(frameNode, "rand", 100, 0, 100); offsetY -= imageSet->getHeight() - 32; offsetX -= imageSet->getWidth() / 2 - 16; if (xmlNameEqual(frameNode, "frame")) { const int index = XML::getProperty(frameNode, "index", -1); if (index < 0) { logger->log1("No valid value for 'index'"); continue; } Image *img = imageSet->get(index + variant_offset); if (!img) { logger->log("No image at index %d", index + variant_offset); continue; } animation->addFrame(img, delay, offsetX, offsetY, rand); } else if (xmlNameEqual(frameNode, "sequence")) { const int start = XML::getProperty(frameNode, "start", -1); const int end = XML::getProperty(frameNode, "end", -1); const std::string value = XML::getProperty(frameNode, "value", ""); int repeat = XML::getIntProperty(frameNode, "repeat", 1, 0, 100); if (repeat < 1) { logger->log1("No valid value for 'repeat'"); continue; } if (value.empty()) { if (addSequence(start, end, delay, offsetX, offsetY, variant_offset, repeat, rand, imageSet, animation)) { continue; } } else { StringVect vals; splitToStringVector(vals, value, ','); for (StringVectCIter it = vals.begin(), it_end = vals.end(); it != it_end; ++ it) { std::string str = *it; size_t idx = str.find("-"); if (str == "p") { animation->addPause(delay, rand); } else if (idx != std::string::npos) { int v1 = atoi(str.substr(0, idx).c_str()); int v2 = atoi(str.substr(idx + 1).c_str()); addSequence(v1, v2, delay, offsetX, offsetY, variant_offset, repeat, rand, imageSet, animation); } else { Image *img = imageSet->get(atoi( str.c_str()) + variant_offset); if (img) { animation->addFrame(img, delay, offsetX, offsetY, rand); } } } } } else if (xmlNameEqual(frameNode, "pause")) { animation->addPause(delay, rand); } else if (xmlNameEqual(frameNode, "end")) { animation->addTerminator(rand); } else if (xmlNameEqual(frameNode, "jump")) { animation->addJump(XML::getProperty( frameNode, "action", ""), rand); } else if (xmlNameEqual(frameNode, "label")) { std::string name = XML::getProperty(frameNode, "name", ""); if (!name.empty()) animation->addLabel(name); } else if (xmlNameEqual(frameNode, "goto")) { std::string name = XML::getProperty(frameNode, "label", ""); if (!name.empty()) animation->addGoto(name, rand); } } // for frameNode }