void MysteryDungeonMaker::CreateDungeon() { ResetMap(); std::vector<Component> section_components; const size_t sectionRowNum = dungeonSize->DungeonRowNum(); const size_t sectionColumnNum = dungeonSize->DungeonColumnNum(); for (size_t i = 0; i < sectionRowNum; i++) { for (size_t j = 0; j < sectionColumnNum; j++) { section_components.push_back(Component(i, j)); this->sections[i][j].SetComponent(i, j); } } std::random_device rd; shuffle(section_components.begin(), section_components.end(), std::mt19937_64(rd())); for (int i = 0; i < roomNum; i++) { int i_section = section_components[i].i; int j_section = section_components[i].j; int width = GetRandInRange(minRoomWidth, sectionColumnNum - 4); int height = GetRandInRange(minRoomHeight, sectionRowNum - 4); MakeRoom(Component(i_section, j_section), width, height); } MakePath(); }
void RespawnActorMapElement::Save( Json::Value& Element ) { Opt<Actor> actor( Scene::Get().GetActor( mSpawnedActorGUID ) ); if ( !actor.IsValid() ) { return; } MapElement::Save( Element ); std::string actorName; if ( IdStorage::Get().GetName( mActorID, actorName ) ) { Element["actor"] = Json::Value( actorName ); } Json::Value ComponentsArr( Json::arrayValue ); Opt<IPositionComponent> positionC( actor->Get<IPositionComponent>() ); if ( positionC.IsValid() ) { Json::Value Component( Json::objectValue ); positionC->Save( Component ); ComponentsArr.append( Component ); } Opt<PickupCollisionComponent> pickupCollisionC( actor->Get<ICollisionComponent>() ); if ( pickupCollisionC.IsValid() ) { Json::Value Component( Json::objectValue ); pickupCollisionC->Save( Component ); ComponentsArr.append( Component ); } Element["components"] = Json::Value( ComponentsArr ); Element["secs_to_respawn"] = mSecsToRespawnOriginal; }
void CGSeerHut::getCompletionText(MetaString &text, std::vector<Component> &components, bool isCustom, const CGHeroInstance * h) const { quest->getCompletionText (text, components, isCustom, h); switch (rewardType) { case EXPERIENCE: components.push_back(Component (Component::EXPERIENCE, 0, h->calculateXp(rVal), 0)); break; case MANA_POINTS: components.push_back(Component (Component::PRIM_SKILL, 5, rVal, 0)); break; case MORALE_BONUS: components.push_back(Component (Component::MORALE, 0, rVal, 0)); break; case LUCK_BONUS: components.push_back(Component (Component::LUCK, 0, rVal, 0)); break; case RESOURCES: components.push_back(Component (Component::RESOURCE, rID, rVal, 0)); break; case PRIMARY_SKILL: components.push_back(Component (Component::PRIM_SKILL, rID, rVal, 0)); break; case SECONDARY_SKILL: components.push_back(Component (Component::SEC_SKILL, rID, rVal, 0)); break; case ARTIFACT: components.push_back(Component (Component::ARTIFACT, rID, 0, 0)); break; case SPELL: components.push_back(Component (Component::SPELL, rID, 0, 0)); break; case CREATURE: components.push_back(Component (Component::CREATURE, rID, rVal, 0)); break; } }
void MultipleAvroFileWriter::commit() { RMF_TRACE("Writing frame " << frame_.index); for (unsigned int i = 0; i < categories_.size(); ++i) { if (categories_[i].dirty) { if (!categories_[i].writer) { std::string name = get_category_dynamic_file_path(Category(i)); try { categories_[i].writer.reset( new internal_avro::DataFileWriter<RMF_avro_backend::Data>( name.c_str(), internal_avro::compileJsonSchemaFromString( data_deprecated_avro::data_json))); } catch (const std::exception& e) { RMF_THROW(Message(e.what()) << Component(name), IOException); } } // show(categories_[i].data); RMF_INTERNAL_CHECK(categories_[i].data.frame == frame_.index, "Trying to write category that is at wrong frame."); categories_[i].writer->write(categories_[i].data); categories_[i].writer->flush(); } categories_[i].data = RMF_avro_backend::Data(); // go to the about to be added frame categories_[i].data.frame = frame_.index + 1; } for (unsigned int i = 0; i < static_categories_.size(); ++i) { if (static_categories_dirty_[i]) { std::string name = get_category_static_file_path(Category(i)); try { internal_avro::DataFileWriter<RMF_avro_backend::Data> writer( name.c_str(), internal_avro::compileJsonSchemaFromString( data_deprecated_avro::data_json)); writer.write(static_categories_[i]); writer.flush(); } catch (const std::exception& e) { RMF_THROW(Message(e.what()) << Component(name), IOException); } // std::cout << "Writing data for " << get_category_name(Category(i)) << // std::endl; // show(static_categories_[i]); static_categories_dirty_[i] = false; } } RMF_COMMIT(File, file); RMF_COMMIT(Nodes, nodes); if (frames_dirty_) { if (!frame_writer_) { frame_writer_.reset( new internal_avro::DataFileWriter<RMF_avro_backend::Frame>( get_frames_file_path().c_str(), internal_avro::compileJsonSchemaFromString( data_deprecated_avro::frame_json))); } frame_writer_->write(frame_); frames_dirty_ = false; } }
static Component parseUriEscapedValue(uint32_t type, const char* input, size_t len) { std::ostringstream oss; unescape(oss, input, len); std::string value = oss.str(); if (value.find_first_not_of('.') == std::string::npos) { // all periods if (value.size() < 3) { NDN_THROW(Component::Error("Illegal URI (name component cannot be . or ..)")); } return Component(type, reinterpret_cast<const uint8_t*>(value.data()), value.size() - 3); } return Component(type, reinterpret_cast<const uint8_t*>(value.data()), value.size()); }
SignatureGB::SignatureGB( Basis&& basis, Processor&& processor, Reducer::ReducerType reductiontyp, int divlookup_type, int montable_type, bool postponeKoszul, bool useBaseDivisors, bool preferSparseReducers, bool useSingularCriterionEarly, size_t queueType ): mBreakAfter(0), mPrintInterval(0), R(basis.getPolyRing()), mPostponeKoszul(postponeKoszul), mUseBaseDivisors(useBaseDivisors), stats_sPairSignaturesDone(0), stats_sPairsDone(0), stats_koszulEliminated(0), stats_SignatureCriterionLate(0), stats_relativelyPrimeEliminated(0), stats_pairsReduced(0), stats_nsecs(0.0), GB(make_unique<SigPolyBasis>(R, divlookup_type, montable_type, preferSparseReducers)), mKoszuls(R->monoid()), Hsyz(ModuleMonoSet::make(R->monoid(), montable_type, basis.size(), !mPostponeKoszul)), Hsyz2(ModuleMonoSet::make(R->monoid(), montable_type, basis.size(), !mPostponeKoszul)), reducer(Reducer::makeReducer(reductiontyp, *R)), SP(make_unique<SigSPairs>(R, GB.get(), Hsyz.get(), reducer.get(), mPostponeKoszul, mUseBaseDivisors, useSingularCriterionEarly, queueType)) { mProcessor = make_unique<MonoProcessor<Monoid>>(std::move(processor)); if (basis.size() > std::numeric_limits<Component>::max()) mathic::reportError("Dimension of module too large."); const auto componentCount = Component(basis.size()); mProcessor->setComponentCount(componentCount); // Populate GB for (Component j = 0; j < componentCount; j++) GB->addComponent(); for (Component i = 0; i < componentCount; i++) { Poly *g = new Poly(*R); basis.getPoly(i)->copy(*g); g->makeMonic(); monomial sig = 0; sig = R->allocMonomial(); R->monomialEi(i, sig); mProcessor->preprocess(sig); { std::unique_ptr<Poly> autoG(g); GB->insert(sig, std::move(autoG)); } } // Populate SP for (size_t i = 0; i < basis.size(); i++) SP->newPairs(i); }
/* Purpose: To add a component of given type at given x and y position * Pre: Current layer exists, * List of starting position, * Component type * Integer x and y positions * Post: Adds component of given type at given position * Author: Matthew James Harrison ******************************************************************************/ void addComponent(Layer &layer, StartingList &startingList, const ComponentType type, const int xPos, const int yPos) { Component component; int currentLayer = 0; Component tmp; currentLayer = layer.getCurrentLayer(); tmp = layer.get(currentLayer)->get(xPos, yPos); /* If the target position has a power component */ if (tmp.getID() == COMPONENT_NAME[static_cast<int>(POWER)]) { startingList.remove(currentLayer, xPos, yPos); } /* Add the component */ component = Component(COMPONENT_NAME[static_cast<int>(type)]); layer.get(currentLayer)->set(xPos, yPos, component); /* If adding a power component */ if (type == POWER) { startingList.add(currentLayer, xPos, yPos); } }
CMMFBuffer* COmxInputPort::CBody::MipCreateBuffer(TInt aBufferSize) { CMMFBuffer* buffer = NULL; TInt err = KErrNone; TRAP(err, buffer = Component()->OmxAllocateBufferL(iPortIndex, aBufferSize)); return buffer; }
TUint32 COmxInputPort::CBody::MipBufferSize() const { OMX_PARAM_PORTDEFINITIONTYPE portInfo; portInfo.nPortIndex = 0; Component()->OmxGetParameter(OMX_IndexParamPortDefinition, &portInfo); return portInfo.nBufferSize; }
////////////////////////////////////////////////////////////////////////// // processAddRemove void ScnCore::processAddRemove() { for( ScnEntityListIterator It( RemoveEntityList_.begin() ); It != RemoveEntityList_.end(); ++It ) { ScnEntityRef Entity( *It ); Entity->onDetachScene(); EntityList_.remove( Entity ); // Do onDetachComponent for all entities current components. for( BcU32 Idx = 0; Idx < Entity->getNoofComponents(); ++Idx ) { ScnComponentRef Component( Entity->getComponent( Idx ) ); onDetachComponent( ScnEntityWeakRef( Entity ), Component ); Component->onDetach( ScnEntityWeakRef( Entity ) ); // HACK? I don't think this should be called. Entities are still attached to the entity. } } RemoveEntityList_.clear(); for( ScnEntityListIterator It( AddEntityList_.begin() ); It != AddEntityList_.end(); ++It ) { ScnEntityRef Entity( *It ); Entity->onAttachScene(); EntityList_.push_back( Entity ); // Do onAttachComponent for all entities current components. for( BcU32 Idx = 0; Idx < Entity->getNoofComponents(); ++Idx ) { onAttachComponent( ScnEntityWeakRef( Entity ), Entity->getComponent( Idx ) ); } } AddEntityList_.clear(); }
EXPORT_C CUrl* CUrl::AllocL(TComponent aComponent) const { if (aComponent == EUrlGenericCompare) return AllocL(); else if (aComponent == EUrlNoCredentials) { TInt usernameStart; TInt locationStart; TInt scratch; Part(EUrlUsername, *iUrlDes, usernameStart, scratch); Part(EUrlLocation, *iUrlDes, locationStart, scratch); // If there isn't a location and a username, we can just // return the current URL. if (locationStart == KCUrlInvalidCharPos || usernameStart == KCUrlInvalidCharPos) return AllocL(); // Make a CUrl of the right length and then copy the correct // data into it. TInt lengthOfReturnedUrl = iUrlDes->Length() - locationStart + usernameStart; CUrl* result = CUrl::NewL(iUrlDes->Left(lengthOfReturnedUrl)); result->iUrlDes->Des().Replace(usernameStart, lengthOfReturnedUrl - usernameStart, iUrlDes->Right(lengthOfReturnedUrl - usernameStart)); return result; } else return CUrl::NewL(Component(aComponent)); }
ComponentPtr Entity::GetOrCreateComponent(u32 typeId, const QString &name, AttributeChange::Type change, bool replicated) { ComponentPtr new_comp = Component(typeId, name); if (new_comp) return new_comp; return CreateComponent(typeId, name, change, replicated); }
ComponentPtr Entity::GetOrCreateComponent(const QString &type_name, const QString &name, AttributeChange::Type change, bool replicated) { ComponentPtr existing = Component(type_name, name); if (existing) return existing; return CreateComponent(type_name, name, change, replicated); }
ComponentPtr Entity::GetOrCreateComponent(u32 typeId, AttributeChange::Type change, bool replicated) { ComponentPtr existing = Component(typeId); if (existing) return existing; return CreateComponent(typeId, change, replicated); }
CAComponent::CAComponent (const ComponentInstance& compInst) : mComp (Component(compInst)), mManuName(0), mAUName(0), mCompName(0), mCompInfo (0) { GetComponentInfo (Comp(), &mDesc, NULL, NULL, NULL); }
void Name::set(const char* uriOrig) { clear(); std::string uri = uriOrig; trim(uri); if (uri.size() == 0) return; size_t iColon = uri.find(':'); if (iColon != std::string::npos) { // Make sure the colon came before a '/'. size_t iFirstSlash = uri.find('/'); if (iFirstSlash == std::string::npos || iColon < iFirstSlash) { // Omit the leading protocol such as ndn: uri.erase(0, iColon + 1); trim(uri); } } // Trim the leading slash and possibly the authority. if (uri[0] == '/') { if (uri.size() >= 2 && uri[1] == '/') { // Strip the authority following "//". size_t iAfterAuthority = uri.find('/', 2); if (iAfterAuthority == std::string::npos) // Unusual case: there was only an authority. return; else { uri.erase(0, iAfterAuthority + 1); trim(uri); } } else { uri.erase(0, 1); trim(uri); } } size_t iComponentStart = 0; // Unescape the components. while (iComponentStart < uri.size()) { size_t iComponentEnd = uri.find("/", iComponentStart); if (iComponentEnd == std::string::npos) iComponentEnd = uri.size(); Component component = Component::fromEscapedString(&uri[0], iComponentStart, iComponentEnd); // Ignore illegal components. This also gets rid of a trailing '/'. if (!component.empty()) append(Component(component)); iComponentStart = iComponentEnd + 1; } }
void Entity::RemoveComponentRaw(QObject* comp) { LogWarning("Entity::RemoveComponentRaw: This function is deprecated and will be removed. Use RemoveComponent or RemoveComponentById instead."); IComponent* compPtr = dynamic_cast<IComponent*>(comp); if (compPtr) { ComponentPtr ptr = Component(compPtr->TypeName(), compPtr->Name()); //the shared_ptr to this component RemoveComponent(ptr); } }
void ompl::base::MultiOptimizationObjective::addObjective(const OptimizationObjectivePtr& objective, double weight) { if (locked_) { throw Exception("This optimization objective is locked. No further objectives can be added."); } else components_.push_back(Component(objective, weight)); }
virtual Component getFirstScript() override { for (int i = 0; i < m_script_entities.size(); ++i) { if (m_script_entities[i] != -1) { return Component(Entity(&m_universe, m_script_entities[i]), SCRIPT_HASH, this, i); } } return Component::INVALID; }
virtual Component getNextScript(const Component& cmp) override { for (int i = cmp.index + 1; i < m_script_entities.size(); ++i) { if (m_script_entities[i] != -1) { return Component(Entity(&m_universe, m_script_entities[i]), SCRIPT_HASH, this, i); } } return Component::INVALID; }
// calculate power/delay values for wires with suboptimal repeater sizing/spacing void Wire::init_wire() { wire_length = 1; delay_optimal_wire(); double sp, si; powerDef pow; si = repeater_size; sp = repeater_spacing; sp *= 1e6; // in microns double i, j, del; repeated_wire.push_back(Component()); for (j = sp; j < 4 * sp; j += 100) { for (i = si; i > 1; i--) { pow = wire_model(j * 1e-6, i, &del); if (j == sp && i == si) { global.delay = del; global.power = pow; global.area.h = si; global.area.w = sp * 1e-6; // m } // cout << "Repeater size - "<< i << // " Repeater spacing - " << j << // " Delay - " << del << // " PowerD - " << pow.readOp.dynamic << // " PowerL - " << pow.readOp.leakage <<endl; repeated_wire.back().delay = del; repeated_wire.back().power.readOp = pow.readOp; repeated_wire.back().area.w = j * 1e-6; //m repeated_wire.back().area.h = i; repeated_wire.push_back(Component()); } } repeated_wire.pop_back(); update_fullswing(); auto l_wire = new Wire(Low_swing, 1000/* 1 mm*/, 1); low_swing.delay = l_wire->delay; low_swing.power = l_wire->power; delete l_wire; }
Component Entity::_getComponent(m::u64 type) { for (m::i32 i = 0; i < m_components->size(); ++i) { Component c = m_components->get(i); if (c.getInstanceTypeId() == type) { return c; } } return Component(); }
EXPORT_C TInt CUrl::Compare(CUrl& aUrl, TInt aCompareComps) const // // Scheme is case insensitive, rest of url is case sensitive { TInt result =0; if (aCompareComps & EUrlScheme) { result += Component(EUrlScheme).CompareF(aUrl.Component(EUrlScheme)); if (result !=0) return result; } if (aCompareComps & EUrlLocation) { result += Component(EUrlLocation).Compare(aUrl.Component(EUrlLocation)); if (result !=0) return result; } if (aCompareComps & EUrlUsername) { result += Component(EUrlUsername).Compare(aUrl.Component(EUrlUsername)); if (result !=0) return result; } if (aCompareComps & EUrlPassword) { result += Component(EUrlPassword).Compare(aUrl.Component(EUrlPassword)); if (result !=0) return result; } if (aCompareComps & EUrlPath) { result += Component(EUrlPath).Compare(aUrl.Component(EUrlPath)); if (result !=0) return result; } if (aCompareComps & EUrlQuery) { result += Component(EUrlQuery).Compare(aUrl.Component(EUrlQuery)); if (result !=0) return result; } if (aCompareComps & EUrlFragment) { result += Component(EUrlFragment).Compare(aUrl.Component(EUrlFragment)); if (result !=0) return result; } return result; }
Component Component::getSuccessor() const { bool isOverflow = false; Component successor; std::tie(isOverflow, successor) = detail::getComponentTypeTable().get(type()).getSuccessor(*this); if (!isOverflow) { return successor; } uint32_t type = this->type() + 1; const std::vector<uint8_t>& value = detail::getComponentTypeTable().get(type).getMinValue(); return Component(type, value.data(), value.size()); }
/** * サンプリング * @param ret サンプルされたボリュームバッファ値 * @param x X位置 * @param y Y位置 * @param z Z位置 */ void Sample(float* ret, float x, float y, float z) { float xx = x; float yy = y; float zz = z; if (m_isNonUniform) { // remap coordinate. if (SpacingX()->GetNum() > 0) { xx = remap(xx, static_cast<const float*>(SpacingX()->GetBuffer()), SpacingX()->GetNum()); } if (SpacingX()->GetNum() > 0) { yy = remap(yy, static_cast<const float*>(SpacingY()->GetBuffer()), SpacingY()->GetNum()); } if (SpacingX()->GetNum() > 0) { zz = remap(zz, static_cast<const float*>(SpacingZ()->GetBuffer()), SpacingZ()->GetNum()); } } size_t ix = (std::min)((std::max)((size_t)(xx * Width()), (size_t)(Width()-1)), (size_t)0); size_t iy = (std::min)((std::max)((size_t)(yy * Height()), (size_t)(Height()-1)), (size_t)0); size_t iz = (std::min)((std::max)((size_t)(zz * Depth()), (size_t)(Depth()-1)), (size_t)0); size_t idx = Component() * (iz * Width() * Height() + iy * Width() + ix); const float* buf = static_cast<const float*>(m_buffer->GetBuffer()); for (size_t c = 0; c < Component(); c++) { ret[c] = buf[idx + c]; } }
DungeonData MysteryDungeonMaker::DungeonData() { ::DungeonData dData(dungeonSize->DungeonHeight(), dungeonSize->DungeonWidth()); const size_t rowNum = dungeonSize->DungeonHeight(); const size_t columnNum = dungeonSize->DungeonWidth(); for (size_t i = 0; i < rowNum; i++) { for (size_t j = 0; j < columnNum; j++) { dData.AddType(Component(i, j), tiles[i][j]); } } return dData; }
CollisionComponent* CollisionComponent::Factory(GameObject &gameObject, Collider *collider) { if (nullptr == collider) { TransformComponent *transform = static_cast<TransformComponent*>(gameObject.FilterComponent("Transform").front().get()); SDL_Rect pos = transform->GetPosition(); SDL_Rect *scale = transform->GetScale(); collider = new CircleCollider(Vector2D((float)pos.x, (float)pos.y), (scale->h/2)); } CollisionComponent *collisionComponent = new CollisionComponent(collider); gameObject.RegisterComponent(Component(new CollisionComponent(collider))); return collisionComponent; }
void CRewardInfo::loadComponents(std::vector<Component> & comps, const CGHeroInstance * h) const { for (auto comp : extraComponents) comps.push_back(comp); if (gainedExp) { comps.push_back(Component( Component::EXPERIENCE, 0, h->calculateXp(gainedExp), 0)); } if (gainedLevels) comps.push_back(Component(Component::EXPERIENCE, 0, gainedLevels, 0)); if (manaDiff) comps.push_back(Component(Component::PRIM_SKILL, 5, manaDiff, 0)); for (size_t i=0; i<primary.size(); i++) { if (primary[i] != 0) comps.push_back(Component(Component::PRIM_SKILL, i, primary[i], 0)); } for (auto & entry : secondary) comps.push_back(Component(Component::SEC_SKILL, entry.first, entry.second, 0)); for (auto & entry : artifacts) comps.push_back(Component(Component::ARTIFACT, entry, 1, 0)); for (auto & entry : spells) comps.push_back(Component(Component::SPELL, entry, 1, 0)); for (auto & entry : creatures) comps.push_back(Component(Component::CREATURE, entry.type->idNumber, entry.count, 0)); for (size_t i=0; i<resources.size(); i++) { if (resources[i] !=0) comps.push_back(Component(Component::RESOURCE, i, resources[i], 0)); } }
/** * Show the necromancy dialog with information about units raised. * @param raisedStack Pair where the first element represents ID of the raised creature * and the second element the amount. */ void CGHeroInstance::showNecromancyDialog(const CStackBasicDescriptor &raisedStack) const { InfoWindow iw; iw.soundID = soundBase::pickup01 + cb->gameState()->getRandomGenerator().nextInt(6); iw.player = tempOwner; iw.components.push_back(Component(raisedStack)); if (raisedStack.count > 1) // Practicing the dark arts of necromancy, ... (plural) { iw.text.addTxt(MetaString::GENERAL_TXT, 145); iw.text.addReplacement(raisedStack.count); } else // Practicing the dark arts of necromancy, ... (singular) { iw.text.addTxt(MetaString::GENERAL_TXT, 146); } iw.text.addReplacement(raisedStack); cb->showInfoDialog(&iw); }
void CUrl::ConstructL(const TDesC& aUrl) // // Non-trivial c'tor - can be used for all general urls { // Stripe any leading whitespace TPtrC url = aUrl; while( url.Locate(' ') == 0 ) { // Remove the leading whitespace -> set pointer to second character url.Set(url.Mid(1)); } iUrlDes = url.AllocL(); // Check to see if there's ':' at start of aUrl TInt colonPos = aUrl.Locate(':'); if (colonPos == 0) User::Leave(EWapErrCorruptUrl); TPtrC scheme(Component(EUrlScheme)); CheckSchemeValidL(scheme); }