• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ std::unordered_map类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中std::unordered_map的典型用法代码示例。如果您正苦于以下问题:C++ unordered_map类的具体用法?C++ unordered_map怎么用?C++ unordered_map使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了unordered_map类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: ic


//.........这里部分代码省略.........

            sinfo.is_patched = true;
            sinfo.decision_path = decision_path;
            return &sinfo.entry;
        }
    }

    for (int i = 0; i < getNumSlots(); i++) {
        SlotInfo &sinfo = slots[i];
        if (sinfo.is_patched && sinfo.decision_path != decision_path) {
            continue;
        }

        if (VERBOSITY()) {
            printf("committing %s icentry to in-use slot %d at %p\n", debug_name, i, start_addr);
        }

        sinfo.is_patched = true;
        sinfo.decision_path = decision_path;
        return &sinfo.entry;
    }
    if (VERBOSITY()) printf("not committing %s icentry since it is not compatible (%lx)\n", debug_name, decision_path);
    return NULL;
}



ICInfo::ICInfo(void* start_addr, void* continue_addr, StackInfo stack_info, int num_slots, int slot_size, llvm::CallingConv::ID calling_conv, const std::unordered_set<int> &live_outs, assembler::GenericRegister return_register) : stack_info(stack_info), num_slots(num_slots), slot_size(slot_size), calling_conv(calling_conv), live_outs(live_outs.begin(), live_outs.end()), return_register(return_register), start_addr(start_addr), continue_addr(continue_addr) {
    for (int i = 0; i < num_slots; i++) {
        slots.push_back(SlotInfo(this, i));
    }
}

