当前位置: 首页>>代码示例>>C++>>正文


C++ QTimer::setTimerType方法代码示例

本文整理汇总了C++中QTimer::setTimerType方法的典型用法代码示例。如果您正苦于以下问题:C++ QTimer::setTimerType方法的具体用法?C++ QTimer::setTimerType怎么用?C++ QTimer::setTimerType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QTimer的用法示例。


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

示例1: executeScript


//.........这里部分代码省略.........
    Frame::registerFrameHandler(AUDIO_FRAME_TYPE, [this, &scriptedAvatar](Frame::ConstPointer frame) {
        static quint16 audioSequenceNumber{ 0 };

        QByteArray audio(frame->data);

        if (_isNoiseGateEnabled) {
            int16_t* samples = reinterpret_cast<int16_t*>(audio.data());
            int numSamples = AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL;
            _audioGate.render(samples, samples, numSamples);
        }

        computeLoudness(&audio, scriptedAvatar);

        // state machine to detect gate opening and closing
        bool audioGateOpen = (scriptedAvatar->getAudioLoudness() != 0.0f);
        bool openedInLastBlock = !_audioGateOpen && audioGateOpen;  // the gate just opened
        bool closedInLastBlock = _audioGateOpen && !audioGateOpen;  // the gate just closed
        _audioGateOpen = audioGateOpen;
        Q_UNUSED(openedInLastBlock);

        // the codec must be flushed to silence before sending silent packets,
        // so delay the transition to silent packets by one packet after becoming silent.
        auto packetType = PacketType::MicrophoneAudioNoEcho;
        if (!audioGateOpen && !closedInLastBlock) {
            packetType = PacketType::SilentAudioFrame;
        }

        Transform audioTransform;
        auto headOrientation = scriptedAvatar->getHeadOrientation();
        audioTransform.setTranslation(scriptedAvatar->getWorldPosition());
        audioTransform.setRotation(headOrientation);

        QByteArray encodedBuffer;
        if (_encoder) {
            _encoder->encode(audio, encodedBuffer);
        } else {
            encodedBuffer = audio;
        }

        AbstractAudioInterface::emitAudioPacket(encodedBuffer.data(), encodedBuffer.size(), audioSequenceNumber, false, 
            audioTransform, scriptedAvatar->getWorldPosition(), glm::vec3(0),
            packetType, _selectedCodecName);
    });

    auto avatarHashMap = DependencyManager::set<AvatarHashMap>();
    _scriptEngine->registerGlobalObject("AvatarList", avatarHashMap.data());

    auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
    packetReceiver.registerListener(PacketType::BulkAvatarData, avatarHashMap.data(), "processAvatarDataPacket");
    packetReceiver.registerListener(PacketType::KillAvatar, avatarHashMap.data(), "processKillAvatar");
    packetReceiver.registerListener(PacketType::AvatarIdentity, avatarHashMap.data(), "processAvatarIdentityPacket");

    // register ourselves to the script engine
    _scriptEngine->registerGlobalObject("Agent", this);

    _scriptEngine->registerGlobalObject("SoundCache", DependencyManager::get<SoundCache>().data());
    _scriptEngine->registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCache>().data());

    QScriptValue webSocketServerConstructorValue = _scriptEngine->newFunction(WebSocketServerClass::constructor);
    _scriptEngine->globalObject().setProperty("WebSocketServer", webSocketServerConstructorValue);

    auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();

    _scriptEngine->registerGlobalObject("EntityViewer", &_entityViewer);

    _scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter,
        LocationScriptingInterface::locationSetter);

    auto recordingInterface = DependencyManager::get<RecordingScriptingInterface>();
    _scriptEngine->registerGlobalObject("Recording", recordingInterface.data());

    entityScriptingInterface->init();

    _entityViewer.init();

    entityScriptingInterface->setEntityTree(_entityViewer.getTree());

    DependencyManager::set<AssignmentParentFinder>(_entityViewer.getTree());

    QMetaObject::invokeMethod(&_avatarAudioTimer, "start");

    // Agents should run at 45hz
    static const int AVATAR_DATA_HZ = 45;
    static const int AVATAR_DATA_IN_MSECS = MSECS_PER_SECOND / AVATAR_DATA_HZ;
    QTimer* avatarDataTimer = new QTimer(this);
    connect(avatarDataTimer, &QTimer::timeout, this, &Agent::processAgentAvatar);
    avatarDataTimer->setSingleShot(false);
    avatarDataTimer->setInterval(AVATAR_DATA_IN_MSECS);
    avatarDataTimer->setTimerType(Qt::PreciseTimer);
    avatarDataTimer->start();

    _scriptEngine->run();

    Frame::clearFrameHandler(AUDIO_FRAME_TYPE);
    Frame::clearFrameHandler(AVATAR_FRAME_TYPE);

    DependencyManager::destroy<RecordingScriptingInterface>();

    setFinished(true);
}
开发者ID:SeijiEmery,项目名称:hifi,代码行数:101,代码来源:Agent.cpp


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