PDA

View Full Version : Low Frame Rate. How to deal with this problem?!?!?!?!?



hammer
13-04-2004, 08:18 AM
okay i know that this has been asked and before but how can i improve my frame rate.
The game i am making (turn based strategy) is going with a fps 50-60 on a 2000 mhz cpu, and i don't think it will run good enought at slower pc-s 300-400 mhz.
I will test it in a couple of days on a slower machines but until then i hope someone can help with tips/tricks 8) to improve the fps in my game.

Harry Hunt
13-04-2004, 12:49 PM
DelphiX may give you lower results than theoretically possible if WaitVSync is set to true (which is a parameter of the Flip method). So you may get a frame rate around 60 FPS even if your engine is actually capable of much higher frame rates. This doesn't mean you should disable VSyncing, it just means that your game may run at the same framerate on slower machines.

There are of course ways to optimize the speed of your game:
1) Avoid using alpha blending as this will significantly slow down blitting.

2) Make sure you only draw what's actually visible (if you have sprites, check their X and Y coordinates to see if they're currently visible on the screen)

3) Draw things that don't get updated a lot on a separate surface and then just blit that onto your backbuffer.

Hope that helped.

Traveler
13-04-2004, 01:08 PM
Seems to me that a turn based game doesn't need a high fps. :roll:

In any case, here's a few general things you might want to look at:
- using 256 colored graphics will help some.
- using 8bit color mode will help even more
- limit the drawing to the visible parts of your game.
- don't use alpha blending
- don't use canvas.fill(0) if your screen is already filled with tiles
- don't use standaard texts (ie. canvas.textout)
(- decrease the resolution, 1024x768 is too much for DelphiX)

Perhaps you can post a few screenshots. It might help a little to see where the problem areas are.

Traveler
13-04-2004, 01:10 PM
Hmm,. seems you posted before me Harry :D

I really should write faster

hammer
14-04-2004, 02:45 PM
You are right it doesnt but i just want to know why its slow :)

thanks to both for repling i am going to do some changes in the code :)

by the way Traveler

- don't use standaard texts (ie. canvas.textout)

what should i use to display text ??

hammer
14-04-2004, 03:11 PM
i will compile and upload the game so you can test it guys :)
soon will post the url

hammer
14-04-2004, 03:30 PM
http://members.lycos.co.uk/dhsoft/game.rar
the game is in bulgarian language so dont wonder why you cant read :)
please test it and post any problems you find
ou and ignore the text displayed after 2 units fight its still under construction :)

Traveler
14-04-2004, 07:36 PM
Looking pretty good hammer! Reminded me somewhat of civilisation :)
The fps is pretty good as well, but like you said, around 55~60. (1.3mhz, 256mb ram)

One odd thing I noticed was the flickering when the screen with all the text appeared. It stopped (fortunately), when the game actually started.

To answer you question about the text, a few words here and there, like what you did with the numbers next to the icons won't hurt that much. But large amounts, I've noticed, do. Better use graphical text (pictures)instead. Perhaps a bit more work, but it will pay off, and it looks much nicer in the end as well.

WiZz
14-04-2004, 07:48 PM
nice game :), but need better graphics

TheLion
14-04-2004, 08:52 PM
Well writing the text the way you do is using the normal Canvas (GDI) which is pretty slow in comparisson to DirectX/DelphiX, what you could use instead is bitmap fonts, which basically means that each letter is a bitmap.

When you want to draw text you simple traverse through the string and draw the corresponding bitmap at the correct position! :) It's faster than the canvas method and gives you a greater variaty of fonts! ;)


P.S. For a 2D game 60 FPS is pretty good and some books even advise you to limit your frames at 60 FPS in 2D games. :)

hammer
15-04-2004, 05:38 AM
The Lion - there is a limiter also included in the game it activates with the "F" button :) it limits the fps to 60.

WiZz - i know the graphics sux :( but the guy thats doing them is quite lazy :) and i cant talk him into improving them and adding more.

Traveler - the flickering you were saying what Video Card do you have?
because i've noticed it too but only on a few VGA cards.
on my GF4 MX440 it doesnt flicker and on a 1 mb Matrox VGA also doesnt flicker but on some does and i cant understand why.
About the new text method you and TheLion mentioned i will try it out :)

thanks for all the quick replies

by the way the game have quite some features
it includes (usually) a map editor which allows to create/edit maps and create your own campaigns, the graphics are easy to manipulate/edit/replace/add same for the sound/music (the music in this version is cutted off because its 6 mb)
by the way the music is quite good :).

