Ejemplo n.º 1
0
bool UI_RenderInterface::LoadTexture(Rocket::Core::TextureHandle & texture_handle, Rocket::Core::Vector2i & texture_dimensions, const Rocket::Core::String & source)
{
    shader_t *shader;
    Rocket::Core::String source2( source );

    if( source2[0] == '/' )
        source2.Erase( 0, 1 );

    shader = trap::R_RegisterPic( source2.CString() );
    if( !shader )
    {
        Com_Printf(S_COLOR_RED"Warning: RenderInterface couldnt load pic %s!\n", source.CString() );
        return false;
    }

    trap::R_GetShaderDimensions( shader, &texture_dimensions.x, &texture_dimensions.y );

    AddShaderToCache( source2 );

    texture_handle = TextureHandle( shader );

    // Com_Printf( "RenderInterface::LoadTexture %s successful (dimensions %dx%d\n", source.CString(), texture_dimensions.x, texture_dimensions.y );

    return true;
}
Ejemplo n.º 2
0
int main( int argc, char * argv[])
{
    {
        boost::coroutines::asymmetric_coroutine< void >::pull_type source1( boost::bind( first, _1) );
        boost::coroutines::asymmetric_coroutine< void >::pull_type source2( boost::bind( second, _1) );
        while ( source1 && source2) {
            source1();
            std::cout << " ";
            source2();
            std::cout << " ";
        }
    }

    std::cout << "\nDone" << std::endl;

    return EXIT_SUCCESS;
}
Ejemplo n.º 3
0
double QgsCoordinateTransform::scaleFactor( const QgsRectangle &ReferenceExtent ) const
{
  QgsPointXY source1( ReferenceExtent.xMinimum(), ReferenceExtent.yMinimum() );
  QgsPointXY source2( ReferenceExtent.xMaximum(), ReferenceExtent.yMaximum() );
  double distSourceUnits = std::sqrt( source1.sqrDist( source2 ) );
  QgsPointXY dest1 = transform( source1 );
  QgsPointXY dest2 = transform( source2 );
  double distDestUnits = std::sqrt( dest1.sqrDist( dest2 ) );
  return distDestUnits / distSourceUnits;
}
Ejemplo n.º 4
0
int main()
{
    {
        typedef std::unique_ptr<A> APtr;
        APtr s(new A);
        A* p = s.get();
        APtr s2 = std::move(s);
        assert(s2.get() == p);
        assert(s.get() == 0);
        assert(A::count == 1);
    }
    assert(A::count == 0);
    {
        typedef Deleter<A> MoveDel;
        typedef std::unique_ptr<A, MoveDel> APtr;
        MoveDel d(5);
        APtr s(new A, std::move(d));
        assert(d.state() == 0);
        assert(s.get_deleter().state() == 5);
        A* p = s.get();
        APtr s2 = std::move(s);
        assert(s2.get() == p);
        assert(s.get() == 0);
        assert(A::count == 1);
        assert(s2.get_deleter().state() == 5);
        assert(s.get_deleter().state() == 0);
    }
    assert(A::count == 0);
    {
        typedef NCDeleter<A> NonCopyDel;
        typedef std::unique_ptr<A, NonCopyDel&> APtr;

        NonCopyDel d;
        APtr s(new A, d);
        A* p = s.get();
        APtr s2 = std::move(s);
        assert(s2.get() == p);
        assert(s.get() == 0);
        assert(A::count == 1);
        d.set_state(6);
        assert(s2.get_deleter().state() == d.state());
        assert(s.get_deleter().state() ==  d.state());
    }
    assert(A::count == 0);
    {
       sink1(source1());
       assert(A::count == 0);
       sink2(source2());
       assert(A::count == 0);
       sink3(source3());
       assert(A::count == 0);
    }
    assert(A::count == 0);
}
Ejemplo n.º 5
0
int				main(void)
{
	Span				span_one(1);
	Span				span(50000);
	std::vector<int>	source1;
	std::vector<int>	source2(46000);

	std::cout << "Trying to push 1 value in a Span of 1 value: ";
	try {
		span_one.addNumber(42);
		std::cout << "Success" << std::endl;
	}
	catch (std::exception &e) {
		std::cout << "ERROR (not expected): " << e.what() << std::endl;
	}

	std::cout << "Trying to push 1 more value in the same Span: ";
	try {
		span_one.addNumber(42);
		std::cout << "Success, but that was not expected" << std::endl;
	}
	catch (std::exception &e) {
		std::cout << "ERROR (Span full expected): " << e.what() << std::endl;
	}

	span.addNumber(100);
	span.addNumber(200);
	span.addNumber(300);
	span.addNumber(400);

	std::cout << "With values from 100 to 400" << std::endl;
	std::cout << "Min: " << span.shortestSpan() << std::endl;
	std::cout << "Max: " << span.longestSpan() << std::endl;

	for (int i = 42; i <= 4242; i++)
		source1.push_back(i);
	span.addNumber(source1.begin(), source1.end());

	std::cout << "With values from 42 to 4242" << std::endl;
	std::cout << "Min: " << span.shortestSpan() << std::endl;
	std::cout << "Max: " << span.longestSpan() << std::endl;

	std::cout << "Trying to push 46000 more values in a Span of 50000 values: ";
	try {
		span.addNumber(source2.begin(), source2.end());
		std::cout << "Success, but that was not expected" << std::endl;
	}
	catch (std::exception &e) {
		std::cout << "ERROR (Span full expected): " << e.what() << std::endl;
	}
	return (0);
}
Ejemplo n.º 6
0
 int string_index_of(const std::string & source, const std::string & search, int start_at)
 {
   std::string source2(source.begin() + start_at, source.end());
   boost::iterator_range<std::string::const_iterator> iter
     = boost::find_first(source2, search);
   // C# returns index 0 if looking for the empty string
   if(search.empty()) {
     // Note: check this after 'find_first' so boost will throw an exception if start_at > source.size()
     return start_at;
   }
   if(iter.begin() == source2.end()) {
     // NOT FOUND
     return -1;
   }
   return iter.begin() - source2.begin() + start_at;
 }
