示例#1
0
void CMaNGOS_Map::ScanFoldersForMaps()
{
    scanDirectory("maps", "*.map", m_MapFiles);
    scanDirectory("vmaps", "*.vmtree", m_VMapFiles);

    m_MapsFound.clear();
    for (FileList::const_iterator itr = m_MapFiles.begin(); itr != m_MapFiles.end(); itr++)
    {
        string fullname(*itr);
        int lastsep = fullname.find_last_of("/");
        string fname = fullname.substr(lastsep + 1);
        string mapStr = fname.substr(0, 3);
        unsigned int mapId = atoi(mapStr.c_str());
        m_MapsFound.insert(mapId);
    }

    for (FileList::const_iterator itr = m_VMapFiles.begin(); itr != m_VMapFiles.end(); itr++)
    {
        string fullname(*itr);
        int lastsep = fullname.find_last_of("/");
        string fname = fullname.substr(lastsep + 1);
        string mapStr = fname.substr(0, 3);
        unsigned int mapId = atoi(mapStr.c_str());
        m_MapsFound.insert(mapId);
    }

    m_mapID = *m_MapsFound.begin();
}
示例#2
0
void CMaNGOS_Map::scanFoldersForTiles()
{
    m_TilesFound.clear();
    if (m_MapsFound.empty())
        return;

    char buff[20];
    snprintf(buff, sizeof(buff), "%03d*.map", m_mapID);
    scanDirectory("maps", buff, m_MapFiles);
    snprintf(buff, sizeof(buff), "%03d*.vmtile", m_mapID);
    scanDirectory("vmaps", buff, m_VMapFiles);
    snprintf(buff, sizeof(buff), "%03d*.mmtile", m_mapID);
    scanDirectory("mmaps", buff, m_MMapFiles);

    for (FileList::const_iterator itr = m_MapFiles.begin(); itr != m_MapFiles.end(); itr++)
    {
        unsigned int tileX = unsigned int(atoi((*itr).substr(3, 2).c_str()));
        unsigned int tileY = unsigned int(atoi((*itr).substr(5, 2).c_str()));

        m_TilesFound.insert(VMAP::StaticMapTree::packTileID(tileX, tileY));
    }

    for (FileList::const_iterator itr = m_VMapFiles.begin(); itr != m_VMapFiles.end(); itr++)
    {
        unsigned int tileX = unsigned int(atoi((*itr).substr(4, 2).c_str()));
        unsigned int tileY = unsigned int(atoi((*itr).substr(7, 2).c_str()));

        m_TilesFound.insert(VMAP::StaticMapTree::packTileID(tileX, tileY));
    }

    if (m_TilesFound.empty())
    {
        m_TilesFound.insert(VMAP::StaticMapTree::packTileID(64, 64));
    }
}
示例#3
0
// Test a full buffer
TEST(FTDCFileManagerTest, TestFull) {
    Client* client = &cc();
    FTDCConfig c;
    c.maxFileSizeBytes = 300;
    c.maxDirectorySizeBytes = 1000;
    c.maxSamplesPerInterimMetricChunk = 1;

    unittest::TempDir tempdir("metrics_testpath");
    boost::filesystem::path dir(tempdir.path());
    createDirectoryClean(dir);

    FTDCCollectorCollection rotate;
    auto swMgr = FTDCFileManager::create(&c, dir, &rotate, client);
    ASSERT_OK(swMgr.getStatus());
    auto mgr = std::move(swMgr.getValue());

    // Test a large numbers of zeros, and incremental numbers in a full buffer
    for (int j = 0; j < 10; j++) {
        ASSERT_OK(
            mgr->writeSampleAndRotateIfNeeded(client,
                                              BSON("name"
                                                   << "joe"
                                                   << "key1" << 3230792343LL << "key2" << 235135)));

        for (size_t i = 0; i <= FTDCConfig::kMaxSamplesPerArchiveMetricChunkDefault - 2; i++) {
            ASSERT_OK(mgr->writeSampleAndRotateIfNeeded(
                client,
                BSON("name"
                     << "joe"
                     << "key1" << static_cast<long long int>(i * j * 37) << "key2"
                     << static_cast<long long int>(i * (645 << j)))));
        }

        ASSERT_OK(mgr->writeSampleAndRotateIfNeeded(client,
                                                    BSON("name"
                                                         << "joe"
                                                         << "key1" << 34 << "key2" << 45)));

        // Add Value
        ASSERT_OK(mgr->writeSampleAndRotateIfNeeded(client,
                                                    BSON("name"
                                                         << "joe"
                                                         << "key1" << 34 << "key2" << 45)));
    }

    mgr->close();

    auto files = scanDirectory(dir);

    int sum = 0;
    for (auto& file : files) {
        int fs = boost::filesystem::file_size(file);
        ASSERT_TRUE(fs < c.maxFileSizeBytes * 1.10);
        if (file.generic_string().find("interim") == std::string::npos) {
            sum += fs;
        }
    }

    ASSERT_TRUE(sum < c.maxDirectorySizeBytes * 1.10 && sum > c.maxDirectorySizeBytes * 0.90);
}
示例#4
0
void ImportMusicDialog::doScan()
{
    m_tracks->clear();
    m_sourceFiles.clear();
    QString location = m_locationEdit->GetText();
    scanDirectory(location, m_tracks);
}
示例#5
0
void Widget::updateFileTable()
{
    totalDownloads = 0;
    QString dir = qApp->applicationDirPath();
    QTreeWidgetItem * root = new QTreeWidgetItem(0);
    QTreeWidgetItem * tempItem = root;
    QTreeWidgetItem * tmp;
    QDir sncdr(dir + "/Sync");

    QFileInfoList syncDir = sncdr.entryInfoList(QDir::NoDotAndDotDot|QDir::AllEntries);


    while(!syncDir.empty())
    {
              if(syncDir.at(0).isDir())
              {
                  tmp = scanDirectory(syncDir.at(0).filePath());
                  tmp->setText(0, syncDir.at(0).fileName());
                  ftpFiles->addTopLevelItem(tmp);
                  totalDownloads++;
              }
              else
              {
                  tmp = new QTreeWidgetItem(0);
                  tmp->setText(0, syncDir.at(0).fileName());
                  ftpFiles->addTopLevelItem(tmp);
                  totalDownloads++;
              }
          syncDir.removeAt(0);
    }
}
示例#6
0
文件: marker.cpp 项目: GiancarloF/POM
/**
 * @brief Scans recursively the given directory to find images
 * @param p_list
 * @param p_path
 */
