[ Pobierz całość w formacie PDF ]
.The other one setsan interval timer that operates as an alarm clock.When the timer lapse expires, the applicationreceives control either in a message handler intercept or a dedicated callback function.Althoughboth methods are used often, processing based on reading the windows tick counter hasconsiderably better resolution than the alarm clock approach.Windows documentation states thatthe resolution of the timer intercepts is approximately 55 milliseconds.This produces a beat of18.2 times per second, which is precisely the default speed of the PC internal clock.In many casesthis beat is barely sufficient to produce smooth and lifelike animations.There are several ways to improve the frequency and reliability of the timed pulse.The multimediaextensions to Windows include a high-resolution timer with a reported resolution of 1 millisecond.Furthermore, the multimedia timer produces more accurate results because it does not rely onWM_TIMER messages posted on the queue.Each multimedia timer has its own thread, and thecallback function is invoked directly regardless of any pending messages.To use the multimedialibrary, code must include mmsystem.h and make sure that winmm.lib is available and referencedat link time.Several timer functions are found in the multimedia library.The most useful one inanimation programming is timeSetEvent().This function starts an event timer, which runs in itsown thread.A callback function, defined in the call to timeSetEvent(), receives control everytime the counter timer expires.The function's general form is as follows:MMRESULT timeSetEvent(UINT uDelay, // 1UINT uResolution, // 2LPTIMECALLBACK lpTimeProc, // 3DWORD dwUser, // 4UINT fuEvent // 5); The first parameter defines the event delay, in milliseconds.If this value is not in the timer's validrange, then the function returns an error.The second parameter is the resolution, in milliseconds,of the timer event.As the values get smaller, the resolution increases.A resolution of 0 indicatesthat timer events should occur with the greatest possible accuracy.Code can use the maximumappropriate value for the timer resolution to reduce system overhead.The third parameter is theaddress of the callback function that is called every time that the event delay counter expires.Thefourth parameter is a double word value passed by Windows to the callback procedure.The fifthparameter encodes the timer event type.This parameter consists of one or more predefinedconstants listed in Table 13-1.Table 13-1: Event-Type Constants in timeSetEvent() FunctionValue MeaningTIME_ONESHOTEvent occurs once, after uDelay milliseconds.TIME_PERIODICEvent occurs every uDelay milliseconds.TIME_CALLBACK_FUNCTIONWindows calls the function pointed to by thethird parameter.This is the default.TIME_CALLBACK_EVENT_SETWindows calls the SetEvent() function to setthe vent pointed to by the third parameter.Thefourth parameter is ignored.TIME_CALLBACK_EVENT_PULSEWindows calls the PulseEvent() function topulse the event pointed to by the thirdparameter.The fourth parameter is ignored.Notice that the multimedia timers support two different modes of operation.In one mode(TIME_ONESHOT) the timer event occurs only once.In the other mode (TIME_PERIODIC) thetimer event takes place every time that the timer counter expires.This mode is the one used inanimation routines.If successful, the call returns an identifier for the timer event.This identifier isalso passed to the callback function.When the timer is no longer needed, applications should callthe timeKillEvent() function to terminate it.Despite its high resolution, it has been documented that the multimedia timer can sufferconsiderable delays in Windows 95.One author states having recorded delays of up to 100milliseconds.Applications requiring very high timer accuracy are recommended to implement themultimedia timer in a 16-bit DLL. The WIN32 API first made available a high-resolution tick counter.These counters are sometimescalled performance monitors because they were originally intended for precisely measuring theperformance of coded routines.Using the high-performance monitors is similar to using theGetTickCount() function already described, but with a few special accommodations.TwoWindows functions are associated with performance monitor counters:QueryPerformanceFrequency() returns the resolution of the counter, which varies accordingto hardware.QueryPerformanceCounter() returns the number of timer ticks since the systemwas started.QueryPerformanceFrequency() can also be used to determine if high-performance counters are available in the hardware, although the presence of the performancemonitoring function can be assumed in any Windows 95, 98, or NT machine.The function prototypes are identical for QueryPerformanceFrequency() andQueryPerformanceCount(): the return type is of type BOOL and the only parameter is a 64-bitinteger of type LARGE_INTEGER.The general forms are as follows:BOOL QueryPerformanceCounter(LARGE_INTEGER*);BOOL QueryPerformanceFrequency(LARGE_INTEGER*);Although it has been stated that the performance frequency on Intel-based PCs is 0.8microseconds, it is safer for applications to call QueryPerformance_Frequency() to obtain thecorrect scaling factor.The following code fragment shows this processing:_int64 TIMER_DELAY = 15; // Milliseconds_int64 frequency; // Timer frequency.QueryPerformanceFrequency((LARGE_INTEGER*) &frequency);TIMER_DELAY = (TIMER_DELAY * frequency) / 1000;After executing, the TIMER_DELAY value has been scaled to the frequency of the high-resolutiontimer.The QueryPerformanceCounter() can now be called in the same manner asGetTickCount(), for example:_int64 lastTickCount;_int64 thisTickCount;.QueryPerformanceCounter((LARGE_INTEGER*) &thisTickCount);if((thisTickCount - lastTickCount) CreateDeviceFromClipper(lpDDClipper,NULL, // Default devicerc.right,rc.bottom,&globVars.aDevice);if (FAILED(retval)){// Display error message herereturn FALSE;}CreateObjects() functionThe function CreateObjects() in the 3DRM InWin Demo1 program in the book's CD-ROMperforms the processing operations discussed in this section.Following is a code listing of thisfunction [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • hanula1950.keep.pl