Haptic Rendering and Provider Loop
The core logic of the Interhaptics Engine involves two main elements: haptic rendering and the device provider loop.
Haptic Rendering
Haptic rendering refers to the computation of haptic buffers during each iteration of the rendering loop, based on the game events. To trigger the rendering of haptic buffers, use the following Engine API call:
///
/// To be called in the application main loop to trigger the rendering of all haptic buffers
/// at a specific time. The Interhaptics Engine will compare the current time with the last
/// know value to build buffers large enough to cover frame drops.
/// Can be called from the main thread or in a parallel loop.
/// Must be called at least once before triggering the device update event.
///
/// Current time in seconds.
///
DLLExport void ComputeAllEvents(double _curTime);
It is important to call ComputeAllEvents() every iteration of the rendering loop, either in the main thread or a parallel thread. This ensures that haptic buffers are generated in real-time based on the subscribed Providers. If no device has subscribed, no buffer will be generated. Refer to the section Interhaptics Engine and Providers Initialization for information on device subscription.
Provider Loop
The provider loop is responsible for rendering the haptic buffers on the devices for playback. All provider implementations follow a common interface, exposing the following APIs:
extern "C"
{
DLLExport bool ProviderInit();
DLLExport bool ProviderIsPresent();
DLLExport bool ProviderClean();
DLLExport void ProviderRenderHaptics();
}
The ProviderRenderHaptics() API triggers the rendering process for the provider by retrieving the necessary haptic buffers, transcoding them if required, and playing them back on the associated device. This API must be called for all targeted devices.
It is mandatory to call ComputeAllEvents() from the Interhaptics Engine before calling ProviderRenderHaptics() for synchronized haptic rendering. Typically, both APIs are implemented in the same loop, with ComputeAllEvents() called before the ProviderRenderHaptics() calls.
Additionally, you can use ProviderIsPresent() to check the availability of the device before triggering haptic playback. This optional step can help improve performance.