void QmlProfilerRangeModel::findBindingLoops() { typedef QPair<int, int> CallStackEntry; QStack<CallStackEntry> callStack; for (int i = 0; i < count(); ++i) { int potentialParent = callStack.isEmpty() ? -1 : callStack.top().second; while (potentialParent != -1 && !(endTime(potentialParent) > startTime(i))) { callStack.pop(); potentialParent = callStack.isEmpty() ? -1 : callStack.top().second; } // check whether event is already in stack for (int ii = 0; ii < callStack.size(); ++ii) { if (callStack.at(ii).first == typeId(i)) { m_data[i].bindingLoopHead = callStack.at(ii).second; break; } } CallStackEntry newEntry(typeId(i), i); callStack.push(newEntry); } }
ValueType<T>::ValueType(const T& val, ByteOrder byteOrder) : Value(getType<T>()), pDataArea_(0), sizeDataArea_(0) { read(reinterpret_cast<const byte*>(&val), TypeInfo::typeSize(typeId()), byteOrder); }
XMLNode Entity::save(XMLNode &parent) const { XMLNode node = parent.addChild(toString(typeId())); node.addAttrib("pos", m_pos); if(m_dir_angle != 0.0f) node.addAttrib("angle", m_dir_angle); return node; }
int item::volume() { if (typeId() == itm_corpse) { switch (corpse->size) { case MS_TINY: return 2; case MS_SMALL: return 40; case MS_MEDIUM: return 75; case MS_LARGE: return 160; case MS_HUGE: return 600; } } if( is_null() ) return 0; int ret = type->volume; if (count_by_charges()) { ret *= charges; ret /= 100; } if (is_gun()) { for (int i = 0; i < contents.size(); i++) ret += contents[i].volume(); } return ret; }
std::string item::save_info() { if (type == NULL) debugmsg("Tried to save an item with NULL type!"); int ammotmp = 0; /* TODO: This causes a segfault sometimes, even though we check to make sure * curammo isn't NULL. The crashes seem to occur most frequently when saving an * NPC, or when saving map data containing an item an NPC has dropped. */ if (curammo != NULL) ammotmp = curammo->id; if (ammotmp < 0 || ammotmp > num_items) ammotmp = 0; // Saves us from some bugs std::stringstream dump;// (std::stringstream::in | std::stringstream::out); dump << " " << int(invlet) << " " << int(typeId()) << " " << int(charges) << " " << int(damage) << " " << int(burnt) << " " << poison << " " << ammotmp << " " << owned << " " << int(bday); if (active) dump << " 1"; else dump << " 0"; if (corpse != NULL) dump << " " << corpse->id; else dump << " -1"; dump << " " << mission_id << " " << player_id; size_t pos = name.find_first_of("\n"); while (pos != std::string::npos) { name.replace(pos, 1, "@@"); pos = name.find_first_of("\n"); } dump << " '" << name << "'"; return dump.str(); }
void ValueType<T>::read(const byte* buf, long len, ByteOrder byteOrder) { value_.clear(); for (long i = 0; i < len; i += TypeInfo::typeSize(typeId())) { value_.push_back(getValue<T>(buf + i, byteOrder)); } }
void NotesModel::update(int index, const QString &text) { Note ¬e = m_data[index]; if (text != note.text) { note.text = text; emit changed(typeId(index), note.timelineModel, note.timelineIndex); } }
bool ToolChain::operator == (const ToolChain &tc) const { if (this == &tc) return true; // We ignore displayname return typeId() == tc.typeId() && isAutoDetected() == tc.isAutoDetected(); }
nc_color item::color() { if (typeId() == itm_corpse) return corpse->color; if( is_null() ) return c_black; return type->color; }
void vehicle::turret_reload( vehicle_part &pt ) { item &gun = pt.base; if( !gun.is_gun() || gun.ammo_type() == "NULL" ) { return; } // try to reload using stored fuel from onboard vehicle tanks for( const auto &e : fuels_left() ) { const itype *fuel = item::find_type( e.first ); if( !fuel->ammo || e.second < gun.ammo_required() ) { continue; } if( ( gun.ammo_current() == "null" && fuel->ammo->type == gun.ammo_type() ) || ( gun.ammo_current() == e.first ) ) { int qty = gun.ammo_remaining(); gun.ammo_set( e.first, e.second ); drain( e.first, gun.ammo_remaining() - qty ); return; } } // otherwise try to reload from turret cargo space for( auto it = pt.items.begin(); it != pt.items.end(); ++it ) { if( it->is_ammo() && ( ( gun.ammo_current() == "null" && it->ammo_type() == gun.ammo_type() ) || ( gun.ammo_current() == it->typeId() ) ) ) { int qty = gun.ammo_remaining(); gun.ammo_set( it->typeId(), it->charges ); it->charges -= gun.ammo_remaining() - qty; if( it->charges <= 0 ) { pt.items.erase( it ); } return; } } }
QVariantList NotesModel::byTypeId(int selectedType) const { QVariantList ret; for (int noteId = 0; noteId < count(); ++noteId) { if (selectedType == typeId(noteId)) ret << noteId; } return ret; }
const MessageType *MessageTypePool::type(const std::string &typeName) const { const Id id = typeId(typeName); if (id == npos) { return nullptr; } else { return type(id); } }
void NotesModel::remove(int index) { Note ¬e = m_data[index]; int noteType = typeId(index); int timelineModel = note.timelineModel; int timelineIndex = note.timelineIndex; m_data.removeAt(index); emit changed(noteType, timelineModel, timelineIndex); }
void NodeMetadata::serialize(std::ostream &os) { u8 buf[2]; writeU16(buf, typeId()); os.write((char*)buf, 2); std::ostringstream oss(std::ios_base::binary); serializeBody(oss); os<<serializeString(oss.str()); }
bool item::made_of(material mat) { if( is_null() ) return false; if (typeId() == itm_corpse) return (corpse->mat == mat); return (type->m1 == mat || type->m2 == mat); }
void CloudReconnectWorker::processNotification( AbsOptCloudClientWorker::TypeId tId, const AbsOptCloudClientWorker::BufferType& data ) { LOG_Debug(core, "Process event message type notification ..."); IUccSessionListener::TypeId typeId(tId); // Here we need to verify if the notification correspond to uccReconnectRequest. if( typeId == gvr::communication::ucc::UccMessageCloudReconnect::GetTypeId() ) { doReconnect(data); } }
void CiffComponent::print(std::ostream& os, ByteOrder byteOrder, const std::string& prefix) const { os << prefix << "tag = 0x" << std::setw(4) << std::setfill('0') << std::hex << std::right << tagId() << ", dir = 0x" << std::setw(4) << std::setfill('0') << std::hex << std::right << dir() << ", type = " << TypeInfo::typeName(typeId()) << ", size = " << std::dec << size_ << ", offset = " << offset_ << "\n"; Value::AutoPtr value; if (typeId() != directory) { value = Value::create(typeId()); value->read(pData_, size_, byteOrder); if (value->size() < 100) { os << prefix << *value << "\n"; } } } // CiffComponent::print
void QmlProfilerRangeModel::computeExpandedLevels() { QHash<int, int> eventRow; int eventCount = count(); for (int i = 0; i < eventCount; i++) { int eventTypeId = typeId(i); if (!eventRow.contains(eventTypeId)) { eventRow[eventTypeId] = m_expandedRowTypes.size(); m_expandedRowTypes << eventTypeId; } m_data[i].displayRowExpanded = eventRow[eventTypeId]; } setExpandedRowCount(m_expandedRowTypes.size()); }
int item::weight() { if (typeId() == itm_corpse) { int ret; switch (corpse->size) { case MS_TINY: ret = 5; break; case MS_SMALL: ret = 60; break; case MS_MEDIUM: ret = 520; break; case MS_LARGE: ret = 2000; break; case MS_HUGE: ret = 4000; break; } if (made_of(VEGGY)) ret /= 10; else if (made_of(IRON) || made_of(STEEL) || made_of(STONE)) ret *= 5; return ret; } if( is_null() ) return 0; int ret = type->weight; if (count_by_charges() && !made_of(LIQUID)) { ret *= charges; ret /= 100; } for (int i = 0; i < contents.size(); i++) if (contents[i].made_of(LIQUID)) { if (contents[i].type->is_food()) { it_comest* tmp_comest = dynamic_cast<it_comest*>(contents[i].type); ret += contents[i].weight() * (contents[i].charges / tmp_comest->charges); } else if (contents[i].type->is_ammo()) { it_ammo* tmp_ammo = dynamic_cast<it_ammo*>(contents[i].type); ret += contents[i].weight() * (contents[i].charges / tmp_ammo->count); } else ret += contents[i].weight(); } else ret += contents[i].weight(); return ret; }
FurnaceNodeMetadata::FurnaceNodeMetadata(IGameDef *gamedef): NodeMetadata(gamedef) { NodeMetadata::registerType(typeId(), typeName(), create, create); m_inventory = NULL; m_infotext = "Furnace is inactive"; m_step_accumulator = 0; m_fuel_totaltime = 0; m_fuel_time = 0; m_src_totaltime = 0; m_src_time = 0; }
//============================================================================== bool ContextDefinitionManager::deserializeDefinitions(ISerializer& serializer) { // load generic definitions size_t count = 0; serializer.deserialize(count); for (size_t i = 0; i < count; i++) { std::string defName; serializer.deserialize(defName); std::string parentDefName; serializer.deserialize(parentDefName); auto pDef = getDefinition(defName.c_str()); IClassDefinitionModifier* modifier = nullptr; if (!pDef) { auto definition = registerDefinition(createGenericDefinition(defName.c_str())); modifier = definition->getDetails().getDefinitionModifier(); } size_t size = 0; serializer.deserialize(size); std::string propName; std::string typeName; uint32_t flags; for (size_t j = 0; j < size; j++) { propName.clear(); typeName.clear(); serializer.deserialize(propName); serializer.deserialize(typeName); serializer.deserialize(flags); IBasePropertyPtr property = nullptr; auto metaType = MetaType::find(typeName.c_str()); if (modifier) { bool isCollection = flags & ContextDefinitionManagerDetails::IS_COLLECTION; auto property = modifier->addProperty( propName.c_str(), metaType != nullptr ? metaType->typeId().getName() : typeName.c_str(), nullptr, isCollection); // TF_ASSERT( property ); } } } return true; }
GenericNodeMetadata(IGameDef *gamedef): NodeMetadata(gamedef), m_inventory(NULL), m_text(""), m_owner(""), m_infotext("GenericNodeMetadata"), m_inventorydrawspec(""), m_allow_text_input(false), m_removal_disabled(false), m_enforce_owner(false), m_inventory_modified(false), m_text_modified(false) { NodeMetadata::registerType(typeId(), typeName(), create, create); }
QVariantMap QmlProfilerTimelineModel::locationFromTypeId(int index) const { QVariantMap result; int id = typeId(index); if (id < 0) return result; auto types = modelManager()->qmlModel()->eventTypes(); if (id >= types.length()) return result; QmlEventLocation location = types.at(id).location(); result.insert(QStringLiteral("file"), location.filename()); result.insert(QStringLiteral("line"), location.line()); result.insert(QStringLiteral("column"), location.column()); return result; }
bool item::is_food(player *u) const { if (!u) return is_food(); if( is_null() ) return false; if (type->is_food()) return true; if (u->has_bionic("bio_batteries") && is_ammo() && (dynamic_cast<it_ammo*>(type))->type == AT_BATT) return true; if (u->has_bionic("bio_furnace") && is_flammable(type->m1) && is_flammable(type->m2) && typeId() != "corpse") return true; return false; }
/** * Returns the value of the property \a name, taking into account that it may * be inherited from another object or from the type. * * - A Tile instance can inherit properties based on its type * - A MapObject instance can inherit properties based on: * - Its template object * - Its tile * - Its type (or the type of its tile) */ QVariant Object::inheritedProperty(const QString &name) const { if (hasProperty(name)) return property(name); QString objectType; switch (typeId()) { case MapObjectType: { auto mapObject = static_cast<const MapObject*>(this); objectType = mapObject->type(); if (const MapObject *templateObject = mapObject->templateObject()) if (templateObject->hasProperty(name)) return templateObject->property(name); if (Tile *tile = mapObject->cell().tile()) { if (tile->hasProperty(name)) return tile->property(name); if (objectType.isEmpty()) objectType = tile->type(); } break; } case TileType: objectType = static_cast<const Tile*>(this)->type(); break; default: return QVariant(); } if (!objectType.isEmpty()) { for (const ObjectType &type : qAsConst(mObjectTypes)) { if (type.name == objectType) if (type.defaultProperties.contains(name)) return type.defaultProperties.value(name); } } return QVariant(); }
bool item::is_food(player *u) { if (u == NULL) return is_food(); if( is_null() ) return false; if (type->is_food()) return true; if (u->has_bionic(bio_batteries) && is_ammo() && (dynamic_cast<it_ammo*>(type))->type == AT_BATT) return true; if (u->has_bionic(bio_furnace) && is_flammable(type->m1) && is_flammable(type->m2) && typeId() != itm_corpse) return true; return false; }
std::string item::save_info() { if (type == NULL){ debugmsg("Tried to save an item with NULL type!"); } itype_id ammotmp = "null"; /* TODO: This causes a segfault sometimes, even though we check to make sure * curammo isn't NULL. The crashes seem to occur most frequently when saving an * NPC, or when saving map data containing an item an NPC has dropped. */ if (curammo != NULL){ ammotmp = curammo->id; } if( std::find(unreal_itype_ids.begin(), unreal_itype_ids.end(), ammotmp) != unreal_itype_ids.end() && std::find(artifact_itype_ids.begin(), artifact_itype_ids.end(), ammotmp) != artifact_itype_ids.end() ) { ammotmp = "null"; //Saves us from some bugs, apparently? } std::stringstream dump; dump << " " << int(invlet) << " " << typeId() << " " << int(charges) << " " << int(damage) << " " << int(item_flags) << " " << int(burnt) << " " << poison << " " << ammotmp << " " << owned << " " << int(bday); if (active) dump << " 1"; else dump << " 0"; if (corpse != NULL) dump << " " << corpse->id; else dump << " -1"; dump << " " << mission_id << " " << player_id; size_t pos = name.find_first_of("\n"); while (pos != std::string::npos) { name.replace(pos, 1, "@@"); pos = name.find_first_of("\n"); } dump << " '" << name << "'"; return dump.str(); }
bool VariantStreamHandler::read(Variant& v, const NodePtr& node, const char* typeName) { // Check that we've been given a valid Variant if (v.isVoid() || v.type() == nullptr) { return false; } auto variantTypeName = this->getReservedNames().variantInternalType; std::string typeData = node->getChildNode(variantTypeName, strlen(variantTypeName))->getValueString(); TypeId typeId(typeData.c_str()); // Check that the types match if (strcmp(v.type()->typeId().getName(), typeId.getName()) != 0) { return false; } ResizingMemoryStream rs(node->getValueString()); TextStream ts(rs); ts >> v; return true; }
//! Return the size in bytes of one component of this type long typeSize() const { return TypeInfo::typeSize(typeId()); }
//! Return the name of the type const char* typeName() const { return TypeInfo::typeName(typeId()); }