Archived

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

Andre Luiz Silva

Windows Vs. My Game

Recommended Posts

While I''m running my 2D game, sometimes Windows start doing some background jobs, writing to/reading from the hard disk, and while Windows is on it my frame rate drops or even worse - my game stops for some milliseconds and then returns back to normal. Is there a way to stop or minimize it? I think so, because when I play commercial games (Unreal, for example) I''ve never noticed something like that. Thanks, André Luiz Silva "There is no knowledge that is not power"

Share this post


Link to post
Share on other sites
I don''t know how to do it in code, but to stop Windows from randomly screwing around with the cache, set your cache minimum and maximum both to 2.5 times the amount of RAM you have. It''s in the System dialog somewhere. That should stop it from resizing.


Lack

Christianity, Creation, metric, Dvorak, and BeOS for all!

Share this post


Link to post
Share on other sites
Perhaps you are accidently allocation and/or deallocation a lot of memory and windows needs to resize the swapfile often...
you can set the virtual memory to a given size like LackOfKnack said. press [Windows-key]-[Pause] and click on the most right tab.

Share this post


Link to post
Share on other sites
You could call SetPriorityClass (at least I think thats the call). I personally dont advocate using it though, as Windows programs should share resources (even at the detriment of performance).

If you do chose to use it, a word of advice: don''t use the realtime priority class unless you think it''s neccasary to halt up OS tasks!

--TheGoop

Share this post


Link to post
Share on other sites
I''m a big supporter of using SetPriorityClass and SetPriorityThread. In my game, I''m doing absolutely no memory allocation or disk access during a level, yet Window''s would butt in every so often and I''d lose 1 to 10+ frames. I can''t see any other way of keeping Window''s in line, and lets face it, the user shouldn''t really be running background stuff when playing games. Just make sure you set the priority low when they alt-tab out of the game, or use some other way to do nothing until the game is restored.

Rock

Share this post


Link to post
Share on other sites
First of all - thank you all...

LackOfKnack/Ridcully: if I choose to change my virtual memory settings, I would have to recommend it to everyone who wants to play my game. And I am using about 2 MB of memory to store artwork, what give about 14 MB''s of video avaiable video memory.

nullpointer: I understand what you said, but that''s not the case

TheGoop/Rock2000: I will try to use it. And I agree with Rock2000 about playing and running background stuff.

If you have any other suggestions, please let me know...

Thank you all


André Luiz Silva
"There is no knowledge that is not power"

Share this post


Link to post
Share on other sites
Never change your priority to Real-Time, or anything from the default. This is only for drivers, not applications.

Read msn''s rant in the mail bag or whatever section it is for more information on that.

-Dan Smith
dans@3dgamedev.com

Share this post


Link to post
Share on other sites
What''s a good class-priority setting, if not using real-time?
I''m doing:

HANDLE hProcess, hThread;

hProcess = GetCurrentProcess();
hThread = GetCurrentThread();

SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS);
SetThreadPriority(hThread, THREAD_PRIORITY_HIGHEST);


And it magically removes all my on-screen jitters.

Share this post


Link to post
Share on other sites
I''m not looking for a flame war or anything, so I''ll keep this brief.

Dont set your priority. Your doing something wrong if you have to set the priority like that. You will run into problems doing it later on, you may not on your system - but you will eventually.

Bottom line is, dont do it. Pretend you never heard of the API call for that.

-Dan Smith
dans@3dgamedev.com

Share this post


Link to post
Share on other sites
Hey, guys. Have you never experienced something like that while running your games? I''ve noticed that too when I am using the NeoRageX emulator. If we should not to change the priority, there must be another way to turn Windows off... Of course - it''s easy to blame Windows for something like that, but my code is so simple that I don''t think I''m doing something wrong...

Thanks,

André Luiz Silva
"There is no knowledge that is not power"

Share this post


Link to post
Share on other sites
Well, I asked around for a month to get a better fix, but nobody ever gave me one. This is the ONLY thing that has alleviated me of the problem, and my code is doing nothing it shouldn''t be. Until somebody gives me another fix I''m going to stay on the priority train.

Rock

Share this post


Link to post
Share on other sites
Andre, if other games don''t seem to have that problem, I''d agree with Ridcully that it''s your game that''s responsible for the swap. It''s not necessarily an error of yours; I think that if you alocate something then dealocate inside a cicle, while it is perfectly legal, you could make windows start rearanging the virtual mem. If this is the case, you could try to pass frequently allocated/dealocated memory to outside cycles or functions that get called often, or even alocating that memory once at the start of the program. If not for this reason, it will at least give you some speedup
Boa sorte

Share this post


Link to post
Share on other sites
Ugh, once again, ignorance abounds...

PeekMessage( &msg, hwnd, 0,0, PM_NOYIELD );

Use this to process your windows messages. This prevents the idle system process from kicking in unnecessarily.

MSN