void Marker::scanDirectory(QStringList* p_list, QString p_path, bool p_sub_folders)
{
    QDir l_dir = QDir(p_path);
    QStringList l_filters;

    l_filters << "*.png" << "*.jpg" << "*.bmp" << "*.gif";
    QFileInfoList l_list = l_dir.entryInfoList(l_filters, QDir::Files|QDir::NoDotAndDotDot);

    for(int i = 0; i < l_list.size(); i++)
    {
#ifdef DBG_MARKER
        qDebug() << "Marker::scanDirectory() found file #"<<i << ": " <<  l_list.at(i).filePath();
#endif      
        p_list->append(l_list.at(i).filePath());
    }

    if(p_sub_folders)
    {
        l_filters.clear();
        l_list.clear();
        l_list = l_dir.entryInfoList(l_filters, QDir::AllDirs|QDir::NoSymLinks|QDir::NoDotAndDotDot);

        for(int i = 0; i < l_list.size(); i++)
        {
#ifdef DBG_MARKER
            qDebug() << "Marker::scanDirectory() found dir #"<<i << ": " <<  l_list.at(i).filePath();
#endif
            // calling recursively this method
            scanDirectory(p_list, l_list.at(i).filePath());
        }
    }
}
示例#7
0
void FileInfo::scanDirectory(std::string path, bool directories, std::vector<shared<FileInfo> >& output)
{
  shared<Dir> dir = Dir::opendir(path);
  shared<Dirent> dirent = dir->readdir();

  while(dirent.get() != NULL)
  {
    if(dirent->d_name().at(0) != '.')
    {
      try
      {
        scanDirectory(path + DIR_CHAR + dirent->d_name(), directories, output);

        if(directories == true)
        {
          output.push_back(FileInfo::create(path + DIR_CHAR + dirent->d_name()));
        }
      }
      catch(std::exception& e)
      {
        if(directories == false)
        {
          output.push_back(FileInfo::create(path + DIR_CHAR + dirent->d_name()));
        }
      }
    }

    dirent = dir->readdir();
  }
}
示例#8
0
int main(int argc, char **argv) {
	FILE *fp;
	int sec;
	FILE_MAIN m;

	if (argc <3) {
		fprintf(stderr, "Usage: %s <source directory> <output filename>\n", argv[0]);
		return -1;
	}

	if ((fp = fopen(argv[2], "wb+")) == NULL) {
		fprintf(stderr, "Error: Unable to open target %s (wb+)\n", argv[2]);
		return -1;
	}

	m.magic = htonl(MAGIC);
	m.sections = htonl(0);

	fwrite(&m, sizeof(FILE_MAIN), 1, fp);
	if ((sec = scanDirectory(argv[1], fp)) < 1) {
		fprintf(stderr, "No usable data, found, aborting...\n");
		fclose(fp);
		unlink(argv[2]);
		return -1;
	}

	fseek(fp, 0, SEEK_SET);
	m.sections = htonl(sec);
	fwrite(&m, sizeof(FILE_MAIN), 1, fp);
	fclose(fp);

	return 0;
}
示例#9
0
bool ImportCoverArtDialog::Create()
{
    if (!LoadWindowFromXML("music-ui.xml", "import_coverart", this))
        return false;

    bool err = false;
    UIUtilE::Assign(this, m_filenameText,    "file", &err);
    UIUtilE::Assign(this, m_currentText,     "position", &err);
    UIUtilE::Assign(this, m_statusText,      "status", &err);
    UIUtilE::Assign(this, m_destinationText, "destination", &err);
    UIUtilE::Assign(this, m_coverartImage,   "coverart", &err);
    UIUtilE::Assign(this, m_copyButton,      "copy", &err);
    UIUtilE::Assign(this, m_exitButton,      "exit", &err);
    UIUtilE::Assign(this, m_prevButton,      "prev", &err);
    UIUtilE::Assign(this, m_nextButton,      "next", &err);
    UIUtilE::Assign(this, m_typeList,        "type", &err);

    if (err)
    {
        LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'import_coverart'");
        return false;
    }

    if (m_typeList)
    {
        new MythUIButtonListItem(m_typeList, tr("Front Cover"),
                                 qVariantFromValue(0));
        new MythUIButtonListItem(m_typeList, tr("Back Cover"),
                                 qVariantFromValue(1));
        new MythUIButtonListItem(m_typeList, tr("CD"),
                                 qVariantFromValue(2));
        new MythUIButtonListItem(m_typeList, tr("Inlay"),
                                 qVariantFromValue(3));
        new MythUIButtonListItem(m_typeList, tr("<Unknown>"),
                                 qVariantFromValue(4));

        connect(m_typeList, SIGNAL(itemSelected(MythUIButtonListItem *)),
                SLOT(selectorChanged()));
    }

    if (m_copyButton)
        connect(m_copyButton, SIGNAL(Clicked()), this, SLOT(copyPressed()));

    if (m_exitButton)
        connect(m_exitButton, SIGNAL(Clicked()), this, SLOT(Close()));

    if (m_prevButton)
        connect(m_prevButton, SIGNAL(Clicked()), this, SLOT(prevPressed()));

    if (m_nextButton)
        connect(m_nextButton, SIGNAL(Clicked()), this, SLOT(nextPressed()));

    BuildFocusList();

    scanDirectory();

    return true;
}
void RecastToolKit::RenderLevelSelection()
{
	int levelToLoad = -1;

	if (ImGui::BeginPopup("levelSelection"))
	{
		ImGui::Text("Select Level");
		ImGui::Separator();
		scanDirectory("Meshes", ".obj", files);
		for (size_t i = 0; i < files.size(); ++i)
		{
			if (ImGui::Selectable(files[i].c_str()))
			{
				levelToLoad = i;
				strncpy(meshName, files[i].c_str(), sizeof(meshName));
			}
		}

		ImGui::EndPopup();
	}
	if (levelToLoad != -1)
	{
		meshName[sizeof(meshName) - 1] = '\0';
		showLevels = false;

		geom.release();
		geom = 0;

		char path[256];
		strcpy(path, "Meshes/");
		strcat(path, meshName);

		geom = std::unique_ptr<InputGeom>(new InputGeom);
		if (!geom || !geom->loadMesh(&ctx, path))
		{
			geom.release();
			geom = 0;

			showLog = true;
			ctx.dumpLog("Geom load log %s:", meshName);
		}
		if (sample && geom)
		{
			sample->handleMeshChanged(geom.get());
		}

		if (geom || sample)
		{
			this->ResetCameraAndFog(geom, sample, camx, camy, camz, camr, rx, ry);
		}

	}
}
示例#11
0
文件: marker.cpp 项目: GiancarloF/POM
/**
 * @brief  Returns a QStringList containing all the files at m_albums.at(p_album_id)->_path
 * @param  p_album_id
 * @return QStringList
 * @note   Invoked in MainWindow and the result is passed to ImageViewer->setContents
 */
