Archived

This topic is now archived and is closed to further replies.

Is your game "slightly" jerky, jumpy, or shaky? Here's a fix!

This topic is 5009 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I worked for a few hours trying to solve the "jumpiness" of my game. It was only slightly jumpy... and I could not figure out what the deal was... Sure enough, when I put this one line of code in: SetPriorityClass(process handle, priority); // SetPriorityClass(hInst, HIGH_PRIORITY_CLASS); // code for me My game went from jumpy to smooth. ARG WINDOWS #()$&(#&$)(#&)($*)(#&$

Share this post


Link to post
Share on other sites
What was jerky, jumpy, or shaky about it? Were you using time-based movement?

edit: from MSDN:
quote:

MSDN
Process that performs time-critical tasks that must be executed immediately. The threads of the process preempt the threads of normal or idle priority class processes. An example is the Task List, which must respond quickly when called by the user, regardless of the load on the operating system. Use extreme care when using the high-priority class, because a high-priority class application can use nearly all available CPU time.



[edited by - Fuzztrek on March 29, 2004 9:05:03 PM]

Share this post


Link to post
Share on other sites
Setting the process to high priority is not a very good idea. It will cause more problems than its worth. This isn't like the days of DOS when you could make your game use near 100% of the CPU time and get away with it. You need to make your app work nicely with other apps and with the OS. Otherwise, your typical user will think your program is bad because everytime they run it, Windows becomes very sluggish, and they won't know why, other than your program is bad. The better way to remove the jumpiness is to optimize the app, not use brute force.

[edited by - Mastaba on March 29, 2004 9:27:07 PM]

Share this post


Link to post
Share on other sites
still its not an idea with out merit, if your game is full screen how much else on windows can they be using, and even so you could lower the piority when they alt tab out

Share this post


Link to post
Share on other sites
I always try to do other things while gaming. I can''t stand how Unreal Tournament is a processor hog, so I play counter-strike instead most of the time.

If your game is small, the problem is probably in your algorithms/code. Maybe if you could figure out the bottleneck we could provide some solutions. You may be performing too many resource allocations, etc.


Brian J

Share this post


Link to post
Share on other sites
quote:
Original post by 2dcoder
"I always try to do other things while gaming."

what the, huh? Then why are you gaming at all?


If the game is windowed, you can easily chat/browse the web, etc while playing most types of games.

Share this post


Link to post
Share on other sites
My game is a little jerky, but i think it has something to do with my main loop and how it sleeps. I use this:


// Start of loop
long startTime = GetTickCount();

// End of loop
long processTime = GetTickCount() - startTime;

while( processTime < 1000/MAX_FRAMERATE ) {
Sleep( 1 );
processTime = GetTickCount() - startTime;
}


