Page 1 of 2

2D performance problem

Posted: Wed Sep 08, 2004 4:27 pm
by Nelligan
I made a 2d tile scrolling engine for my mmorpg project. Simple and unoptimized just 2 FORs inside wich I display the appropriate tile with a pixeloffset for a pixel smooth scrolling.

It works ok but it is not smooth. I tried to optimize my routine and even simpilfy it to always display the same tiles but it still does small hiccups.

So I searched the forum and ressoures sites for every scrolling examples I could find. Some isometric some not but every single one with the small hiccups.

Most recent I tried was isometric and converted from blitz basic. This one got a FPS counter, and it always stays a little above 50, but still isn't smooth. Its like it stops from time to time for a fraction of a second.

I'm at a loss because I think that purebasic si powerfull enough to pull something like that at blazing speed, so what is happening?

Did someone else experience something similar?

Windows XP Purebasic 3.91
P3 800e, 256 RAM, GeForce 2MX

Posted: Wed Sep 08, 2004 4:45 pm
by Moonshine
Best thing to do would be to post your code, then people can see if its an error on your part or not :)

Re: 2D performance problem

Posted: Wed Sep 08, 2004 4:48 pm
by PB
> Did someone else experience something similar?

Yes, I have. The sand app at this post:

viewtopic.php?t=12215

When I run the compiled exe of it, the dropping sand usually pauses every
now and then, for a tiny fraction of a second. I just thought it was my PC.

Posted: Wed Sep 08, 2004 4:51 pm
by Num3
Hum, sounds like bad code structure...

I had this problem once...

I advice you to take a look at purearea.net and search for game code template.

This can also be 'cause you're using FX without StartSpecialFX() code...

Maybe you can post some pseudo code on what is done in the main loop...

Posted: Wed Sep 08, 2004 6:07 pm
by Nelligan
@Moonshine: Yes, I realize that. That is why I searched better coded :) examples that exibit the same problem. This is the isometric sample by aaron that I last tried: viewtopic.php?t=12351. Is this smooth on your part?

@PB: I tried it and I think I see small hiccups. But in the sample above it is more apparent, maybe because it is the all screen which is updated.

@Num3: That is what I thought at first and maybe still do, but every tile scrolling code I found(not that many) does the same thing. I browsed through Purearea and the codearchiv and many good examples does the same thing. In my case I do not use FX.

basicaly i do this:

repeat
FlipBuffers
clrscr
check events
check input
draw map
check GUI
delay(1)
until

Posted: Wed Sep 08, 2004 7:14 pm
by GreenGiant
You could try upping the delay a bit? Make sure the debugger's off? You running any other DirectX pprograms at the same time? Just random guesses here.

Posted: Wed Sep 08, 2004 7:28 pm
by Nelligan
Tried the delay, I can make it go slower but still jerky. Running from the compiled app does the same thing. And no other DirectX programs that I know of.

I must say though that I have troubles between my sound card and DirectX. After I start anything in purebasic or other DirectX game, the sound pops. I have to reboot to correct the problem. I tried an app which changed register on my sound card (Aureal MX300) but it didn't fix it.

Posted: Wed Sep 08, 2004 8:33 pm
by Codemonger
This sounds like it could be a number of things ... heres a couple of suggestions:

- remove your clear screen (you may not even need to clear the screen at all if your background is not transparent or translucent). This would cause overdraw, the higher the screen resolution the more overdraw.

- disable any virus scanning software or background programs you have running (this could cause hiccups if CPU is sharing too much between apps). Even try turning up the applications priority using WINAPI commands to a higher setting.

- are you using Sprite3D ? if so you might want to batch texture like tiles together as fillrate is irrelevant , but texture thrashing in GPU might cause hiccups. Driver support will more than likely not resend the texture into Video Memory if its already there and cached.

- remove any code that is not graphic related (AI, Sound, Input) and sorta do a manual profiling of your application. If the hiccups disapear then you can add each module back in one at a time. this is the most basic of manual debugging.

- check your computer for viruses. This could cause slowdowns in your program and you would only notice it when your running application intensive programs (again framerate hiccups).

- try your code on a different computer, maybe you are using all video memory up, and video has to swap between system memory and video memory. What kind of system do you have, how fast ? etc ...

- are you using fast hardware supported functions that use Direct Draw that use video memory or are you using slower ASM pixel functions or software blitting function ?

- also I almost forgot are you running any debug versions of DirectX Runtime DLL's ?

Posted: Wed Sep 08, 2004 8:50 pm
by GedB
The isometric example is silky smooth for me.

The sand demo also runs without hicups.

Have you run Task Manager alongside your code. Does it show any high CPU usage?

Posted: Wed Sep 08, 2004 10:42 pm
by Nelligan
@Codemonger : I tried most of your suggestions without success. But when I tested the isometric sample on another computer, I found that the problem was not visible. The other machine is a little slower than mine (Athlon700, 256 mb RAM and a NVIDIA TNT2). So there you have it, I probably have a problem with DirectX.

Like I said in my first post I have a P3 800e 256 mb RAM and a GeForce2 MX.

I don't think I have a debug version of DirectX and all the graphic calls are pure purebasic.

@GedB : Task manager says 40% CPU usage. I want it to be silky too :).

Posted: Thu Sep 09, 2004 9:05 am
by Num3
Did you tweak your nvidia card?

And disabled Vsync ??? That causes jerks....

Posted: Thu Sep 09, 2004 1:28 pm
by PB
> Task manager says 40% CPU usage.

Use the Task Manager to give the app a High (instead of Normal) priority,
and see how it goes. Disabling VSYNC for me didn't help either. :(

Posted: Thu Sep 09, 2004 2:50 pm
by Nelligan
Ok, I thought it was time to investigate on my poping sound problem because I began to believe more and more it was related.

What I discovered was that Winblows XP, in all its ACPI glory, had put on the IRQ 9 bandwagon, 2 network cards, graphic card, sound card, PCI-ISA bridge and a couple of other things that I don't remember.

So as XP overwrides the BIOS I had to change ACPI to "Standard PC" in windows and redetect all my hardware, wich worked fine.

Now, the isometric and the sand samples are working like a charm. So it was a conflict between my video card and something else probably the sound card.

For my engine, well there are still jerks sometimes but now I know it is something with my code and from all your helpfull responses, I know i'll be able to fix it.

Thank you everybody!

Posted: Fri Sep 10, 2004 1:50 pm
by LarsG
does the hiccup occur when you're running a full screen, or only when running in windowed mode?

I would guess it's a windows issue..

Posted: Fri Sep 10, 2004 2:35 pm
by Nelligan
@LarsG: Actually, everytime I started something using DirectX, my sound card would act up and the hiccups would appear. Every game would cause the sound and hiccup problem. Even old tech 2d games like the great URW did the same. And back in purebasic, regarless of windowed or fullscreen mode, the hiccups where there.

Even if I posted this now, this problem was with me for a long time and I was kind of depressed to not be able to do my smooth scrolling so I stopped working on that for a while concentrating on other parts of the engine.

Right now my code is in windowed mode and I'm wrestling with capping the speed on faster computers and getting a smooth refresh regardless of the machines refresh rate. I will probably post on that on another thread today. And for the remaining hiccups, I'll try fullscreen to see if what you suggested will correct it right away. I have many other thing to try because I was focused on solving the global problem I had, but now it's time for my specific problem to go away :).