void AudioInjector::stop() { _shouldStop = true; if (_options.localOnly) { // we're only a local injector, so we can say we are finished right away too setIsFinished(true); } }
Task::Task(time_t deadline, int priority, string description, int cronFreq, bool isFinished, int serialNumber, string group, time_t ft){ // cout<<"newing task"<<endl; setDeadline(deadline); setPriority(priority); setDescription(description); setIsFinished(isFinished); setSerialNumber(serialNumber); setGroup(group); setFinishTime(ft); }
void ModelBaker::checkIfTexturesFinished() { // check if we're done everything we need to do for this model // and emit our finished signal if we're done if (_bakingTextures.isEmpty()) { if (shouldStop()) { // if we're checking for completion but we have errors // that means one or more of our texture baking operations failed if (_pendingErrorEmission) { setIsFinished(true); } return; } else { qCDebug(model_baking) << "Finished baking, emitting finished" << _modelURL; setIsFinished(true); } } }
void TextureBaker::processTexture() { // the baked textures need to have the source hash added for cache checks in Interface // so we add that to the processed texture before handling it off to be serialized auto hashData = QCryptographicHash::hash(_originalTexture, QCryptographicHash::Md5); std::string hash = hashData.toHex().toStdString(); // IMPORTANT: _originalTexture is empty past this point auto processedTexture = image::processImage(std::move(_originalTexture), _textureURL.toString().toStdString(), ABSOLUTE_MAX_TEXTURE_NUM_PIXELS, _textureType, _abortProcessing); processedTexture->setSourceHash(hash); if (shouldStop()) { return; } if (!processedTexture) { handleError("Could not process texture " + _textureURL.toString()); return; } auto memKTX = gpu::Texture::serialize(*processedTexture); if (!memKTX) { handleError("Could not serialize " + _textureURL.toString() + " to KTX"); return; } const char* data = reinterpret_cast<const char*>(memKTX->_storage->data()); const size_t length = memKTX->_storage->size(); // attempt to write the baked texture to the destination file path auto filePath = _outputDirectory.absoluteFilePath(_bakedTextureFileName); QFile bakedTextureFile { filePath }; if (!bakedTextureFile.open(QIODevice::WriteOnly) || bakedTextureFile.write(data, length) == -1) { handleError("Could not write baked texture for " + _textureURL.toString()); } else { _outputFiles.push_back(filePath); } qCDebug(model_baking) << "Baked texture" << _textureURL; setIsFinished(true); }
/** * Determines whether a guessed phrase is correct. This is a fundamental gameplay * component of Hangman. * guess a string vector containing the guess * returns a bool indicating whether the guess was correct. */ bool GameAttempt::guessPhrase(vector<string> guess) { bool guessSuccess(true); vector<string> phrase = getGame().getPhrase(); setNumPhraseGuesses(getNumPhraseGuesses() + 1); if(guess.size() == phrase.size()) { for(int i = 0; i < guess.size() && guessSuccess; i++) { if(!HangTools::equalsIgnoreCase(phrase[i], guess[i])) { guessSuccess = false; } } } else { guessSuccess = false; } setIsFinished(isFinished() || guessSuccess); return guessSuccess; }
void Process::cycle(int cycleNum) { switch(getState()) { case NOT_ARRIVED: //if the process is supposed to arrive at this cycle if(cycleNum == getArrivalCycle()) { setIsReady(); if(onArrived != NULL) { onArrived->run(this); } } break; case RUNNING: cout << getProcessId() << ":running "; //if this is the first cycle the process is running if(getCpuTimeRemaining() == getTotalCpuTime()) { setStartCycle(cycleNum); } if(onRunning != NULL) { onRunning->run(this); } if(!decrementCpuTimeRemaining()) { //tried decrementing a process with no remaining cpu time? //throw exception } //in the special case of 0 ioTime and odd cpuTime //getCpuTimeRemaining() will never equal getCpuTimeBeforeBlock() //because we initialize cpuTimeRemaining and cpuTimeBeforeBlock to totalCpuTime //and since there is a call that decrements cpuTimeRemaining before this check //it will never equal totalCpuTime at this point if(getCpuTimeRemaining() == getCpuTimeBeforeBlock()) { if(getIoTimeRemaining() > 0) { setIsBlocked(); if(onBlocked != NULL) { onBlocked->run(this); } } } else if(getCpuTimeRemaining() == 0) { setIsFinished(); if(onFinished != NULL) { onFinished->run(this); } setFinishCycle(cycleNum); } break; case READY: cout << getProcessId() << ":ready "; break; case BLOCKED: cout << getProcessId() << ":blocked "; if(!decrementIoTimeRemaining()) { //tried decrementing a process with no remaining io time? //throw exception } if(getIoTimeRemaining() == 0) { setIsReady(); if(onReady != NULL) { onReady->run(this); } } break; default: break; } }
void AudioInjector::injectToMixer() { if (_currentSendOffset < 0 || _currentSendOffset >= _audioData.size()) { _currentSendOffset = 0; } auto nodeList = DependencyManager::get<NodeList>(); // make sure we actually have samples downloaded to inject if (_audioData.size()) { auto audioPacket = NLPacket::create(PacketType::InjectAudio); // setup the packet for injected audio QDataStream audioPacketStream(audioPacket.get()); // pack some placeholder sequence number for now audioPacketStream << (quint16) 0; // pack stream identifier (a generated UUID) audioPacketStream << QUuid::createUuid(); // pack the stereo/mono type of the stream audioPacketStream << _options.stereo; // pack the flag for loopback uchar loopbackFlag = (uchar) true; audioPacketStream << loopbackFlag; // pack the position for injected audio int positionOptionOffset = audioPacket->pos(); audioPacketStream.writeRawData(reinterpret_cast<const char*>(&_options.position), sizeof(_options.position)); // pack our orientation for injected audio audioPacketStream.writeRawData(reinterpret_cast<const char*>(&_options.orientation), sizeof(_options.orientation)); // pack zero for radius float radius = 0; audioPacketStream << radius; // pack 255 for attenuation byte int volumeOptionOffset = audioPacket->pos(); quint8 volume = MAX_INJECTOR_VOLUME * _options.volume; audioPacketStream << volume; audioPacketStream << _options.ignorePenumbra; int audioDataOffset = audioPacket->pos(); QElapsedTimer timer; timer.start(); int nextFrame = 0; bool shouldLoop = _options.loop; // loop to send off our audio in NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL byte chunks quint16 outgoingInjectedAudioSequenceNumber = 0; while (_currentSendOffset < _audioData.size() && !_shouldStop) { int bytesToCopy = std::min(((_options.stereo) ? 2 : 1) * AudioConstants::NETWORK_FRAME_BYTES_PER_CHANNEL, _audioData.size() - _currentSendOffset); // Measure the loudness of this frame _loudness = 0.0f; for (int i = 0; i < bytesToCopy; i += sizeof(int16_t)) { _loudness += abs(*reinterpret_cast<int16_t*>(_audioData.data() + _currentSendOffset + i)) / (AudioConstants::MAX_SAMPLE_VALUE / 2.0f); } _loudness /= (float)(bytesToCopy / sizeof(int16_t)); audioPacket->seek(0); // pack the sequence number audioPacket->writePrimitive(outgoingInjectedAudioSequenceNumber); audioPacket->seek(positionOptionOffset); audioPacket->writePrimitive(_options.position); audioPacket->writePrimitive(_options.orientation); volume = MAX_INJECTOR_VOLUME * _options.volume; audioPacket->seek(volumeOptionOffset); audioPacket->writePrimitive(volume); audioPacket->seek(audioDataOffset); // copy the next NETWORK_BUFFER_LENGTH_BYTES_PER_CHANNEL bytes to the packet audioPacket->write(_audioData.data() + _currentSendOffset, bytesToCopy); // set the correct size used for this packet audioPacket->setPayloadSize(audioPacket->pos()); // grab our audio mixer from the NodeList, if it exists SharedNodePointer audioMixer = nodeList->soloNodeOfType(NodeType::AudioMixer); if (audioMixer) { // send off this audio packet nodeList->sendUnreliablePacket(*audioPacket, *audioMixer); outgoingInjectedAudioSequenceNumber++; } _currentSendOffset += bytesToCopy; // send two packets before the first sleep so the mixer can start playback right away if (_currentSendOffset != bytesToCopy && _currentSendOffset < _audioData.size()) { // process events in case we have been told to stop and be deleted QCoreApplication::processEvents(); if (_shouldStop) { break; } // not the first packet and not done // sleep for the appropriate time int usecToSleep = (++nextFrame * AudioConstants::NETWORK_FRAME_USECS) - timer.nsecsElapsed() / 1000; if (usecToSleep > 0) { usleep(usecToSleep); } } if (shouldLoop && _currentSendOffset >= _audioData.size()) { _currentSendOffset = 0; } } } setIsFinished(true); _isPlaying = !_isFinished; // Which can be false if a restart was requested }
void AudioInjector::restartPortionAfterFinished() { disconnect(this, &AudioInjector::finished, this, &AudioInjector::restartPortionAfterFinished); setIsFinished(false); QMetaObject::invokeMethod(this, "injectAudio", Qt::QueuedConnection); }
void Baker::handleErrors(const QStringList& errors) { // we're appending errors, presumably from a baking operation we called // add those to our list and emit that we are finished _errorList.append(errors); setIsFinished(true); }
void Baker::handleError(const QString& error) { qCCritical(model_baking).noquote() << error; _errorList.append(error); setIsFinished(true); }
void FSTBaker::handleModelBakerFinished() { handleModelBakerEnded(); setIsFinished(true); }
void AudioInjector::injectToMixer() { if (_currentSendPosition < 0 || _currentSendPosition >= _audioData.size()) { _currentSendPosition = 0; } auto nodeList = DependencyManager::get<NodeList>(); // make sure we actually have samples downloaded to inject if (_audioData.size()) { // setup the packet for injected audio QByteArray injectAudioPacket = nodeList->byteArrayWithPopulatedHeader(PacketTypeInjectAudio); QDataStream packetStream(&injectAudioPacket, QIODevice::Append); // pack some placeholder sequence number for now int numPreSequenceNumberBytes = injectAudioPacket.size(); packetStream << (quint16)0; // pack stream identifier (a generated UUID) packetStream << QUuid::createUuid(); // pack the stereo/mono type of the stream packetStream << _options.stereo; // pack the flag for loopback uchar loopbackFlag = (uchar) true; packetStream << loopbackFlag; // pack the position for injected audio int positionOptionOffset = injectAudioPacket.size(); packetStream.writeRawData(reinterpret_cast<const char*>(&_options.position), sizeof(_options.position)); // pack our orientation for injected audio int orientationOptionOffset = injectAudioPacket.size(); packetStream.writeRawData(reinterpret_cast<const char*>(&_options.orientation), sizeof(_options.orientation)); // pack zero for radius float radius = 0; packetStream << radius; // pack 255 for attenuation byte int volumeOptionOffset = injectAudioPacket.size(); quint8 volume = MAX_INJECTOR_VOLUME * _options.volume; packetStream << volume; packetStream << _options.ignorePenumbra; QElapsedTimer timer; timer.start(); int nextFrame = 0; int numPreAudioDataBytes = injectAudioPacket.size(); bool shouldLoop = _options.loop; // loop to send off our audio in NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL byte chunks quint16 outgoingInjectedAudioSequenceNumber = 0; while (_currentSendPosition < _audioData.size() && !_shouldStop) { int bytesToCopy = std::min(((_options.stereo) ? 2 : 1) * AudioConstants::NETWORK_FRAME_BYTES_PER_CHANNEL, _audioData.size() - _currentSendPosition); // Measure the loudness of this frame _loudness = 0.0f; for (int i = 0; i < bytesToCopy; i += sizeof(int16_t)) { _loudness += abs(*reinterpret_cast<int16_t*>(_audioData.data() + _currentSendPosition + i)) / (AudioConstants::MAX_SAMPLE_VALUE / 2.0f); } _loudness /= (float)(bytesToCopy / sizeof(int16_t)); memcpy(injectAudioPacket.data() + positionOptionOffset, &_options.position, sizeof(_options.position)); memcpy(injectAudioPacket.data() + orientationOptionOffset, &_options.orientation, sizeof(_options.orientation)); volume = MAX_INJECTOR_VOLUME * _options.volume; memcpy(injectAudioPacket.data() + volumeOptionOffset, &volume, sizeof(volume)); // resize the QByteArray to the right size injectAudioPacket.resize(numPreAudioDataBytes + bytesToCopy); // pack the sequence number memcpy(injectAudioPacket.data() + numPreSequenceNumberBytes, &outgoingInjectedAudioSequenceNumber, sizeof(quint16)); // copy the next NETWORK_BUFFER_LENGTH_BYTES_PER_CHANNEL bytes to the packet memcpy(injectAudioPacket.data() + numPreAudioDataBytes, _audioData.data() + _currentSendPosition, bytesToCopy); // grab our audio mixer from the NodeList, if it exists SharedNodePointer audioMixer = nodeList->soloNodeOfType(NodeType::AudioMixer); // send off this audio packet nodeList->writeDatagram(injectAudioPacket, audioMixer); outgoingInjectedAudioSequenceNumber++; _currentSendPosition += bytesToCopy; // send two packets before the first sleep so the mixer can start playback right away if (_currentSendPosition != bytesToCopy && _currentSendPosition < _audioData.size()) { // process events in case we have been told to stop and be deleted QCoreApplication::processEvents(); if (_shouldStop) { break; } // not the first packet and not done // sleep for the appropriate time int usecToSleep = (++nextFrame * AudioConstants::NETWORK_FRAME_USECS) - timer.nsecsElapsed() / 1000; if (usecToSleep > 0) { usleep(usecToSleep); } } if (shouldLoop && _currentSendPosition >= _audioData.size()) { _currentSendPosition = 0; } } } setIsFinished(true); }