P.S. You might want to add in some post-processing of WM_QUIT to make sure your program cleans up correctly.

Share this post


Link to post
Share on other sites
Rock2000: I almost posted the same thing, but in the MSDN 6.0a docs it doesn''t seem to mention that anywhere? Perhaps they updated the information, as I think it has something to do with WaitForInputIdle. (The 4.0 version of MSDN does say it doesn''t do anything, though.) Odd, isn''t it? Anybody know more about it?



- null_pointer
Sabre Multimedia

Share this post


Link to post
Share on other sites
Well, god only knows with Microsoft. One second they say ''don''t use it, it doesn''t do anything'', and the next they say ''hey guess what, its back''. If they''re reusing an old value for something new, then I''ve lost yet more faith in them, which is almost impossible.

But even if does do something new now, it wouldn''t be what msn said, because running a normal PeekMessage loop doesn''t allow for idle processing anyway, according the msdn (Direct quote below).

------------------------------------------------------

// This PeekMessage loop will NOT let the system go idle.

for( ;; )
{

while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
return TRUE;

TranslateMessage(&msg);
DispatchMessage(&msg);
}

BackgroundProcessing();
}
-----------------------------------------------------

Rock

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Rock2000

But even if does do something new now, it wouldn''t be what msn said, because running a normal PeekMessage loop doesn''t allow for idle processing anyway, according the msdn (Direct quote below).

Rock


Hmm... that wasn''t the point I was making, so let me clarify...

PeekMessage should be used as opposed to GetMessage, since GetMessage tells the system your app is **WAITING** for messages, hence, it''s an opportunity for the system to perform some background stuff. PeekMessage tells the system you''re still busy and youwant to make sure your messages don''t get backed up. This prevents the system from flagging your process as [Not-Responding].

Trust me, I know what I''m talking about. Knowledge is more than just bitfields and flags...

MSN

Share this post


Link to post
Share on other sites
Well, OK, nobody is going to dispute that statement, but that isn''t really what we''re talking about. I certainly hope nobody is using GetMessage for games. The point is that using a loop like the example I quoted I above (except where BackgroundProcessing is the game loop), the game still loses time to Window''s stuff every once in a while. As I''ve said, the only way around it that I''ve seen is to up the priority to keep that from happening.

Rock

Share this post


Link to post
Share on other sites
Rock2000 - maybe you are right, as you said you had always used SetPriorityClass. I had never tried the PeekMessage loop, and although we loose some time, maybe, it will be faster than the problems I''ve encountered. My game really stops for some milliseconds, I can hear my hard disk reading/writing and then things come back to normal. What I am trying to say is that we should give a try to every entry here. That''s the only way to discover the pros/cons each one has to offer.

Thanks,


André Luiz Silva
"There is no knowledge that is not power"

Share this post


Link to post
Share on other sites
I''ve seen commercial games use thread priorities. Check this out.
I have this Win32 SDK tool called Pview 95 (process viewer) which
shows all running processes, their priority, and how many threads
they are using.

I just downloaded a game demo called Metal Fatigue, ran it, alt-tabbed
out to windows, ran process viewer, and it showed that the game
had two threads running, one was set at 28 (time critical!) and the
other was set at 13 (normal).

I also have a Starcraft demo, and it showed it had 5 threads running,
3 were 8 (normal), 1 was 9 (above normal), and 1 was 10 (highest).

So, I think it is perfectly ok to use those functions, especially
if you have more than one thread running. For instance, if you had
a rendering thread and an input thread, you could give one a higher
priority than the other.

Rasta

Share this post


Link to post
Share on other sites
quote:
Original post by Rasta

So, I think it is perfectly ok to use those functions, especially
if you have more than one thread running. For instance, if you had
a rendering thread and an input thread, you could give one a higher
priority than the other.

Rasta




Normally, when discussing advanced resource utilization on these boards, most people:

a.) Have no idea what they are talking about.
b.) Have some idea of what they''re talking about, but their program/app probably needs improvement elsewhere (algorithm, API calls, structure, etc.) Like the PeekMessage loop.
c.) Have a good idea of what they need to do.

C never happens here (Actually, rarely... normally those issues come out on the algo/sweng lists.)

So, I tend to view most problems as a or b (leaning heavily towards a as of late...)



So, before you go off into thread priority hell, here are some helpful guidelines you should not violate unless you know exactly what you are doing or you''re running exclusively on SMP machines.

1. Use higher priorities for threads that will do less work, but need to do it w/ little latency: input, network, etc... NOT video.

2. Make sure those threads (from 1) sleep as much as possible.

MSN

Share this post


Link to post
Share on other sites
msn12b,

I agree 100% with you. I''m not an expert, and I have never stated that I
was an expert. So don''t listen to me. All I would tell someone else to
do is run your favorite game, check out how many threads it is running and
see what priorities they are set at, and make your own decision on what you
should do.

Rasta

Share this post


Link to post
Share on other sites