Page 1 of 1

Low FPS

Posted: Tue Feb 06, 2007 7:21 am
by Catprog
I am trying out a way of tiling hightmaps

The problem I am having is I am getting FPS rates as low as 20.

Here is my game loop

Code: Select all

	while(device->run())
	if (device->isWindowActive())
	{

		//Work out where we are and what needs to be drawn

		v = camera->getAbsolutePosition();

		int curXTerrain = (int) v.X/9600;

		int curZTerrain = abs((int) v.Z/9600);

		curZTerrain = (v.Z < 0?curZTerrain+1:curZTerrain);

		int XStart = 0;		
		int XFinish = NUMBER_OF_ROWS-1;

		if (v.X <= 0){
			v.X = 0;
			XStart = 0;
			XFinish = 1;
		}else if(curXTerrain > (NUMBER_OF_ROWS-1)){
			v.X = NUMBER_OF_ROWS * LENGTH_OF_TERRAIN ;
			XStart = curXTerrain-1;
			XFinish = (NUMBER_OF_ROWS-1);
		}

		
		XStart = curXTerrain-2;
		XFinish = curXTerrain + 2;

		XStart = (XStart <= 0?0:XStart);
		XFinish = (XFinish >= (NUMBER_OF_ROWS-1)?(NUMBER_OF_ROWS-1):XFinish);

		int ZStart = 0;		
		int ZFinish = NUMBER_OF_COLS-1;


		if (v.Z > LENGTH_OF_TERRAIN){
			v.Z = LENGTH_OF_TERRAIN;
			ZStart = 0;
		}else if(curZTerrain > (NUMBER_OF_COLS-1)){
			v.Z = (NUMBER_OF_COLS-1) * -LENGTH_OF_TERRAIN ;
			ZFinish = (NUMBER_OF_COLS-1);
		}
		
		ZStart = curZTerrain-2;
		ZFinish = curZTerrain + 2;

		ZStart = (ZStart <= 0?0:ZStart);
		ZFinish = (ZFinish >= (NUMBER_OF_COLS-1)?(NUMBER_OF_COLS-1):XFinish);

		
		camera->setPosition(v);

		for(int row= XStart; row <= XFinish; row++){
		for(int col= ZStart; col <= ZFinish; col++){
			
			terrain[col][row]->setVisible(true);

		}
		}

		
		driver->beginScene(true, true, 0 );

		smgr->drawAll();
		env->drawAll();

		driver->endScene();


		
		for(int row= XStart; row <= XFinish; row++){
		for(int col= ZStart; col <= ZFinish; col++){
			
			terrain[col][row]->setVisible(false);
			terrain[col][row]->setMaterialType(video::EMT_DETAIL_MAP);

		}
		}


		bool useXStart = false;

		int Diffrence = XStart - curXTerrain;
		if (Diffrence > 1 || Diffrence < -1){
			useXStart=true;
		}

		bool useXFinish = false;

		Diffrence = XFinish - curXTerrain;
		if (Diffrence > 1 || Diffrence < -1){
			useXFinish=true;
		}

		//Remove detail on the edges
		for(int col= ZStart; col <= ZFinish; col++){
			if(useXStart)
				terrain[col][XStart]->setMaterialType(video::EMT_SOLID);
			

			
			if (useXFinish)
				terrain[col][XFinish]->setMaterialType(video::EMT_SOLID);
			
		}


		// display frames per second in window title
		
		int fps = driver->getFPS();

		core::stringw str = L"Terrain Renderer - Irrlicht Engine [";
		str += driver->getName();
		str += "] FPS:";
		str += fps;

		str += " ";
		str += curXTerrain;
		str += " ";
		str += (int)(v.X);
		str += ",";
		str += curZTerrain; 
		str += " ";
		str += (int)(v.Z);
			
		str += " ";
		str += (XFinish-curZTerrain);

			
			

		device->setWindowCaption(str.c_str());
		lastFPS = fps;
	}

Posted: Wed Feb 07, 2007 3:19 am
by Catprog
It is now changed so that setting the visibility and detail map is done in a function which only is called when you move to another square.

The strange thing is, when all detail is on the FPS rate is higher then if some do have detail off.

Posted: Wed Feb 28, 2007 6:13 am
by devosbi
Try changing the rendering, Software tends to lag, try OpenGL or DirectX

Posted: Wed Apr 04, 2007 4:58 am
by Catprog
I can't rember what it was but I think it was OpenGL.

From what I can gather the heightmaps are quite slow compared with meshs which is what I am using now.

Thanks for trying to help anyway.

Posted: Wed Apr 04, 2007 11:03 pm
by Phant0m51
For me there's a huge difference in performance between OpenGL and D3D (D3D is about 5 times faster) but it's just my video card.