Ejemplo n.º 1
0
// -----------------------------------------------------------------------------
OSStatus refr_timer(EventLoopTimerRef *     inOutTimer, 
                    EventLoopTimerProcPtr   inTimerProc,
                    EventTimerInterval      inFireDelay,
                    EventTimerInterval      inInterval, /* 0 is one-shot */
                    void *                  inOutUserData)
{
    OSStatus err = noErr;
    
    if (inOutTimer == NULL)
    {
        debug0msg0("inOutTimer == NULL");
        err = -1;
    }
    else if (*inOutTimer == NULL)
    {
        EventLoopTimerUPP upp = NewEventLoopTimerUPP(inTimerProc);
        err = InstallEventLoopTimer(GetMainEventLoop(), 
                                    inFireDelay, inInterval, 
                                    upp, inOutUserData, inOutTimer);
        debug0msg("created new timer, ret code=%ld", err);
    }
    else
    {
        err = SetEventLoopTimerNextFireTime(*inOutTimer, inInterval);
        debug0msg("SetEventLoopTimerNextFireTime, ret code=%ld", err);
    }
    
    return err;
}
Ejemplo n.º 2
0
void MacOpTimer::Start(UINT32 ms)
{
	UnsignedWide ticks;
	Microseconds(&ticks);
	long long msecs = ticks.hi;
	msecs <<= 32;
	msecs |= ticks.lo;
	m_startTime = msecs / 1000;
	m_interval = ms;

	EventTimerInterval fireDelay = ms * kEventDurationMillisecond;

	if (m_timerRef)
	{
		SetEventLoopTimerNextFireTime(m_timerRef,fireDelay);
	}
	else
	{
		InstallEventLoopTimer(gMainEventLoop,//GetMainEventLoop(),
							 fireDelay,
							 kEventDurationNoWait,
							 timerUPP,
							 this,
							 &m_timerRef);
	}
}
Ejemplo n.º 3
0
static pascal void MyMovieIdlingTimer(EventLoopTimerRef inTimer, void *inUserData)
{
#pragma unused(inTimer)

    OSStatus error;
    long durationInMillis;
    MyStatePtr myState = (MyStatePtr)inUserData; // Application's state
    // related to its list of movies
    
    /* You insert the code here to idle the movies and/or movie controllers that the
    application has in use––for example, calls to MCIdle(). */
    IdleMovie();
    
    // Ask the idling mechanism when we should fire the next time.
#ifdef __APPLE_CC__
    error = QTGetTimeUntilNextTask(&durationInMillis, 1000);
#else
	error = mQTGetTimeUntilNextTaskPtr(&durationInMillis, 1000);
#endif
    // 1000 == millisecond timescale
    if (durationInMillis == 0) // When zero, pin the duration
    // to our minimum
        durationInMillis = kMinimumIdleDurationInMillis;
    // Reschedule the event loop timer
    SetEventLoopTimerNextFireTime(myState->theEventTimer, durationInMillis * kEventDurationMillisecond);
}
void myTMReset(
	myTMTaskPtr task)
{
	if (task->primed) {
		SetEventLoopTimerNextFireTime(task->task,
			task->time * kDurationMillisecond);
	}
	else
	{
		task->primed=true;
		InstallEventLoopTimer(GetMainEventLoop(),
			task->time * kEventDurationMillisecond,
			task->time * kEventDurationMillisecond,
			timer_upp,
			task,
			&task->task);
	}
}
Ejemplo n.º 5
0
static pascal void TaskNeededSoonerCallback(TimeValue duration, unsigned long flags, void *refcon)
{
#pragma unused(flags)
    SetEventLoopTimerNextFireTime((EventLoopTimerRef)refcon, duration * kEventDurationMillisecond);
}
Ejemplo n.º 6
0
int main(int  argc, char *argv[])
{
	AGLPixelFormat		format;		/* OpenGL pixel format */
	WindowPtr		window;		/* Window */
	int			winattrs;	/* Window attributes */
	Str255			title;		/* Title of window */
	Rect			rect;		/* Rectangle definition */
	EventHandlerUPP		handler;	/* Event handler */
	EventLoopTimerUPP	thandler;	/* Timer handler */
	EventLoopTimerRef	timer;		/* Timer for animating the window */
	ProcessSerialNumber	psn;		/* Process serial number */

	static EventTypeSpec	events[] =	/* Events we are interested in... */
			{
			  { kEventClassMouse, kEventMouseDown },
			  { kEventClassMouse, kEventMouseUp },
			  { kEventClassMouse, kEventMouseMoved },
			  { kEventClassMouse, kEventMouseDragged },
			  { kEventClassWindow, kEventWindowDrawContent },
			  { kEventClassWindow, kEventWindowShown },
			  { kEventClassWindow, kEventWindowHidden },
			  { kEventClassWindow, kEventWindowActivated },
			  { kEventClassWindow, kEventWindowDeactivated },
			  { kEventClassWindow, kEventWindowClose },
			  { kEventClassWindow, kEventWindowBoundsChanged },
			  { kCoreEventClass, kAEOpenApplication }
			};
	
	static GLint 		attributes[] =	/* OpenGL attributes */
			{
			  AGL_RGBA,
			  AGL_GREEN_SIZE, 1,
			  AGL_DOUBLEBUFFER,
			  AGL_DEPTH_SIZE, 16,
			  AGL_NONE
			};

	//Set initial values for window
	const int		        origWinHeight = 628;
	const int		        origWinWidth  = 850;
	const int		        origWinXOffset = 50;
	const int		        origWinYOffset = 50;


	// Create the window...

	aglContext = 0;
	WindowVisible = 0;

	SetRect(&rect, origWinXOffset, origWinYOffset, origWinWidth, origWinHeight);

	winattrs =	kWindowStandardHandlerAttribute | kWindowCloseBoxAttribute |
			kWindowCollapseBoxAttribute | kWindowFullZoomAttribute |
			kWindowResizableAttribute | kWindowLiveResizeAttribute;
	winattrs &= GetAvailableWindowAttributes(kDocumentWindowClass);

	strcpy((char *)(title + 1), "Rigid Body Dynamics");
	title[0] = strlen((char *)(title + 1));

	CreateNewWindow(kDocumentWindowClass, winattrs, &rect, &window);
	SetWTitle(window, title);

	handler = NewEventHandlerUPP(EventHandler);
	InstallWindowEventHandler(window, handler, sizeof(events) / sizeof(events[0]), events, NULL, 0L);
	thandler = NewEventLoopTimerUPP((void (*)(EventLoopTimerRef, void *))IdleFunc);
	InstallEventLoopTimer(GetMainEventLoop(), 0, 0, thandler, 0, &timer);

	GetCurrentProcess(&psn);
	SetFrontProcess(&psn);

	DrawGrowIcon(window);
	ShowWindow(window);

	// Create the OpenGL context and bind it to the window...
	format     = aglChoosePixelFormat(NULL, 0, attributes);
	aglContext = aglCreateContext(format, NULL);
	aglSetCurrentContext(aglContext);
	
	if (aglContext == NULL)
	{
		printf("Unable to create OpenGL context.\n");
		return 1;
	}

	aglDestroyPixelFormat(format);
	aglSetDrawable(aglContext, GetWindowPort(window));

	// Set the initial size of the cube
	altEngine.init((void *)&window, (void *)&aglContext);
	altEngine.resize(origWinWidth - origWinXOffset, origWinHeight - origWinYOffset);


	for (;;)
	{
		if (WindowVisible)
			SetEventLoopTimerNextFireTime(timer, 0.05);
	
		RunApplicationEventLoop();
	
		if (WindowVisible)
		{
			altEngine.step();
			//render frame, must pass a message to event handler
			altEngine.render();
		}
	}
}