void exercise_constructor(unsigned int dim){
	std::cout << "Dimension " << dim << '\n';
	const size_t size=dim*dim;
	const double initVal=3.14;
	
	SU_vector source1(dim);
	source1.SetAllComponents(initVal);
	
	std::unique_ptr<double[]> buffer(new double[size]);
	for(unsigned int i=0; i<size; i++)
		buffer[i]=initVal;
	SU_vector source2(dim,buffer.get());
	
	std::cout << "Internal storage\n";
	alloc_counting::reset_allocation_counters();
	SU_vector dest1(source1);
	auto allocated=alloc_counting::mem_allocated;
	std::cout << allocated/sizeof(double) << " entries allocated" << '\n';
	//check the number of components
	auto components=dest1.GetComponents();
	std::cout << components.size() << " components stored" << '\n';
	//check that all components are initialized to the correct value
	std::cout << "components " <<
		(std::all_of(components.begin(),components.end(),[=](double c){ return(c==initVal); })?
		 "are":"are not") << " correctly set\n";
	//check that memory is not aliased
	source1[0]=0;
	std::cout << "Memory aliasing: " << (dest1[0]==source1[0]) << '\n';
	
	std::cout << "External storage\n";
	alloc_counting::reset_allocation_counters();
	SU_vector dest2(source2);
	allocated=alloc_counting::mem_allocated;
	std::cout << allocated/sizeof(double) << " entries allocated" << '\n';
	//check the number of components
	components=dest2.GetComponents();
	std::cout << components.size() << " components stored" << '\n';
	//check that all components are initialized to the correct value
	std::cout << "components " <<
		(std::all_of(components.begin(),components.end(),[=](double c){ return(c==initVal); })?
		 "are":"are not") << " correctly set\n";
	//check that memory is not aliased
	source2[0]=0;
	std::cout << "Memory aliasing: " << (dest2[0]==source2[0]) << '\n';
	std::cout << '\n';
}
Ejemplo n.º 8
0
void test()
{
   //Single unique_ptr
   reset_counters(); 
   sink1(source1());
   sink2(source2());
   sink3(source3());
   BOOST_TEST(A::count == 0);
   //Unbounded array unique_ptr
   reset_counters();
   sink1_unbounded_array(source1_unbounded_array());
   sink2_unbounded_array(source2_unbounded_array());
   sink3_unbounded_array(source3_unbounded_array());
   BOOST_TEST(A::count == 0);
   //Bbounded array unique_ptr
   reset_counters();
   sink1_bounded_array(source1_bounded_array());
   sink2_bounded_array(source2_bounded_array());
   sink3_bounded_array(source3_bounded_array());
   BOOST_TEST(A::count == 0);
}
Ejemplo n.º 9
0
int draw_lasers(osg::ref_ptr<osg::Node> model, Configuration params)
{
	
	float deg2rad = 2 * PI / 360;
	
	// Il nodo root è un group, un cui figlio è il modello 
	osg::ref_ptr<osg::Group> root = new osg::Group;

	root->addChild(model.get());

	float cameraX = params.cameraPos[0];
	float cameraY = params.cameraPos[1];
	float cameraZ = params.cameraPos[2];

	std::vector<osg::ref_ptr<osg::Vec3Array> > bundle, bundle2;	// Vettore contenente tutti i punti necessari a disegnare le rette del fascio
	std::vector<osg::ref_ptr<osg::Geode> > bundleGeode, bundle2Geode;
	std::vector<osg::ref_ptr<osg::Geometry> > bundleGeometry, bundle2Geometry;

	osg::ref_ptr<osg::Group> bundleNode = new osg::Group, bundle2Node = new osg::Group;
	root->addChild(bundleNode.get());			//verso il meno
	root->addChild(bundle2Node.get());		//verso il più
	
	float laserX = cameraX, laserY = cameraY + params.baseline, laserZ = cameraZ;
	osg::Vec3 source(laserX, laserY, laserZ);					//punto di partenza del laser
	float centerX = laserX;
	float centerY = laserY - params.laserLength*cos(deg2rad*(params.alphaLaser));
	float centerZ = laserZ - params.laserLength*sin(deg2rad*(params.alphaLaser));

	float laser2X = cameraX, laser2Y = cameraY - params.baseline, laser2Z = cameraZ;
	osg::Vec3 source2(laser2X, laser2Y, laser2Z);						//punto di partenza del secondo laser
	float center2X = laser2X;
	float center2Y = laser2Y + params.laserLength*cos(deg2rad*(params.alphaLaser));
	float center2Z = laser2Z - params.laserLength*sin(deg2rad*(params.alphaLaser));
	osg::ref_ptr<osg::Vec4Array> color = new osg::Vec4Array;
	color->push_back(osg::Vec4(1.0, 0.0, 0.0, 1.0));

	int i = 0;
	float actualAngle = -params.fanLaser / 2;
	float minAngle = params.fanLaser / params.numLaser;

	for (i; actualAngle <= params.fanLaser / 2; i++, actualAngle+=minAngle) {

		bundle.push_back(new osg::Vec3Array);
		bundleGeode.push_back(new osg::Geode());
		bundleGeometry.push_back(new osg::Geometry());

		// costruzione del fascio di rette
		bundle[i]->push_back(source);
		float X;
		if (actualAngle<0)
			X = centerX - params.laserLength*tan(deg2rad*fabs(actualAngle));
		else
			X = centerX + params.laserLength*tan(deg2rad*fabs(actualAngle));
		float Y = centerY;
		float Z = centerZ;
		osg::Vec3 end(X, Y, Z);
		bundle[i]->push_back(end);
		
		bundleGeometry[i]->setVertexArray(bundle[i].get());
		bundleGeometry[i]->setColorArray(color.get());
		bundleGeometry[i]->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE_SET);
		bundleGeometry[i]->addPrimitiveSet(new osg::DrawArrays(GL_LINES, 0, 2));
		bundleGeode[i]->addDrawable(bundleGeometry[i].get());
		bundleNode->addChild(bundleGeode[i].get());

		//2
		bundle2.push_back(new osg::Vec3Array);
		bundle2Geode.push_back(new osg::Geode());
		bundle2Geometry.push_back(new osg::Geometry());
		bundle2[i]->push_back(source2);

		if (actualAngle<0)
			X = center2X - params.laserLength*tan(deg2rad*fabs(actualAngle));
		else
			X = center2X + params.laserLength*tan(deg2rad*fabs(actualAngle));

		Y = center2Y;
		Z = center2Z;
		end.set(X, Y, Z);
		bundle2[i]->push_back(end);
		
		bundle2Geometry[i]->setVertexArray(bundle2[i].get());
		bundle2Geometry[i]->setColorArray(color.get());
		bundle2Geometry[i]->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE_SET);
		bundle2Geometry[i]->addPrimitiveSet(new osg::DrawArrays(GL_LINES, 0, 2));
		bundle2Geode[i]->addDrawable(bundle2Geometry[i].get());
		bundle2Node->addChild(bundle2Geode[i].get());
	}

	osgViewer::Viewer viewer;
	viewer.setSceneData(root.get());

	viewer.setUpViewInWindow(0,0, 640, 480);
	viewer.realize();
	viewer.run();

	return 0;
}
Ejemplo n.º 10
0
/** \brief Create progessive icon

Do QIcon with top and bottom image mixed and percent writed on it.
The icon it be search in the style path.
Do by mongaulois, remake by alpha_one_x86.
\param percent indique how many percent need be showed, sould be between 0 and 100
\param text The showed text if needed (optionnal)
\return QIcon of the final image
\note Can be used as it: dynaIcon(75,"...")
*/
QIcon Themes::dynaIcon(int percent,QString text) const
{
    #ifdef ULTRACOPIER_PLUGIN_DEBUG
    if(pixmapTop.isNull() || pixmapBottom.isNull())
        ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,"Error loading the icons");
    #endif
    if(percent==-1)
        percent=getOldProgression;
    if(percent<0)
        percent=0;
    if(percent>100)
        percent=100;
    //pixmap avec un fond transparent
    #ifdef Q_OS_WIN32
    quint8 imageSize=16;
    #else
    quint8 imageSize=22;
    #endif
    QPixmap resultImage(imageSize,imageSize);
    resultImage.fill(Qt::transparent);
    {
        QPainter painter(&resultImage);
        #ifndef Q_OS_WIN32
        QFont font(QStringLiteral("Courier New"),9);
        font.setBold(true);
        font.setKerning(true);
        painter.setFont(font);
        #endif
        #ifdef Q_OS_WIN32
        QFont font(QStringLiteral("Courier New"),8);
        font.setBold(true);
        font.setKerning(true);
        painter.setFont(font);
        #endif

        //preprocessing the calcul
        quint8 bottomPixel=(percent*imageSize)/100;
        quint8 topPixel=imageSize-bottomPixel;

        //top image
        if(topPixel>0)
        {
            QRect target(0, 0, imageSize, topPixel);
            QRect source(0, 0, imageSize, topPixel);
            painter.drawPixmap(target, pixmapTop, source);
        }

        //bottom image
        if(bottomPixel>0)
        {
            QRect target2(0, topPixel, imageSize, bottomPixel);
            QRect source2(0, topPixel, imageSize, bottomPixel);
            painter.drawPixmap(target2, pixmapBottom, source2);
        }

        qint8 textxOffset=0;
        qint8 textyOffset=0;
        if(text.isEmpty())
        {
            if(percent!=100)
                text=QString::number(percent);
            else
            {
                text=QStringLiteral(":)");
                #ifdef Q_OS_WIN32
                textyOffset-=2;
                #else
                textyOffset-=1;
                #endif
            }
        }
        if(text.size()==1)
        {
            textxOffset+=3;
            #ifdef Q_OS_WIN32
            textxOffset-=1;
            #endif
        }
        else
        {
            #ifdef Q_OS_WIN32
            textxOffset-=1;
            #endif
        }
        #ifndef Q_OS_WIN32
        textxOffset+=2;
        textyOffset+=3;
        #endif
        painter.setPen(QPen(Qt::black));
        painter.drawText(3+textxOffset,13+textyOffset,text);
        painter.setPen(QPen(Qt::white));
        painter.drawText(2+textxOffset,12+textyOffset,text);
    }
    return QIcon(resultImage);
}
Ejemplo n.º 11
0
const bool ToUTF8(const std::wstring &wcstring, std::string &utf8string)
{
	if(wcstring.size()==0)
	{
		utf8string.assign("");
		return true;
	}

	std::vector<std::wstring::value_type> source(wcstring.begin(),wcstring.end());

	if(sizeof(std::wstring::value_type)==2 && sizeof(UTF16)==2)
	{
		std::vector<std::string::value_type> dest(wcstring.size()*2,0);
		
		const UTF16 *sourcestart=reinterpret_cast<const UTF16 *>(&source[0]);
		const UTF16 *sourceend=sourcestart+source.size();
		
		UTF8 *deststart=reinterpret_cast<UTF8 *>(&dest[0]);
		UTF8 *destend=deststart+dest.size();
		
		ConversionResult rval=ConvertUTF16toUTF8(&sourcestart,sourceend,&deststart,destend,lenientConversion);
		
		if(rval!=conversionOK)
		{
			return false;
		}
		
		utf8string.assign(dest.begin(),dest.end()-(destend-deststart));
		
	}
	else if(sizeof(std::wstring::value_type)==4 && sizeof(UTF32)==4)
	{
		std::vector<std::string::value_type> dest(wcstring.size()*4,0);
		
		const UTF32 *sourcestart=reinterpret_cast<const UTF32 *>(&source[0]);
		const UTF32 *sourceend=sourcestart+source.size();
		
		UTF8 *deststart=reinterpret_cast<UTF8 *>(&dest[0]);
		UTF8 *destend=deststart+dest.size();
		
		ConversionResult rval=ConvertUTF32toUTF8(&sourcestart,sourceend,&deststart,destend,lenientConversion);
		
		if(rval!=conversionOK)
		{
			return false;
		}
		
		utf8string.assign(dest.begin(),dest.end()-(destend-deststart));
		
	}
	else
	{
		std::vector<UTF32> source2(wcstring.begin(),wcstring.end());
		std::vector<std::string::value_type> dest(wcstring.size()*sizeof(std::wstring::value_type),0);
		
		const UTF32 *sourcestart=reinterpret_cast<const UTF32 *>(&source2[0]);
		const UTF32 *sourceend=sourcestart+source2.size();

		UTF8 *deststart=reinterpret_cast<UTF8 *>(&dest[0]);
		UTF8 *destend=deststart+dest.size();

		ConversionResult rval=ConvertUTF32toUTF8(&sourcestart,sourceend,&deststart,destend,lenientConversion);

		if(rval!=conversionOK)
		{
			return false;
		}

		utf8string.assign(dest.begin(),dest.end()-(destend-deststart));

	}

	return true;
}