QStringList Marker::listAlbumDir(int p_album_id, bool p_sub_folders)
{
#ifdef DBG_MARKER
    qDebug() << "Marker::listAlbumDir() p_album_id = " <<  p_album_id;
#endif
    QStringList l_files;
    if(p_album_id < m_albums.size())
    {
        scanDirectory(&l_files, m_albums.at(p_album_id)->_path, p_sub_folders);
    }
    return l_files;
}
示例#12
0
// Test a run of the controller and the data it logs to log file
TEST(FTDCControllerTest, TestFull) {
    unittest::TempDir tempdir("metrics_testpath");
    boost::filesystem::path dir(tempdir.path());

    createDirectoryClean(dir);

    FTDCConfig config;
    config.enabled = true;
    config.period = Milliseconds(1);
    config.maxFileSizeBytes = FTDCConfig::kMaxFileSizeBytesDefault;
    config.maxDirectorySizeBytes = FTDCConfig::kMaxDirectorySizeBytesDefault;

    FTDCController c(dir, config);

    auto c1 = std::unique_ptr<FTDCMetricsCollectorMock2>(new FTDCMetricsCollectorMock2());
    auto c2 = std::unique_ptr<FTDCMetricsCollectorMockRotate>(new FTDCMetricsCollectorMockRotate());

    auto c1Ptr = c1.get();
    auto c2Ptr = c2.get();

    c1Ptr->setSignalOnCount(100);

    c.addPeriodicCollector(std::move(c1));

    c.addOnRotateCollector(std::move(c2));

    c.start();

    // Wait for 100 samples to have occured
    c1Ptr->wait();

    c.stop();

    auto docsPeriodic = c1Ptr->getDocs();
    ASSERT_GREATER_THAN_OR_EQUALS(docsPeriodic.size(), 100UL);

    auto docsRotate = c2Ptr->getDocs();
    ASSERT_EQUALS(docsRotate.size(), 1UL);

    std::vector<BSONObj> allDocs;
    allDocs.insert(allDocs.end(), docsRotate.begin(), docsRotate.end());
    allDocs.insert(allDocs.end(), docsPeriodic.begin(), docsPeriodic.end());

    auto files = scanDirectory(dir);

    ASSERT_EQUALS(files.size(), 2UL);

    auto alog = files[0];

    ValidateDocumentList(alog, allDocs);
}
示例#13
0
QTreeWidgetItem * Widget::scanDirectory(QString path)
{
    QTreeWidgetItem * root;
    QDir myDir(path);
    QTreeWidgetItem * tmp;
    root = new QTreeWidgetItem(0);
    root->setText(0, myDir.dirName());
    QString dir = qApp->applicationDirPath();
    QDirIterator * scanDir= new QDirIterator(path, QDir::AllEntries|QDir::NoDotAndDotDot);
    QString nxt;


    while(scanDir->hasNext())
    {
        nxt = scanDir->next();

        qDebug(scanDir->filePath().toAscii());

        if(scanDir->fileInfo().isDir())
        {
            root->addChild(scanDirectory(scanDir->filePath()));
            totalDownloads++;
        }
        else
        {
            tmp = new QTreeWidgetItem(0);
            tmp->setText(0, scanDir->fileName());
            root->addChild(tmp);
            totalDownloads++;
        }
    }


    /*if(!nxt.isNull())
    {
        qDebug(scanDir->filePath().toAscii());
        if(scanDir->fileInfo().isDir())
        {
            root->addChild(scanDirectory(scanDir->filePath()));
        }
        else
        {
            tmp = new QTreeWidgetItem(0);
            tmp->setText(0, scanDir->fileName());
            root->addChild(tmp);
        }
    }*/

   return root;
}
示例#14
0
int main(int argc, char** argv) {
  QApplication app(argc, argv);

#if GUI
  checkScansDirectoryExists();

  MainWindow window;
  window.show();
#endif

#if PIE
  QStandardItemModel* model = new QStandardItemModel(0, 2);
  model->setHeaderData(0, Qt::Horizontal, "Label");
  model->setHeaderData(1, Qt::Horizontal, "Quantity");

  QDir scanDirectory("/home/valentin/Images/Scans");
  QStringList mangasList = scanDirectory.entryList(QDir::Dirs | QDir::NoDotAndDotDot);

  int row = 0;
  for (const QString& manga: mangasList) {
    model->insertRow(row, QModelIndex());

    QDir mangaDirectory(scanDirectory.path()+"/"+manga);
    QString nbChapters = QString::number(mangaDirectory.entryList(QDir::Dirs | QDir::NoDotAndDotDot).size());

    int r = (16*(row+1))%256;
    int g = (32*(row+1))%256;
    int b = (64*(row+1))%256;

    model->setData(model->index(row, 0, QModelIndex()), manga);
    model->setData(model->index(row, 1, QModelIndex()), nbChapters);
    model->setData(model->index(row, 0, QModelIndex()), QColor(r, g, b), Qt::DecorationRole);

    row++;
  }

  PieView* view = new PieView;
  //QTableView* view = new QTableView;
  view->setModel(model);

  //QHeaderView* headerView = view->horizontalHeader();
  //headerView->setStretchLastSection(true);

  view->show();
#endif

  return app.exec();
}
示例#15
0
void loadTextures(){
	//glGenTextures(1, &defaultTex);

	vector<string> files;
	scanDirectory(files,"Textures");


	GLuint temps[files.size()];
	glGenTextures(files.size(),temps);

	for(int x=0;x<files.size();x++){
		loadPicture("Textures/"+files.at(x),temps[x]);
		loadedTextures[files.at(x).substr(0,files.at(x).size()-4)]=temps[x];
	}

}
示例#16
0
void handleInterrupt21(int ax, int bx, int cx, int dx) {
  if (ax == 0) { /* printString */
    printString(bx);
  } else if (ax == 1) {
    if (cx == 0) {
      readStringAndReturnSize(bx);
    } else {
      *((int*)cx) = readStringAndReturnSize(bx);
    }
  } else if (ax == 2) {
    readSector(bx, cx);
  } else if (ax == 3) {
    readFile(bx, cx, ROOT_SECTOR);
  } else if (ax == 4) {
    runProgram(bx, ROOT_SECTOR);
  } else if (ax == 5) {
    terminate();
  } else if (ax == 6) {
    writeSector(bx, cx);
  } else if (ax == 7) {
    deleteFile(bx, ROOT_SECTOR);
  } else if (ax == 8) {
    writeFile(bx, cx, dx, ROOT_SECTOR);
  } else if (ax == 9) {
    scanDirectory(bx, cx, dx);
  } else if (ax == 10) {
    killProcess(bx);
  } else if (ax == 11) {
    shellWait(runProgram(bx, ROOT_SECTOR));
  } else if (ax == 12) {
    clear();
  } else if (ax == 13) {
    printProcTable();
  } else {
    char errorMsg[8];
    errorMsg[0] = 'E';
    errorMsg[1] = 'r';
    errorMsg[2] = 'r';
    errorMsg[3] = 'o';
    errorMsg[4] = 'r';
    errorMsg[5] = '!';
    errorMsg[6] = '!';
    errorMsg[7] = '\0';
    printString(errorMsg);
  }
}
void scanDirectory(const CFileSystemObject& root, const std::function<void(const CFileSystemObject&)>& observer, const std::atomic<bool>& abort)
{
	if (observer)
		observer(root);

	if (!root.isDir() || abort)
		return;

	const auto list = root.qDir().entryInfoList(QDir::Files | QDir::Dirs | QDir::Hidden | QDir::NoSymLinks | QDir::NoDotAndDotDot | QDir::System);
	for (const auto& entry : list)
	{
		scanDirectory(CFileSystemObject(entry), observer, abort);

		if (abort)
			return;
	}
}
示例#18
0
void ImportMusicDialog::scanDirectory(QString &directory, vector<TrackInfo*> *tracks)
{
    QDir d(directory);

    if (!d.exists())
        return;

    const QFileInfoList list = d.entryInfoList();
    if (list.isEmpty())
        return;

    QFileInfoList::const_iterator it = list.begin();
    const QFileInfo *fi;

    while (it != list.end())
    {
        fi = &(*it);
        ++it;
        if (fi->fileName() == "." || fi->fileName() == "..")
            continue;
        QString filename = fi->absoluteFilePath();
        if (fi->isDir())
            scanDirectory(filename, tracks);
        else
        {
            Decoder *decoder = Decoder::create(filename, NULL, NULL, true);
            if (decoder)
            {
                Metadata *metadata = decoder->getMetadata();
                if (metadata)
                {
                    TrackInfo * track = new TrackInfo;
                    track->metadata = metadata;
                    track->isNewTune = Ripper::isNewTune(metadata->Artist(),
                            metadata->Album(), metadata->Title());
                    track->metadataHasChanged = false;
                    tracks->push_back(track);
                    m_sourceFiles.append(filename);
                }

                delete decoder;
            }
        }
    }
}
示例#19
0
QList<IccProfile> IccSettings::IccSettingsPriv::scanDirectories(const QStringList& dirs)
{
    QList<IccProfile> profiles;

    QStringList filters;
    filters << "*.icc" << "*.icm";
    kDebug() << dirs;
    foreach (const QString& dirPath, dirs)
    {
        QDir dir(dirPath);

        if (!dir.exists())
        {
            continue;
        }

        scanDirectory(dir.path(), filters, &profiles);
    }
示例#20
0
Status FTDCFileManager::rotate(Client* client) {
    auto s = _writer.close();
    if (!s.isOK()) {
        return s;
    }

    auto files = scanDirectory();

    // Rotate as needed
    trimDirectory(files);

    auto swFile = generateArchiveFileName(_path, terseUTCCurrentTime());
    if (!swFile.isOK()) {
        return swFile.getStatus();
    }

    return openArchiveFile(client, swFile.getValue(), {});
}
示例#21
0
StatusWith<std::unique_ptr<FTDCFileManager>> FTDCFileManager::create(
    const FTDCConfig* config,
    const boost::filesystem::path& path,
    FTDCCollectorCollection* collection,
    Client* client) {
    const boost::filesystem::path dir = boost::filesystem::absolute(path);

    if (!boost::filesystem::exists(dir)) {
        // Create the directory
        boost::system::error_code ec;
        boost::filesystem::create_directories(dir, ec);
        if (ec) {
            return {ErrorCodes::NonExistentPath,
                    str::stream() << "\'" << dir.generic_string()
                                  << "\' could not be created: " << ec.message()};
        }
    }

    auto mgr =
        std::unique_ptr<FTDCFileManager>(new FTDCFileManager(config, dir, std::move(collection)));

    // Enumerate the metrics files
    auto files = mgr->scanDirectory();

    // Recover the interim file
    auto interimDocs = mgr->recoverInterimFile();

    // Open the archive file for writing
    auto swFile = mgr->generateArchiveFileName(path, terseUTCCurrentTime());
    if (!swFile.isOK()) {
        return swFile.getStatus();
    }

    Status s = mgr->openArchiveFile(client, swFile.getValue(), interimDocs);
    if (!s.isOK()) {
        return s;
    }

    // Rotate as needed after we appended interim data to the archive file
    mgr->trimDirectory(files);

    return {std::move(mgr)};
}
示例#22
0
void MediaManager::scanDirectory(const QString &path)
{
    QDir root(path);
    for (QFileInfo& dir : root.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot))
    {
        if(!dir.isHidden() && dir.isReadable())
        {
            scanDirectory(dir.absoluteFilePath());
        }
    }

    for (QFileInfo& file : root.entryInfoList(supportedFormats, QDir::Files))
    {
        if(!file.isHidden() && file.isReadable())
        {
           processVideo(file.absoluteFilePath());
        }
    }
}
示例#23
0
// ----------------------------------------------------------------------------
// Decode the received command
// ----------------------------------------------------------------------------
void  MB8877::decode_command()
{
#ifdef FDC_DEBUG
  Serial.println("FDC Decoder");
#endif
  reg[STATUS] = FDC_ST_BUSY;      // We are BUSY

  if (reg[STATUS] & FDC_ST_NOTREADY)    // Try again to open the directory
  {
    scanSD();
    scanDirectory(fdc.disk);
    if (reg[STATUS] & FDC_ST_NOTREADY) return;  // Still no SD
  }
  
  fdc.cmdtype = 0;  // Reset current command
  
  switch(reg[CMD] & 0xf0) {     // Decode which command to execute
  // type I
    case 0x00: cmd_restore(FDC_CMD_RESTORE); break;
    case 0x10: cmd_seek(FDC_CMD_SEEK); break;
    case 0x20: cmd_step(0); break;
    case 0x30: cmd_step(1); break;
    case 0x40: cmd_step(FDC_CMD_STEP_IN, 0); break;
    case 0x50: cmd_step(FDC_CMD_STEP_IN, 1); break;
    case 0x60: cmd_step(FDC_CMD_STEP_OUT, 0); break;
    case 0x70: cmd_step(FDC_CMD_STEP_OUT, 1); break;
  // type II
    case 0x80: cmd_readdata(FDC_CMD_RD_SEC); break;
    case 0x90: cmd_readdata(FDC_CMD_RD_MSEC); break;
    case 0xa0: cmd_writedata(FDC_CMD_WR_SEC); break;
    case 0xb0: cmd_writedata(FDC_CMD_WR_MSEC); break;
  // type III
    case 0xc0: cmd_readaddr(FDC_CMD_RD_ADDR); break;
    case 0xe0: cmd_readtrack(FDC_CMD_RD_TRK); break;
    case 0xf0: cmd_writetrack(FDC_CMD_WR_TRK); break;
  // type IV
    case 0xd0: cmd_forceint(FDC_CMD_TYPE4); break;
    default: break;
  }
  digitalWrite(FDC_IRQ, LOW);   // Generate interrupt, command completed
}
示例#24
0
文件: File.cpp 项目: Felard/MoSync
/**
 * Returns a linked list of the files in
 * this directory. If this file is not a
 * directory, the list will be empty
 *
 * @return Linked list with files.
 */
