/* I'm not sure what is the point of this function. Checked */ std::list<BookData>::iterator BookCollection::displayIsbn(std::list<BookData>::iterator iter, int num) { char rightBook = 'Y'; // Is this the right book std::string input; // to hold user input /// a book? if (iter == bookList.end()) { std::cout << " Not a valid ISBN number." << std::endl; } // end if else { iter->bookInfo(); std::cout << " Is this the right book? (y/n)" << std::endl; std::getline(std::cin, input); rightBook = input.at(0); // if it is the add the book to the users total if (rightBook == 'Y' || rightBook == 'y') { if (booksAvailable(iter, num)) { return iter; } // end if else { std::cout << "Not enough books available." << std::endl; return bookList.end(); } // end if //// check to see if there are books available //if (books->operator[](pos).getQuantity() > numBooks) //{ // std::cout << " Adding book" << endl; // // Add the book to the vector // buyMe.push_back(books->operator[](pos)); // numB.push_back(numBooks); // int newQ = books->operator[](pos).getQuantity() // - numBooks; // books->operator[](pos).setQuantity(newQ); //} // end if //else //{ // std::cout << "Not enough books available." << std::endl; //} // end else } // end if } // end else //// To hold the position of the found book //std::list<BookData>::iterator pos = bookList.begin(); //for (unsigned int index = 0; index < bookList.size(); index++) //{ // std::cout << std::left << std::setw(WIDTH) << "Title: " // << pos->getTitle() << std::endl; // std::cout << std::left << std::setw(WIDTH) << "ISBN: " // << pos->getIsbn() << std::endl; // std::cout << std::endl; // pos++; //} // end for return bookList.end(); std::cout << std::endl; } // end function displayIsbn
const bool ofxWidget::isAtFront() const { if (sAllWidgets.empty()) return false; auto it = findIt(mThis, sAllWidgets.begin(), sAllWidgets.end()); return (std::prev(it, mNumChildren) == sAllWidgets.begin()); }
void output_html_results(bool show_description, const std::string& tagname) { std::stringstream os; if(result_list.size()) { // // start by outputting the table header: // os << "<table border=\"1\" cellspacing=\"1\">\n"; os << "<tr><td><strong>Expression</strong></td>"; if(show_description) os << "<td><strong>Text</strong></td>"; #if defined(BOOST_HAS_GRETA) if(time_greta == true) os << "<td><strong>GRETA</strong></td>"; if(time_safe_greta == true) os << "<td><strong>GRETA<BR>(non-recursive mode)</strong></td>"; #endif if(time_boost == true) os << "<td><strong>Boost</strong></td>"; if(time_localised_boost == true) os << "<td><strong>Boost + C++ locale</strong></td>"; #if defined(BOOST_HAS_POSIX) if(time_posix == true) os << "<td><strong>POSIX</strong></td>"; #endif #ifdef BOOST_HAS_PCRE if(time_pcre == true) os << "<td><strong>PCRE</strong></td>"; #endif #ifdef BOOST_HAS_XPRESSIVE if(time_xpressive == true) os << "<td><strong>Dynamic Xpressive</strong></td>"; #endif os << "</tr>\n"; // // Now enumerate through all the test results: // std::list<results>::const_iterator first, last; first = result_list.begin(); last = result_list.end(); while(first != last) { os << "<tr><td><code>" << html_quote(first->expression) << "</code></td>"; if(show_description) os << "<td>" << html_quote(first->description) << "</td>"; #if defined(BOOST_HAS_GRETA) if(time_greta == true) { print_result(os, first->greta_time, first->factor); if(first->greta_time > 0) { greta_total += first->greta_time / first->factor; ++greta_test_count; } } if(time_safe_greta == true) { print_result(os, first->safe_greta_time, first->factor); if(first->safe_greta_time > 0) { safe_greta_total += first->safe_greta_time / first->factor; ++safe_greta_test_count; } } #endif #if defined(BOOST_HAS_POSIX) if(time_boost == true) { print_result(os, first->boost_time, first->factor); if(first->boost_time > 0) { boost_total += first->boost_time / first->factor; ++boost_test_count; } } #endif if(time_localised_boost == true) { print_result(os, first->localised_boost_time, first->factor); if(first->localised_boost_time > 0) { locale_boost_total += first->localised_boost_time / first->factor; ++locale_boost_test_count; } } if(time_posix == true) { print_result(os, first->posix_time, first->factor); if(first->posix_time > 0) { posix_total += first->posix_time / first->factor; ++posix_test_count; } } #if defined(BOOST_HAS_PCRE) if(time_pcre == true) { print_result(os, first->pcre_time, first->factor); if(first->pcre_time > 0) { pcre_total += first->pcre_time / first->factor; ++pcre_test_count; } } #endif #if defined(BOOST_HAS_XPRESSIVE) if(time_xpressive == true) { print_result(os, first->xpressive_time, first->factor); if(first->xpressive_time > 0) { xpressive_total += first->xpressive_time / first->factor; ++xpressive_test_count; } } #endif os << "</tr>\n"; ++first; } os << "</table>\n"; result_list.clear(); } else { os << "<P><I>Results not available...</I></P>\n"; } std::string result = os.str(); std::string::size_type pos = html_contents.find(tagname); if(pos != std::string::npos) { html_contents.replace(pos, tagname.size(), result); } }
void writeReports(std::string scale) { std::map<std::string, Report>::iterator repIter = reports.begin(); std::cout << std::endl; std::cout << FORMAT_COL << "byte sent"; std::cout << FORMAT_COL << "pkts sent"; std::cout << FORMAT_COL << "sleep"; std::cout << FORMAT_COL << "scale"; switch (type) { case PUB_RTP: { std::cout << FORMAT_COL << "[RTP]"; break; } case PUB_MCAST: { std::cout << FORMAT_COL << "[RTP/MCAST]"; break; } case PUB_TCP: { std::cout << FORMAT_COL << "[TCP]"; break; } } std::cout << FORMAT_COL << bytesToDisplay(bytesTotal); std::cout << FORMAT_COL << std::endl; // === std::cout << FORMAT_COL << bytesToDisplay(intervalFactor * (double)bytesWritten) + "/s"; std::cout << FORMAT_COL << toStr(intervalFactor * (double)packetsWritten) + "pkt/s"; std::cout << FORMAT_COL << timeToDisplay(delay * 1000); std::cout << FORMAT_COL << scale; std::cout << FORMAT_COL << "---"; std::cout << std::endl; if (reports.size() > 0) { // print report messages std::cout << FORMAT_COL << "byte recv"; std::cout << FORMAT_COL << "pkts recv"; std::cout << FORMAT_COL << "pkts loss"; std::cout << FORMAT_COL << "% loss"; std::cout << FORMAT_COL << "compression"; std::cout << FORMAT_COL << "pkts late"; std::cout << FORMAT_COL << "RTT"; std::cout << FORMAT_COL << "dscvd"; std::cout << FORMAT_COL << "name"; std::cout << std::endl; repIter = reports.begin(); while(repIter != reports.end()) { Report& report = repIter->second; std::cout << FORMAT_COL << bytesToDisplay(intervalFactor * (double)(report.bytesRcvd)) + "/s"; std::cout << FORMAT_COL << toStr(intervalFactor * (double)(report.pktsRcvd)) + "pkt/s"; std::cout << FORMAT_COL << toStr(intervalFactor * (double)(report.pktsDropped)) + "pkt/s"; std::cout << FORMAT_COL << toStr(report.pcntLoss) + "%"; // 0.0746/0.0227 inter message // 0.925/0.402 intra message std::stringstream comprSS; comprSS << std::setprecision(3) << report.compressRatioHead << "/" << std::setprecision(3) << report.compressRatioPayload; std::cout << FORMAT_COL << comprSS.str(); std::cout << FORMAT_COL << (report.pktsLate > 100000 ? "N/A" : toStr(report.pktsLate) + "pkt"); std::cout << FORMAT_COL << (report.roundTripTime > 100000 ? "N/A" : toStr(report.roundTripTime) + "ms"); std::cout << FORMAT_COL << (report.discoveryTime > 100000 ? "N/A" : toStr(report.discoveryTime) + "ms"); std::cout << FORMAT_COL << report.pubId.substr(0, 6) + " (" + report.hostName + ")"; std::cout << std::endl; report.pktsRcvd = 0; report.bytesRcvd = 0; report.pktsLate = 0; report.roundTripTime = 10000000; repIter++; } } // reports.clear(); // append our information into allReports Report senderReport; senderReport.bytesRcvd = bytesWritten; senderReport.pktsRcvd = packetsWritten; senderReport.pertainingPacket = currSeqNr; senderReports.push_back(senderReport); }
void ofxWidget::bringToFront(std::list<weak_ptr<ofxWidget>>::iterator it_) { if (it_->expired()) return; // ---------| invariant: element is valid auto element = it_->lock(); // We're conservative with re-ordering. // Let's move the iterator backward to see if we are actually // already sorted. // If the list were already sorted, then moving back from the current // iterator by the number of its children would bring us // to the beginning of sAllWidgets. Then, there is no need to re-order. if (std::prev(it_, element->mNumChildren) == sAllWidgets.begin()) return; // ----------| invariant: element (range) not yet at front. /* Algorithm: while current object range has a parent, put current object range to the front of parent range make parent range current object range. As soon as there is no parent anymore, put last object range to the front of the list Heuristic: parent iterator's position always to be found after current iterator. */ auto parent = element->mParent.lock(); auto elementIt = it_; while (parent) { auto itParent = findIt(element->mParent, std::next(elementIt), sAllWidgets.end()); // start our search for parent after current element. // if element has parent, bring element range to front of parent range. if (std::prev(elementIt, element->mNumChildren) != std::prev(itParent, parent->mNumChildren)) { sAllWidgets.splice( std::prev(itParent, parent->mNumChildren), // where to move elements to -> front of parent range sAllWidgets, // where to take elements from std::prev(elementIt, element->mNumChildren), std::next(elementIt)); // range of elements to move -> range of current element and its children } // because sAllWidgets is a list, splice will only invalidate iterators // before our next search range. elementIt = itParent; element = elementIt->lock(); parent = element->mParent.lock(); } // now move the element range (which is now our most senior parent element range) to the front fo the list. if (std::prev(elementIt, element->mNumChildren) != sAllWidgets.begin()) { sAllWidgets.splice( sAllWidgets.begin(), sAllWidgets, std::prev(elementIt, element->mNumChildren), // from the beginning of our now most senior parent element range std::next(elementIt)); // to the end of our now most senior parent element range } ofxWidget::bVisibleListDirty = true; }
bool Monsters::loadMonster(const std::string& file, const std::string& monsterName, std::list<std::pair<MonsterType*, std::string>>& monsterScriptList, bool reloading /*= false*/) { MonsterType* mType = nullptr; bool new_mType = true; pugi::xml_document doc; pugi::xml_parse_result result = doc.load_file(file.c_str()); if (!result) { printXMLError("Error - Monsters::loadMonster", file, result); return false; } pugi::xml_node monsterNode = doc.child("monster"); if (!monsterNode) { std::cout << "[Error - Monsters::loadMonster] Missing monster node in: " << file << std::endl; return false; } pugi::xml_attribute attr; if (!(attr = monsterNode.attribute("name"))) { std::cout << "[Error - Monsters::loadMonster] Missing name in: " << file << std::endl; return false; } if (reloading) { mType = getMonsterType(monsterName); if (mType != nullptr) { new_mType = false; mType->reset(); } } if (new_mType) { mType = &monsters[asLowerCaseString(monsterName)]; } mType->name = attr.as_string(); if ((attr = monsterNode.attribute("nameDescription"))) { mType->nameDescription = attr.as_string(); } else { mType->nameDescription = "a " + mType->name; toLowerCaseString(mType->nameDescription); } if ((attr = monsterNode.attribute("race"))) { std::string tmpStrValue = asLowerCaseString(attr.as_string()); uint16_t tmpInt = pugi::cast<uint16_t>(attr.value()); if (tmpStrValue == "venom" || tmpInt == 1) { mType->race = RACE_VENOM; } else if (tmpStrValue == "blood" || tmpInt == 2) { mType->race = RACE_BLOOD; } else if (tmpStrValue == "undead" || tmpInt == 3) { mType->race = RACE_UNDEAD; } else if (tmpStrValue == "fire" || tmpInt == 4) { mType->race = RACE_FIRE; } else if (tmpStrValue == "energy" || tmpInt == 5) { mType->race = RACE_ENERGY; } else { std::cout << "[Warning - Monsters::loadMonster] Unknown race type " << attr.as_string() << ". " << file << std::endl; } } if ((attr = monsterNode.attribute("experience"))) { mType->experience = pugi::cast<uint64_t>(attr.value()); } if ((attr = monsterNode.attribute("speed"))) { mType->baseSpeed = pugi::cast<int32_t>(attr.value()); } if ((attr = monsterNode.attribute("manacost"))) { mType->manaCost = pugi::cast<uint32_t>(attr.value()); } if ((attr = monsterNode.attribute("skull"))) { mType->skull = getSkullType(attr.as_string()); } if ((attr = monsterNode.attribute("script"))) { monsterScriptList.emplace_back(mType, attr.as_string()); } pugi::xml_node node; if ((node = monsterNode.child("health"))) { if ((attr = node.attribute("now"))) { mType->health = pugi::cast<int32_t>(attr.value()); } else { std::cout << "[Error - Monsters::loadMonster] Missing health now. " << file << std::endl; } if ((attr = node.attribute("max"))) { mType->healthMax = pugi::cast<int32_t>(attr.value()); } else { std::cout << "[Error - Monsters::loadMonster] Missing health max. " << file << std::endl; } } if ((node = monsterNode.child("flags"))) { for (auto flagNode : node.children()) { attr = flagNode.first_attribute(); const char* attrName = attr.name(); if (strcasecmp(attrName, "summonable") == 0) { mType->isSummonable = attr.as_bool(); } else if (strcasecmp(attrName, "attackable") == 0) { mType->isAttackable = attr.as_bool(); } else if (strcasecmp(attrName, "hostile") == 0) { mType->isHostile = attr.as_bool(); } else if (strcasecmp(attrName, "illusionable") == 0) { mType->isIllusionable = attr.as_bool(); } else if (strcasecmp(attrName, "convinceable") == 0) { mType->isConvinceable = attr.as_bool(); } else if (strcasecmp(attrName, "pushable") == 0) { mType->pushable = attr.as_bool(); } else if (strcasecmp(attrName, "canpushitems") == 0) { mType->canPushItems = attr.as_bool(); } else if (strcasecmp(attrName, "canpushcreatures") == 0) { mType->canPushCreatures = attr.as_bool(); } else if (strcasecmp(attrName, "staticattack") == 0) { uint32_t staticAttack = pugi::cast<uint32_t>(attr.value()); if (staticAttack > 100) { std::cout << "[Warning - Monsters::loadMonster] staticattack greater than 100. " << file << std::endl; staticAttack = 100; } mType->staticAttackChance = staticAttack; } else if (strcasecmp(attrName, "lightlevel") == 0) { mType->lightLevel = pugi::cast<uint16_t>(attr.value()); } else if (strcasecmp(attrName, "lightcolor") == 0) { mType->lightColor = pugi::cast<uint16_t>(attr.value()); } else if (strcasecmp(attrName, "targetdistance") == 0) { mType->targetDistance = std::max<int32_t>(1, pugi::cast<int32_t>(attr.value())); } else if (strcasecmp(attrName, "runonhealth") == 0) { mType->runAwayHealth = pugi::cast<int32_t>(attr.value()); } else if (strcasecmp(attrName, "hidehealth") == 0) { mType->hiddenHealth = attr.as_bool(); } else { std::cout << "[Warning - Monsters::loadMonster] Unknown flag attribute: " << attrName << ". " << file << std::endl; } } //if a monster can push creatures, // it should not be pushable if (mType->canPushCreatures && mType->pushable) { mType->pushable = false; } } if ((node = monsterNode.child("targetchange"))) { if ((attr = node.attribute("speed")) || (attr = node.attribute("interval"))) { mType->changeTargetSpeed = pugi::cast<uint32_t>(attr.value()); } else { std::cout << "[Warning - Monsters::loadMonster] Missing targetchange speed. " << file << std::endl; } if ((attr = node.attribute("chance"))) { mType->changeTargetChance = pugi::cast<int32_t>(attr.value()); } else { std::cout << "[Warning - Monsters::loadMonster] Missing targetchange chance. " << file << std::endl; } } if ((node = monsterNode.child("look"))) { if ((attr = node.attribute("type"))) { mType->outfit.lookType = pugi::cast<uint16_t>(attr.value()); if ((attr = node.attribute("head"))) { mType->outfit.lookHead = pugi::cast<uint16_t>(attr.value()); } if ((attr = node.attribute("body"))) { mType->outfit.lookBody = pugi::cast<uint16_t>(attr.value()); } if ((attr = node.attribute("legs"))) { mType->outfit.lookLegs = pugi::cast<uint16_t>(attr.value()); } if ((attr = node.attribute("feet"))) { mType->outfit.lookFeet = pugi::cast<uint16_t>(attr.value()); } if ((attr = node.attribute("addons"))) { mType->outfit.lookAddons = pugi::cast<uint16_t>(attr.value()); } } else if ((attr = node.attribute("typeex"))) { mType->outfit.lookTypeEx = pugi::cast<uint16_t>(attr.value()); } else { std::cout << "[Warning - Monsters::loadMonster] Missing look type/typeex. " << file << std::endl; } if ((attr = node.attribute("mount"))) { mType->outfit.lookMount = pugi::cast<uint16_t>(attr.value()); } if ((attr = node.attribute("corpse"))) { mType->lookcorpse = pugi::cast<uint16_t>(attr.value()); } } if ((node = monsterNode.child("attacks"))) { for (auto attackNode : node.children()) { spellBlock_t sb; if (deserializeSpell(attackNode, sb, monsterName)) { mType->attackSpells.emplace_back(std::move(sb)); } else { std::cout << "[Warning - Monsters::loadMonster] Cant load spell. " << file << std::endl; } } } if ((node = monsterNode.child("defenses"))) { if ((attr = node.attribute("defense"))) { mType->defense = pugi::cast<int32_t>(attr.value()); } if ((attr = node.attribute("armor"))) { mType->armor = pugi::cast<int32_t>(attr.value()); } for (auto defenseNode : node.children()) { spellBlock_t sb; if (deserializeSpell(defenseNode, sb, monsterName)) { mType->defenseSpells.emplace_back(std::move(sb)); } else { std::cout << "[Warning - Monsters::loadMonster] Cant load spell. " << file << std::endl; } } } if ((node = monsterNode.child("immunities"))) { for (auto immunityNode : node.children()) { if ((attr = immunityNode.attribute("name"))) { std::string tmpStrValue = asLowerCaseString(attr.as_string()); if (tmpStrValue == "physical") { mType->damageImmunities |= COMBAT_PHYSICALDAMAGE; mType->conditionImmunities |= CONDITION_BLEEDING; } else if (tmpStrValue == "energy") { mType->damageImmunities |= COMBAT_ENERGYDAMAGE; mType->conditionImmunities |= CONDITION_ENERGY; } else if (tmpStrValue == "fire") { mType->damageImmunities |= COMBAT_FIREDAMAGE; mType->conditionImmunities |= CONDITION_FIRE; } else if (tmpStrValue == "poison" || tmpStrValue == "earth") { mType->damageImmunities |= COMBAT_EARTHDAMAGE; mType->conditionImmunities |= CONDITION_POISON; } else if (tmpStrValue == "drown") { mType->damageImmunities |= COMBAT_DROWNDAMAGE; mType->conditionImmunities |= CONDITION_DROWN; } else if (tmpStrValue == "ice") { mType->damageImmunities |= COMBAT_ICEDAMAGE; mType->conditionImmunities |= CONDITION_FREEZING; } else if (tmpStrValue == "holy") { mType->damageImmunities |= COMBAT_HOLYDAMAGE; mType->conditionImmunities |= CONDITION_DAZZLED; } else if (tmpStrValue == "death") { mType->damageImmunities |= COMBAT_DEATHDAMAGE; mType->conditionImmunities |= CONDITION_CURSED; } else if (tmpStrValue == "lifedrain") { mType->damageImmunities |= COMBAT_LIFEDRAIN; } else if (tmpStrValue == "manadrain") { mType->damageImmunities |= COMBAT_MANADRAIN; } else if (tmpStrValue == "paralyze") { mType->conditionImmunities |= CONDITION_PARALYZE; } else if (tmpStrValue == "outfit") { mType->conditionImmunities |= CONDITION_OUTFIT; } else if (tmpStrValue == "drunk") { mType->conditionImmunities |= CONDITION_DRUNK; } else if (tmpStrValue == "invisible" || tmpStrValue == "invisibility") { mType->conditionImmunities |= CONDITION_INVISIBLE; } else if (tmpStrValue == "bleed") { mType->conditionImmunities |= CONDITION_BLEEDING; } else { std::cout << "[Warning - Monsters::loadMonster] Unknown immunity name " << attr.as_string() << ". " << file << std::endl; } } else if ((attr = immunityNode.attribute("physical"))) { if (attr.as_bool()) { mType->damageImmunities |= COMBAT_PHYSICALDAMAGE; mType->conditionImmunities |= CONDITION_BLEEDING; } } else if ((attr = immunityNode.attribute("energy"))) { if (attr.as_bool()) { mType->damageImmunities |= COMBAT_ENERGYDAMAGE; mType->conditionImmunities |= CONDITION_ENERGY; } } else if ((attr = immunityNode.attribute("fire"))) { if (attr.as_bool()) { mType->damageImmunities |= COMBAT_FIREDAMAGE; mType->conditionImmunities |= CONDITION_FIRE; } } else if ((attr = immunityNode.attribute("poison")) || (attr = immunityNode.attribute("earth"))) { if (attr.as_bool()) { mType->damageImmunities |= COMBAT_EARTHDAMAGE; mType->conditionImmunities |= CONDITION_POISON; } } else if ((attr = immunityNode.attribute("drown"))) { if (attr.as_bool()) { mType->damageImmunities |= COMBAT_DROWNDAMAGE; mType->conditionImmunities |= CONDITION_DROWN; } } else if ((attr = immunityNode.attribute("ice"))) { if (attr.as_bool()) { mType->damageImmunities |= COMBAT_ICEDAMAGE; mType->conditionImmunities |= CONDITION_FREEZING; } } else if ((attr = immunityNode.attribute("holy"))) { if (attr.as_bool()) { mType->damageImmunities |= COMBAT_HOLYDAMAGE; mType->conditionImmunities |= CONDITION_DAZZLED; } } else if ((attr = immunityNode.attribute("death"))) { if (attr.as_bool()) { mType->damageImmunities |= COMBAT_DEATHDAMAGE; mType->conditionImmunities |= CONDITION_CURSED; } } else if ((attr = immunityNode.attribute("lifedrain"))) { if (attr.as_bool()) { mType->damageImmunities |= COMBAT_LIFEDRAIN; } } else if ((attr = immunityNode.attribute("manadrain"))) { if (attr.as_bool()) { mType->damageImmunities |= COMBAT_MANADRAIN; } } else if ((attr = immunityNode.attribute("paralyze"))) { if (attr.as_bool()) { mType->conditionImmunities |= CONDITION_PARALYZE; } } else if ((attr = immunityNode.attribute("outfit"))) { if (attr.as_bool()) { mType->conditionImmunities |= CONDITION_OUTFIT; } } else if ((attr = immunityNode.attribute("bleed"))) { if (attr.as_bool()) { mType->conditionImmunities |= CONDITION_BLEEDING; } } else if ((attr = immunityNode.attribute("drunk"))) { if (attr.as_bool()) { mType->conditionImmunities |= CONDITION_DRUNK; } } else if ((attr = immunityNode.attribute("invisible")) || (attr = immunityNode.attribute("invisibility"))) { if (attr.as_bool()) { mType->conditionImmunities |= CONDITION_INVISIBLE; } } else { std::cout << "[Warning - Monsters::loadMonster] Unknown immunity. " << file << std::endl; } } } if ((node = monsterNode.child("voices"))) { if ((attr = node.attribute("speed")) || (attr = node.attribute("interval"))) { mType->yellSpeedTicks = pugi::cast<uint32_t>(attr.value()); } else { std::cout << "[Warning - Monsters::loadMonster] Missing voices speed. " << file << std::endl; } if ((attr = node.attribute("chance"))) { mType->yellChance = pugi::cast<uint32_t>(attr.value()); } else { std::cout << "[Warning - Monsters::loadMonster] Missing voices chance. " << file << std::endl; } for (auto voiceNode : node.children()) { voiceBlock_t vb; if ((attr = voiceNode.attribute("sentence"))) { vb.text = attr.as_string(); } else { std::cout << "[Warning - Monsters::loadMonster] Missing voice sentence. " << file << std::endl; } if ((attr = voiceNode.attribute("yell"))) { vb.yellText = attr.as_bool(); } else { vb.yellText = false; } mType->voiceVector.emplace_back(vb); } } if ((node = monsterNode.child("loot"))) { for (auto lootNode : node.children()) { LootBlock lootBlock; if (loadLootItem(lootNode, lootBlock)) { mType->lootItems.emplace_back(std::move(lootBlock)); } else { std::cout << "[Warning - Monsters::loadMonster] Cant load loot. " << file << std::endl; } } } if ((node = monsterNode.child("elements"))) { for (auto elementNode : node.children()) { if ((attr = elementNode.attribute("physicalPercent"))) { mType->elementMap[COMBAT_PHYSICALDAMAGE] = pugi::cast<int32_t>(attr.value()); } else if ((attr = elementNode.attribute("icePercent"))) { mType->elementMap[COMBAT_ICEDAMAGE] = pugi::cast<int32_t>(attr.value()); } else if ((attr = elementNode.attribute("poisonPercent")) || (attr = elementNode.attribute("earthPercent"))) { mType->elementMap[COMBAT_EARTHDAMAGE] = pugi::cast<int32_t>(attr.value()); } else if ((attr = elementNode.attribute("firePercent"))) { mType->elementMap[COMBAT_FIREDAMAGE] = pugi::cast<int32_t>(attr.value()); } else if ((attr = elementNode.attribute("energyPercent"))) { mType->elementMap[COMBAT_ENERGYDAMAGE] = pugi::cast<int32_t>(attr.value()); } else if ((attr = elementNode.attribute("holyPercent"))) { mType->elementMap[COMBAT_HOLYDAMAGE] = pugi::cast<int32_t>(attr.value()); } else if ((attr = elementNode.attribute("deathPercent"))) { mType->elementMap[COMBAT_DEATHDAMAGE] = pugi::cast<int32_t>(attr.value()); } else if ((attr = elementNode.attribute("drownPercent"))) { mType->elementMap[COMBAT_DROWNDAMAGE] = pugi::cast<int32_t>(attr.value()); } else if ((attr = elementNode.attribute("lifedrainPercent"))) { mType->elementMap[COMBAT_LIFEDRAIN] = pugi::cast<int32_t>(attr.value()); } else if ((attr = elementNode.attribute("manadrainPercent"))) { mType->elementMap[COMBAT_MANADRAIN] = pugi::cast<int32_t>(attr.value()); } else { std::cout << "[Warning - Monsters::loadMonster] Unknown element percent. " << file << std::endl; } } } if ((node = monsterNode.child("summons"))) { if ((attr = node.attribute("maxSummons"))) { mType->maxSummons = std::min<uint32_t>(pugi::cast<uint32_t>(attr.value()), 100); } else { std::cout << "[Warning - Monsters::loadMonster] Missing summons maxSummons. " << file << std::endl; } for (auto summonNode : node.children()) { int32_t chance = 100; int32_t speed = 1000; if ((attr = summonNode.attribute("speed")) || (attr = summonNode.attribute("interval"))) { speed = pugi::cast<int32_t>(attr.value()); } if ((attr = summonNode.attribute("chance"))) { chance = pugi::cast<int32_t>(attr.value()); } if ((attr = summonNode.attribute("name"))) { summonBlock_t sb; sb.name = attr.as_string(); sb.speed = speed; sb.chance = chance; mType->summons.emplace_back(sb); } else { std::cout << "[Warning - Monsters::loadMonster] Missing summon name. " << file << std::endl; } } } if ((node = monsterNode.child("script"))) { for (auto eventNode : node.children()) { if ((attr = eventNode.attribute("name"))) { mType->scripts.emplace_back(attr.as_string()); } else { std::cout << "[Warning - Monsters::loadMonster] Missing name for script event. " << file << std::endl; } } } mType->summons.shrink_to_fit(); mType->lootItems.shrink_to_fit(); mType->attackSpells.shrink_to_fit(); mType->defenseSpells.shrink_to_fit(); mType->voiceVector.shrink_to_fit(); mType->scripts.shrink_to_fit(); return true; }
void FilterTargets(std::list<Unit*>& unitList) { unitList.remove_if (OrientationCheck(GetCaster())); }
bool Vma::get_pages_for_range(const RangePtr &mrange, std::list<PartialPageInfo> &ppinfo) { ppinfo.clear(); if (mrange->size() <= 0) { warn << "Vma::get_pages_for_range - invalid range\n"; return false; } if (!range()->contains(mrange)) { warn << "Vma::get_pages_for_range - range " << mrange->to_string() << " outside vma " << to_string() << "\n"; return false; } unsigned int start_pgnum, end_pgnum; if (!addr_to_pgnum(mrange->start(), start_pgnum)) { warn << "Vma::get_pages_for_range - can't get start pgnum\n"; return false; } if (!addr_to_pgnum(mrange->end() - 1, end_pgnum)) { warn << "Vma::get_pages_for_range - can't get end pgnum\n"; return false; } if (start_pgnum > end_pgnum) { warn << "start_pgnum greater than end: " << start_pgnum << ", " << end_pgnum << "\n"; return false; } if (start_pgnum >= _pages.size()) { warn << "Vma::get_pages_for_range - start pgnum out of range: " << start_pgnum << ", " << _pages.size() << " " << _fname << "\n"; return false; } if (end_pgnum >= _pages.size()) { warn << "Vma::get_pages_for_range - end pgnum out of range: " << end_pgnum << ", " << _pages.size() << "\n"; return false; } if (start_pgnum == end_pgnum) { ppinfo.push_back(PartialPageInfo(_pages[start_pgnum], mrange->size())); return true; } Address bytes = Elf::page_size() - (mrange->start() - Elf::page_align_down(mrange->start())); ppinfo.push_back(PartialPageInfo(_pages[start_pgnum], bytes)); bytes = mrange->end() - Elf::page_align_down(mrange->end() - 1); if (bytes > 0) { ppinfo.push_back(PartialPageInfo(_pages[end_pgnum], bytes)); } bytes = Elf::page_size(); for (unsigned int pgnum = start_pgnum + 1; pgnum < end_pgnum; ++pgnum) { ppinfo.push_back(PartialPageInfo(_pages[pgnum], bytes)); } return true; }
void M3U8Parser::parseSegments(vlc_object_t *p_obj, Representation *rep, const std::list<Tag *> &tagslist) { SegmentList *segmentList = new (std::nothrow) SegmentList(rep); rep->setTimescale(100); rep->b_loaded = true; mtime_t totalduration = 0; mtime_t nzStartTime = 0; mtime_t absReferenceTime = VLC_TS_INVALID; uint64_t sequenceNumber = 0; bool discontinuity = false; std::size_t prevbyterangeoffset = 0; const SingleValueTag *ctx_byterange = NULL; SegmentEncryption encryption; const ValuesListTag *ctx_extinf = NULL; std::list<Tag *>::const_iterator it; for(it = tagslist.begin(); it != tagslist.end(); ++it) { const Tag *tag = *it; switch(tag->getType()) { /* using static cast as attribute type permits avoiding class check */ case SingleValueTag::EXTXMEDIASEQUENCE: { sequenceNumber = (static_cast<const SingleValueTag*>(tag))->getValue().decimal(); } break; case ValuesListTag::EXTINF: { ctx_extinf = static_cast<const ValuesListTag *>(tag); } break; case SingleValueTag::URI: { const SingleValueTag *uritag = static_cast<const SingleValueTag *>(tag); if(uritag->getValue().value.empty()) { ctx_extinf = NULL; ctx_byterange = NULL; break; } HLSSegment *segment = new (std::nothrow) HLSSegment(rep, sequenceNumber++); if(!segment) break; segment->setSourceUrl(uritag->getValue().value); if((unsigned)rep->getStreamFormat() == StreamFormat::UNKNOWN) setFormatFromExtension(rep, uritag->getValue().value); if(ctx_extinf) { if(ctx_extinf->getAttributeByName("DURATION")) { const mtime_t nzDuration = CLOCK_FREQ * ctx_extinf->getAttributeByName("DURATION")->floatingPoint(); segment->duration.Set(ctx_extinf->getAttributeByName("DURATION")->floatingPoint() * (uint64_t) rep->getTimescale()); segment->startTime.Set(rep->getTimescale().ToScaled(nzStartTime)); nzStartTime += nzDuration; totalduration += nzDuration; if(absReferenceTime > VLC_TS_INVALID) { segment->utcTime = absReferenceTime; absReferenceTime += nzDuration; } } ctx_extinf = NULL; } segmentList->addSegment(segment); if(ctx_byterange) { std::pair<std::size_t,std::size_t> range = ctx_byterange->getValue().getByteRange(); if(range.first == 0) range.first = prevbyterangeoffset; prevbyterangeoffset = range.first + range.second; segment->setByteRange(range.first, prevbyterangeoffset); ctx_byterange = NULL; } if(discontinuity) { segment->discontinuity = true; discontinuity = false; } if(encryption.method != SegmentEncryption::NONE) segment->setEncryption(encryption); } break; case SingleValueTag::EXTXTARGETDURATION: rep->targetDuration = static_cast<const SingleValueTag *>(tag)->getValue().decimal(); break; case SingleValueTag::EXTXPLAYLISTTYPE: rep->b_live = (static_cast<const SingleValueTag *>(tag)->getValue().value != "VOD"); break; case SingleValueTag::EXTXBYTERANGE: ctx_byterange = static_cast<const SingleValueTag *>(tag); break; case SingleValueTag::EXTXPROGRAMDATETIME: rep->b_consistent = false; absReferenceTime = VLC_TS_0 + UTCTime(static_cast<const SingleValueTag *>(tag)->getValue().value).mtime(); break; case AttributesTag::EXTXKEY: { const AttributesTag *keytag = static_cast<const AttributesTag *>(tag); if( keytag->getAttributeByName("METHOD") && keytag->getAttributeByName("METHOD")->value == "AES-128" && keytag->getAttributeByName("URI") ) { encryption.method = SegmentEncryption::AES_128; encryption.key.clear(); Url keyurl(keytag->getAttributeByName("URI")->quotedString()); if(!keyurl.hasScheme()) { keyurl.prepend(Helper::getDirectoryPath(rep->getPlaylistUrl().toString()).append("/")); } block_t *p_block = Retrieve::HTTP(p_obj, keyurl.toString()); if(p_block) { if(p_block->i_buffer == 16) { encryption.key.resize(16); memcpy(&encryption.key[0], p_block->p_buffer, 16); } block_Release(p_block); } if(keytag->getAttributeByName("IV")) { encryption.iv.clear(); encryption.iv = keytag->getAttributeByName("IV")->hexSequence(); } } else { /* unsupported or invalid */ encryption.method = SegmentEncryption::NONE; encryption.key.clear(); encryption.iv.clear(); } } break; case Tag::EXTXDISCONTINUITY: discontinuity = true; break; case Tag::EXTXENDLIST: rep->b_live = false; break; } } if(rep->isLive()) { rep->getPlaylist()->duration.Set(0); } else if(totalduration > rep->getPlaylist()->duration.Get()) { rep->getPlaylist()->duration.Set(totalduration); } rep->setSegmentList(segmentList); }
void Floor::addWaitingPeople(const std::list<HumanPtr>& people) { containedPeople_.insert(containedPeople_.end(), people.begin(), people.end()); }
void FilterTargets(std::list<WorldObject*>& unitList) { unitList.remove_if(Trinity::ObjectGUIDCheck(GetCaster()->GetChannelObjectGuid())); }
virtual ~Block() { blocks.remove(this); }
Block( XGame *g ) : Sprite(g) { blocks.push_back(this); z = maxZ--; }
void FilterTargets(std::list<Unit*>& unitList) { unitList.remove_if(SanctumSentryCheck()); }
int countValueDuplicators(const std::list<TemplateBase<DuplicatorType> >& values) { return values.size(); }
void GameState_BasePlayable::HandleSFEvents(std::list<sf::Event>& sfEvents) { mMenuStateMachine->RefreshStack(); if (inoutFader != 0) { if (cancelNavMapGenBtn) cancelNavMapGenBtn->HandleSFEvents(sfEvents); std::list<sf::Event>::iterator itSfEvent = sfEvents.begin(); while (itSfEvent != sfEvents.end()) { switch (itSfEvent->Type) { case sf::Event::Closed: Game->GetRenderWindow()->Close(); break; default: break; } ++itSfEvent; } return; } if (!mMenuStateMachine->IsEmpty()) mMenuStateMachine->HandleSFEvents(sfEvents); std::list<sf::Event>::iterator itSfEvent = sfEvents.begin(); while (itSfEvent != sfEvents.end()) { switch (itSfEvent->Type) { case sf::Event::Closed: Game->GetRenderWindow()->Close(); break; case sf::Event::KeyPressed: switch (itSfEvent->Key.Code) { case sf::Key::Escape: if (!finished) { if (!mMenuStateMachine->IsEmpty()) OnPause(false); else OnPause(true); } break; case sf::Key::Space: if (HUD) { GameObject* interactee = HUD->GetInteractee(); if (interactee) { if (interactee == chest && chest) { goldPickedUp += MyMagicNumbers::goldValue_chest; for (unsigned int i = 0; i != 2; ++i) { if (objectives[i] == chest) { OnObjectiveCompleted(i); objectives[i] = 0; } } PopWorldSpace(chest); delete chest; chest = 0; SoundEffect* coinJingle = new SoundEffect("Content/Audio/coin.wav"); coinJingle->oneShot = true; Sounds->RefreshVol_Effect_Of(coinJingle); coinJingle->Play(); HUD->SetAmountGold(goldPickedUp); HUD->SetInteractContextNote(0); } else if (/*interactee == princess && */princess) { princess->StartFollowing(princess->IsFollowingAnyone() ? 0 : player); HUD->SetInteractContextNote(0); // if following than it's considered completed.. if (princess->IsFollowingAnyone()) { for (unsigned int i = 0; i != 2; ++i) { // if it was the active objective if (objectives[i] == princess && objectives[i]->objectiveState == ACTIVE) { OnObjectiveCompleted(i); } } } else { // However.. for (unsigned int i = 0; i != 2; ++i) { // if the active objective is a goal if (objectives[i] && objectives[i]->objectiveState == ACTIVE && objectives[i]->entityType == ID_GOAL) { // looking backwards for (int j = i - 1; j >= 0; --j) { // j represents the last objective // if it was this princess if (objectives[j] == princess) { // then that princess should have been brought here // so we set the current goal state to inactive, and hide it objectives[i]->objectiveState = INACTIVE; PopWorldSpace(dynamic_cast<Goal*>(objectives[i])); // and reactivate the former princess objective objectives[j]->objectiveState = ACTIVE; HUD->SetObjective("Content/Textures/princess_thumbnail.png"); } } } } } } } } break; default: break; } break; default: break; } ++itSfEvent; } if (finished) { if (player) player->PauseAudio(); if (princess) princess->PauseAudio(); const EntityMap& guards = (*GameObjects)[ID_GUARD]; for (EntityMap::const_iterator itG = guards.begin(); itG != guards.end(); itG++) { dynamic_cast<Guard*>(itG->second)->PauseAudio(); } } }
void Creature::startAutoWalk(const std::list<Direction>& listDir) { listWalkDir = listDir; addEventWalk(listDir.size() == 1); }
void FilterTargets(std::list<Unit*>& unitList) { unitList.remove_if(PlayerOrPetCheck()); }
void MouseTest( GLFWwindow* window, GameObjectBird *pBird, ScreenLine* pLine1, ScreenLine* pLine2, std::list<GameObject *> gameObjectList ) { // Quick and dirty test, if these work the rest do. // --> try move the mouse inside the window, click right, click left if (!pBird) return; if (pBird->bState==SLING) { pBird->pBody->SetActive(false); b2Vec2 newPos( PixelToMeter((float)slingX), PixelToMeter((float)slingY) ); pBird->pBody->SetTransform( newPos, 0.0f ); } double xpos; double ypos; static float lastXPos; static float lastYPos; // get mouse position glfwGetCursorPos( window, &xpos, &ypos); Camera *pCam = Camera::Instance(); pCam; // correct for origin double t = ypos / 600.0; ypos = 600.0 + t * (-600.0); MouseState mState = NONE; PositionState pState = UNKNOWN; GameObject* b = pBird; Matrix viewMatrix = pCam->getViewMatrix(); Matrix projMatrix = pCam->getProjMatrix(); Matrix worldMatrix = b->pGameSprite->returnWorld(); Vect vout = Vect(0.0f,0.0f,0.0f) * worldMatrix * viewMatrix * projMatrix; float zoom = vout[w]; vout[x] = vout[x]/vout[w]; vout[y] = vout[y]/vout[w]; float X = (vout[x]+1.0f)*(pCam->viewport_width/2.0f); float Y= (vout[y]+1.0f)*(pCam->viewport_height/2.0f); Vect birdPos(pBird->pos.x, pBird->pos.y,0.0f); Vect mousePos((float ) xpos,(float ) ypos, 0.0f); Vect local( X, Y, 0.0f); Vect Dist = mousePos - local; if ( Dist.mag() < (10.0f / zoom) ) { pState = INSIDE; } else { pState = OUTSIDE; } //printf("%f - %f", Dist[x],Dist[y] ); //printf(" | %f - %f", X, Y ); //xpos = xpos + Dist[x]*zoom; //ypos = ypos + Dist[y]*zoom; //printf("%f - %f ",xpos, ypos); mState = NONE; if( glfwGetMouseButton (window, GLFW_MOUSE_BUTTON_RIGHT ) == GLFW_PRESS) { mState = RIGHT; } if( glfwGetMouseButton (window, GLFW_MOUSE_BUTTON_LEFT ) == GLFW_PRESS) { mState = LEFT; } if (mState == LEFT && pBird->bState == NORMAL1) { pBird->bState = NORMAL2; pBird->onMouseAction(); } // Enter MOVING state if( mState == LEFT && pState == INSIDE) { ; pBird->bState = MOVING; pBird->pBody->SetActive(false); } // small sublty here, once moving, left dictates mode if ( pBird->bState == MOVING) { if( mState == LEFT )//this drags the bird around { /*b2Vec2 newPos( PixelToMeter((float)xpos), PixelToMeter((float)ypos) ); pBird->pBody->SetTransform( newPos, 0.0f ); pLine1->posB=B; pLine2->posB=B;*/ b2Vec2 slingPos(PixelToMeter((float)slingX), PixelToMeter((float)slingY)); b2Vec2 newPos(PixelToMeter((float)pBird->pos.x+Dist[x]*zoom), PixelToMeter((float)pBird->pos.y+Dist[y]*zoom)); b2Vec2 check(PixelToMeter((float)pBird->pos.x+Dist[x]*zoom-slingX), PixelToMeter((float)pBird->pos.y+Dist[y]*zoom - slingY)); if (check.Length() > 2) { check.Normalize(); newPos = slingPos + 2*check; } else { newPos.Set( PixelToMeter((float)pBird->pos.x+Dist[x]*zoom), PixelToMeter((float)pBird->pos.y+Dist[y]*zoom) ); } //printf("%f - %f ",newPos.x, newPos.y); pBird->pBody->SetTransform( newPos, 0.0f ); Vect2D B(MeterToPixel((float)newPos.x), MeterToPixel((float)newPos.y)); pLine1->posB=B; pLine2->posB=B; } else//this fires bird from the slingshot { b2Vec2 slingshot(PixelToMeter(slingX-pBird->pos.x), PixelToMeter(slingY-pBird->pos.y)); pBird->bState = NORMAL1; pBird->pBody->SetActive(true); float32 mag = slingshot.Length(); if (mag>2) mag=2; slingshot.Normalize(); if (pBird->pBody->GetMass()<10) mag*=20; else mag*=200; b2Vec2 vel; vel = mag * slingshot; pBird->pBody->ApplyLinearImpulse( vel, pBird->pBody->GetWorldCenter(), true ); pBird->pBody->SetActive(true); Vect2D B(slingX, slingY) ; pLine1->posB=B; pLine2->posB=B; pBird->launch(); AzulCore::clearTrails(); std::list< GameObject *>::iterator it=gameObjectList.begin(); while( it!=gameObjectList.end() ) { GameObject *pGameObj = *it++; pGameObj->damageActive=true; } } } if (pBird->bState==SLING) { pBird->pBody->SetActive(false); b2Vec2 newPos( PixelToMeter((float)slingX), PixelToMeter((float)slingY) ); pBird->pBody->SetTransform( newPos, 0.0f ); } if (pBird->bState==SLING||pBird->bState==MOVING) { AzulCore::setTargetAndSpeed((slingX), (slingY), -0.2f,0.01f); } else { AzulCore::setTargetAndSpeed(pBird->pos.x, pBird->pos.y, 0.1f,10.0f); } }
void levelClass::readLevelEdit(std::string nameLevel, std::list<infoEvent>& listEvent, std::list<characterClass*>& listEnemy, std::map<std::pair<int, int>, itemClass*>& mapLevel, int& endOfLevel, int& heightLevel, std::string& typeLevel) { std::ifstream file(nameLevel.c_str()); if(file.is_open()) { std::string line; std::string typeLine = "END"; while(std::getline(file, line)) { if(line == "END") { if(typeLine == "SPAWN_ENEMY" || typeLine == "CHANGE_MAP") typeLine = "EVENT"; else typeLine = "END"; } if(typeLine == "MAP") { std::string name = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseX = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseY = line; mapLevel.insert(std::pair<std::pair<int, int>, itemClass*>(std::pair<int, int>(std::atoi(poseX.c_str()), std::atoi(poseY.c_str())), new basicBlocClass(name, std::atoi(poseX.c_str()), std::atoi(poseY.c_str())))); } else if(typeLine == "ENEMY") { std::string name = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseX = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseY = line; if(name == "BOSS") listEnemy.push_back(new bossEnemyClass(std::atoi(poseX.c_str()), std::atoi(poseY.c_str()), name)); else listEnemy.push_back(new basicEnemyClass(std::atoi(poseX.c_str()), std::atoi(poseY.c_str()), name)); } else if(typeLine == "EVENT") { std::string name = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); if(name == "MESSAGE") { std::string poseX = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseY = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string width = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string height = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string message = line; while(message.find("\\n") != std::string::npos) { message.replace(message.find("\\n"), 2, "&n"); } infoEvent tmp; sf::RectangleShape surface; surface.setPosition(std::atoi(poseX.c_str()), std::atoi(poseY.c_str())); surface.setSize(sf::Vector2f(std::atoi(width.c_str()), std::atoi(height.c_str()))); surface.setFillColor(sf::Color::Cyan); tmp.name = "MESSAGE"; tmp.surface = surface; tmp.valX = 0; tmp.valY = 0; tmp.action.push_back(message); listEvent.push_back(tmp); } else if(name == "SPAWN_ENEMY") { std::string poseX = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseY = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string width = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string height = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string newPoseX = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string newPoseY = line; sf::RectangleShape surface; surface.setPosition(std::atoi(poseX.c_str()), std::atoi(poseY.c_str())); surface.setSize(sf::Vector2f(std::atoi(width.c_str()), std::atoi(height.c_str()))); surface.setFillColor(sf::Color::Cyan); infoEvent tmp; tmp.name = "SPAWN_ENEMY"; tmp.surface = surface; tmp.valX = std::atoi(newPoseX.c_str()); tmp.valY = std::atoi(newPoseY.c_str()); typeLine = "SPAWN_ENEMY"; listEvent.push_back(tmp); } else if(name == "CHANGE_MAP") { std::string poseX = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseY = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string width = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string height = line; sf::RectangleShape surface; surface.setPosition(std::atoi(poseX.c_str()), std::atoi(poseY.c_str())); surface.setSize(sf::Vector2f(std::atoi(width.c_str()), std::atoi(height.c_str()))); surface.setFillColor(sf::Color::Cyan); infoEvent tmp; tmp.name = "CHANGE_MAP"; tmp.surface = surface; tmp.valX = 0; tmp.valY = 0; typeLine = "CHANGE_MAP"; listEvent.push_back(tmp); } } else if(typeLine == "SPAWN_ENEMY") { std::string name = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseX = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseY = line; listEvent.back().action.push_back(name + " " + poseX + " " + poseY); } else if(typeLine == "CHANGE_MAP") { std::string name = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseX = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseY = line; listEvent.back().action.push_back(name + " " + poseX + " " + poseY); } else if(typeLine == "HEIGHT") { heightLevel = std::atoi(line.c_str()); } else if(typeLine == "ENDOFLEVEL") { endOfLevel = std::atoi(line.c_str()); } else if(typeLine == "TYPELEVEL") { typeLevel = line.c_str(); } if(line == "MAP") typeLine = "MAP"; else if(line == "ENEMY") typeLine = "ENEMY"; else if(line == "EVENT") typeLine = "EVENT"; else if(line == "HEIGHT") typeLine = "HEIGHT"; else if(line == "ENDOFLEVEL") typeLine = "ENDOFLEVEL"; else if(line == "TYPELEVEL") typeLine = "TYPELEVEL"; } file.close(); } }
void Stage::execute(StreamPointTable& table, std::list<Stage *>& stages) { std::vector<bool> skips(table.capacity()); std::list<Stage *> filters; SpatialReference srs; // Separate out the first stage. Stage *reader = stages.front(); // Build a list of all stages except the first. We may have a writer in // this list in addition to filters, but we treat them in the same way. auto begin = stages.begin(); begin++; std::copy(begin, stages.end(), std::back_inserter(filters)); for (Stage *s : stages) { s->ready(table); srs = s->getSpatialReference(); if (!srs.empty()) table.setSpatialReference(srs); } // Loop until we're finished. We handle the number of points up to // the capacity of the StreamPointTable that we've been provided. bool finished = false; while (!finished) { // Clear the spatial reference when processing starts. table.clearSpatialReferences(); PointId idx = 0; PointRef point(table, idx); point_count_t pointLimit = table.capacity(); // When we get false back from a reader, we're done, so set // the point limit to the number of points processed in this loop // of the table. for (PointId idx = 0; idx < pointLimit; idx++) { point.setPointId(idx); finished = !reader->processOne(point); if (finished) pointLimit = idx; } srs = reader->getSpatialReference(); if (!srs.empty()) table.setSpatialReference(srs); // When we get a false back from a filter, we're filtering out a // point, so add it to the list of skips so that it doesn't get // processed by subsequent filters. for (Stage *s : filters) { for (PointId idx = 0; idx < pointLimit; idx++) { if (skips[idx]) continue; point.setPointId(idx); if (!s->processOne(point)) skips[idx] = true; } srs = s->getSpatialReference(); if (!srs.empty()) table.setSpatialReference(srs); } // Yes, vector<bool> is terrible. Can do something better later. for (size_t i = 0; i < skips.size(); ++i) skips[i] = false; table.reset(); } for (Stage *s : stages) s->done(table); }
void levelClass::readLevel(std::string nameLevel, std::list<eventClass*>& listEvent, std::list<characterClass*>& listEnemy, std::map<std::pair<int, int>, itemClass*>& mapLevel, int& endOfLevel, int& heightLevel, std::string& typeLevel, int poseXPlayer, lightManagerClass& lightManager) { std::ifstream file(nameLevel.c_str()); if(file.is_open()) { std::string line; std::string typeLine = "END"; spawnEnemyEventClass* tmpEventSpawn; changeMapEventClass* tmpChangeMap; while(std::getline(file, line)) { if(line == "END") { if(typeLine == "SPAWN_ENEMY" || typeLine == "CHANGE_MAP") typeLine = "EVENT"; else typeLine = "END"; } if(typeLine == "MAP") { std::string name = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseX = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseY = line; mapLevel.insert(std::pair<std::pair<int, int>, itemClass*>(std::pair<int, int>(std::atoi(poseX.c_str()), std::atoi(poseY.c_str())), new basicBlocClass(name, std::atoi(poseX.c_str()), std::atoi(poseY.c_str())))); } else if(typeLine == "ENEMY") { std::string name = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseX = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseY = line; if(name == "BOSS") listEnemy.push_back(new bossEnemyClass(std::atoi(poseX.c_str()), std::atoi(poseY.c_str()), name)); else listEnemy.push_back(new basicEnemyClass(std::atoi(poseX.c_str()), std::atoi(poseY.c_str()), name)); } else if(typeLine == "EVENT") { std::string name = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); if(name == "MESSAGE") { std::string poseX = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseY = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string width = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string height = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string message = line; while(message.find("\\n") != std::string::npos) { message.replace(message.find("\\n"), 2, "\n"); } if(std::atoi(poseX.c_str()) > poseXPlayer) { sf::RectangleShape surface; surface.setPosition(std::atoi(poseX.c_str()), std::atoi(poseY.c_str())); surface.setSize(sf::Vector2f(std::atoi(width.c_str()), std::atoi(height.c_str()))); listEvent.push_back(new messageEventClass(message, surface)); } } else if(name == "SPAWN_ENEMY") { std::string poseX = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseY = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string width = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string height = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string newPoseX = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string newPoseY = line; sf::RectangleShape surface; surface.setPosition(std::atoi(poseX.c_str()), std::atoi(poseY.c_str())); surface.setSize(sf::Vector2f(std::atoi(width.c_str()), std::atoi(height.c_str()))); tmpEventSpawn = new spawnEnemyEventClass(surface, std::atoi(newPoseX.c_str()), std::atoi(newPoseY.c_str())); typeLine = "SPAWN_ENEMY"; listEvent.push_back(tmpEventSpawn); } else if(name == "CHANGE_MAP") { std::string poseX = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseY = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string width = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string height = line; sf::RectangleShape surface; surface.setPosition(std::atoi(poseX.c_str()), std::atoi(poseY.c_str())); surface.setSize(sf::Vector2f(std::atoi(width.c_str()), std::atoi(height.c_str()))); tmpChangeMap = new changeMapEventClass(surface); typeLine = "CHANGE_MAP"; listEvent.push_back(tmpChangeMap); } } else if(typeLine == "SPAWN_ENEMY") { std::string name = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseX = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseY = line; tmpEventSpawn->addToList(name, std::atoi(poseX.c_str()), std::atoi(poseY.c_str())); } else if(typeLine == "CHANGE_MAP") { std::string name = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseX = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseY = line; tmpChangeMap->addToList(name, std::atoi(poseX.c_str()), std::atoi(poseY.c_str())); } else if(typeLine == "LIGHT_WALL") { std::string poseXFirst = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseYFirst = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseXSecond = line.substr(0, line.find(' ')); line.erase(0, line.find(' ') + 1); std::string poseYSecond = line; lightManager.addWall(sf::Vector2f(atoi(poseXFirst.c_str()), atoi(poseYFirst.c_str())), sf::Vector2f(atoi(poseXSecond.c_str()), atoi(poseYSecond.c_str()))); } else if(typeLine == "HEIGHT") { heightLevel = std::atoi(line.c_str()); } else if(typeLine == "ENDOFLEVEL") { endOfLevel = std::atoi(line.c_str()); } else if(typeLine == "TYPELEVEL") { typeLevel = line.c_str(); } if(line == "MAP") typeLine = "MAP"; else if(line == "ENEMY") typeLine = "ENEMY"; else if(line == "EVENT") typeLine = "EVENT"; else if(line == "LIGHT_WALL") typeLine = "LIGHT_WALL"; else if(line == "HEIGHT") typeLine = "HEIGHT"; else if(line == "ENDOFLEVEL") typeLine = "ENDOFLEVEL"; else if(line == "TYPELEVEL") typeLine = "TYPELEVEL"; } file.close(); } }
int main(int argc, char** argv) { int option; streamFile = argv[0]; // default while ((option = getopt(argc, argv, "zcsm:w:l:r:f:t:i:o:d:x:y:e:")) != -1) { switch(option) { case 'z': useZeroCopy = true; break; case 'y': compressionWithState = true; // fall through case 'x': { char* compArg = optarg; // http://stackoverflow.com/a/53878/990120 std::list<std::string> compArgs; do { const char *begin = compArg; while(*compArg != ':' && *compArg) compArg++; compArgs.push_back(std::string(begin, compArg - begin)); } while(0 != *compArg++); if (!compArgs.empty()) { compressionType = compArgs.front(); compArgs.pop_front(); } else { printUsageAndExit(); } if (!compArgs.empty()) { compressionLevel = strTo<int>(compArgs.front()); if (toStr(compressionLevel) != compArgs.front()) printUsageAndExit(); compArgs.pop_front(); } if (!compArgs.empty()) { if (!compressionWithState) printUsageAndExit(); compressionRefreshInterval = strTo<int>(compArgs.front()); if (toStr(compressionRefreshInterval) != compArgs.front()) printUsageAndExit(); compArgs.pop_front(); } } break; case 'c': isClient = true; break; case 's': isServer = true; break; case 'l': pcntLossOk = atof((const char*)optarg); break; case 't': if (strncasecmp(optarg, "tcp", 3) == 0) { type = PUB_TCP; } else if (strncasecmp(optarg, "mcast", 5) == 0) { type = PUB_MCAST; } else if (strncasecmp(optarg, "rtp", 3) == 0) { type = PUB_RTP; } break; case 'f': streamFile = optarg; break; case 'm': mtu = displayToBytes(optarg); break; case 'e': waitToConclude = strTo<uint64_t>(optarg); break; case 'r': if (strcmp(optarg, "max") == 0 || strcmp(optarg, "inf") == 0) { fixedBytesPerSecond = (size_t)-1; } else { fixedBytesPerSecond = displayToBytes(optarg); } break; case 'd': duration = atoi((const char*)optarg); break; case 'o': filePrefix = optarg; break; case 'w': waitForSubs = atoi((const char*)optarg); break; case 'i': reportInterval = atoi((const char*)optarg); break; default: printUsageAndExit(); break; } } if (!isClient && !isServer) printUsageAndExit(); if (fixedBytesPerSecond > 0) bytesPerSecond = fixedBytesPerSecond; if (mtu < MIN_MTU) mtu = MIN_MTU; DiscoveryConfigMDNS discConfig; // discConfig.setDomain("throughput"); disc = Discovery(&discConfig); Subscriber sub("reports"); ReportReceiver reportRecv; sub.setReceiver(&reportRecv); node.addSubscriber(sub); if (isServer) { runAsServer(); } else { runAsClient(); } if (filePrefix.size() > 0) { // wait for missing reports, then make sure no more reports are coming in Thread::sleepMs(waitToConclude); sub.setReceiver(NULL); // write files std::map<std::string, std::list<Report> >::iterator reportIter = allReports.begin(); std::map<std::string, std::ofstream*> fileHandles; // open a file per reporter and write header while(reportIter != allReports.end()) { std::string pubUUID = reportIter->first; std::string reportFileName = filePrefix + pubUUID.substr(0,8) + ".data"; fileHandles[pubUUID] = new std::ofstream(); fileHandles[pubUUID]->open(reportFileName.c_str(), std::fstream::out); Report::writeCSVHead(*fileHandles[pubUUID]); #ifdef UNIX // that's only useful if there is only a single reporter per host std::string linkFrom = filePrefix + pubUUID.substr(0,8) + ".data"; std::string linkTo = filePrefix + reportIter->second.back().hostId + ".host.data"; unlink(linkTo.c_str()); symlink(linkFrom.c_str(), linkTo.c_str()); #endif reportIter++; } // write reports std::fstream senderReport; std::string senderReportFileName = filePrefix + "sender.data"; senderReport.open(senderReportFileName.c_str(), std::fstream::out); senderReport << "\"Payload Compressibility\", \"Bytes Sent\", \"Packets sent\"" << std::endl; std::list<Report>::iterator senderRepIter = senderReports.begin(); while(senderRepIter!= senderReports.end()) { senderReport << compressionActualRatio << ", "; senderReport << senderRepIter->bytesRcvd << ", "; senderReport << senderRepIter->pktsRcvd << std::endl; senderRepIter++; reportIter = allReports.begin(); while(reportIter != allReports.end()) { if (reportIter->second.size() == 0) { // all data consumed - insert missing at end *fileHandles[reportIter->first] << "-" << std::endl; break; } if (reportIter->second.front().pertainingPacket > senderRepIter->pertainingPacket) { // no data for reporting period! *fileHandles[reportIter->first] << "-" << std::endl; } else { reportIter->second.front().writeCSVData(*fileHandles[reportIter->first]); reportIter->second.pop_front(); } #if 0 // discard multiple reports? while(reportIter->second.size() > 0 && reportIter->second.front().pertainingPacket < senderRepIter->pertainingPacket) { reportIter->second.pop_front(); } #endif reportIter++; } } std::map<std::string, std::ofstream*>::iterator fhIter = fileHandles.begin(); while(fhIter != fileHandles.end()) { fhIter->second->close(); delete(fhIter->second); fhIter++; } senderReport.close(); #if 0 while(true) { reportIter = allReports.begin(); size_t nextReportingEnd = 4294967295; // 2**32 - 1 std::string nextReporter; // break when we consumed all reports if (allReports.size() == 0) break; while(reportIter != allReports.end()) { // walk through the report iterators and find next report due size_t nextDueReport = reportIter->second.front().pertainingPacket; if (nextDueReport < nextReportingEnd) { nextReportingEnd = nextDueReport; nextReporter = reportIter->first; } reportIter++; } // ok, write earliest report into earlist's reports file Report& nextReport = allReports[nextReporter].front(); fileHandles[nextReporter] << nextReport.discoveryTime << ", "; fileHandles[nextReporter] << nextReport.bytesRcvd << ", "; fileHandles[nextReporter] << nextReport.pktsRcvd << ", "; fileHandles[nextReporter] << nextReport.pktsLate << ", "; fileHandles[nextReporter] << nextReport.roundTripTime << ", "; fileHandles[nextReporter] << nextReport.pcntLoss << ", "; fileHandles[nextReporter] << nextReport.pktsDropped << ", "; fileHandles[nextReporter] << nextReport.hostName << std::endl; allReports[nextReporter].pop_front(); if (allReports[nextReporter].size() == 0) { allReports.erase(nextReporter); } else { // fill with newlines if we skipped reports Report& upcomingReport = allReports[nextReporter].front(); for(int i = 1; nextReport.reportNr + i < upcomingReport.reportNr; i++) { fileHandles[nextReporter] << std::endl; } } } std::map<std::string, std::fstream>::iterator fhIter = fileHandles.begin(); while(fhIter != fileHandles.end()) { fhIter->second.close(); fhIter++; } // write sender reports std::fstream senderReport; std::string reportFileName = filePrefix + "sender.data"; senderReport.open(reportFileName.c_str(), std::fstream::out); std::list<Report>::iterator senderRepIter = senderReports.begin(); while(senderRepIter!= senderReports.end()) { senderReport << senderRepIter->bytesRcvd << ", "; senderReport << senderRepIter->pktsRcvd << std::endl; senderRepIter++; } senderReport.close(); #endif } }
_branch *add(int p) { _branch *b = new _branch(p); inner.push_back(b); return b; }
// ---------------------------------------------------------------------- // static method - called once for all widgets by the // WidgetEventResponder, which self- // registers to all events upon creation of the first widget. // bool ofxWidget::mouseEvent(ofMouseEventArgs& args_) { // If we register a mouse down event, we do a hit test over // all visible widgets, and re-order if necessary. // Then, and in all other cases, we do a hit-test on the // frontmost widget and, if positive, forward the event to this // widget. updateVisibleWidgetsList(); if (sVisibleWidgets.empty()) return false; // ---------| invariant: there are some widgets flying around. bool eventAttended = false; float mx = args_.x; float my = args_.y; // if we have a mouse down on a widget, we need to check which // widget was hit and potentially re-order widgets. // find the first widget that is under the mouse, that is also visible // if it is not yet up front, bring it to the front. // hit-test only visible widgets - this makes sure to only evaluate // the widgets which are visible, and whose parents are visible, too. auto itUnderMouse = std::find_if(sVisibleWidgets.begin(), sVisibleWidgets.end(), [&mx, &my](std::weak_ptr<ofxWidget>& w) ->bool { auto p = w.lock(); if (p && p->mVisible && p->mRect.inside(mx, my)) { return true; } else { return false; } }); // if we have a click, we want to make sure the widget gets to be the topmost widget. if (args_.type == ofMouseEventArgs::Pressed) { // --- now iterate over sAllWidgets instead of just the visible widgets. // we need to do this, because otherwise the reorder check won't be safe // as the number of children in sVisibleWidgets is potentially incorrect, // as the number of children there refers to all children of a widget, // and not just the visible children of the widget. auto itPressedWidget = (itUnderMouse == sVisibleWidgets.end() ? sAllWidgets.end() : findIt(*itUnderMouse, sAllWidgets.begin(), sAllWidgets.end())); if (itPressedWidget != sAllWidgets.end()) { if (!isSame(*itPressedWidget, sFocusedWidget)) { // change in focus detected. // first, let the first element know that it is losing focus if (auto previousElementInFocus = sFocusedWidget.lock()) if (previousElementInFocus->onFocusLeave) previousElementInFocus->onFocusLeave(); sFocusedWidget = *itPressedWidget; // now that the new wiget is at the front, send an activate callback. if (auto nextFocusedWidget = sFocusedWidget.lock()) if (nextFocusedWidget->onFocusEnter) nextFocusedWidget->onFocusEnter(); } bringToFront(itPressedWidget); // reorder widgets } else { // hit test was not successful, no wigets found. if (auto previousElementInFocus = sFocusedWidget.lock()) if (previousElementInFocus->onFocusLeave) previousElementInFocus->onFocusLeave(); sFocusedWidget.reset(); // no widget gets the focus, then. } } // end if (args_.type == ofMouseEventArgs::Pressed) // now, we will attempt to send the mouse event to the widget that // is in focus. if (itUnderMouse != sVisibleWidgets.end()) { // a widget is under the mouse. // is it the same as the current widget under the mouse? if (!isSame(*itUnderMouse, sWidgetUnderMouse)) { if (auto nU = itUnderMouse->lock()) { // there is a new widget under the mouse if (auto w = sWidgetUnderMouse.lock()) { // there was an old widget under the mouse if (w->onMouseLeave) w->onMouseLeave(); w->mHover = false; } if (nU->onMouseEnter) nU->onMouseEnter(); nU->mHover = true; sWidgetUnderMouse = *itUnderMouse; } } } else { if (auto w = sWidgetUnderMouse.lock()) { // there was a widget under mouse, // but now there is none. if (w->onMouseLeave) w->onMouseLeave(); w->mHover = false; sWidgetUnderMouse.reset(); } } if (auto w = sFocusedWidget.lock()) { if (w->onMouse) { w->onMouse(args_); eventAttended = true; } } // store last mouse position last thing, so that // we are able to calculate a difference. sLastMousePos.set(mx, my); return eventAttended; }
void FilterTargets(std::list<WorldObject*>& targets) { targets.remove(GetExplTargetUnit()); }
const bool ofxWidget::isActivated() const { return (sAllWidgets.empty()) ? false : isSame(mThis, sFocusedWidget); }
int countValueIdentities(const std::list<ValueIdentity>& values) { return values.size(); }
void JustSummoned(Creature* pSummon) { SummonList.push_back(pSummon->GetGUID()); }
coverage_generator(Syn const* rule, std::list<sbmt::span_string> const& lst, Constituents rng, bool toplevel, sbmt::span_t total) : rule(rule), itr(lst.begin()), end(lst.end()), rng(boost::begin(rng),boost::end(rng)), toplevel(toplevel), total(total) { pop(); }