static std::unordered_map<void*, ICInfo*> ics_by_return_addr;
void registerCompiledPatchpoint(uint8_t* start_addr, PatchpointSetupInfo* pp, StackInfo stack_info, std::unordered_set<int> live_outs) {
    int size = pp->totalSize();
    uint8_t* end_addr = start_addr + size;
    void* slowpath_addr = end_addr;

    uint8_t* rtn_addr;

    assembler::GenericRegister return_register;
    assert(pp->getCallingConvention() == llvm::CallingConv::C || pp->getCallingConvention() == llvm::CallingConv::PreserveAll);
    if (pp->hasReturnValue()) {
        static const int DWARF_RAX = 0;
        // It's possible that the return value doesn't get used, in which case
        // we can avoid copying back into RAX at the end
        if (live_outs.count(DWARF_RAX)) {
            live_outs.erase(DWARF_RAX);
        }

        // TODO we only need to do this if 0 was in live_outs, since if it wasn't, that indicates
        // the return value won't be used and we can optimize based on that.
        return_register = assembler::RAX;
    }

    if (pp->getCallingConvention() != llvm::CallingConv::C) {
        uint8_t* slowpath_start = start_addr + pp->num_slots * pp->slot_size;
        rtn_addr = initializePatchpoint2(start_addr, slowpath_start, (uint8_t*)end_addr, stack_info, live_outs);
    } else {
        //for (int regnum : live_outs) {
            //// LLVM has a bug where it incorrectly determines the set of liveouts;
            //// so far it only seems to add additional ones to the set, which should 
            //// hopefully be safe.
            //// Otherwise, I'd like to test here that it's only the registers
            //// that we'd expect to be saved...
开发者ID:Bassem450,项目名称:pyston,代码行数:67,代码来源:icinfo.cpp


示例2: qDebug

void BakerCLI::bakeFile(QUrl inputUrl, const QString& outputPath, const QString& type) {

    // if the URL doesn't have a scheme, assume it is a local file
    if (inputUrl.scheme() != "http" && inputUrl.scheme() != "https" && inputUrl.scheme() != "ftp" && inputUrl.scheme() != "file") {
        inputUrl = QUrl::fromLocalFile(inputUrl.toString());
    }

    qDebug() << "Baking file type: " << type;

    static const QString MODEL_EXTENSION { "fbx" };
    static const QString SCRIPT_EXTENSION { "js" };

    // check what kind of baker we should be creating
    bool isFBX = type == MODEL_EXTENSION;
    bool isScript = type == SCRIPT_EXTENSION;

    // If the type doesn't match the above, we assume we have a texture, and the type specified is the
    // texture usage type (albedo, cubemap, normals, etc.)
    auto url = inputUrl.toDisplayString();
    auto idx = url.lastIndexOf('.');
    auto extension = idx >= 0 ? url.mid(idx + 1).toLower() : "";
    bool isSupportedImage = QImageReader::supportedImageFormats().contains(extension.toLatin1());

    _outputPath = outputPath;

    // create our appropiate baker
    if (isFBX) {
        _baker = std::unique_ptr<Baker> {
            new FBXBaker(inputUrl,
                         []() -> QThread* { return Oven::instance().getNextWorkerThread(); },
                         outputPath)
        };
        _baker->moveToThread(Oven::instance().getNextWorkerThread());
    } else if (isScript) {
        _baker = std::unique_ptr<Baker> { new JSBaker(inputUrl, outputPath) };
        _baker->moveToThread(Oven::instance().getNextWorkerThread());
    } else if (isSupportedImage) {
        static const std::unordered_map<QString, image::TextureUsage::Type> STRING_TO_TEXTURE_USAGE_TYPE_MAP {
            { "default", image::TextureUsage::DEFAULT_TEXTURE },
            { "strict", image::TextureUsage::STRICT_TEXTURE },
            { "albedo", image::TextureUsage::ALBEDO_TEXTURE },
            { "normal", image::TextureUsage::NORMAL_TEXTURE },
            { "bump", image::TextureUsage::BUMP_TEXTURE },
            { "specular", image::TextureUsage::SPECULAR_TEXTURE },
            { "metallic", image::TextureUsage::METALLIC_TEXTURE },
            { "roughness", image::TextureUsage::ROUGHNESS_TEXTURE },
            { "gloss", image::TextureUsage::GLOSS_TEXTURE },
            { "emissive", image::TextureUsage::EMISSIVE_TEXTURE },
            { "cube", image::TextureUsage::CUBE_TEXTURE },
            { "occlusion", image::TextureUsage::OCCLUSION_TEXTURE },
            { "scattering", image::TextureUsage::SCATTERING_TEXTURE },
            { "lightmap", image::TextureUsage::LIGHTMAP_TEXTURE },
        };

        auto it = STRING_TO_TEXTURE_USAGE_TYPE_MAP.find(type);
        if (it == STRING_TO_TEXTURE_USAGE_TYPE_MAP.end()) {
            qCDebug(model_baking) << "Unknown texture usage type:" << type;
            QCoreApplication::exit(OVEN_STATUS_CODE_FAIL);
        }
        _baker = std::unique_ptr<Baker> { new TextureBaker(inputUrl, it->second, outputPath) };
        _baker->moveToThread(Oven::instance().getNextWorkerThread());
    } else {
        qCDebug(model_baking) << "Failed to determine baker type for file" << inputUrl;
        QCoreApplication::exit(OVEN_STATUS_CODE_FAIL);
        return;
    }

    // invoke the bake method on the baker thread
    QMetaObject::invokeMethod(_baker.get(), "bake");

    // make sure we hear about the results of this baker when it is done
    connect(_baker.get(), &Baker::finished, this, &BakerCLI::handleFinishedBaker);
}
开发者ID:Menithal,项目名称:hifi,代码行数:73,代码来源:BakerCLI.cpp


示例3: UpdateAI


//.........这里部分代码省略.........
                            Stomach_Map[(*i)->getUnitGuid()] = false;   //Outside stomach

                        //Spawn 2 flesh tentacles
                        FleshTentaclesKilled = 0;

                        //Spawn flesh tentacle
                        for (uint8 i = 0; i < 2; i++)
                        {
                            Creature* spawned = me->SummonCreature(NPC_FLESH_TENTACLE, FleshTentaclePos[i], TEMPSUMMON_CORPSE_DESPAWN);
                            if (!spawned)
                                ++FleshTentaclesKilled;
                        }

                        PhaseTimer = 0;
                    } else PhaseTimer -= diff;

                    break;

                //Body Phase
                case PHASE_CTHUN_STOMACH:
                    //Remove Target field
                    me->SetTarget(ObjectGuid::Empty);

                    //Weaken
                    if (FleshTentaclesKilled > 1)
                    {
                        instance->SetData(DATA_CTHUN_PHASE, PHASE_CTHUN_WEAK);

                        Talk(EMOTE_WEAKENED);
                        PhaseTimer = 45000;

                        DoCast(me, SPELL_PURPLE_COLORATION, true);

                        std::unordered_map<ObjectGuid, bool>::iterator i = Stomach_Map.begin();

                        //Kick all players out of stomach
                        while (i != Stomach_Map.end())
                        {
                            //Check for valid player
                            Unit* unit = ObjectAccessor::GetUnit(*me, i->first);

                            //Only move units in stomach
                            if (unit && i->second == true)
                            {
                                //Teleport each player out
                                DoTeleportPlayer(unit, me->GetPositionX(), me->GetPositionY(), me->GetPositionZ() + 10, float(rand32() % 6));

                                //Cast knockback on them
                                DoCast(unit, SPELL_EXIT_STOMACH_KNOCKBACK, true);

                                //Remove the acid debuff
                                unit->RemoveAurasDueToSpell(SPELL_DIGESTIVE_ACID);

                                i->second = false;
                            }
                            ++i;
                        }

                        return;
                    }

                    //Stomach acid
                    if (StomachAcidTimer <= diff)
                    {
                        //Apply aura to all players in stomach
                        std::unordered_map<ObjectGuid, bool>::iterator i = Stomach_Map.begin();
开发者ID:Aravu,项目名称:Talador-Project,代码行数:67,代码来源:boss_cthun.cpp


示例4: convert_talk_topic

std::string convert_talk_topic( talk_topic_enum const old_value )
{
    static const std::unordered_map<talk_topic_enum, std::string> talk_topic_enum_mapping = { {
// This macro creates the appropriate new names (as string) for each enum value, so one does not
// have to repeat so much (e.g. 'WRAP(TALK_ARSONIST)' instead of '{ TALK_ARSONIST, "TALK_ARSONIST" }')
// It also ensures that each name is exactly as the name of the enum value.
#define WRAP(value) { value, #value }
 WRAP(TALK_NONE),
 WRAP(TALK_DONE),
 WRAP(TALK_GUARD),
 WRAP(TALK_MISSION_LIST),
 WRAP(TALK_MISSION_LIST_ASSIGNED),
 WRAP(TALK_MISSION_DESCRIBE),
 WRAP(TALK_MISSION_OFFER),
 WRAP(TALK_MISSION_ACCEPTED),
 WRAP(TALK_MISSION_REJECTED),
 WRAP(TALK_MISSION_ADVICE),
 WRAP(TALK_MISSION_INQUIRE),
 WRAP(TALK_MISSION_SUCCESS),
 WRAP(TALK_MISSION_SUCCESS_LIE),
 WRAP(TALK_MISSION_FAILURE),
 WRAP(TALK_MISSION_REWARD),
 WRAP(TALK_EVAC_MERCHANT),
 WRAP(TALK_EVAC_MERCHANT_NEW),
 WRAP(TALK_EVAC_MERCHANT_PLANS),
 WRAP(TALK_EVAC_MERCHANT_PLANS2),
 WRAP(TALK_EVAC_MERCHANT_PLANS3),
 WRAP(TALK_EVAC_MERCHANT_WORLD),
 WRAP(TALK_EVAC_MERCHANT_HORDES),
 WRAP(TALK_EVAC_MERCHANT_PRIME_LOOT),
 WRAP(TALK_EVAC_MERCHANT_ASK_JOIN),
 WRAP(TALK_EVAC_MERCHANT_NO),
 WRAP(TALK_EVAC_MERCHANT_HELL_NO),
 WRAP(TALK_FREE_MERCHANT_STOCKS),
 WRAP(TALK_FREE_MERCHANT_STOCKS_NEW),
 WRAP(TALK_FREE_MERCHANT_STOCKS_WHY),
 WRAP(TALK_FREE_MERCHANT_STOCKS_ALL),
 WRAP(TALK_FREE_MERCHANT_STOCKS_JERKY),
 WRAP(TALK_FREE_MERCHANT_STOCKS_CORNMEAL),
 WRAP(TALK_FREE_MERCHANT_STOCKS_FLOUR),
 WRAP(TALK_FREE_MERCHANT_STOCKS_SUGAR),
 WRAP(TALK_FREE_MERCHANT_STOCKS_WINE),
 WRAP(TALK_FREE_MERCHANT_STOCKS_BEER),
 WRAP(TALK_FREE_MERCHANT_STOCKS_SMMEAT),
 WRAP(TALK_FREE_MERCHANT_STOCKS_SMFISH),
 WRAP(TALK_FREE_MERCHANT_STOCKS_OIL),
 WRAP(TALK_FREE_MERCHANT_STOCKS_DELIVERED),
 WRAP(TALK_EVAC_GUARD1),
 WRAP(TALK_EVAC_GUARD1_PLACE),
 WRAP(TALK_EVAC_GUARD1_GOVERNMENT),
 WRAP(TALK_EVAC_GUARD1_TRADE),
 WRAP(TALK_EVAC_GUARD1_JOIN),
 WRAP(TALK_EVAC_GUARD1_JOIN2),
 WRAP(TALK_EVAC_GUARD1_JOIN3),
 WRAP(TALK_EVAC_GUARD1_ATTITUDE),
 WRAP(TALK_EVAC_GUARD1_JOB),
 WRAP(TALK_EVAC_GUARD1_OLDGUARD),
 WRAP(TALK_EVAC_GUARD1_BYE),
 WRAP(TALK_EVAC_GUARD2),
 WRAP(TALK_EVAC_GUARD2_NEW),
 WRAP(TALK_EVAC_GUARD2_RULES),
 WRAP(TALK_EVAC_GUARD2_RULES_BASEMENT),
 WRAP(TALK_EVAC_GUARD2_WHO),
 WRAP(TALK_EVAC_GUARD2_TRADE),
 WRAP(TALK_EVAC_GUARD3),
 WRAP(TALK_EVAC_GUARD3_NEW),
 WRAP(TALK_EVAC_GUARD3_RULES),
 WRAP(TALK_EVAC_GUARD3_HIDE1),
 WRAP(TALK_EVAC_GUARD3_HIDE2),
 WRAP(TALK_EVAC_GUARD3_WASTE),
 WRAP(TALK_EVAC_GUARD3_DEAD),
 WRAP(TALK_EVAC_GUARD3_HOSTILE),
 WRAP(TALK_EVAC_GUARD3_INSULT),
 WRAP(TALK_EVAC_HUNTER),
 WRAP(TALK_EVAC_HUNTER_SMELL),
 WRAP(TALK_EVAC_HUNTER_DO),
 WRAP(TALK_EVAC_HUNTER_LIFE),
 WRAP(TALK_EVAC_HUNTER_HUNT),
 WRAP(TALK_EVAC_HUNTER_SALE),
 WRAP(TALK_EVAC_HUNTER_ADVICE),
 WRAP(TALK_EVAC_HUNTER_BYE),
 WRAP(TALK_OLD_GUARD_REP),
 WRAP(TALK_OLD_GUARD_REP_NEW),
 WRAP(TALK_OLD_GUARD_REP_NEW_DOING),
 WRAP(TALK_OLD_GUARD_REP_NEW_DOWNSIDE),
 WRAP(TALK_OLD_GUARD_REP_WORLD),
 WRAP(TALK_OLD_GUARD_REP_WORLD_2NDFLEET),
 WRAP(TALK_OLD_GUARD_REP_WORLD_FOOTHOLDS),
 WRAP(TALK_OLD_GUARD_REP_ASK_JOIN),
 WRAP(TALK_ARSONIST),
 WRAP(TALK_ARSONIST_NEW),
 WRAP(TALK_ARSONIST_DOING),
 WRAP(TALK_ARSONIST_DOING_REBAR),
 WRAP(TALK_ARSONIST_WORLD),
 WRAP(TALK_ARSONIST_WORLD_OPTIMISTIC),
 WRAP(TALK_ARSONIST_JOIN),
 WRAP(TALK_ARSONIST_MUTATION),
 WRAP(TALK_ARSONIST_MUTATION_INSULT),
 WRAP(TALK_SCAVENGER_MERC),
 WRAP(TALK_SCAVENGER_MERC_NEW),
//.........这里部分代码省略.........
开发者ID:ProfoundDarkness,项目名称:Cataclysm-DDA,代码行数:101,代码来源:savegame_legacy.cpp


示例5: assert

std::unordered_set<TileID, TileID::Hash>
AnnotationManager::addTileFeature(const uint32_t annotationID,
                                  const AnnotationSegments& segments,
                                  const std::vector<std::vector<vec2<double>>>& projectedFeature,
                                  const AnnotationType& type,
                                  const StyleProperties& styleProperties,
                                  const std::unordered_map<std::string, std::string>& featureProperties,
                                  const std::string layerId,
                                  const uint8_t maxZoom) {

    assert(type != AnnotationType::Any);

    // track the annotation global ID and its original geometry
    auto anno_it = annotations.emplace(annotationID,
        std::make_unique<Annotation>(type, layerId, segments, styleProperties));

    std::unordered_set<TileID, TileID::Hash> affectedTiles;

    if (type == AnnotationType::Shape) {

        orderedShapeAnnotations.push_back(annotationID);

        using namespace mapbox::util::geojsonvt;

        const double z2 = 1 << maxZoom;
        const double baseTolerance = 3;
        const double extent = 4096;

        const double tolerance = baseTolerance / (z2 * extent);

        ProjectedGeometryContainer rings;

        std::vector<LonLat> points;

        for (size_t i = 0; i < segments[0].size(); ++i) { // first segment for now (no holes)
            const double constraintedLatitude = ::fmin(::fmax(segments[0][i].latitude, -util::LATITUDE_MAX), util::LATITUDE_MAX);
            points.push_back(LonLat(segments[0][i].longitude, constraintedLatitude));
        }

        ProjectedFeatureType featureType;

        if (styleProperties.is<FillProperties>()) {
            featureType = ProjectedFeatureType::Polygon;

            if (points.front().lon != points.back().lon || points.front().lat != points.back().lat) {
                points.push_back(LonLat(points.front().lon, points.front().lat));
            }
        } else {
            featureType = ProjectedFeatureType::LineString;
        }

        ProjectedGeometryContainer ring = Convert::project(points, tolerance);

        rings.members.push_back(ring);

        std::vector<ProjectedFeature> features;

        Tags tags;
        tags.insert(featureProperties.begin(), featureProperties.end());

        features.push_back(Convert::create(tags, featureType, rings));

        shapeTilers.emplace(annotationID, std::make_unique<GeoJSONVT>(features, maxZoom, 4, 100, 10));

    } else {

        // side length of map at max zoom
        double z2 = 1 << maxZoom;

        const double extent = 4096;

        uint32_t x = 0;
        uint32_t y = 0;

        for (int8_t z = maxZoom; z >= 0; z--) {

            std::unordered_map<TileID, GeometryCollection, TileID::Hash> featureTiles;

            if (type == AnnotationType::Point) {
                auto& pp = projectedFeature[0][0];

                x = pp.x * z2;
                y = pp.y * z2;

                const Coordinate coordinate(extent * (pp.x * z2 - x), extent * (pp.y * z2 - y));

                GeometryCollection geometries = {{ {{ coordinate }} }};

                featureTiles.emplace(TileID(z, x, y, z), geometries);
            } else {
                for (size_t l = 0; l < projectedFeature.size(); ++l) {
                    for (size_t p = 0; p < projectedFeature[l].size(); ++p) {

                        auto& pp = projectedFeature[l][p];

                        x = pp.x * z2;
                        y = pp.y * z2;

                        const Coordinate coordinate(extent * (pp.x * z2 - x), extent * (pp.y * z2 - y));

//.........这里部分代码省略.........
开发者ID:TrueFlow,项目名称:mapbox-gl-native,代码行数:101,代码来源:annotation.cpp


示例6: get_tweener

tweener_t get_tweener(std::wstring name)
{
    std::transform(name.begin(), name.end(), name.begin(), std::tolower);

    if(name == L"linear")
        return [](double t, double b, double c, double d) {
        return ease_none(t, b, c, d, std::vector<double>());
    };

    std::vector<double> params;

    static const boost::wregex expr(L"(?<NAME>\\w*)(:(?<V0>\\d+\\.?\\d?))?(:(?<V1>\\d+\\.?\\d?))?"); // boost::regex has no repeated captures?
    boost::wsmatch what;
    if(boost::regex_match(name, what, expr))
    {
        name = what["NAME"].str();
        if(what["V0"].matched)
            params.push_back(boost::lexical_cast<double>(what["V0"].str()));
        if(what["V1"].matched)
            params.push_back(boost::lexical_cast<double>(what["V1"].str()));
    }

    typedef std::function<double(double, double, double, double, const std::vector<double>&)> tween_t;
    static const std::unordered_map<std::wstring, tween_t> tweens = boost::assign::map_list_of
            (L"",					ease_none		   )
            (L"linear",				ease_none		   )
            (L"easenone",			ease_none		   )
            (L"easeinquad",			ease_in_quad	   )
            (L"easeoutquad",		ease_out_quad	   )
            (L"easeinoutquad",		ease_in_out_quad   )
            (L"easeoutinquad",		ease_out_in_quad   )
            (L"easeincubic",		ease_in_cubic	   )
            (L"easeoutcubic",		ease_out_cubic	   )
            (L"easeinoutcubic",		ease_in_out_cubic  )
            (L"easeoutincubic",		ease_out_in_cubic  )
            (L"easeinquart", 		ease_in_quart 	   )
            (L"easeoutquart",		ease_out_quart	   )
            (L"easeinoutquart",		ease_in_out_quart  )
            (L"easeoutinquart",		ease_out_in_quart  )
            (L"easeinquint",		ease_in_quint	   )
            (L"easeoutquint",		ease_out_quint	   )
            (L"easeinoutquint",		ease_in_out_quint  )
            (L"easeoutinquint",		ease_out_in_quint  )
            (L"easeinsine",			ease_in_sine	   )
            (L"easeoutsine",		ease_out_sine	   )
            (L"easeinoutsine",		ease_in_out_sine   )
            (L"easeoutinsine",		ease_out_in_sine   )
            (L"easeinexpo",			ease_in_expo	   )
            (L"easeoutexpo",		ease_out_expo	   )
            (L"easeinoutexpo",		ease_in_out_expo   )
            (L"easeoutinexpo",		ease_out_in_expo   )
            (L"easeincirc",			ease_in_circ	   )
            (L"easeoutcirc",		ease_out_circ	   )
            (L"easeinoutcirc",		ease_in_out_circ   )
            (L"easeoutincirc",		ease_out_in_circ   )
            (L"easeinelastic",		ease_in_elastic	   )
            (L"easeoutelastic",		ease_out_elastic   )
            (L"easeinoutelastic",	ease_in_out_elastic)
            (L"easeoutinelastic",	ease_out_in_elastic)
            (L"easeinback",			ease_in_back	   )
            (L"easeoutback",		ease_out_back	   )
            (L"easeinoutback",		ease_in_out_back   )
            (L"easeoutintback",		ease_out_int_back  )
            (L"easeoutbounce",		ease_out_bounce	   )
            (L"easeinbounce",		ease_in_bounce	   )
            (L"easeinoutbounce",	ease_in_out_bounce )
            (L"easeoutinbounce",	ease_out_in_bounce );

    auto it = tweens.find(name);
    if(it == tweens.end())
        it = tweens.find(L"linear");

    return [=](double t, double b, double c, double d)
    {
        return it->second(t, b, c, d, params);
    };
};
开发者ID:Mistobaan,项目名称:CasparCG,代码行数:77,代码来源:tweener.cpp


示例7: tail

namespace VM
{
	#define COLLISION_PADDING 0.1f

	std::vector<Script> scripts;
	std::unordered_map<std::string, scriptID> loadedScripts;

	ScriptStack::ScriptStack()
		: tail(0)
	{
		stack = new unsigned char[ptr_max];
		clear();
	}

	ScriptStack::~ScriptStack()
	{
		delete [] stack;
	}

	void ScriptStack::push(unsigned char* data, ptr size)
	{
		assert ( (tail+size) < ptr_max);
		memcpy(stack + tail, data, size);
		tail += size;
	}

	unsigned char* ScriptStack::get(ptr index)
	{
		assert( index < tail );
		return &stack[index];
	}

	void ScriptStack::clear()
	{
		tail = 0;
		memset(stack, 0xCD, ptr_max);
	}


	// FUNCTIONS ////////////////////////////////////////////////////////////////////////
	scriptID AddScript(const Script& script)
	{
		scriptID scriptid = scripts.size();
		scripts.push_back(Script());
		Script& newScript = scripts.back();

		CopyScript(newScript, script);

		return scriptid;
	}
	////////////////////////////////////////////////////////////////////////////////////////
	const Script& GetScript(scriptID id)
	{
		return scripts[id];
	}
	////////////////////////////////////////////////////////////////////////////////////////
	scriptID LoadCompiledScript(const std::string& scriptFile)
	{
		std::unordered_map<std::string, scriptID>::iterator scriptIter = loadedScripts.find(scriptFile);
		if (scriptIter != loadedScripts.end())
		{
			return loadedScripts[scriptFile];
		}
		std::fstream file;
		size_t dataSize;
		unsigned char code;
		unsigned char data[256];
		file.open(scriptFile, std::ios::in | std::ios::binary);

		scriptID newscriptID = scripts.size();
		scripts.push_back(Script());
		Script& newScript = scripts.back();

		size_t scriptSize;
		file.read((char*)&scriptSize, sizeof(size_t));
		newScript.reserve(scriptSize);

		for(size_t i = 0; i < scriptSize; ++i)
		{
			file.read((char*) &dataSize, sizeof(size_t));
			file.read((char*) &code, sizeof(unsigned char));
			file.read((char*) data, sizeof(unsigned char) * dataSize);

			newScript.push_back( Instruction(code, &data[0], dataSize) );
		}

		loadedScripts[scriptFile] = newscriptID;

		return newscriptID;
	}

	/////////////////////////////////////////////////////////////////////////////////////
	void SaveCompiledScript(const std::string& scriptFile, scriptID id)
	{
		std::fstream file;
		file.open(scriptFile, std::ios::out | std::ios::binary);

		Script script = scripts[id];

		Script::const_iterator it = script.begin();
//.........这里部分代码省略.........
开发者ID:Foxious,项目名称:phEngine,代码行数:101,代码来源:ActorScript.cpp


示例8: check_empty_map

bool TestHelpers::check_empty_map(const std::unordered_map<std::string,int64_t> & m) {
    return m.empty();
}
开发者ID:Kleist,项目名称:djinni,代码行数:3,代码来源:test_helpers.cpp


示例9: INITIAL_STACK_SIZE

namespace pyston {

static uint64_t next_stack_addr = 0x4270000000L;
static std::deque<uint64_t> available_addrs;

// There should be a better way of getting this:
#define PAGE_SIZE 4096

#define INITIAL_STACK_SIZE (8 * PAGE_SIZE)
#define STACK_REDZONE_SIZE PAGE_SIZE
#define MAX_STACK_SIZE (4 * 1024 * 1024)

static std::unordered_map<void*, BoxedGenerator*> s_generator_map;
static_assert(THREADING_USE_GIL, "have to make the generator map thread safe!");

class RegisterHelper {
private:
    void* frame_addr;

public:
    RegisterHelper(BoxedGenerator* generator, void* frame_addr) : frame_addr(frame_addr) {
        s_generator_map[frame_addr] = generator;
    }
    ~RegisterHelper() {
        assert(s_generator_map.count(frame_addr));
        s_generator_map.erase(frame_addr);
    }
};

static void freeGeneratorStack(BoxedGenerator* g) {
    if (g->stack_begin == NULL)
        return;

    available_addrs.push_back((uint64_t)g->stack_begin);
    // Limit the number of generator stacks we keep around:
    if (available_addrs.size() > 5) {
        uint64_t addr = available_addrs.front();
        available_addrs.pop_front();
        int r = munmap((void*)(addr - MAX_STACK_SIZE), MAX_STACK_SIZE);
        assert(r == 0);
    }

    g->stack_begin = NULL;
}

Context* getReturnContextForGeneratorFrame(void* frame_addr) {
    BoxedGenerator* generator = s_generator_map[frame_addr];
    assert(generator);
    return generator->returnContext;
}

void generatorEntry(BoxedGenerator* g) {
    {
        assert(g->cls == generator_cls);
        assert(g->function->cls == function_cls);

        threading::pushGenerator(g, g->stack_begin, g->returnContext);
        try {
            RegisterHelper context_registerer(g, __builtin_frame_address(0));

            // call body of the generator
            BoxedFunctionBase* func = g->function;

            Box** args = g->args ? &g->args->elts[0] : nullptr;
            callCLFunc(func->f, nullptr, func->f->numReceivedArgs(), func->closure, g, func->globals, g->arg1, g->arg2,
                       g->arg3, args);
        } catch (ExcInfo e) {
            // unhandled exception: propagate the exception to the caller
            g->exception = e;
        }

        // we returned from the body of the generator. next/send/throw will notify the caller
        g->entryExited = true;
        threading::popGenerator();
    }
    swapContext(&g->context, g->returnContext, 0);
}

Box* generatorIter(Box* s) {
    return s;
}

// called from both generatorHasNext and generatorSend/generatorNext (but only if generatorHasNext hasn't been called)
static void generatorSendInternal(BoxedGenerator* self, Box* v) {
    STAT_TIMER(t0, "us_timer_generator_switching", 0);

    if (self->running)
        raiseExcHelper(ValueError, "generator already executing");

    // check if the generator already exited
    if (self->entryExited) {
        freeGeneratorStack(self);
        raiseExcHelper(StopIteration, (const char*)nullptr);
    }

    self->returnValue = v;
    self->running = true;

#if STAT_TIMERS
    if (!self->prev_stack)
//.........这里部分代码省略.........
开发者ID:rowhit,项目名称:pyston,代码行数:101,代码来源:generator.cpp


示例10: addStartupOpts

void CarbonRouterInstanceBase::addStartupOpts(
    std::unordered_map<std::string, std::string> additionalOpts) {
  additionalStartupOpts_.insert(additionalOpts.begin(), additionalOpts.end());
}
开发者ID:zmyer,项目名称:mcrouter,代码行数:4,代码来源:CarbonRouterInstanceBase.cpp


示例11: HandleContacts

namespace GameEngine{
	//Initialise static attributes to null{0}
	btDynamicsWorld* PhysicsEngine::_world = 0;
	btDefaultCollisionConfiguration* PhysicsEngine::_config = 0;
	btCollisionDispatcher* PhysicsEngine::_dispatcher = 0;
	btBroadphaseInterface* PhysicsEngine::_broadphase = 0;
	btSequentialImpulseConstraintSolver* PhysicsEngine::_solver = 0;
	std::list<btRigidBody*> PhysicsEngine::_rigidBodies = std::list<btRigidBody*>();

	std::unordered_map<Entity*, std::set<Entity*>> contacts;

	bool HandleContacts(btManifoldPoint& point, btCollisionObject* body0, btCollisionObject* body1){
		//Get the 2 entities involved by accessing the user pointer of the bodies in contact
		Entity* entity0 = (Entity*)body0->getUserPointer();
		Entity* entity1 = (Entity*)body1->getUserPointer();

		// check if entity0 is already in map
		auto found = contacts.find(entity0);
		if(found != contacts.end()){
			//Entity in map. Add entity2 to the set mapped to it
			//Sets don't allow duplicates, so value won't be added if it already exists
			found->second.insert(entity1);
		}else{
			//entity1 not in map. Create new set and add entity1
			std::set<Entity*> set;
			set.insert(entity1);
			//add entity0 mapped to the new set in the contacts map
			contacts[entity0] = set;
		}
		return true;
	}

	bool PhysicsEngine::initialise(){
		_config = new btDefaultCollisionConfiguration();
		_dispatcher = new btCollisionDispatcher(_config);
		_broadphase = new btAxisSweep3(btVector3(-1000, -1000, -1000), btVector3(1000, 1000, 1000));
		_solver = new btSequentialImpulseConstraintSolver();
		_world = new btDiscreteDynamicsWorld(_dispatcher, _broadphase, _solver, _config);

		//set the collision processed callback
		gContactProcessedCallback = (ContactProcessedCallback)HandleContacts;
		
		//could check everything's ok but just return true for now
		return true;
	}

	bool PhysicsEngine::update(float deltaTime){
		_world->stepSimulation(deltaTime, 60);

		//iterate across the contacts map
		for(auto contactsIter = contacts.begin(); contactsIter!=contacts.end(); ++contactsIter){
			//get the entity key from  teh current entry in the map
			Entity* collider0 = contactsIter->first;
			//get the set of colliders from the current entry in the map
			std::set<Entity*>& set = contactsIter->second;
			//iterate thru all the entities in the set
			for(auto entityIter = set.begin(); entityIter!=set.end(); ++entityIter){
				// get the other colider from the iterator
				Entity* collider1 = *entityIter;
				//create 2 messages - one for collider and one for the entity being hit
				Message msg1(collider0, "COLLISION", collider1);
				Message msg2(collider1, "COLLISION", collider0);
				//dispatch teh messages
				MessageHandler::sendMessage(msg1);
				MessageHandler::sendMessage(msg2);
			}
		}
		//empty the contacts map ready for next time
		contacts.clear();

		//for now
		return true;
	}

	void PhysicsEngine::shutdown(){
		//remove all  rigid bodies
		for(auto iter = _rigidBodies.begin(); iter != _rigidBodies.end(); ++iter){
			//remove from world simulation
			_world->removeRigidBody(*iter);
			//delete from memory
			delete *iter;
			//set pointer to null{0}
			*iter = 0;
		}
		//now empty the list
		_rigidBodies.clear();

		//start deleting the physics components
		delete _world;
		_world = 0;
		delete _solver;
		_solver = 0;
		delete _dispatcher;
		_dispatcher = 0;
		delete _broadphase;
		_broadphase = 0;
		delete _config;
		_config = 0;
		//Physics now shutdown
	}
//.........这里部分代码省略.........
开发者ID:00Dave,项目名称:games-engineering-project,代码行数:101,代码来源:PhysicsEngine.cpp


示例12: getICInfo

ICInfo* getICInfo(void* rtn_addr) {
    std::unordered_map<void*, ICInfo*>::iterator it = ics_by_return_addr.find(rtn_addr);
    if (it == ics_by_return_addr.end())
        return NULL;
    return it->second;
}
开发者ID:Bassem450,项目名称:pyston,代码行数:6,代码来源:icinfo.cpp


示例13: THDRegisterCudaStream

void THDRegisterCudaStream(cudaStream_t stream) {
  streamIdMap.emplace(stream, nextStreamId++);
}
开发者ID:gtgalone,项目名称:pytorch,代码行数:3,代码来源:Cuda.cpp


示例14: get

		Obj * get(const Util::StringIdentifier & id)const{
			const auto it = map_idToObj.find(id);
			return it==map_idToObj.end() ? nullptr : it->second.get();
		}
开发者ID:MeisterYeti,项目名称:MinSG,代码行数:4,代码来源:SceneManager.cpp


示例15: is_member

 bool is_member(std::string name)
 {
     return stringTextureMap.find(name) != std::end(name);
 }
开发者ID:Brianmj,项目名称:knu_libs,代码行数:4,代码来源:texture_manager.hpp


示例16: index

 inline const int index(const W& word) {
   return (word_idx.find(word) == word_idx.end()) ? 0 : word_idx[word];
 }
开发者ID:fmof,项目名称:unified-probabilistic-frames,代码行数:3,代码来源:wtm.hpp


示例17: removeObserver

void OnlineFileRequestImpl::removeObserver(FileRequest* req) {
    observers.erase(req);
}
开发者ID:daniel-j-h,项目名称:mapbox-gl-native,代码行数:3,代码来源:online_file_source.cpp


示例18: RegisterDataProvider

EXPORT_CDECL(bool) RegisterDataProvider(LPCWSTR name, IDataProvider *provider) {
  sDataProviders.emplace(name, provider);
  return true;
}
开发者ID:alur,项目名称:nModules,代码行数:4,代码来源:DataManager.cpp


示例19: hasObservers

bool OnlineFileRequestImpl::hasObservers() const {
    return !observers.empty();
}
开发者ID:daniel-j-h,项目名称:mapbox-gl-native,代码行数:3,代码来源:online_file_source.cpp


示例20: is_running

 /// Check whether the given subsystem is running or not
 bool is_running(const std::string &sub) noexcept {
   return subsystems.count(sub) > 0;
 }
开发者ID:Elzair,项目名称:code,代码行数:4,代码来源:Subsystem.hpp



注:本文中的std::unordered_map类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ std::unordered_multimap类代码示例发布时间:2022-05-31
下一篇:
C++ std::unique_ptr类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap