2D performance problem

Advanced game related topics
Nelligan
User
User
Posts: 13
Joined: Sat May 10, 2003 6:04 am

2D performance problem

Post 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
Moonshine
Enthusiast
Enthusiast
Posts: 263
Joined: Tue May 25, 2004 12:13 am
Location: UK

Post 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 :)
Mark my words, when you least expect it, your uppance will come...
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: 2D performance problem

Post 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.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post 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...
Nelligan
User
User
Posts: 13
Joined: Sat May 10, 2003 6:04 am

Post 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
GreenGiant
Enthusiast
Enthusiast
Posts: 252
Joined: Fri Feb 20, 2004 5:43 pm

Post 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.
Nelligan
User
User
Posts: 13
Joined: Sat May 10, 2003 6:04 am

Post 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.
Codemonger
Enthusiast
Enthusiast
Posts: 384
Joined: Sat May 24, 2003 8:02 pm
Location: Canada
Contact:

Post 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 ?
<br>"I deliver Justice, not Mercy"

    - Codemonger, 2004 A.D.
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post 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?
Nelligan
User
User
Posts: 13
Joined: Sat May 10, 2003 6:04 am

Post 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 :).
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

Did you tweak your nvidia card?

And disabled Vsync ??? That causes jerks....
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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. :(
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Nelligan
User
User
Posts: 13
Joined: Sat May 10, 2003 6:04 am

Post 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!
LarsG
Enthusiast
Enthusiast
Posts: 713
Joined: Mon Jun 02, 2003 1:06 pm
Location: Norway
Contact:

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

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
Nelligan
User
User
Posts: 13
Joined: Sat May 10, 2003 6:04 am

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