Low FPS

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Catprog
Posts: 164
Joined: Wed Jan 31, 2007 9:07 am
Contact:

Low FPS

Post 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;
	}
Catprog
Posts: 164
Joined: Wed Jan 31, 2007 9:07 am
Contact:

Post 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.
devosbi
Posts: 5
Joined: Tue Feb 27, 2007 2:10 am

Post by devosbi »

Try changing the rendering, Software tends to lag, try OpenGL or DirectX
If you can write your future... you can change your past...
%20
<Distant Past> Completion 0%.......(x)...........%100
Catprog
Posts: 164
Joined: Wed Jan 31, 2007 9:07 am
Contact:

Post 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.
Phant0m51
Posts: 106
Joined: Mon Jan 15, 2007 6:07 am

Post 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.
Post Reply