int CWinThread::Run() /*******************/ { MSG msg; LONG lCount = 0L; for( ;; ) { while( !::PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) ) { if( OnIdle( lCount ) ) { lCount++; } else { ::WaitMessage(); } } if( !PumpMessage() ) { break; } if( IsIdleMessage( &msg ) ) { if( OnIdle( lCount ) ) { lCount++; } else { ::WaitMessage(); } } else { lCount = 0L; } } return( ExitInstance() ); }
bool VideoPipelineSource::Run() { while (!(sink_->IsExhausted() && sink_->GetQueueSize() == 0)) { FrameSetPtr frame_set_ptr; float timeout = 200; // 0.2 ms if (max_fps_ > 0) { timeout = 1.0f / max_fps_ * 1e6; // in micros. } if (sink_->TryFetchingFrameSet(&frame_set_ptr)) { // Measure time difference. boost::posix_time::ptime curr_time = boost::posix_time::microsec_clock::local_time(); if (frame_num_ > 0) { float micros_passed = boost::posix_time::time_period( prev_process_time_, curr_time).length().total_microseconds(); int wait_time = timeout - micros_passed; while (wait_time > 10) { OnIdle(); // Update wait time. curr_time = boost::posix_time::microsec_clock::local_time(); micros_passed = boost::posix_time::time_period( prev_process_time_, curr_time).length().total_microseconds(); wait_time = timeout - micros_passed; // We only sleep a fraction of the wait time to keep OnIdle going. if (wait_time > 100) { boost::thread::sleep(boost::get_system_time() + boost::posix_time::microseconds(wait_time / 5)); } } } // Update processing time. prev_process_time_ = boost::posix_time::microsec_clock::local_time(); // Pass to children. for (auto child : children_) { child->ProcessFrameImpl(frame_set_ptr, this); } ++frame_num_; } else { OnIdle(); boost::thread::sleep(boost::get_system_time() + boost::posix_time::microseconds(timeout / 5)); } } PostProcessImpl(this); return true; }
int CRadiantApp::Run( void ) { BOOL bIdle = TRUE; LONG lIdleCount = 0; #if _MSC_VER >= 1300 MSG *msg = AfxGetCurrentMessage(); // TODO Robert fix me!! #else MSG *msg = &m_msgCur; #endif // phase1: check to see if we can do idle work while( bIdle && !::PeekMessage( msg, NULL, NULL, NULL, PM_NOREMOVE ) ) { // call OnIdle while in bIdle state if( !OnIdle( lIdleCount++ ) ) { bIdle = FALSE; // assume "no idle" state } } // phase2: pump messages while available do { // pump message, but quit on WM_QUIT if( !PumpMessage() ) { return ExitInstance(); } // reset "no idle" state after pumping "normal" message if( IsIdleMessage( msg ) ) { bIdle = TRUE; lIdleCount = 0; } } while( ::PeekMessage( msg, NULL, NULL, NULL, PM_NOREMOVE ) ); return 0; }
int CWinThread::RunLoop() { bool bIdle = true; LONG lIdleCount = 0; _AFX_THREAD_STATE* pState = AfxGetThreadState(); while (true) { #if UCFG_GUI while (bIdle && !::PeekMessage(&(pState->m_msgCur), 0, 0, 0, PM_NOREMOVE)) bIdle = OnIdle(lIdleCount++); #endif do { //#ifndef NO_GUI //!!! if (!PumpMessage()) return ExitInstance(); //#endif if (IsIdleMessage(pState->m_msgCur)) { bIdle = true; lIdleCount = 0; } } while (::PeekMessage(&(pState->m_msgCur), NULL, NULL, NULL, PM_NOREMOVE)); } }
void CProtectedWinThread::PumpIdle() { long lIdleCount = 0; while (OnIdle(lIdleCount++)) ; return; }
//**関数*************************************************************************** // 概要 : デフォルトのメッセージ ループ //********************************************************************************* int CWindow::Run() { if (!InitInstance()) return ExitInstance(); bool bIdle = TRUE; long lIdleCount = 0; for (;;) { while (bIdle && !::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE)) { if (!OnIdle(lIdleCount++)) bIdle = false; } do { if (!PumpMessage()) return ExitInstance(); if (IsIdleMessage(&m_msgCur)) { bIdle = true; lIdleCount = 0; } } while (::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE)); } return -1; // ここには来ないはず。 }
BOOL CGameService::StartRun() { if(!CLog::GetInstancePtr()->StartLog("StatisticsServer")) { ASSERT_FAIELD; return FALSE; } if(!CGlobalConfig::GetInstancePtr()->Load("StatisticsServer.ini")) { ASSERT_FAIELD; CLog::GetInstancePtr()->AddLog("配制文件加载失败!"); return FALSE; } if(!StartService()) { ASSERT_FAIELD; CLog::GetInstancePtr()->AddLog("启动服务失败!"); return FALSE; } m_ServerCmdHandler.Init(0); m_StatCmdHandler.Init(0); OnIdle(); return TRUE; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { #if defined _DEBUG _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF | _CRTDBG_ALLOC_MEM_DF); _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE); _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); #endif MSG msg = {0}; WNDCLASSEX wcl = {0}; wcl.cbSize = sizeof(wcl); wcl.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; wcl.lpfnWndProc = WindowProc; wcl.cbClsExtra = 0; wcl.cbWndExtra = 0; wcl.hInstance = g_hInstance = hInstance; wcl.hIcon = LoadIcon(0, IDI_APPLICATION); wcl.hCursor = LoadCursor(0, IDC_ARROW); wcl.hbrBackground = 0; wcl.lpszMenuName = 0; wcl.lpszClassName = "GL3WindowClass"; wcl.hIconSm = 0; if (!RegisterClassEx(&wcl)) return 0; g_hWnd = CreateAppWindow(wcl, "CastleLib Test App"); if (g_hWnd==NULL) return 0; if (!Init()) // Init OpenGL context and our library return 0; ShowWindow(g_hWnd, nShowCmd); UpdateWindow(g_hWnd); while (true) { while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); } if (msg.message == WM_QUIT) break; if (g_hasFocus) OnIdle(); else WaitMessage(); } return msg.wParam; }
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance ,LPSTR lpszCmdParam,int nCmdShow) { HWND hWnd; MSG Message; WNDCLASS WndClass; g_hInst=hInstance; WndClass.cbClsExtra=0; WndClass.cbWndExtra=0; WndClass.hbrBackground=NULL; WndClass.hCursor=LoadCursor(NULL,IDC_ARROW); WndClass.hIcon=LoadIcon(hInstance,MAKEINTRESOURCE(IDI_APIDRAW)); WndClass.hInstance=hInstance; WndClass.lpfnWndProc=WndProc; WndClass.lpszClassName=lpszClass; WndClass.lpszMenuName=MAKEINTRESOURCE(IDR_MENU1); WndClass.style=0; RegisterClass(&WndClass); WndClass.hbrBackground=NULL; WndClass.lpfnWndProc=CanvasProc; WndClass.lpszClassName="Canvas"; WndClass.lpszMenuName=NULL; WndClass.style=CS_DBLCLKS; RegisterClass(&WndClass); hWnd=CreateWindow(lpszClass,lpszClass,WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT, NULL,(HMENU)NULL,hInstance,NULL); ShowWindow(hWnd,nCmdShow); HACCEL hAccel; BOOL AllowIdle=TRUE; hAccel=LoadAccelerators(hInstance,MAKEINTRESOURCE(IDR_ACCELERATOR1)); for (;;) { do { if (!GetMessage(&Message,NULL,0,0)) goto endloop; if (Message.message != 0x118/*WM_SYSTIMER*/) { AllowIdle=TRUE; } if (!TranslateAccelerator(hWnd,hAccel,&Message)) { TranslateMessage(&Message); DispatchMessage(&Message); } } while (PeekMessage(&Message,NULL,0,0,PM_NOREMOVE)); if (AllowIdle) { OnIdle(); AllowIdle=FALSE; } } endloop: return (int)Message.wParam; }
LONG CIdleDialog::OnStartIdle( UINT, LONG ) { MSG msg; if ( !PeekMessage( &msg, GetSafeHwnd(), 0,0, PM_NOREMOVE ) ) OnIdle(); m_cWinIdle.NextIdle(); return 0; }
void CProtectedWinThread::PumpMessages() { ASSERT_VALID(this); // for tracking the idle time state BOOL bIdle = TRUE; LONG lIdleCount = 0; #if _MFC_VER >= 0x0710 _AFX_THREAD_STATE* pState = AfxGetThreadState(); MSG &msgCur = pState->m_msgCur; #else MSG &msgCur = m_msgCur; #endif /* _MFC_VER_ */ // acquire and dispatch messages until a WM_QUIT message is received. for (;;) { // phase1: check to see if we can do idle work while (bIdle && !::PeekMessage(&msgCur, NULL, NULL, NULL, PM_NOREMOVE)) { // call OnIdle while in bIdle state if (!OnIdle(lIdleCount++)) bIdle = FALSE; // assume "no idle" state } // phase2: pump messages while available do { // pump message, but quit on WM_QUIT if (!PumpMessage()) { #if defined(_DEBUG) # if _MFC_VER < 0x0710 m_nDisablePumpCount--; // application must NOT die # else pState->m_nDisablePumpCount--; // application must NOT die # endif #endif return; } // reset "no idle" state after pumping "normal" message if (IsIdleMessage(&msgCur)) { bIdle = TRUE; lIdleCount = 0; } } while (::PeekMessage(&msgCur, NULL, NULL, NULL, PM_NOREMOVE)); } ASSERT(FALSE); // not reachable }
///////////////////////////////////////////// // This is called on a Resize of the glut window ///////////////////////////////////////////// static void OnReshape( int width, int height ) { // save these params in case your app needs them AppWindow::width = width; AppWindow::height = height; // set your viewport to the extents of the window glViewport( 0, 0, width, height ); // let the app run idle, while resizing, // glut does not do this for us automatically, so call OnIdle explicitly. OnIdle(); }
BOOL CDrawApp::InitInstance() { // Initialize OLE 2.0 libraries if (!AfxOleInit()) { AfxMessageBox(IDP_OLE_INIT_FAILED); return FALSE; } // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. Enable3dControls(); // enable 3d controls in dialogs LoadStdProfileSettings(); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views. CSingleDocTemplate* pDocTemplate; pDocTemplate = new CSingleDocTemplate( IDR_MAINFRAME, RUNTIME_CLASS(CDrawDoc), RUNTIME_CLASS(CMainFrame), RUNTIME_CLASS(CDrawView)); pDocTemplate->SetContainerInfo(IDR_SEPEDTTYPE_CNTR_IP); AddDocTemplate(pDocTemplate); // enable file manager drag/drop and DDE Execute open EnableShellOpen(); RegisterShellFileTypes(); // simple command line parsing if (m_lpCmdLine[0] == '\0') { // create a new (empty) document OnFileNew(); } else { // open an existing document OpenDocumentFile(m_lpCmdLine); } m_pMainWnd->DragAcceptFiles(); OnIdle(0); // updates buttons before showing the window return TRUE; }
HRESULT HandleVisioEvent( IN IUnknown* ipSink, // ipSink [assert] IN short nEventCode, // code of event that's firing. IN IDispatch* pSourceObj, // object that is firing event. IN long lEventID, // id of event that is firing. IN long lEventSeqNum, // sequence number of event. IN IDispatch* pSubjectObj, // subject of this event. IN VARIANT vMoreInfo, // other info. OUT VARIANT* pvResult) // return a value to Visio for query events. { ENTER_METHOD(); switch(nEventCode) { case (short)(Visio::visEvtApp|Visio::visEvtWinActivate): theApp.SetNeedUpdate(true); break; case (short)(Visio::visEvtWindow|Visio::visEvtDel): theApp.SetNeedUpdate(true); break; case (short)(Visio::visEvtApp|Visio::visEvtIdle): OnIdle(); break; case (short)(Visio::visEvtCodeWinSelChange): theApp.SetNeedUpdate(true); break; case (short)(Visio::visEvtFormula|Visio::visEvtMod): OnFormulaChanged(pSubjectObj); break; case (short)(Visio::visEvtApp|Visio::visEvtNonePending): OnNoEventsPending(); break; case (short)(Visio::visEvtCodeWinPageTurn): theApp.OnCommand(0); break; } return S_OK; LEAVE_METHOD(); }
LRESULT CPlayList::OnNMRclickLsv1(int /*idCtrl*/, LPNMHDR pNMHDR, BOOL& /*bHandled*/) { OnIdle(); //force UI Updating POINT pt; GetCursorPos(&pt); CMenu menu; menu.LoadMenu(IDR_POPUPMENU_PLIST); CMenuHandle menuPop = menu.GetSubMenu(0); // Display the shortcut menu. Track the right mouse button. ::TrackPopupMenuEx(menuPop, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, m_hWnd, NULL); return 0; }
// --------------- AI状态切换函数 --------------------------------------- void KAIBase::DoIdle(int nIdleFrame) { //KGLogPrintf(KGLOG_DEBUG, "[AI State] {%s} Turn to Idle\n", m_pSelf->m_szName); SetAIInterval(1.0); m_pSelf->Stop(); if (m_eAIState == aisIdle) { int nTmpFrameCount = g_pSO3World->m_nGameLoop + nIdleFrame; m_IdleData.nIdleFrameCount = (m_IdleData.nIdleFrameCount > nTmpFrameCount) ? m_IdleData.nIdleFrameCount : nTmpFrameCount; } else { m_IdleData.nIdleFrameCount = g_pSO3World->m_nGameLoop + nIdleFrame; } SetAIState(aisIdle); OnIdle(); }
KBOOL AppFrame::frameRenderingQueued( const Ogre::FrameEvent& evt ) { //PROFILE("frameRendering"); if(m_pWindow->isClosed()) return false; if (m_bShutDown) return false; m_pInputMgr->Tick(evt.timeSinceLastFrame); if (!m_bPaused) OnIdle(evt.timeSinceLastFrame); return true;
void InformApp::RunMessagePump(void) { LONG count = 0; while (OnIdle(count++)); MSG msg; while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE)) { if (msg.message == WM_COMMAND) ::PeekMessage(&msg,NULL,0,0,PM_REMOVE); else if (PumpMessage() == FALSE) exit(ExitInstance()); } if (IsWaitCursor()) RestoreWaitCursor(); }
bool CMultiXWSStream::DoWork() { WaitEventReturnCodes ReturnCode; ReturnCode = Wait(1); if(ReturnCode == NoEventPending) { try { if(OnIdle()) return true; ReturnCode = Wait(5000); } catch (CMultiXException &e) { return OnMultiXException(e); } } try { switch(ReturnCode) { case MultiXEventPending : { CMultiXEvent *Event = Dequeue(); if(Event) { OnNewEvent(Event); } } break; #ifdef WindowsOs case WindowsMessagePending : { MSG Msg; PeekMessage(&Msg, NULL, 0, 0, PM_NOREMOVE); } break; #endif } } catch (CMultiXException &e) { return OnMultiXException(e); } return true; }
int SMessageLoop::Run() { BOOL bDoIdle = TRUE; int nIdleCount = 0; BOOL bRet; m_bRunning = TRUE; m_bQuit = FALSE; for(;;) { while(bDoIdle && !::PeekMessage(&m_msg, NULL, 0, 0, PM_NOREMOVE)) { if(!OnIdle(nIdleCount++)) bDoIdle = FALSE; if (m_bQuit) goto exit_loop; } bRet = ::GetMessage(&m_msg, NULL, 0, 0); if(bRet == -1) { SLOGFMTE(_T("::GetMessage returned -1 (error)")); continue; // error, don't process } else if(!bRet) { SLOGFMTT(_T("SMessageLoop::Run - exiting,code = %d"),(int)m_msg.wParam); break; // WM_QUIT, exit message loop } OnMsg(&m_msg); if(IsIdleMessage(&m_msg)) { bDoIdle = TRUE; nIdleCount = 0; } if (m_bQuit) break; } exit_loop: m_bRunning = FALSE; return (int)m_msg.wParam; }
/*---------------------------------------------------------------------------------------------- Load settings specific to this window. ----------------------------------------------------------------------------------------------*/ void DcMainWnd::LoadSettings(const achar * pszRoot, bool fRecursive) { AssertPszN(pszRoot); SuperClass::LoadSettings(pszRoot, fRecursive); FwSettings * pfws; pfws = AfApp::GetSettings(); // TODO: Use methods defined on pfws to load settings. // Get window position. LoadWindowPosition(pszRoot, "Position"); ::ShowWindow(m_hwnd, SW_SHOW); OnIdle(); ::UpdateWindow(m_hwnd); }
bool CEditToolApp::MainFrame(void) { ImpTimeSystem_t::Inst()->PushLogicTime(); int32 nTimeError = ImpTimeSystem_t::Inst()->GetTimeError(); if( nTimeError>=0 ) nTimeError = OnIdle( uint32(nTimeError) ); if( nTimeError < 0 ) nTimeError = 0; uint32 uResult = GetEvent( uint32( nTimeError ) ); for( ;; ) { switch( uResult ) { case eGER_TimedOut: return !m_bQuit; case eGER_SysMsg: OnSysMsg(); break; case eGER_Iocp: //OnIocp(); break; case eGER_NetMsg: break; case eGER_Canceled: OnCanceled(); if( m_bQuit ) return false; break; default: { ostringstream strm; strm<<"m_pPipeReactor->GetEvent return unknown value "<<uResult; GenErr(strm.str()); } } uResult = GetEvent( 0 ); } return !m_bQuit; }
dword Tapplication::EventHandler( word event, dword param1, dword param2 ) { if (IsClosing()) return param1; switch ( event ) { case EVT_IDLE: OnIdle(); return 0; case EVT_KEY: if (m_reshowUIKey != 0) return OnKeyWhenHidden(param1, param2); return OnKey( param1, param2 ); default: return OnOtherEvent(event, param1, param2); } }
// やっぱオーバライドしないと動きおかしい int CIperfThread::Run() { ASSERT_VALID(this); _AFX_THREAD_STATE* pState = AfxGetThreadState(); do { if(! OnIdle(1)) { if(WaitForSingleObject(m_ProcessInfo.hProcess, INFINITE) == WAIT_OBJECT_0) { break; } } } while(1); ExitInstance(); return 0; }
void IEventChannel::FiredEvents() { ChannelEventFlags val=mFiredEvents; mFiredEvents = ChannelEventFlags::None; if (MEDUSA_FLAG_HAS(val,ChannelEventFlags::Read)) { OnActive(); OnRead(); } if (!mIsAlive) { return; } if (MEDUSA_FLAG_HAS(val, ChannelEventFlags::Write)) { OnActive(); OnWrite(); } if (MEDUSA_FLAG_HAS(val, ChannelEventFlags::Timeout)) { OnTimeout(); } if (MEDUSA_FLAG_HAS(val, ChannelEventFlags::Retry)) { OnRetry(); } if (MEDUSA_FLAG_HAS(val, ChannelEventFlags::Fault)) { OnError(); } if (MEDUSA_FLAG_HAS(val, ChannelEventFlags::Idle)) { OnIdle(); } }
//--------------------------------------------------------------------------------------------------------------------- void CApplication::MessageLoop() { assert(m_hAppWindow && "application window has not been created!"); MSG xMessage = {0, 0, 0, 0, 0, 0}; while (xMessage.message != WM_QUIT) { if (PeekMessage(&xMessage, NULL, 0U, 0U, PM_REMOVE) != 0) { TranslateMessage(&xMessage); DispatchMessage(&xMessage); } else { float fDeltaTime = GetDeltaTime(); OnIdle(fDeltaTime); } } }
void KAI_Wood::Activate(void) { if (m_eAIType <= aitInvalid || m_eAIType >= aitTotal) return; if (g_pSO3World->m_nGameLoop < m_nNextActiveFrame) return; m_nNextActiveFrame = g_pSO3World->m_nGameLoop + g_pSO3World->m_Settings.m_ConstList.nAIInterval; CheckAIEvent(); KG_PROCESS_ERROR(m_pSelf->m_pScene && m_pSelf->m_pCell && m_pSelf->m_eMoveState != cmsOnDeath); //Npc可能在脚本中被删除,所以调用脚本之后要判断下 //木桩只会有一种状态 OnIdle(); return; Exit0: return; }
int CApplication::Run(void) { MSG msg={0}; while(msg.message!=WM_QUIT) { if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) || !m_bActive) { if(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } } else OnIdle(); } return msg.wParam; }
BOOL CGameService::StartRun() { if(!CLog::GetInstancePtr()->StartLog("DBServer")) { ASSERT_FAIELD; return FALSE; } CLog::GetInstancePtr()->AddLog("---------服务器开始启动-----------"); if(!CGlobalConfig::GetInstancePtr()->Load("DBServer.ini")) { ASSERT_FAIELD; CLog::GetInstancePtr()->AddLog("配制文件加载失败!"); return FALSE; } if(!StartService()) { ASSERT_FAIELD; CLog::GetInstancePtr()->AddLog("启动服务失败!"); return FALSE; } if(!m_ServerCmdHandler.Init(0)) { ASSERT_FAIELD; CLog::GetInstancePtr()->AddLog("启动默认连接消息处理器失败!"); return FALSE; } for(int i = 0; i < DB_THREAD_NUM; i++) { m_DBCmdHandler[i].Init(0); } OnIdle(); return TRUE; }
void CWinApp::Run() { MSG msg; int bFlag = TRUE; while ( TRUE ) { if ( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) ) { if ( msg.message == WM_QUIT ) break; TranslateMessage( &msg ); DispatchMessage( &msg ); bFlag = TRUE; }//if if ( bFlag ) bFlag = OnIdle(); }//while }//CWinApp::Run()