but there is still a lot of work on the game the code at the moment is sooooo messed up that when i begin to write i need atleast 2 minutes to understand where i am :(
not to mention the AI and PathFinding which are at the lowest possible level :(

again thanks for all the replies

cairnswm
15-04-2004, 06:21 AM
Question thats been buggin me that I havn't tried to answer yet but maybe someone here can do so for me:

On the issue of writting text, would it work to create a surface and use the GDI methods to draw the text to that surface and then internal to the program use the surface as an image to draw to screen?

TheLion
15-04-2004, 07:46 AM
@ Cairns, yes it would work, but I'm affraid it would have the same disadvantages as writing the canvas text directly to the screen, since you will still be using the GDI functions for writing the text it will also slow you down.

Traveler
15-04-2004, 08:04 AM
@Hammer: I'm using a radeon 8500.
The flickering is especially visible underneath the texts. Perhaps you could try to replace it with an image and remove the text.

@cairnswm: Thats an interesting idea! Write the text to a surface once and then use that image over and over again.

This is how it would work:

(..)
var
Form1: TForm1;
textImg : TDirectDrawsurface;

implementation

{$R *.DFM}

procedure TForm1.DXDraw1Initialize(Sender: TObject);
var counter : byte;
begin
randomize;
textImg := TDirectDrawSurface.Create(DXDraw1.DDraw);
textImg.SetSize(250,150);
TextImg.Fill(0);
TextImg.Canvas.Font.Color:= clred;
TextImg.Canvas.brush.Style := bsclear;
for counter := 1 to 10 do
TextImg.Canvas.TextOut(random(50)+10,(15*counter), 'A GameProgrammer''s Journey');
TextImg.Canvas.Release;

dxdraw1.surface.Canvas.Font.Color:= clblue;
dxdraw1.surface.Canvas.brush.Style := bsclear;

dxtimer1.Enabled:=true;
end;

procedure TForm1.DXTimer1Timer(Sender: TObject; LagCount: Integer);
begin
dxdraw1.surface.Fill(0);
dxdraw1.Surface.Draw(0,0, TextImg.ClientRect,TextImg,true);
dxdraw1.Surface.canvas.textout(form1.width-50,10,'fps:'+inttostr(dxtimer1.framerate));
dxdraw1.Surface.canvas.release;
dxdraw1.flip;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
textImg.free;
end;

end.

Of course this solution does not work when you constantly need to change the text, like the fps text in my sample.

Btw, since this still is a topic on how to deal with fps. Notice that I init the font color and brush of the dxdraw canvas in the DXDraw1Initialize procedure. I've seen quite a few people doing this in the dxtimer procedure.

@Lion. Not necessarily. As you can see, the text is written at startup. It doesn't really matter how long it takes. After the text is written onto the image, you can simply use the image to display the text.

And in case you need to change the text, (not continuesly of course) you can write a procedure to erase the image and write a new text on to it.

TheLion
15-04-2004, 09:01 AM
@Traveler & Cairns, yes if the text is more or less static it would indeed work, I just figured he meant dynamic text that would change all the time, like a framerate value or score, however if you would only write the text to the bitmap when it changes you would slow down you app in 1 frame and keep fast speed the rest from the frames losing only a little bit in speed! :) I stand corrected! ;) hehe

cairnswm
15-04-2004, 10:44 AM
Even doing a score or FPS might be faster doing it this way. A players score doesn;t change every frame, but only every few seconds - if this method saves a few ms each time writing to the temp surface would still increase FPS.

hammer
15-04-2004, 03:33 PM
Traveler - hm... yes indeed, now it seems that the idea for bitmap fonts is more and more needed. But i am still wondering why the screen is flickering maybe something is not supported by the ATI drivers or ... i just dont know.

i will try out the idea about the second surface to see if there is any improvement.

TheLion
15-04-2004, 06:51 PM
Even doing a score or FPS might be faster doing it this way. A players score doesn;t change every frame, but only every few seconds - if this method saves a few ms each time writing to the temp surface would still increase FPS.

I agree, my post was more or less thinking out loud! :) My last line was: "I Stand corrected"! ;) hehe

cairnswm
16-04-2004, 05:36 AM
I agree, my post was more or less thinking out loud!

My reply was sort of after reading your first sentance.... I was too quick on the reply :)

Clootie
16-04-2004, 05:30 PM
Small report:
1) your FPS is limited by VSync, so on mine system it's equal 60fps.
2) disabling VSync raises FPS to 100 - seems it's limited by timer/phisics when - NOT by 3D card. YEP: "DXTimer.Interval = 10" !!!
3) Cirillic text is rendered OK in mine Russian locale system.
4) Now text/graphics flickering awfully in "mission debrief" (first to display) screen in default mode. But when I disable VSync it's rendered correctly.
5) "destructor Destroy ; reintroduce;" --> should be "destructor Destroy; override;"

hammer
17-04-2004, 09:51 AM
okay i've uploaded a new version at
http://members.lycos.co.uk/dhsoft/game.rar

i hope it solves the problem with the flickering

ou and can you guys tell me if it flickers on all of the screens or only on Briefing Screen??

if it does then write a reply :) if it doesnt then again write a reply :)

until i do the text via bitmap.

Clootie or Traveler or anyone with the flickering problem please download and test again.

by the way here are some of the assinged keys for the game
H = Help (view assinged keys)
E = New Turn
A = Transparent/Solid Text
F = Change FPS Mode (Max/60FPS)
S = Sound On/Off
B = Briefing

Traveler
18-04-2004, 11:16 AM
The first time I tried the new version the game locked, or so it appeared. I had to restart, because zoneAlarm mentioned a very serious error. Anyway, since it didn't happen a second time, I'm nothing going to think too much about it.

About the game. The flickering in the Briefing screen is still not solved. So you might want to check this again. The other options work okay, though its a bit weird that with 'F' I suddenly get 2 fps values. One is around 60 and the other constant at 60.

hammer
18-04-2004, 03:54 PM
hm.... this flickering stuff is very annoying :(

Traveler about the F key
the F switchesh between 2 intervals in dxtimer the default is 10 and the other is 1000 / 60 the so called (atleast i was told so 60 FPS lock).