Exemplo n.º 1
0
void GFont::renderCharVertexArray(RenderDevice* renderDevice, const Array<CPUCharVertex>& cpuCharArray, Array<int>& indexArray) const {

    // Avoid the overhead of Profiler events by not calling LAUNCH_SHADER...
    static const shared_ptr<Shader> fontShader = Shader::getShaderFromPattern("GFont_render.*");

    renderDevice->setBlendFunc(RenderDevice::BLEND_SRC_ALPHA, RenderDevice::BLEND_ONE_MINUS_SRC_ALPHA);
    renderDevice->setCullFace(CullFace::NONE);

    const shared_ptr<VertexBuffer>& vb = VertexBuffer::create((cpuCharArray.size() * sizeof(CPUCharVertex)) + (indexArray.size() * sizeof(int)) + 8, VertexBuffer::WRITE_EVERY_FRAME);

    IndexStream indexStream(indexArray, vb);
    AttributeArray interleavedArray(cpuCharArray.size() * sizeof(CPUCharVertex), vb);

    CPUCharVertex dummy;
#   define OFFSET(field) ((size_t)(&dummy.field) - (size_t)&dummy)
        AttributeArray  texCoordArray   (dummy.texCoord,    cpuCharArray.size(), interleavedArray, OFFSET(texCoord),    sizeof(CPUCharVertex));
        AttributeArray  positionArray   (dummy.position,    cpuCharArray.size(), interleavedArray, OFFSET(position),    sizeof(CPUCharVertex));
        AttributeArray  colorArray      (dummy.color,       cpuCharArray.size(), interleavedArray, OFFSET(color),       sizeof(CPUCharVertex));
        AttributeArray  borderColorArray(dummy.borderColor, cpuCharArray.size(), interleavedArray, OFFSET(borderColor), sizeof(CPUCharVertex));
#   undef OFFSET
    
    CPUCharVertex* dst = (CPUCharVertex*)interleavedArray.mapBuffer(GL_WRITE_ONLY);
    System::memcpy(dst, cpuCharArray.getCArray(), cpuCharArray.size() * sizeof(CPUCharVertex));
    interleavedArray.unmapBuffer();

    Args args;
    args.enableG3DArgs(false); // Lower CPU overhead for uniform bind

    args.setAttributeArray("g3d_Vertex",    positionArray);
    args.setAttributeArray("g3d_TexCoord0", texCoordArray);
    args.setAttributeArray("borderColor",   borderColorArray);    
    args.setAttributeArray("color",         colorArray);
    args.setIndexArray(indexStream);
    args.setPrimitiveType(PrimitiveType::TRIANGLES);

    args.setUniform("g3d_ObjectToScreenMatrixTranspose", RenderDevice::current->objectToScreenMatrix().transpose()); 
    args.setUniform("textureMatrix",        Matrix4(m_textureMatrix));
    args.setUniform("borderWidth",          Vector2(m_textureMatrix[0], m_textureMatrix[5]));
    args.setUniform("textureLODBias",       -0.6f);
    args.setUniform("fontTexture",          m_texture, Sampler::defaults());
    args.setUniform("alphaThreshold",       1.0f / 255.0f);
    args.setUniform("translation",          Vector2(0, 0));
    
    RenderDevice::current->apply(fontShader, args);
}
Exemplo n.º 2
0
int main(int ac, char* av[]){
    
    // Yeah, I know this isn't the best way to do this, but YAY STREAMS
    std::cout << "The ASCII Project Server - 0.0.1f" << std::endl;
    std::cout << "--------------------------------" << std::endl;
    std::cout << std::endl;

    
    ConfigParser *cfgParse = new ConfigParser(ac, av);
    cfgParse->parse();
    
    dbEngine = new DBConnector(cfgParse->db_hostname, cfgParse->db_port, cfgParse->db_username, cfgParse->db_pass, cfgParse->db_name);    
    
    if(!fileExists("data/maps/World.idx")){
        worldMap = new WorldMap(cfgParse->worldX, cfgParse->worldY, cfgParse->worldZ);
        worldMap->initWorldMap();
        worldMap->backupToDisk();
        
        std::ofstream indexOutStream("data/maps/World.idx");
        boost::archive::binary_oarchive indexOut(indexOutStream);
        indexOut << worldMap;
        indexOutStream.close();
    }
    else{
        
        std::ifstream indexStream("data/maps/World.idx");
        boost::archive::binary_iarchive indexLoad(indexStream);
        indexLoad >> worldMap;
        
        worldMap->loadFromDisk();
        
    }
    

    try
    {
        std::cout << "Preparing to start listening on port " << cfgParse->serverPort;
        sleep(0.5);
        std::cout << ".";
        sleep(0.5);
        std::cout << ".";
        sleep(0.5);
        std::cout << "." << std::endl;
        
        boost::asio::io_service io_service;
        tcp::endpoint endpoint(tcp::v4(), cfgParse->serverPort);
        boost::asio::signal_set signals(io_service, SIGINT, SIGTERM);
        signals.async_wait(boost::bind(&boost::asio::io_service::stop, &io_service));
        game_server server(io_service, endpoint);
        
        std::cout << "Server startup complete, have fun!" << std::endl;
        std::cout << std::endl;
        
        io_service.run();
    }
    catch (std::exception& e)
    {
        std::cerr << e.what() << std::endl;
    }
    
    return 0;
}
Exemplo n.º 3
0
/*!
	Parses and loads multi definitions
*/
void cMultiCache::load( const QString &basePath )
{
	QFile indexFile( basePath + "multi.idx" );
	if( !indexFile.open( IO_ReadOnly ) )
		throw wpException( QString( "Error opening file %1 for reading." ).arg( basePath + "multi.idx" ) );

	QDataStream indexStream( &indexFile );
	indexStream.setByteOrder( QDataStream::LittleEndian );

	QFile multiFile( basePath + "multi.mul" );
	if ( !multiFile.open( IO_ReadOnly ) )
		throw wpException( QString( "Error opening file %1 for reading." ).arg( basePath + "multi.mul" ) );

	struct
	{
		Q_INT32 start;
		Q_INT32 length;
		Q_INT32 unknown;
	} indexData;
	ushort currentID = 0;
	while ( !indexStream.atEnd() )
	{
		indexFile.at( currentID * 12 );
		indexStream >> indexData.start;
		indexStream >> indexData.length;
		indexStream >> indexData.unknown;

		if ( indexData.start == -1 ) // empty record?
		{
			++currentID;
			continue;
		}

		QValueVector<multiItem_st> items;
		items.reserve( indexData.length / 12 );
		uint i = 0;

		multiFile.at( indexData.start );
		QDataStream multiStream( &multiFile );
		multiStream.setByteOrder( QDataStream::LittleEndian );

		for (; i < indexData.length / 12; ++i )
		{
			multiItem_st item;
			multiStream >> item.tile;
			multiStream >> item.x;
			multiStream >> item.y;
			multiStream >> item.z;
			Q_UINT8  empty;
			multiStream >> empty; // ????
			Q_UINT32 isVisible = 0;
			multiStream >> isVisible;
			item.visible = isVisible > 0 ? true : false;

			if ( item.visible ) // we ignore invisible items (?)
				items.push_back(item);
		}
		MultiDefinition* multi = new MultiDefinition;
		multi->setItems( items );
		
		multis.insert( currentID++, multi );
	}
}
Exemplo n.º 4
0
int rapMapMap(int argc, char* argv[]) {
    std::cerr << "RapMap Mapper\n";

    std::string versionString = rapmap::version;
    TCLAP::CmdLine cmd(
            "RapMap Mapper",
            ' ',
            versionString);
    cmd.getProgramName() = "rapmap";

    TCLAP::ValueArg<std::string> index("i", "index", "The location of the pseudoindex", true, "", "path");
    TCLAP::ValueArg<std::string> read1("1", "leftMates", "The location of the left paired-end reads", false, "", "path");
    TCLAP::ValueArg<std::string> read2("2", "rightMates", "The location of the right paired-end reads", false, "", "path");
    TCLAP::ValueArg<std::string> unmatedReads("r", "unmatedReads", "The location of single-end reads", false, "", "path");
    TCLAP::ValueArg<uint32_t> numThreads("t", "numThreads", "Number of threads to use", false, 1, "positive integer");
    TCLAP::ValueArg<uint32_t> maxNumHits("m", "maxNumHits", "Reads mapping to more than this many loci are discarded", false, 200, "positive integer");
    TCLAP::ValueArg<std::string> outname("o", "output", "The output file (default: stdout)", false, "", "path");
    TCLAP::SwitchArg endCollectorSwitch("e", "endCollector", "Use the simpler (and faster) \"end\" collector as opposed to the more sophisticated \"skipping\" collector", false);
    TCLAP::SwitchArg noout("n", "noOutput", "Don't write out any alignments (for speed testing purposes)", false);
    cmd.add(index);
    cmd.add(noout);

    cmd.add(read1);
    cmd.add(read2);
    cmd.add(unmatedReads);
    cmd.add(outname);
    cmd.add(numThreads);
    cmd.add(maxNumHits);
    cmd.add(endCollectorSwitch);

    auto consoleSink = std::make_shared<spdlog::sinks::stderr_sink_mt>();
    auto consoleLog = spdlog::create("stderrLog", {consoleSink});

    try {

	cmd.parse(argc, argv);
	bool pairedEnd = (read1.isSet() or read2.isSet());
	if (pairedEnd and (read1.isSet() != read2.isSet())) {
	    consoleLog->error("You must set both the -1 and -2 arguments to align "
		    "paired end reads!");
	    std::exit(1);
	}

	if (pairedEnd and unmatedReads.isSet()) {
	    consoleLog->error("You cannot specify both paired-end and unmated "
		    "reads in the input!");
	    std::exit(1);
	}

	if (!pairedEnd and !unmatedReads.isSet()) {
	    consoleLog->error("You must specify input; either both paired-end "
			      "or unmated reads!");
	    std::exit(1);

	}

	std::string indexPrefix(index.getValue());
	if (indexPrefix.back() != '/') {
	    indexPrefix += "/";
	}

	if (!rapmap::fs::DirExists(indexPrefix.c_str())) {
	    consoleLog->error("It looks like the index you provided [{}] "
		    "doesn't exist", indexPrefix);
	    std::exit(1);
	}


	IndexHeader h;
	std::ifstream indexStream(indexPrefix + "header.json");
	{
		cereal::JSONInputArchive ar(indexStream);
		ar(h);
	}
	indexStream.close();

	if (h.indexType() != IndexType::PSEUDO) {
	    consoleLog->error("The index {} does not appear to be of the "
			    "appropriate type (pseudo)", indexPrefix);
	    std::exit(1);
	}

	RapMapIndex rmi;
	rmi.load(indexPrefix);

	std::cerr << "\n\n\n\n";

	// from: http://stackoverflow.com/questions/366955/obtain-a-stdostream-either-from-stdcout-or-stdofstreamfile
	// set either a file or cout as the output stream
	std::streambuf* outBuf;
	std::ofstream outFile;
	bool haveOutputFile{false};
	if (outname.getValue() == "") {
	    outBuf = std::cout.rdbuf();
	} else {
	    outFile.open(outname.getValue());
	    outBuf = outFile.rdbuf();
	    haveOutputFile = true;
	}
	// Now set the output stream to the buffer, which is
	// either std::cout, or a file.
	std::ostream outStream(outBuf);

	// Must be a power of 2
	size_t queueSize{268435456};
	spdlog::set_async_mode(queueSize);
	auto outputSink = std::make_shared<spdlog::sinks::ostream_sink_mt>(outStream);
	auto outLog = std::make_shared<spdlog::logger>("outLog", outputSink);
	outLog->set_pattern("%v");

	uint32_t nthread = numThreads.getValue();
	std::unique_ptr<paired_parser> pairParserPtr{nullptr};
	std::unique_ptr<single_parser> singleParserPtr{nullptr};

	if (!noout.getValue()) {
	    rapmap::utils::writeSAMHeader(rmi, outLog);
	}

	SpinLockT iomutex;
	{
	    ScopedTimer timer;
	    HitCounters hctrs;
	    consoleLog->info("mapping reads . . . \n\n\n");
	    if (pairedEnd) {
		std::vector<std::thread> threads;
		std::vector<std::string> read1Vec = rapmap::utils::tokenize(read1.getValue(), ',');
		std::vector<std::string> read2Vec = rapmap::utils::tokenize(read2.getValue(), ',');

		if (read1Vec.size() != read2Vec.size()) {
		    consoleLog->error("The number of provided files for "
			    "-1 and -2 must be the same!");
		    std::exit(1);
		}

		size_t numFiles = read1Vec.size() + read2Vec.size();
		char** pairFileList = new char*[numFiles];
		for (size_t i = 0; i < read1Vec.size(); ++i) {
		    pairFileList[2*i] = const_cast<char*>(read1Vec[i].c_str());
		    pairFileList[2*i+1] = const_cast<char*>(read2Vec[i].c_str());
		}
		size_t maxReadGroup{1000}; // Number of reads in each "job"
		size_t concurrentFile{2}; // Number of files to read simultaneously
		pairParserPtr.reset(new paired_parser(4 * nthread, maxReadGroup,
			    concurrentFile,
			    pairFileList, pairFileList+numFiles));

		/** Create the threads depending on the collector type **/
		if (endCollectorSwitch.getValue()) {
		    EndCollector endCollector(&rmi);
		    for (size_t i = 0; i < nthread; ++i) {
			threads.emplace_back(processReadsPair<EndCollector, SpinLockT>,
				pairParserPtr.get(),
				std::ref(rmi),
				std::ref(endCollector),
				&iomutex,
				outLog,
				std::ref(hctrs),
				maxNumHits.getValue(),
				noout.getValue());
		    }
		} else {
		    SkippingCollector skippingCollector(&rmi);
		    for (size_t i = 0; i < nthread; ++i) {
			threads.emplace_back(processReadsPair<SkippingCollector, SpinLockT>,
				pairParserPtr.get(),
				std::ref(rmi),
				std::ref(skippingCollector),
				&iomutex,
				outLog,
				std::ref(hctrs),
				maxNumHits.getValue(),
				noout.getValue());
		    }
		}

		for (auto& t : threads) { t.join(); }
		delete [] pairFileList;
	    } else {
		std::vector<std::thread> threads;
		std::vector<std::string> unmatedReadVec = rapmap::utils::tokenize(unmatedReads.getValue(), ',');
		size_t maxReadGroup{1000}; // Number of reads in each "job"
		size_t concurrentFile{1};
		stream_manager streams( unmatedReadVec.begin(), unmatedReadVec.end(),
			concurrentFile);
		singleParserPtr.reset(new single_parser(4 * nthread,
			    maxReadGroup,
			    concurrentFile,
			    streams));

		/** Create the threads depending on the collector type **/
		if (endCollectorSwitch.getValue()) {
		    EndCollector endCollector(&rmi);
		    for (size_t i = 0; i < nthread; ++i) {
			threads.emplace_back(processReadsSingle<EndCollector, SpinLockT>,
				singleParserPtr.get(),
				std::ref(rmi),
				std::ref(endCollector),
				&iomutex,
				outLog,
				std::ref(hctrs),
				maxNumHits.getValue(),
				noout.getValue());
		    }
		} else {
		    SkippingCollector skippingCollector(&rmi);
		    for (size_t i = 0; i < nthread; ++i) {
			threads.emplace_back(processReadsSingle<SkippingCollector, SpinLockT>,
				singleParserPtr.get(),
				std::ref(rmi),
				std::ref(skippingCollector),
				&iomutex,
				outLog,
				std::ref(hctrs),
				maxNumHits.getValue(),
				noout.getValue());
		    }
		}
		for (auto& t : threads) { t.join(); }
	    }
	    consoleLog->info("Done mapping reads.");
        consoleLog->info("In total saw {} reads.", hctrs.numReads);
        consoleLog->info("Final # hits per read = {}", hctrs.totHits / static_cast<float>(hctrs.numReads));
	    consoleLog->info("Discarded {} reads because they had > {} alignments",
		    hctrs.tooManyHits, maxNumHits.getValue());

	    consoleLog->info("flushing output");
	    outLog->flush();
	}

	if (haveOutputFile) {
	    outFile.close();
	}
	return 0;
    } catch (TCLAP::ArgException& e) {
	consoleLog->error("Exception [{}] when parsing argument {}", e.error(), e.argId());
	return 1;
    }

}