std::list<File> File::listFiles ( void )
{
	std::list<File> l;

	// Can only list files for directories
	if ( isDirectory( ) == false )
		return l;

	g_fileList = &l;

// FIX (niklas): I don't know why this should work in another way?
//#ifndef WIN32
//	g_currentPath = "";
//#else
	g_currentPath = m_path + F_SEPERATOR;
//#endif
	scanDirectory( (m_path + "/*").c_str( ), callback );
	g_fileList = NULL;

	return l;
}
示例#25
0
文件: dialog.cpp 项目: pa23/strcnt
void Dialog::scanDirectory(QString dir) {

    QDir projectDirectory(dir);
    QString fullName;
    QFileInfo fileInfo;

    QStringList fileNamesList(projectDirectory.entryList(QDir::Dirs | QDir::Files, QDir::Name));

    for (ptrdiff_t i=0; i<fileNamesList.count(); i++) {

        fullName = dir + QDir::separator() + fileNamesList.at(i);
        fileInfo.setFile(fullName);

        if ( fileInfo.isDir() && ( ( fileNamesList.at(i) != "." ) && ( fileNamesList.at(i) != ".." ) ) ) {

            scanDirectory(fullName);
        }
        else if ( fileInfo.isFile() && itsOurFile(fileInfo.suffix()) ) {

            files->push_back(fullName);
        }
    }
}
示例#26
0
文件: dialog.cpp 项目: pa23/strcnt
void Dialog::on_pushButton_start_clicked() {

    ui->pushButton_selectDirectory->setEnabled(false);
    ui->pushButton_start->setEnabled(false);
    ui->pushButton_quit->setEnabled(false);

    //

    fileExtensions = ui->lineEdit_fileExtensions->text().split(";", QString::SkipEmptyParts);

    scanDirectory(ui->lineEdit_path->text());
    getSourceCodeStringsNumber();

    ui->label_stringsNumber->setText(QString::number(lines));

    files->clear();
    lines = 0;

    //

    ui->pushButton_selectDirectory->setEnabled(true);
    ui->pushButton_start->setEnabled(true);
    ui->pushButton_quit->setEnabled(true);
}
示例#27
0
std::wstring SaveDialog::preInsert(Coord &cursor, const std::wstring &value)
{
  if (cursor.y == 1 && value.find(L"\n") == std::wstring::npos)
    return value;
  else if (value.find(L"\n") != std::wstring::npos && cursor.y > 0)
  {
    struct stat buf;
    auto fileName = toUtf8(buffer_[screen_->cursor().y]);
    stat(fileName.c_str(), &buf);
    if (S_ISDIR(buf.st_mode))
    {
      auto folderName = buffer_[0];
      folderName = { begin(folderName) + folderName.rfind(L"/") + 1, end(folderName) - 1 };
      int res = chdir(fileName.c_str());
      if (res != 0)
      {
        throw std::runtime_error(std::string("chdir ") + strerror(errno) + " " + std::to_string(errno));
      }
      scanDirectory();
      int line = -1;
      for (size_t i = 0; i < buffer_.size(); ++i)
        if (buffer_[i] == folderName)
        {
          line = i;
          break;
        }
      if (line != -1)
        cursor = { 0, line };
      else
        cursor = { 0, 1 };
    }
    else
      saveAs(this, textFile_, fileName);
  }
  return L"";
}
示例#28
0
int main(int /*argc*/, char** /*argv*/)
{
	// Init SDL
	if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
	{
		printf("Could not initialise SDL\n");
		return -1;
	}
	
	// Center window
	char env[] = "SDL_VIDEO_CENTERED=1";
	putenv(env);

	// Init OpenGL
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
//#ifndef WIN32
	SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
	SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
//#endif

	const SDL_VideoInfo* vi = SDL_GetVideoInfo();

	bool presentationMode = false;

	int width, height;
	SDL_Surface* screen = 0;
	
	if (presentationMode)
	{
        width = 1700;
        height = 1000;
		screen = SDL_SetVideoMode(width, height, 0, SDL_OPENGL|SDL_FULLSCREEN);
	}
	else
	{	
        width = 1700;
        height = 1000;
		screen = SDL_SetVideoMode(width, height, 0, SDL_OPENGL);
	}
	
	if (!screen)
	{
		printf("Could not initialise SDL opengl\n");
		return -1;
	}

	glEnable(GL_MULTISAMPLE);

	SDL_WM_SetCaption("Recast Demo", 0);
	
	if (!imguiRenderGLInit("DroidSans.ttf"))
	{
		printf("Could not init GUI renderer.\n");
		SDL_Quit();
		return -1;
	}
	
	float t = 0.0f;
	float timeAcc = 0.0f;
	Uint32 lastTime = SDL_GetTicks();
	int mx = 0, my = 0;
	float rx = 45;
	float ry = -45;
	float moveW = 0, moveS = 0, moveA = 0, moveD = 0;
	float camx = 0, camy = 0, camz = 0, camr = 1000;
	float origrx = 0, origry = 0;
	int origx = 0, origy = 0;
	float scrollZoom = 0;
	bool rotate = false;
	bool movedDuringRotate = false;
	float rays[3], raye[3]; 
	bool mouseOverMenu = false;
	bool showMenu = !presentationMode;
	bool showLog = false;
	bool showTools = true;
	bool showLevels = false;
	bool showSample = false;
	bool showTestCases = false;

	int propScroll = 0;
	int logScroll = 0;
	int toolsScroll = 0;
	
	char sampleName[64] = "Choose Sample..."; 
	
	FileList files;
	char meshName[128] = "Choose Mesh...";
	
	float mpos[3] = {0,0,0};
	bool mposSet = false;
	
	SlideShow slideShow;
	slideShow.init("slides/");
	
	InputGeom* geom = 0;
	Sample* sample = 0;
	TestCase* test = 0;

	BuildContext ctx;
	
	glEnable(GL_CULL_FACE);
	
	float fogCol[4] = { 0.32f, 0.31f, 0.30f, 1.0f };
	glEnable(GL_FOG);
	glFogi(GL_FOG_MODE, GL_LINEAR);
	glFogf(GL_FOG_START, camr*0.1f);
	glFogf(GL_FOG_END, camr*1.25f);
	glFogfv(GL_FOG_COLOR, fogCol);
	
	glDepthFunc(GL_LEQUAL);
	
	bool done = false;
	while(!done)
	{
		// Handle input events.
		int mscroll = 0;
		bool processHitTest = false;
		bool processHitTestShift = false;
		SDL_Event event;
		
		while (SDL_PollEvent(&event))
		{
			switch (event.type)
			{
				case SDL_KEYDOWN:
					// Handle any key presses here.
					if (event.key.keysym.sym == SDLK_ESCAPE)
					{
						done = true;
					}
					else if (event.key.keysym.sym == SDLK_t)
					{
						showLevels = false;
						showSample = false;
						showTestCases = true;
						scanDirectory("Tests", ".txt", files);
					}
					else if (event.key.keysym.sym == SDLK_TAB)
					{
						showMenu = !showMenu;
					}
					else if (event.key.keysym.sym == SDLK_SPACE)
					{
						if (sample)
							sample->handleToggle();
					}
					else if (event.key.keysym.sym == SDLK_1)
					{
						if (sample)
							sample->handleStep();
					}
					else if (event.key.keysym.sym == SDLK_9)
					{
						if (geom)
							geom->save("geomset.txt");
					}
					else if (event.key.keysym.sym == SDLK_0)
					{
						delete geom;
						geom = new InputGeom;
						if (!geom || !geom->load(&ctx, "geomset.txt"))
						{
							delete geom;
							geom = 0;
							
							showLog = true;
							logScroll = 0;
							ctx.dumpLog("Geom load log %s:", meshName);
						}
						if (sample && geom)
						{
							sample->handleMeshChanged(geom);
						}
							
						if (geom || sample)
						{
							const float* bmin = 0;
							const float* bmax = 0;
							if (sample)
							{
								bmin = sample->getBoundsMin();
								bmax = sample->getBoundsMax();
							}
							else if (geom)
							{
								bmin = geom->getMeshBoundsMin();
								bmax = geom->getMeshBoundsMax();
							}
							// Reset camera and fog to match the mesh bounds.
							if (bmin && bmax)
							{
								camr = sqrtf(rcSqr(bmax[0]-bmin[0]) +
											 rcSqr(bmax[1]-bmin[1]) +
											 rcSqr(bmax[2]-bmin[2])) / 2;
								camx = (bmax[0] + bmin[0]) / 2 + camr;
								camy = (bmax[1] + bmin[1]) / 2 + camr;
								camz = (bmax[2] + bmin[2]) / 2 + camr;
								camr *= 3;
							}
							rx = 45;
							ry = -45;
							glFogf(GL_FOG_START, camr*0.2f);
							glFogf(GL_FOG_END, camr*1.25f);
						}
					}
					else if (event.key.keysym.sym == SDLK_RIGHT)
					{
						slideShow.nextSlide();
					}
					else if (event.key.keysym.sym == SDLK_LEFT)
					{
						slideShow.prevSlide();
					}
					break;
					
				case SDL_MOUSEBUTTONDOWN:
					if (event.button.button == SDL_BUTTON_RIGHT)
					{
						if (!mouseOverMenu)
						{
							// Rotate view
							rotate = true;
							movedDuringRotate = false;
							origx = mx;
							origy = my;
							origrx = rx;
							origry = ry;
						}
					}	
					else if (event.button.button == SDL_BUTTON_WHEELUP)
					{
						if (mouseOverMenu)
							mscroll--;
						else
							scrollZoom -= 1.0f;
					}
					else if (event.button.button == SDL_BUTTON_WHEELDOWN)
					{
						if (mouseOverMenu)
							mscroll++;
						else
							scrollZoom += 1.0f;
					}
					break;
					
				case SDL_MOUSEBUTTONUP:
					// Handle mouse clicks here.
					if (event.button.button == SDL_BUTTON_RIGHT)
					{
						rotate = false;
						if (!mouseOverMenu)
						{
							if (!movedDuringRotate)
							{
								processHitTest = true;
								processHitTestShift = true;
							}
						}
					}
					else if (event.button.button == SDL_BUTTON_LEFT)
					{
						if (!mouseOverMenu)
						{
							processHitTest = true;
							processHitTestShift = (SDL_GetModState() & KMOD_SHIFT) ? true : false;
						}
					}
					
					break;
					
				case SDL_MOUSEMOTION:
					mx = event.motion.x;
					my = height-1 - event.motion.y;
					if (rotate)
					{
						int dx = mx - origx;
						int dy = my - origy;
						rx = origrx - dy*0.25f;
						ry = origry + dx*0.25f;
						if (dx*dx+dy*dy > 3*3)
							movedDuringRotate = true;
					}
					break;
					
				case SDL_QUIT:
					done = true;
					break;
					
				default:
					break;
			}
		}

		unsigned char mbut = 0;
		if (SDL_GetMouseState(0,0) & SDL_BUTTON_LMASK)
			mbut |= IMGUI_MBUT_LEFT;
		if (SDL_GetMouseState(0,0) & SDL_BUTTON_RMASK)
			mbut |= IMGUI_MBUT_RIGHT;
		
		Uint32	time = SDL_GetTicks();
		float	dt = (time - lastTime) / 1000.0f;
		lastTime = time;
		
		t += dt;


		// Hit test mesh.
		if (processHitTest && geom && sample)
		{
			float hitt;
			bool hit = geom->raycastMesh(rays, raye, hitt);
			
			if (hit)
			{
				if (SDL_GetModState() & KMOD_CTRL)
				{
					// Marker
					mposSet = true;
					mpos[0] = rays[0] + (raye[0] - rays[0])*hitt;
					mpos[1] = rays[1] + (raye[1] - rays[1])*hitt;
					mpos[2] = rays[2] + (raye[2] - rays[2])*hitt;
				}
				else
				{
					float pos[3];
					pos[0] = rays[0] + (raye[0] - rays[0])*hitt;
					pos[1] = rays[1] + (raye[1] - rays[1])*hitt;
					pos[2] = rays[2] + (raye[2] - rays[2])*hitt;
					sample->handleClick(rays, pos, processHitTestShift);
				}
			}
			else
			{
				if (SDL_GetModState() & KMOD_CTRL)
				{
					// Marker
					mposSet = false;
				}
			}
		}
		
		// Update sample simulation.
		const float SIM_RATE = 20;
		const float DELTA_TIME = 1.0f/SIM_RATE;
		timeAcc = rcClamp(timeAcc+dt, -1.0f, 1.0f);
		int simIter = 0;
		while (timeAcc > DELTA_TIME)
		{
			timeAcc -= DELTA_TIME;
			if (simIter < 5)
			{
				if (sample)
					sample->handleUpdate(DELTA_TIME);
			}
			simIter++;
		}

		// Clamp the framerate so that we do not hog all the CPU.
		const float MIN_FRAME_TIME = 1.0f/40.0f;
		if (dt < MIN_FRAME_TIME)
		{
			int ms = (int)((MIN_FRAME_TIME - dt)*1000.0f);
			if (ms > 10) ms = 10;
			if (ms >= 0)
				SDL_Delay(ms);
		}
		
		
		// Update and render
		glViewport(0, 0, width, height);
		glClearColor(0.3f, 0.3f, 0.32f, 1.0f);
		glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glDisable(GL_TEXTURE_2D);
		
		// Render 3d
		glEnable(GL_DEPTH_TEST);
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		gluPerspective(50.0f, (float)width/(float)height, 1.0f, camr);
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		glRotatef(rx,1,0,0);
		glRotatef(ry,0,1,0);
		glTranslatef(-camx, -camy, -camz);
		
		// Get hit ray position and direction.
		GLdouble proj[16];
		GLdouble model[16];
		GLint view[4];
		glGetDoublev(GL_PROJECTION_MATRIX, proj);
		glGetDoublev(GL_MODELVIEW_MATRIX, model);
		glGetIntegerv(GL_VIEWPORT, view);
		GLdouble x, y, z;
		gluUnProject(mx, my, 0.0f, model, proj, view, &x, &y, &z);
		rays[0] = (float)x; rays[1] = (float)y; rays[2] = (float)z;
		gluUnProject(mx, my, 1.0f, model, proj, view, &x, &y, &z);
		raye[0] = (float)x; raye[1] = (float)y; raye[2] = (float)z;
		
		// Handle keyboard movement.
		Uint8* keystate = SDL_GetKeyState(NULL);
		moveW = rcClamp(moveW + dt * 4 * (keystate[SDLK_w] ? 1 : -1), 0.0f, 1.0f);
		moveS = rcClamp(moveS + dt * 4 * (keystate[SDLK_s] ? 1 : -1), 0.0f, 1.0f);
		moveA = rcClamp(moveA + dt * 4 * (keystate[SDLK_a] ? 1 : -1), 0.0f, 1.0f);
		moveD = rcClamp(moveD + dt * 4 * (keystate[SDLK_d] ? 1 : -1), 0.0f, 1.0f);
		
		float keybSpeed = 22.0f;
		if (SDL_GetModState() & KMOD_SHIFT)
			keybSpeed *= 4.0f;
		
		float movex = (moveD - moveA) * keybSpeed * dt;
		float movey = (moveS - moveW) * keybSpeed * dt;
		
		movey += scrollZoom * 2.0f;
		scrollZoom = 0;
		
		camx += movex * (float)model[0];
		camy += movex * (float)model[4];
		camz += movex * (float)model[8];
		
		camx += movey * (float)model[2];
		camy += movey * (float)model[6];
		camz += movey * (float)model[10];

		glEnable(GL_FOG);

		if (sample)
			sample->handleRender();
		if (test)
			test->handleRender();
		
		glDisable(GL_FOG);
		
		// Render GUI
		glDisable(GL_DEPTH_TEST);
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		gluOrtho2D(0, width, 0, height);
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		
		mouseOverMenu = false;
		
		imguiBeginFrame(mx,my,mbut,mscroll);
		
		if (sample)
		{
			sample->handleRenderOverlay((double*)proj, (double*)model, (int*)view);
		}
		if (test)
		{
			if (test->handleRenderOverlay((double*)proj, (double*)model, (int*)view))
				mouseOverMenu = true;
		}

		// Help text.
		if (showMenu)
		{
			const char msg[] = "W/S/A/D: Move  RMB: Rotate";
			imguiDrawText(280, height-20, IMGUI_ALIGN_LEFT, msg, imguiRGBA(255,255,255,128));
		}
		
		if (showMenu)
		{
			if (imguiBeginScrollArea("Properties", width-250-10, 10, 250, height-20, &propScroll))
				mouseOverMenu = true;

			if (imguiCheck("Show Log", showLog))
				showLog = !showLog;
			if (imguiCheck("Show Tools", showTools))
				showTools = !showTools;

			imguiSeparator();
			imguiLabel("Sample");
			if (imguiButton(sampleName))
			{
				if (showSample)
				{
					showSample = false;
				}
				else
				{
					showSample = true;
					showLevels = false;
					showTestCases = false;
				}
			}
			
			imguiSeparator();
			imguiLabel("Input Mesh");
			if (imguiButton(meshName))
			{
				if (showLevels)
				{
					showLevels = false;
				}
				else
				{
					showSample = false;
					showTestCases = false;
					showLevels = true;
					scanDirectory("Meshes", ".obj", files);
				}
			}
			if (geom)
			{
				char text[64];
				snprintf(text, 64, "Verts: %.1fk  Tris: %.1fk",
						 geom->getMesh()->getVertCount()/1000.0f,
						 geom->getMesh()->getTriCount()/1000.0f);
				imguiValue(text);
			}
			imguiSeparator();

			if (geom && sample)
			{
				imguiSeparatorLine();
				
				sample->handleSettings();

				if (imguiButton("Build"))
				{
					ctx.resetLog();
					if (!sample->handleBuild())
					{
						showLog = true;
						logScroll = 0;
					}
					ctx.dumpLog("Build log %s:", meshName);
					
					// Clear test.
					delete test;
					test = 0;
				}

				imguiSeparator();
			}
			
			if (sample)
			{
				imguiSeparatorLine();
				sample->handleDebugMode();
			}

			imguiEndScrollArea();
		}
		
		// Sample selection dialog.
		if (showSample)
		{
			static int levelScroll = 0;
			if (imguiBeginScrollArea("Choose Sample", width-10-250-10-200, height-10-250, 200, 250, &levelScroll))
				mouseOverMenu = true;

			Sample* newSample = 0;
			for (int i = 0; i < g_nsamples; ++i)
			{
				if (imguiItem(g_samples[i].name))
				{
					newSample = g_samples[i].create();
					if (newSample)
						strcpy(sampleName, g_samples[i].name);
				}
			}
			if (newSample)
			{
				delete sample;
				sample = newSample;
				sample->setContext(&ctx);
				if (geom && sample)
				{
					sample->handleMeshChanged(geom);
				}
				showSample = false;
			}

			if (geom || sample)
			{
				const float* bmin = 0;
				const float* bmax = 0;
				if (sample)
				{
					bmin = sample->getBoundsMin();
					bmax = sample->getBoundsMax();
				}
				else if (geom)
				{
					bmin = geom->getMeshBoundsMin();
					bmax = geom->getMeshBoundsMax();
				}
				// Reset camera and fog to match the mesh bounds.
				if (bmin && bmax)
				{
					camr = sqrtf(rcSqr(bmax[0]-bmin[0]) +
								 rcSqr(bmax[1]-bmin[1]) +
								 rcSqr(bmax[2]-bmin[2])) / 2;
					camx = (bmax[0] + bmin[0]) / 2 + camr;
					camy = (bmax[1] + bmin[1]) / 2 + camr;
					camz = (bmax[2] + bmin[2]) / 2 + camr;
					camr *= 3;
				}
				rx = 45;
				ry = -45;
				glFogf(GL_FOG_START, camr*0.1f);
				glFogf(GL_FOG_END, camr*1.25f);
			}
			
			imguiEndScrollArea();
		}
		
		// Level selection dialog.
		if (showLevels)
		{
			static int levelScroll = 0;
			if (imguiBeginScrollArea("Choose Level", width-10-250-10-200, height-10-450, 200, 450, &levelScroll))
				mouseOverMenu = true;
			
			int levelToLoad = -1;
			for (int i = 0; i < files.size; ++i)
			{
				if (imguiItem(files.files[i]))
					levelToLoad = i;
			}
			
			if (levelToLoad != -1)
			{
				strncpy(meshName, files.files[levelToLoad], sizeof(meshName));
				meshName[sizeof(meshName)-1] = '\0';
				showLevels = false;
				
				delete geom;
				geom = 0;
				
				char path[256];
				strcpy(path, "Meshes/");
				strcat(path, meshName);
				
				geom = new InputGeom;
				if (!geom || !geom->loadMesh(&ctx, path))
				{
					delete geom;
					geom = 0;
					
					showLog = true;
					logScroll = 0;
					ctx.dumpLog("Geom load log %s:", meshName);
				}
				if (sample && geom)
				{
					sample->handleMeshChanged(geom);
				}

				if (geom || sample)
				{
					const float* bmin = 0;
					const float* bmax = 0;
					if (sample)
					{
						bmin = sample->getBoundsMin();
						bmax = sample->getBoundsMax();
					}
					else if (geom)
					{
						bmin = geom->getMeshBoundsMin();
						bmax = geom->getMeshBoundsMax();
					}
					// Reset camera and fog to match the mesh bounds.
					if (bmin && bmax)
					{
						camr = sqrtf(rcSqr(bmax[0]-bmin[0]) +
									 rcSqr(bmax[1]-bmin[1]) +
									 rcSqr(bmax[2]-bmin[2])) / 2;
						camx = (bmax[0] + bmin[0]) / 2 + camr;
						camy = (bmax[1] + bmin[1]) / 2 + camr;
						camz = (bmax[2] + bmin[2]) / 2 + camr;
						camr *= 3;
					}
					rx = 45;
					ry = -45;
					glFogf(GL_FOG_START, camr*0.1f);
					glFogf(GL_FOG_END, camr*1.25f);
				}
			}
			
			imguiEndScrollArea();
			
		}
		
		// Test cases
		if (showTestCases)
		{
			static int testScroll = 0;
			if (imguiBeginScrollArea("Choose Test To Run", width-10-250-10-200, height-10-450, 200, 450, &testScroll))
				mouseOverMenu = true;

			int testToLoad = -1;
			for (int i = 0; i < files.size; ++i)
			{
				if (imguiItem(files.files[i]))
					testToLoad = i;
			}
			
			if (testToLoad != -1)
			{
				char path[256];
				strcpy(path, "Tests/");
				strcat(path, files.files[testToLoad]);
				test = new TestCase;
				if (test)
				{
					// Load the test.
					if (!test->load(path))
					{
						delete test;
						test = 0;
					}

					// Create sample
					Sample* newSample = 0;
					for (int i = 0; i < g_nsamples; ++i)
					{
						if (strcmp(g_samples[i].name, test->getSampleName()) == 0)
						{
							newSample = g_samples[i].create();
							if (newSample) strcpy(sampleName, g_samples[i].name);
						}
					}
					if (newSample)
					{
						delete sample;
						sample = newSample;
						sample->setContext(&ctx);
						showSample = false;
					}

					// Load geom.
					strcpy(meshName, test->getGeomFileName());
					meshName[sizeof(meshName)-1] = '\0';
					
					delete geom;
					geom = 0;
					
					strcpy(path, "Meshes/");
					strcat(path, meshName);
					
					geom = new InputGeom;
					if (!geom || !geom->loadMesh(&ctx, path))
					{
						delete geom;
						geom = 0;
						showLog = true;
						logScroll = 0;
						ctx.dumpLog("Geom load log %s:", meshName);
					}
					if (sample && geom)
					{
						sample->handleMeshChanged(geom);
					}

					// This will ensure that tile & poly bits are updated in tiled sample.
					if (sample)
						sample->handleSettings();

					ctx.resetLog();
					if (sample && !sample->handleBuild())
					{
						ctx.dumpLog("Build log %s:", meshName);
					}
					
					if (geom || sample)
					{
						const float* bmin = 0;
						const float* bmax = 0;
						if (sample)
						{
							bmin = sample->getBoundsMin();
							bmax = sample->getBoundsMax();
						}
						else if (geom)
						{
							bmin = geom->getMeshBoundsMin();
							bmax = geom->getMeshBoundsMax();
						}
						// Reset camera and fog to match the mesh bounds.
						if (bmin && bmax)
						{
							camr = sqrtf(rcSqr(bmax[0]-bmin[0]) +
										 rcSqr(bmax[1]-bmin[1]) +
										 rcSqr(bmax[2]-bmin[2])) / 2;
							camx = (bmax[0] + bmin[0]) / 2 + camr;
							camy = (bmax[1] + bmin[1]) / 2 + camr;
							camz = (bmax[2] + bmin[2]) / 2 + camr;
							camr *= 3;
						}
						rx = 45;
						ry = -45;
						glFogf(GL_FOG_START, camr*0.2f);
						glFogf(GL_FOG_END, camr*1.25f);
					}
					
					// Do the tests.
					if (sample)
						test->doTests(sample->getNavMesh(), sample->getNavMeshQuery());
				}
			}				
				
			imguiEndScrollArea();
		}

		
		// Log
		if (showLog && showMenu)
		{
			if (imguiBeginScrollArea("Log", 250+20, 10, width - 300 - 250, 200, &logScroll))
				mouseOverMenu = true;
			for (int i = 0; i < ctx.getLogCount(); ++i)
				imguiLabel(ctx.getLogText(i));
			imguiEndScrollArea();
		}
		
		// Tools
		if (!showTestCases && showTools && showMenu) // && geom && sample)
		{
			if (imguiBeginScrollArea("Tools", 10, 10, 250, height-20, &toolsScroll))
				mouseOverMenu = true;

			if (sample)
				sample->handleTools();
			
			imguiEndScrollArea();
		}
		
		slideShow.updateAndDraw(dt, (float)width, (float)height);
		
		// Marker
		if (mposSet && gluProject((GLdouble)mpos[0], (GLdouble)mpos[1], (GLdouble)mpos[2],
								  model, proj, view, &x, &y, &z))
		{
			// Draw marker circle
			glLineWidth(5.0f);
			glColor4ub(240,220,0,196);
			glBegin(GL_LINE_LOOP);
			const float r = 25.0f;
			for (int i = 0; i < 20; ++i)
			{
				const float a = (float)i / 20.0f * RC_PI*2;
				const float fx = (float)x + cosf(a)*r;
				const float fy = (float)y + sinf(a)*r;
				glVertex2f(fx,fy);
			}
			glEnd();
			glLineWidth(1.0f);
		}
		
		imguiEndFrame();
		imguiRenderGLDraw();		
		
		glEnable(GL_DEPTH_TEST);
		SDL_GL_SwapBuffers();
	}
	
	imguiRenderGLDestroy();
	
	SDL_Quit();
	
	delete sample;
	delete geom;
	
	return 0;
}
示例#29
0
文件: filter.cpp 项目: darthvid/sion
/**
 * Updates all associated filtered files in the db
 *
 */
