How to pause processing?
-
Dustin Henry wrote:
I comment out all of my code in the loop except the windows message queue processing and my app jumps from 60fps to about 2000fps.
What do you mean by "fps"? Typically a Windows message loop uses virtually no CPU until a message is received. What's going on in your message loop? Mark
Mark Salsbery wrote:
What do you mean by "fps"?
Well i am guessing he is writing a game/game engine. Applications also lose focus when they are minimized. That is why he probaly needs the application to stop processing.
Artificial Intelligence is no match for Natural Stupidity
No one can understand the truth until he drinks of coffee's frothy goodness. ~Sheik Abd-al-Kadir
I can't always be wrong ... or can I? -
Since my message peek is in the main loop, if I do that it will no longer look for messages and will not tell me when focus has been restored.
Well you could put a copy of the messagepeek functions to the while (!m_bRunning) {}; then there should be no problems
Artificial Intelligence is no match for Natural Stupidity
No one can understand the truth until he drinks of coffee's frothy goodness. ~Sheik Abd-al-Kadir
I can't always be wrong ... or can I? -
Mark Salsbery wrote:
What do you mean by "fps"?
Well i am guessing he is writing a game/game engine. Applications also lose focus when they are minimized. That is why he probaly needs the application to stop processing.
Artificial Intelligence is no match for Natural Stupidity
No one can understand the truth until he drinks of coffee's frothy goodness. ~Sheik Abd-al-Kadir
I can't always be wrong ... or can I?Sorry his reply was not there when i posted mine
Artificial Intelligence is no match for Natural Stupidity
No one can understand the truth until he drinks of coffee's frothy goodness. ~Sheik Abd-al-Kadir
I can't always be wrong ... or can I? -
Sorry his reply was not there when i posted mine
Artificial Intelligence is no match for Natural Stupidity
No one can understand the truth until he drinks of coffee's frothy goodness. ~Sheik Abd-al-Kadir
I can't always be wrong ... or can I?Well I think I fixed it. I basically used CaveFox's idea of a running boolean but in the main loop placed:
if (!g_bRunning) Sleep(1000);
I believe this was happening because I allow the program to basically sit and spin in an infinite loop. Even if I commented out everything in the while(), the same thing happened. I guess the program just needed something to do. Any idea why this is? Thanks for your help guys. Dustin
-
fps = Frames per second. It is a Direct3D application. Typically a Windows message loop uses virtually no CPU until a message is received I thought the same thing, but if I comment out all of my processing except for the message peek and dispatch, the app still eats the CPU when focus is lost. Here is my entire WindowProc:
LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_CREATE: { // do initialization stuff here // return success return(0); } break; case WM_LBUTTONDOWN: { // get the position of the mouse POINT ptMouse = {(int)LOWORD(lParam),(int)HIWORD(lParam)}; g_pInterface->UpdateMouse(ptMouse, true); } break; case WM_LBUTTONUP: { // get the position of the mouse POINT ptMouse = {(int)LOWORD(lParam),(int)HIWORD(lParam)}; g_pInterface->UpdateMouse(ptMouse, false); } break; case WM_MOUSEMOVE: { // get the position of the mouse POINT ptMouse = {(int)LOWORD(lParam),(int)HIWORD(lParam)}; g_pInterface->UpdateMouse(ptMouse); CString stMove; stMove.Format("(%d,%d)",(int)LOWORD(lParam),(int)HIWORD(lParam)); //SetWindowText(g_hWND, stMove); } break; case WM_DESTROY: { // kill the application, this sends a WM_QUIT message PostQuitMessage(0); // return success return(0); } break; case WM_GRAPHNOTIFY: { g_pInterface->GetDirectShow()->OnGraphEvent(); } break; default:break; } // end switch // process any messages that we didn't take care of return (DefWindowProc(hWnd, msg, wParam, lParam)); } // end WinProc
And my main loop: (the message part)
while(TRUE) { // Get the time this function began executing //DWORD dwStartTime = GetTickCount(); // test if there is a message in queue, if so get it if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { // test if this is a quit if (msg.message == WM_QUIT) break; // translate any accelerator keys if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); // send the message to the window proc DispatchMessage(&msg); } } // end if /* Other processing... */ }
Dustin
Try GetMessage instead of PeekMessage You shouldn't have to sleep or mess with thread priority for user interface thread :) Mark
-
Well I think I fixed it. I basically used CaveFox's idea of a running boolean but in the main loop placed:
if (!g_bRunning) Sleep(1000);
I believe this was happening because I allow the program to basically sit and spin in an infinite loop. Even if I commented out everything in the while(), the same thing happened. I guess the program just needed something to do. Any idea why this is? Thanks for your help guys. Dustin
No SLEEP()!!! ;)
while(GetMessage(&msg,NULL,0,0))
{
// translate any accelerator keys
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
// send the message to the window proc
DispatchMessage(&msg);
}
} -
Well I think I fixed it. I basically used CaveFox's idea of a running boolean but in the main loop placed:
if (!g_bRunning) Sleep(1000);
I believe this was happening because I allow the program to basically sit and spin in an infinite loop. Even if I commented out everything in the while(), the same thing happened. I guess the program just needed something to do. Any idea why this is? Thanks for your help guys. Dustin
This should stop all processing (except the messages).
case WM_ACTIVATE: { //See if we lost or gained focus if (LOWORD(wParam) == WA_ACTIVE) { g_bRunning = true; } else { g_bRunning = false; } } break; static bool m_bRunning = true; while(TRUE) { // Get the time this function began executing //DWORD dwStartTime = GetTickCount(); // test if there is a message in queue, if so get it do { if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { // test if this is a quit if (msg.message == WM_QUIT) break; // translate any accelerator keys if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); // send the message to the window proc DispatchMessage(&msg); } } // end if } while(!m_bRunning) /* Other processing... */ }
Artificial Intelligence is no match for Natural Stupidity
No one can understand the truth until he drinks of coffee's frothy goodness. ~Sheik Abd-al-Kadir
I can't always be wrong ... or can I? -
I have an application with a main processing loop ( while(true){} ). When the application is running normally it eats up about 2% of the CPU. Whenever focus is taken away from the application window however, the CPU usage jumps to about 50%. This also happens when I comment out all of my code in the loop except the windows message queue processing and my app jumps from 60fps to about 2000fps. My question is, how do I 'pause' processing when focus is taken away, but still have the abilty to get window messages so I know when focus is given back? Thanks in advance, Dustin
Really, I BEG you guys...pleeeease leave the poor UI thread alone :(( What did it ever do to you??? :)
-
Really, I BEG you guys...pleeeease leave the poor UI thread alone :(( What did it ever do to you??? :)
Yea it was a little overkill (by me X|) ... im sleep deprived and are not thinking strait. Should have solved it with the first post :^)
Artificial Intelligence is no match for Natural Stupidity
No one can understand the truth until he drinks of coffee's frothy goodness. ~Sheik Abd-al-Kadir
I can't always be wrong ... or can I? -
Yea it was a little overkill (by me X|) ... im sleep deprived and are not thinking strait. Should have solved it with the first post :^)
Artificial Intelligence is no match for Natural Stupidity
No one can understand the truth until he drinks of coffee's frothy goodness. ~Sheik Abd-al-Kadir
I can't always be wrong ... or can I?:laugh: It looked right to me - I had to test it before I saw it! As soon as Sleep() comes up, it's time for an intervention :)