I render a (D3DX)Font object, moving it across the screen at a constant speed (2pix/frame). It jerks by about 1 or 2 pixels more than it should every half a second or so. If I decrease MAX_FRAMERATE to about 40 it seems to stop it (I have it at 60 normally). Has anyone else had this, or does anyone know how I should fix it (setting thread to high priority doesn't work either, not that I wanted it to)

[edited by - red_sodium on March 30, 2004 2:27:32 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by 2dcoder
"I always try to do other things while gaming."

what the, huh? Then why are you gaming at all?


if you''re not a very good player you will spend most your time being dead anyway... =P ( I get lots of reading done while playing CS )

Share this post


Link to post
Share on other sites
I''ve always had this in games (mine and other peoples'') with things smoothly scrolling. I finally decided it was psychological/physiological (my problem, not the machine''s). Try focussing on one fixed spot (put some whiteout on your monitor or something ) and see if the jumpiness goes away. It did for me.

Share this post


Link to post
Share on other sites
Ya I use time based movement. Apparently my game was getting thrown back behind other applications in the process scheduling... Now that my game isn''t "low priority" I get no problems.

I worked for hours to take out the jerkiness... once I added this one flag, things are ONE HUNDRED PERCENT SMOOTH... Frame rate is the same, but now my objects move smoothly.

You can update your objects whenever you like and use whatever timing you like, but between then and the time your objects are rendered, if 2 in 40 frames are slightly starved in the processing queue, you have some nice jerkiness.

How to take away the starvation? Increase priority. A 3d game is a time sensitive program. If people want to build power point presentations while they run a game, they should think again, in my opinion.



Share this post


Link to post
Share on other sites
Perhaps ABOVE_NORMAL_PRIORITY_CLASS flag will be better... I"ll check it in my next version tonight.

Perhaps it will satisfy both sides.


Process that has priority above NORMAL_PRIORITY_CLASS but below HIGH_PRIORITY_CLASS.

Share this post


Link to post
Share on other sites

I think what is happening is that the task switching is not fast enough for this kind of loop. When you do Sleep(1) it is not actualy returning in 1/1000th of a second. Also GetTickCount is too low a resolution for this kind of thing, the high performance counter would be better. Setting the priority to high may be tempting, but I''d recommend against it.

Try using time based movement, and just render as fast as you are able.

Share this post


Link to post
Share on other sites
I use time base movement & the function that is measured in microseconds.

By the way - the game never takes more than 20 percent of the CPU... So setting a game that uses 20 percent to high priority only takes away from starvation-induced lag.



microsecond time function: QueryPerformanceCounter

This function pretty much works on any modern day computers.. maybe not 486's

[edited by - oxygen_728 on March 30, 2004 2:57:57 AM]

Share this post


Link to post
Share on other sites
This is not a solution, merely a hack to get your (faulty) code working. You should try to fix the real problem, not tell users how they should run your game.

Share this post


Link to post
Share on other sites
So what's the most efficient way to set up time-based movement (pseudo-code), and are you sure I should just render as fast as I can, without any sleep time? Would other applications not be starved of processor usage?

[edited by - red_sodium on March 30, 2004 7:01:30 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by red_sodium
So what''s the most efficient way to set up time-based movement (pseudo-code), and are you sure I should just render as fast as I can, without any sleep time? Would other applications not be starved of processor usage?

[edited by - red_sodium on March 30, 2004 7:01:30 AM]


Search the forums for "FPS", "Time-based movement" or "QueryPerformanceCounter" and you should find lots of results talking about this. You can also look at my post here on what to do/not to do. In my opinion, you are needlessly slowing things down by using sleep in your game loop.

I agree with DBX, this method of "solving" the unsteadiness of your game is not a very viable solution.

Share this post


Link to post
Share on other sites
I''ve read those posts for hours, and this is the only solution that I''ve found.

I''d have to disagree with you if you were to say that setting the priority to ABOVE AVERAGE is a hack... that''s exactly what the flag was meant for.

HOWEVER, I''m open to ideas...

How do I overcome my starvation-induced jitter without upgrading my priority?



Share this post


Link to post
Share on other sites
quote:
Original post by oxygen_728
I''ve read those posts for hours, and this is the only solution that I''ve found.

I''d have to disagree with you if you were to say that setting the priority to ABOVE AVERAGE is a hack... that''s exactly what the flag was meant for.

HOWEVER, I''m open to ideas...

How do I overcome my starvation-induced jitter without upgrading my priority?



First off all, I think we were talking about the high priority flag. Even so, your code should work well without messing with the priority. Why don''t you post some code? The irregularities could be caused by anything. I still don''t even know what you are talking about - is rendering jumpy, or just physics/movement?

Share this post


Link to post
Share on other sites
When I run my DX app with my ATI, I have no issues, but with my old nVidia (GeForce4 mx440) I got jerkiness. However, disabling my DSL monitor in the background solved the issue - no more jerkiness.

I did experiment with setting the priority higher, and that worked, but I''m happier that I found the real source of the problem and didn''t end up mucking around with priorities.

Does your app still get jerkiness on a "clean" startup (i.e., disable everything in your startup)? I ended up commenting out everything in my Run registry entry and making sure there was nothing "extra" starting up with Windows, then added one thing at a time until the jerkiness returned.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Try running something like SmartAlec Game Accelerator before your app. This can be made to stop all unimportant (to the system) tasks, defrag memory etc. Give you a clean canvas to test on each time.

Share this post


Link to post
Share on other sites
I''ll give it a try...

I''m almost positive the lag comes from rare occurances of starvation during the rendering of the meshes in the scene.

It has nothing to do with not using floats instead of ints...
I know that my timing is fine...

The lag comes between the point I make the call to draw my meshes and the time they are presented to the screen.

About once every 20 frames, roughly, it takes 40 ms to render them... yet with 1 upgrade to the priority this 40 ms delay NEVER happens.

This appears as starvation in the processing queue to me.

By the way, if somebody is running your game... When your game has the focus the priority should be higher than average, in my opinion. It is not a difficult thing to downgrade your priority when the user ALT-TABS out of your game. Might even be able to go to IDLE priority when they do that... thus really freeing up processing for the other apps.

Game Has Focus -> Above Average Priority
Game Loses Focus -> Idle Priority (Only uses processor when it is idle)
Game Gains Focus again -> Above Average Priority

Is this a bad idea? I don''t think so. (IMO)

I''m curious... is changing the priority kind of like using goto''s for some of you guys? That''s what I''m starting to get the feeling... Some people are 100% against goto''s no matter what you say to them, even though there are clearly situations in which they are the most efficient & readable means of doing a task.

Share this post


Link to post
Share on other sites
For the people concerned about my code... Here's the normal render times for my meshes... I'm making these numbers up, but you can get the gist... when I debugged the render times this is what showed up. Also pasted below are the high priority times.

milliseconds to render meshes
5
5
5
5
5
5
5
5
40
5
5
5
5
5
5
5
40
5
5


HIGH PRIRORITY TIMES
milliseconds to render meshes
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5


40's are gone... By some of the logic I've seen in this post.... the 40's SHOULD be reduced to maybe 20 or 30 if there was "a different problem in my code". Why are the 40's reduced to 5's? I believe it is because the program is not being stuck in the back of the processing queue.

Sorry if this isn't clear... I'm just trying to point out why I think it is starvation (getting stuck behind other processes in the process scheudling queue(s)).


[edited by - oxygen_728 on March 30, 2004 2:58:21 PM]

Share this post


Link to post
Share on other sites
No clue, perhaps one of the 44 processes running at any given time on my system? I have 10 programs that run everytime I startup... and I know many "end users" have the same type of setup. The rest are windows processes.

Perhaps you can see how, on a system like mine, it may be a good idea to consider putting the priority of your game over those of most of the 40 processes already running. It''s not a good thing when your program gets stuck behind 40 processes when it is trying to render!

By the way, HIGH_PRIORITY_CLASS preempts IDLE and NORMAL priority processes. The OS critical processes still have a higher priority.

If you want to overwrite those (you may be crazy), you can use the REALTIME_PRIORITY_CLASS.

I''m starting to like the idea of High Priority when it has the focus, and idle priority when it doesn''t... though you would need to code the game to handle zero framerate for possibly long periods of time.


Share this post


Link to post
Share on other sites