void Filter::rescanDirectory() {
    cleanup();
    scanDirectory();
}
示例#30
0
void OfxhPluginCache::scanPluginFiles()
{
	std::set<std::string> foundBinFiles;

	for( std::list<std::string>::iterator paths = _pluginPath.begin();
	     paths != _pluginPath.end();
	     ++paths )
	{
		scanDirectory( foundBinFiles, *paths, _nonrecursePath.find( *paths ) == _nonrecursePath.end() );
	}

	OfxhPluginBinaryList::iterator i = _binaries.begin();
	while( i != _binaries.end() )
	{
		if( foundBinFiles.find( i->getFilePath() ) == foundBinFiles.end() )
		{
			// the binary was in the cache, but was not on the path
			setDirty();
			i = _binaries.erase( i );
		}
		else
		{
			const bool binChanged = i->hasBinaryChanged();

			// the binary was in the cache, but the binary has changed and thus we need to reload
			if( binChanged )
			{
				i->loadPluginInfo( this );
				setDirty();
			}

			for( int j = 0; j < i->getNPlugins(); ++j )
			{
				OfxhPlugin& plug                   = i->getPlugin( j );
				try
				{
					APICache::OfxhPluginAPICacheI& api = plug.getApiHandler();

					if( binChanged )
					{
						api.loadFromPlugin( plug ); // may throw
					}

					std::string reason;

					if( api.pluginSupported( plug, reason ) )
					{
						addPlugin( &plug );
						api.confirmPlugin( plug );
					}
					else
					{
						TUTTLE_COUT_ERROR(
							"Ignoring plugin " << quotes(plug.getIdentifier()) <<
							": unsupported, " << reason << "." );
					}
				}
				catch(...)
				{
					TUTTLE_COUT_ERROR(
						"Ignoring plugin " << quotes(plug.getIdentifier()) <<
						": loading error." );
					
				}
			}

			++i;
		}
	}
}