bool
GHOST_SystemSDL::processEvents(bool waitForEvent)
{
	// Get all the current events -- translate them into
	// ghost events and call base class pushEvent() method.

	bool anyProcessed = false;

	do {
		GHOST_TimerManager *timerMgr = getTimerManager();

		if (waitForEvent && m_dirty_windows.empty() && !SDL_HasEvents(SDL_FIRSTEVENT, SDL_LASTEVENT)) {
			GHOST_TUns64 next = timerMgr->nextFireTime();

			if (next == GHOST_kFireTimeNever) {
				SDL_WaitEventTimeout(NULL, -1);
				//SleepTillEvent(m_display, -1);
			}
			else {
				GHOST_TInt64 maxSleep = next - getMilliSeconds();

				if (maxSleep >= 0) {
					SDL_WaitEventTimeout(NULL, next - getMilliSeconds());
					// SleepTillEvent(m_display, next - getMilliSeconds()); // X11
				}
			}
		}

		if (timerMgr->fireTimers(getMilliSeconds())) {
			anyProcessed = true;
		}

		SDL_Event sdl_event;
		while (SDL_PollEvent(&sdl_event)) {
			processEvent(&sdl_event);
			anyProcessed = true;
		}

		if (generateWindowExposeEvents()) {
			anyProcessed = true;
		}
	} while (waitForEvent && !anyProcessed);

	return anyProcessed;
}
Exemple #2
0
bool GHOST_SystemWin32::processEvents(bool waitForEvent)
{
	MSG msg;
	bool anyProcessed = false;

	do {
		GHOST_TimerManager *timerMgr = getTimerManager();

		if (waitForEvent && !::PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE)) {
#if 1
			::Sleep(1);
#else
			GHOST_TUns64 next = timerMgr->nextFireTime();
			GHOST_TInt64 maxSleep = next - getMilliSeconds();
			
			if (next == GHOST_kFireTimeNever) {
				::WaitMessage();
			}
			else if (maxSleep >= 0.0) {
				::SetTimer(NULL, 0, maxSleep, NULL);
				::WaitMessage();
				::KillTimer(NULL, 0);
			}
#endif
		}

		if (timerMgr->fireTimers(getMilliSeconds())) {
			anyProcessed = true;
		}

		// Process all the events waiting for us
		while (::PeekMessageW(&msg, 0, 0, 0, PM_REMOVE) != 0) {
			// TranslateMessage doesn't alter the message, and doesn't change our raw keyboard data.
			// Needed for MapVirtualKey or if we ever need to get chars from wm_ime_char or similar.
			::TranslateMessage(&msg);
			::DispatchMessageW(&msg);
			anyProcessed = true;
		}
	} while (waitForEvent && !anyProcessed);

	return anyProcessed;
}
Exemple #3
0
bool GHOST_SystemWin32::processEvents(bool waitForEvent)
{
	MSG msg;
	bool anyProcessed = false;

	do {
		GHOST_TimerManager* timerMgr = getTimerManager();

		if (waitForEvent && !::PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE)) {
#if 1
			::Sleep(1);
#else
			GHOST_TUns64 next = timerMgr->nextFireTime();
			GHOST_TInt64 maxSleep = next - getMilliSeconds();
			
			if (next == GHOST_kFireTimeNever) {
				::WaitMessage();
			} else if(maxSleep >= 0.0) {
				::SetTimer(NULL, 0, maxSleep, NULL);
				::WaitMessage();
				::KillTimer(NULL, 0);
			}
#endif
		}

		if (timerMgr->fireTimers(getMilliSeconds())) {
			anyProcessed = true;
		}

		// Process all the events waiting for us
		while (::PeekMessage(&msg, 0, 0, 0, PM_REMOVE) != 0) {
			::TranslateMessage(&msg);
			::DispatchMessage(&msg);
			anyProcessed = true;
		}
	} while (waitForEvent && !anyProcessed);

	return anyProcessed;
}
/* this is an old style low level event queue.
 * As we want to handle our own timers, this is ok.
 * the full screen hack should be removed */
bool GHOST_SystemCarbon::processEvents(bool waitForEvent)
{
	bool anyProcessed = false;
	EventRef event;
	
//	SetMouseCoalescingEnabled(false, NULL);

	do {
		GHOST_TimerManager *timerMgr = getTimerManager();
		
		if (waitForEvent) {
			GHOST_TUns64 next = timerMgr->nextFireTime();
			double timeOut;
			
			if (next == GHOST_kFireTimeNever) {
				timeOut = kEventDurationForever;
			}
			else {
				timeOut = (double)(next - getMilliSeconds()) / 1000.0;
				if (timeOut < 0.0)
					timeOut = 0.0;
			}
			
			::ReceiveNextEvent(0, NULL, timeOut, false, &event);
		}
		
		if (timerMgr->fireTimers(getMilliSeconds())) {
			anyProcessed = true;
		}

		if (getFullScreen()) {
			// Check if the full-screen window is dirty
			GHOST_IWindow *window = m_windowManager->getFullScreenWindow();
			if (((GHOST_WindowCarbon *)window)->getFullScreenDirty()) {
				pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowUpdate, window) );
				anyProcessed = true;
			}
		}

		/* end loop when no more events available */
		while (::ReceiveNextEvent(0, NULL, 0, true, &event) == noErr) {
			OSStatus status = ::SendEventToEventTarget(event, ::GetEventDispatcherTarget());
			if (status == noErr) {
				anyProcessed = true;
			}
			else {
				UInt32 i = ::GetEventClass(event);
				
				/* Ignore 'cgs ' class, no documentation on what they
				 * are, but we get a lot of them
				 */
				if (i != 'cgs ') {
					if (i != 'tblt') {  // tablet event. we use the one packaged in the mouse event
						; //printf("Missed - Class: '%.4s', Kind: %d\n", &i, ::GetEventKind(event));
					}
				}
			}
			::ReleaseEvent(event);
		}
	} while (waitForEvent && !anyProcessed);
	
	return anyProcessed;
}