void CFGInit() { // TODO(Subv): In the future we should use the FS service to query this archive, // currently it is not possible because you can only have one open archive of the same type at any time std::string syssavedata_directory = FileUtil::GetUserPath(D_SYSSAVEDATA_IDX); cfg_system_save_data = Common::make_unique<FileSys::Archive_SystemSaveData>( syssavedata_directory, CFG_SAVE_ID); if (!cfg_system_save_data->Initialize()) { LOG_CRITICAL(Service_CFG, "Could not initialize SystemSaveData archive for the CFG:U service"); return; } // TODO(Subv): All this code should be moved to cfg:i, // it's only here because we do not currently emulate the lower level code that uses that service // Try to open the file in read-only mode to check its existence FileSys::Mode mode = {}; mode.read_flag = 1; FileSys::Path path("config"); auto file = cfg_system_save_data->OpenFile(path, mode); // Load the config if it already exists if (file != nullptr) { file->Read(0, CONFIG_SAVEFILE_SIZE, cfg_config_file_buffer.data()); return; } // Initialize the Username block // TODO(Subv): Initialize this directly in the variable when MSVC supports char16_t string literals CONSOLE_USERNAME_BLOCK.ng_word = 0; CONSOLE_USERNAME_BLOCK.zero = 0; // Copy string to buffer and pad with zeros at the end auto size = Common::UTF8ToUTF16(CONSOLE_USERNAME).copy(CONSOLE_USERNAME_BLOCK.username, 0x14); std::fill(std::begin(CONSOLE_USERNAME_BLOCK.username) + size, std::end(CONSOLE_USERNAME_BLOCK.username), 0); FormatConfig(); }
void DriveTransfer::TransferFile(QString sourcePath, QString relativeFilePath, QString targetPath, int64_t& checksum) { QFile source(sourcePath + "/" + relativeFilePath); _subTaskDescription = "Copying " + relativeFilePath.toStdString(); // TODO: Ensure trailing slash to remove need of appending it in multiple places if (QFile::exists(targetPath + relativeFilePath)) { QFile::remove(targetPath + "/" + relativeFilePath); } QFile target(targetPath + "/" + relativeFilePath); OC_LOG_INFO("From: " + source.fileName().toStdString() + " To: " + target.fileName().toStdString()); source.open(QIODevice::ReadOnly); target.open(QIODevice::WriteOnly); if (source.error() || target.error()) { OC_LOG_ERROR("DriveTransfer failed."); return; } int TRANSFER_BLOCK_SIZE = 1024 * 1024; // 1MB float progressBlock = source.size() / 100.0f; int totalRead = 0; int progress = 0; const std::unique_ptr<IHashGenerator> hashGenerator(new xxHashAdapter()); hashGenerator->Initialize(); // TODO: Error handling char* buffer = new char[TRANSFER_BLOCK_SIZE]; while (!source.atEnd()) { qint64 readSize = source.read(buffer, TRANSFER_BLOCK_SIZE); target.write(buffer, readSize); hashGenerator->Update(buffer, readSize); totalRead += readSize; //progress = totalRead / progressBlock; if (totalRead > progressBlock * progress) { progress += totalRead / progressBlock; ProgressChanged(progress); } } checksum = hashGenerator->Retrieve(); }
bool StateTracker::CreateInstance() { ASSERT(!s_state_tracker); s_state_tracker = std::make_unique<StateTracker>(); if (!s_state_tracker->Initialize()) { s_state_tracker.reset(); return false; } return true; }
void Initialize(ASTContext &Ctx) override { Context = &Ctx; if (llvm::TimePassesIsEnabled) LLVMIRGeneration.startTimer(); Gen->Initialize(Ctx); TheModule.reset(Gen->GetModule()); if (llvm::TimePassesIsEnabled) LLVMIRGeneration.stopTimer(); }
void Initialize(ASTContext &Ctx) override { assert(!Context && "initialized multiple times"); Context = &Ctx; if (llvm::TimePassesIsEnabled) LLVMIRGeneration.startTimer(); Gen->Initialize(Ctx); if (llvm::TimePassesIsEnabled) LLVMIRGeneration.stopTimer(); }
int Plugin_Open(int samplerate, int numchannels, int bitspersamp, int bufferlenms, int prebufferms) { start_t = GetTickCount(); w_offset = 0; writtenbytes = 0; numchan = numchannels; srate = samplerate; bps = bitspersamp; PrebufferBytesCount = ConvertMilisecondsToBytesCount(PrebufferTime); //forwarder->SetOutputDelay(BytesPerSecondCount);// 1 second forwarder->Open(samplerate, numchannels, bitspersamp, bufferlenms, prebufferms); outputStream->Initialize(samplerate, numchannels, bitspersamp); streamManager->open(); //mpdClient->play(); return 0; }
//Entry point of program int WINAPI WinMain(HINSTANCE pHInstance, HINSTANCE pPrevHInstance, PSTR pSTR, int pCmdshow) { //Initialize scene & window scene = make_unique<Scene>(); window = make_unique<W_Window>(); window->Initialize(); //run the main loop map<int, vector<W_WindowInfo>> windowsInfo = { { 0, { { window->GetHWND(), window->GetWidth(), window->GetHeight() } } } }; std::function<void(void)> run = [&windowsInfo]()->void { scene->Run(windowsInfo); }; window->Run(run); //release all Release(); return EXIT_SUCCESS; }
HRESULT GfxInitialize() { UINT dxgiFlags = 0; #ifdef _DEBUG dxgiFlags |= DXGI_CREATE_FACTORY_DEBUG; #endif HRESULT hr = CreateDXGIFactory2(dxgiFlags, IID_PPV_ARGS(&Factory)); CHECKHR(hr); bool createDebug = false; #ifdef _DEBUG createDebug = true; #endif Graphics = std::make_shared<GraphicsDevice>(); hr = Graphics->Initialize(Factory, nullptr, createDebug); CHECKHR(hr); Presenter = std::make_unique<DxgiPresenter>(Graphics, AppWindow); hr = Presenter->Initialize(); CHECKHR(hr); //Renderer = std::make_unique<LPFRenderer>(Graphics); Renderer = std::make_unique<ForwardPlusRenderer>(Graphics); hr = Renderer->Initialize(); CHECKHR(hr); TheScene = std::make_shared<Scene>(); std::vector<std::shared_ptr<Visual>> visuals; Assets = std::make_shared<AssetLoader>(Graphics, L"..\\ProcessedContent"); hr = Assets->LoadModel(L"crytek-sponza\\sponza.model", &visuals); CHECKHR(hr); for (auto& visual : visuals) { TheScene->AddVisual(visual); } #ifdef USE_HEADLIGHT Headlight = std::make_shared<DirectionalLight>(); Headlight->SetColor(XMFLOAT3(1.f, 1.f, 1.f)); Headlight->SetOrientation(QuaternionFromViewDirection(XMVector3Normalize(XMVectorSet(1, -1, 1, 0)), XMVectorSet(0, 1, 0, 0))); TheScene->AddLight(Headlight); #else // Add some lights std::shared_ptr<Light> light = std::make_shared<DirectionalLight>(); light->SetColor(XMFLOAT3(0.6f, 0.6f, 0.4f)); light->SetOrientation(QuaternionFromViewDirection(XMVector3Normalize(XMVectorSet(-1, -1, -1, 0)), XMVectorSet(0, 1, 0, 0))); //TheScene->AddLight(light); light = std::make_shared<DirectionalLight>(); light->SetColor(XMFLOAT3(0.4f, 0.4f, 0.6f)); light->SetOrientation(QuaternionFromViewDirection(XMVector3Normalize(XMVectorSet(1, -1, 1, 0)), XMVectorSet(0, 1, 0, 0))); //TheScene->AddLight(light); srand(0); for (float y = 50; y < 500; y +=100) { for (float x = -1000; x < 1000; x += 100) { for (float z = -500; z < 500; z += 100) { float r = (rand() % 256) / 256.f; float g = (rand() % 256) / 256.f; float b = (rand() % 256) / 256.f; light = std::make_shared<PointLight>(); light->SetColor(XMFLOAT3(r, g, b)); light->SetPosition(XMFLOAT3(x, y, z)); ((PointLight*)light.get())->SetRadius(100.f); TheScene->AddLight(light); } } } #endif Renderer->SetScene(TheScene); BackBufferRT.Texture = Presenter->GetBackBuffer(); BackBufferRT.Viewport.Width = static_cast<float>(BackBufferRT.Texture->GetDesc().Width); BackBufferRT.Viewport.Height = static_cast<float>(BackBufferRT.Texture->GetDesc().Height); BackBufferRT.Viewport.MaxDepth = 1.f; View.NearClipDistance = 1.f; View.FarClipDistance = 5000.f; XMStoreFloat4x4(&View.ViewToProjection, XMMatrixPerspectiveFovLH( XMConvertToRadians(60.f), ClientWidth / (float)ClientHeight, View.NearClipDistance, View.FarClipDistance)); return hr; }
bool SubreadConverter::ConvertFile(HDFBasReader* reader, PacBio::BAM::BamWriter* writer, PacBio::BAM::BamWriter* scrapsWriter) { assert(reader); // initialize with default values (shared across all unmapped subreads) BamRecordImpl bamRecord; // read region table info std::unique_ptr<HDFRegionTableReader> const regionTableReader(new HDFRegionTableReader); RegionTable regionTable; string fn = filenameForReader_[reader]; assert(!fn.empty()); if (regionTableReader->Initialize(fn) == 0) { AddErrorMessage("could not read region table on "+fn); return false; } regionTable.Reset(); regionTableReader->ReadTable(regionTable); regionTableReader->Close(); // initialize read scores InitReadScores(reader); // fetch records from HDF5 file SMRTSequence smrtRecord; while (reader->GetNext(smrtRecord)) { // compute subread & adapter intervals SubreadInterval hqInterval; deque<SubreadInterval> subreadIntervals; deque<SubreadInterval> adapterIntervals; try { hqInterval = ComputeSubreadIntervals(&subreadIntervals, &adapterIntervals, regionTable, smrtRecord.zmwData.holeNumber, smrtRecord.length); } catch (runtime_error& e) { AddErrorMessage(string(e.what())); smrtRecord.Free(); return false; } // sequencing ZMW if (IsSequencingZmw(smrtRecord)) { // write subreads to main BAM file for (const SubreadInterval& interval : subreadIntervals) { // skip invalid or 0-sized intervals if (interval.End <= interval.Start) continue; if (!WriteSubreadRecord(smrtRecord, interval.Start, interval.End, ReadGroupId(), static_cast<uint8_t>(interval.LocalContextFlags), writer)) { smrtRecord.Free(); return false; } } // if scraps BAM file present if (scrapsWriter) { // write 5-end LQ sequence if (hqInterval.Start > 0) { if (!WriteLowQualityRecord(smrtRecord, 0, hqInterval.Start, ScrapsReadGroupId(), scrapsWriter)) { smrtRecord.Free(); return false; } } // write adapters for (const SubreadInterval& interval : adapterIntervals) { // skip invalid or 0-sized adapters if (interval.End <= interval.Start) continue; if (!WriteAdapterRecord(smrtRecord, interval.Start, interval.End, ScrapsReadGroupId(), scrapsWriter)) { smrtRecord.Free(); return false; } } // write 3'-end LQ sequence if (hqInterval.End < smrtRecord.length) { if (!WriteLowQualityRecord(smrtRecord, hqInterval.End, smrtRecord.length, ScrapsReadGroupId(), scrapsWriter)) { smrtRecord.Free(); return false; } } } } // sequencing ZMW // non-sequencing ZMW else { assert(!IsSequencingZmw(smrtRecord)); // only write these if scraps BAM present & we are in 'internal mode' if (settings_.isInternal && scrapsWriter) { // write 5-end LQ sequence to scraps BAM if (hqInterval.Start > 0) { if (!WriteLowQualityRecord(smrtRecord, 0, hqInterval.Start, ScrapsReadGroupId(), scrapsWriter)) { smrtRecord.Free(); return false; } } // write subreads & adapters to scraps BAM, sorted by query start while (!subreadIntervals.empty() && !adapterIntervals.empty()) { const SubreadInterval& subread = subreadIntervals.front(); const SubreadInterval& adapter = adapterIntervals.front(); assert(subread.Start != adapter.Start); if (subread.Start < adapter.Start) { if (!WriteFilteredRecord(smrtRecord, subread.Start, subread.End, ScrapsReadGroupId(), static_cast<uint8_t>(subread.LocalContextFlags), scrapsWriter)) { smrtRecord.Free(); return false; } subreadIntervals.pop_front(); } else { if (!WriteAdapterRecord(smrtRecord, adapter.Start, adapter.End, ScrapsReadGroupId(), scrapsWriter)) { smrtRecord.Free(); return false; } adapterIntervals.pop_front(); } } // flush any traling subread intervals while (!subreadIntervals.empty()) { assert(adapterIntervals.empty()); const SubreadInterval& subread = subreadIntervals.front(); if (!WriteFilteredRecord(smrtRecord, subread.Start, subread.End, ScrapsReadGroupId(), static_cast<uint8_t>(subread.LocalContextFlags), scrapsWriter)) { smrtRecord.Free(); return false; } subreadIntervals.pop_front(); } // flush any remaining adapter intervals while (!adapterIntervals.empty()) { assert(subreadIntervals.empty()); const SubreadInterval& adapter = adapterIntervals.front(); if (!WriteAdapterRecord(smrtRecord, adapter.Start, adapter.End, ScrapsReadGroupId(), scrapsWriter)) { smrtRecord.Free(); return false; } adapterIntervals.pop_front(); } // write 3'-end LQ sequence to scraps BAM if (hqInterval.End < smrtRecord.length) { if (!WriteLowQualityRecord(smrtRecord, hqInterval.End, smrtRecord.length, ScrapsReadGroupId(), scrapsWriter)) { smrtRecord.Free(); return false; } } } } // non-sequencing ZMW smrtRecord.Free(); } // if we get here, all OK return true; }
bool HqRegionConverter::ConvertFile(HDFBasReader* reader, PacBio::BAM::BamWriter* writer, PacBio::BAM::BamWriter* scrapsWriter) { assert(reader); // read region table info std::unique_ptr<HDFRegionTableReader> const regionTableReader(new HDFRegionTableReader); RegionTable regionTable; std::string fn = filenameForReader_[reader]; assert(!fn.empty()); if (regionTableReader->Initialize(fn) == 0) { AddErrorMessage("could not read region table on "+fn); return false; } regionTable.Reset(); regionTableReader->ReadTable(regionTable); regionTableReader->Close(); // initialize read scores InitReadScores(reader); // fetch records from HDF5 file SMRTSequence smrtRecord; int hqStart, hqEnd, score; while (reader->GetNext(smrtRecord)) { // attempt get high quality region if (!LookupHQRegion(smrtRecord.zmwData.holeNumber, regionTable, hqStart, hqEnd, score)) { stringstream s; s << "could not find HQ region for hole number: " << smrtRecord.zmwData.holeNumber; AddErrorMessage(s.str()); smrtRecord.Free(); return false; } // Catch and repair 1-off errors in the HQ region hqEnd = (hqEnd == static_cast<int>(smrtRecord.length)-1) ? smrtRecord.length : hqEnd; // sequencing ZMW if (IsSequencingZmw(smrtRecord)) { // write HQRegion to main BAM file if (hqStart < hqEnd) { if (!WriteRecord(smrtRecord, hqStart, hqEnd, ReadGroupId(), writer)) { smrtRecord.Free(); return false; } } // if scraps BAM file present if (scrapsWriter) { // write 5'-end LQ sequence if (hqStart > 0) { if (!WriteLowQualityRecord(smrtRecord, 0, hqStart, ScrapsReadGroupId(), scrapsWriter)) { smrtRecord.Free(); return false; } } // write 3'-end LQ sequence if (static_cast<size_t>(hqEnd) < smrtRecord.length) { if (!WriteLowQualityRecord(smrtRecord, hqEnd, smrtRecord.length, ScrapsReadGroupId(), scrapsWriter)) { smrtRecord.Free(); return false; } } } } // non-sequencing ZMW else { assert(!IsSequencingZmw(smrtRecord)); // only write these if scraps BAM present & we are in 'internal mode' if (settings_.isInternal && scrapsWriter) { // write 5'-end LQ sequence if (hqStart > 0) { if (!WriteLowQualityRecord(smrtRecord, 0, hqStart, ScrapsReadGroupId(), scrapsWriter)) { smrtRecord.Free(); return false; } } // write HQRegion to scraps BAM file if (hqStart < hqEnd) { if (!WriteFilteredRecord(smrtRecord, hqStart, hqEnd, ScrapsReadGroupId(), scrapsWriter)) { smrtRecord.Free(); return false; } } // write 3'-end LQ sequence if (static_cast<size_t>(hqEnd) < smrtRecord.length) { if (!WriteLowQualityRecord(smrtRecord, hqEnd, smrtRecord.length, ScrapsReadGroupId(), scrapsWriter)) { smrtRecord.Free(); return false; } } } } smrtRecord.Free(); } // if we get here, all OK return true; }