src/haptic/windows/SDL_dinputhaptic.c
author Ryan C. Gordon <icculus@icculus.org>
Mon, 21 May 2018 12:00:21 -0400
changeset 11994 8e094f91ddab
parent 11811 5d94cb6b24d3
child 12503 806492103856
permissions -rw-r--r--
thread: fixed compiler warnings on non-Linux systems that use pthread.

(static function rtkit_setpriority was unused, moved it in with rest of
__LINUX__ section.)
slouken@8972
     1
/*
slouken@8972
     2
  Simple DirectMedia Layer
slouken@11811
     3
  Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
slouken@8972
     4
slouken@8972
     5
  This software is provided 'as-is', without any express or implied
slouken@8972
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@8972
     7
  arising from the use of this software.
slouken@8972
     8
slouken@8972
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@8972
    10
  including commercial applications, and to alter it and redistribute it
slouken@8972
    11
  freely, subject to the following restrictions:
slouken@8972
    12
slouken@8972
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@8972
    14
     claim that you wrote the original software. If you use this software
slouken@8972
    15
     in a product, an acknowledgment in the product documentation would be
slouken@8972
    16
     appreciated but is not required.
slouken@8972
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@8972
    18
     misrepresented as being the original software.
slouken@8972
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@8972
    20
*/
slouken@8972
    21
#include "../../SDL_internal.h"
slouken@8972
    22
icculus@9661
    23
#include "SDL_error.h"
icculus@9661
    24
#include "SDL_haptic.h"
icculus@9662
    25
#include "../SDL_syshaptic.h"
icculus@9661
    26
icculus@9658
    27
#if SDL_HAPTIC_DINPUT
icculus@9658
    28
icculus@9147
    29
#include "SDL_stdinc.h"
slouken@8972
    30
#include "SDL_timer.h"
slouken@8972
    31
#include "SDL_windowshaptic_c.h"
slouken@8972
    32
#include "SDL_dinputhaptic_c.h"
slouken@8972
    33
#include "../../joystick/windows/SDL_windowsjoystick_c.h"
slouken@8972
    34
slouken@8972
    35
/*
slouken@8972
    36
 * External stuff.
slouken@8972
    37
 */
slouken@8972
    38
extern HWND SDL_HelperWindow;
slouken@8972
    39
slouken@8972
    40
slouken@8972
    41
/*
slouken@8972
    42
 * Internal stuff.
slouken@8972
    43
 */
slouken@8972
    44
static SDL_bool coinitialized = SDL_FALSE;
slouken@8972
    45
static LPDIRECTINPUT8 dinput = NULL;
slouken@8972
    46
slouken@8972
    47
slouken@8972
    48
/*
slouken@8972
    49
 * Like SDL_SetError but for DX error codes.
slouken@8972
    50
 */
slouken@8972
    51
static int
slouken@8972
    52
DI_SetError(const char *str, HRESULT err)
slouken@8972
    53
{
slouken@8972
    54
    /*
slouken@8972
    55
       SDL_SetError("Haptic: %s - %s: %s", str,
slouken@8972
    56
       DXGetErrorString8A(err), DXGetErrorDescription8A(err));
slouken@8972
    57
     */
slouken@8972
    58
    return SDL_SetError("Haptic error %s", str);
slouken@8972
    59
}
slouken@8972
    60
slouken@8972
    61
/*
slouken@8972
    62
 * Callback to find the haptic devices.
slouken@8972
    63
 */
slouken@8972
    64
static BOOL CALLBACK
slouken@8972
    65
EnumHapticsCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext)
slouken@8972
    66
{
slouken@8972
    67
    (void) pContext;
slouken@8972
    68
    SDL_DINPUT_MaybeAddDevice(pdidInstance);
slouken@8972
    69
    return DIENUM_CONTINUE;  /* continue enumerating */
slouken@8972
    70
}
slouken@8972
    71
slouken@8972
    72
int
slouken@8972
    73
SDL_DINPUT_HapticInit(void)
slouken@8972
    74
{
slouken@8972
    75
    HRESULT ret;
slouken@8972
    76
    HINSTANCE instance;
slouken@8972
    77
slouken@8972
    78
    if (dinput != NULL) {       /* Already open. */
slouken@8972
    79
        return SDL_SetError("Haptic: SubSystem already open.");
slouken@8972
    80
    }
slouken@8972
    81
slouken@8972
    82
    ret = WIN_CoInitialize();
slouken@8972
    83
    if (FAILED(ret)) {
slouken@8972
    84
        return DI_SetError("Coinitialize", ret);
slouken@8972
    85
    }
slouken@8972
    86
slouken@8972
    87
    coinitialized = SDL_TRUE;
slouken@8972
    88
slouken@8972
    89
    ret = CoCreateInstance(&CLSID_DirectInput8, NULL, CLSCTX_INPROC_SERVER,
slouken@8972
    90
        &IID_IDirectInput8, (LPVOID)& dinput);
slouken@8972
    91
    if (FAILED(ret)) {
slouken@8972
    92
        SDL_SYS_HapticQuit();
slouken@8972
    93
        return DI_SetError("CoCreateInstance", ret);
slouken@8972
    94
    }
slouken@8972
    95
slouken@8972
    96
    /* Because we used CoCreateInstance, we need to Initialize it, first. */
slouken@8972
    97
    instance = GetModuleHandle(NULL);
slouken@8972
    98
    if (instance == NULL) {
slouken@8972
    99
        SDL_SYS_HapticQuit();
slouken@8976
   100
        return SDL_SetError("GetModuleHandle() failed with error code %lu.",
slouken@8972
   101
            GetLastError());
slouken@8972
   102
    }
slouken@8972
   103
    ret = IDirectInput8_Initialize(dinput, instance, DIRECTINPUT_VERSION);
slouken@8972
   104
    if (FAILED(ret)) {
slouken@8972
   105
        SDL_SYS_HapticQuit();
slouken@8972
   106
        return DI_SetError("Initializing DirectInput device", ret);
slouken@8972
   107
    }
slouken@8972
   108
slouken@8972
   109
    /* Look for haptic devices. */
slouken@8972
   110
    ret = IDirectInput8_EnumDevices(dinput,
slouken@8972
   111
        0,
slouken@8972
   112
        EnumHapticsCallback,
slouken@8972
   113
        NULL,
slouken@8972
   114
        DIEDFL_FORCEFEEDBACK |
slouken@8972
   115
        DIEDFL_ATTACHEDONLY);
slouken@8972
   116
    if (FAILED(ret)) {
slouken@8972
   117
        SDL_SYS_HapticQuit();
slouken@8972
   118
        return DI_SetError("Enumerating DirectInput devices", ret);
slouken@8972
   119
    }
slouken@8972
   120
    return 0;
slouken@8972
   121
}
slouken@8972
   122
slouken@8972
   123
int
slouken@8972
   124
SDL_DINPUT_MaybeAddDevice(const DIDEVICEINSTANCE * pdidInstance)
slouken@8972
   125
{
slouken@8972
   126
    HRESULT ret;
slouken@8972
   127
    LPDIRECTINPUTDEVICE8 device;
slouken@8972
   128
    const DWORD needflags = DIDC_ATTACHED | DIDC_FORCEFEEDBACK;
slouken@8972
   129
    DIDEVCAPS capabilities;
slouken@8972
   130
    SDL_hapticlist_item *item = NULL;
slouken@8972
   131
slouken@8972
   132
    if (dinput == NULL) {
slouken@8972
   133
        return -1;  /* not initialized. We'll pick these up on enumeration if we init later. */
slouken@8972
   134
    }
slouken@8972
   135
slouken@8972
   136
    /* Make sure we don't already have it */
slouken@8972
   137
    for (item = SDL_hapticlist; item; item = item->next) {
slouken@8972
   138
        if ((!item->bXInputHaptic) && (SDL_memcmp(&item->instance, pdidInstance, sizeof(*pdidInstance)) == 0)) {
slouken@8972
   139
            return -1;  /* Already added */
slouken@8972
   140
        }
slouken@8972
   141
    }
slouken@8972
   142
slouken@8972
   143
    /* Open the device */
slouken@8972
   144
    ret = IDirectInput8_CreateDevice(dinput, &pdidInstance->guidInstance, &device, NULL);
slouken@8972
   145
    if (FAILED(ret)) {
slouken@8972
   146
        /* DI_SetError("Creating DirectInput device",ret); */
slouken@8972
   147
        return -1;
slouken@8972
   148
    }
slouken@8972
   149
slouken@8972
   150
    /* Get capabilities. */
slouken@8972
   151
    SDL_zero(capabilities);
slouken@8972
   152
    capabilities.dwSize = sizeof(DIDEVCAPS);
slouken@8972
   153
    ret = IDirectInputDevice8_GetCapabilities(device, &capabilities);
slouken@8972
   154
    IDirectInputDevice8_Release(device);
slouken@8972
   155
    if (FAILED(ret)) {
slouken@8972
   156
        /* DI_SetError("Getting device capabilities",ret); */
slouken@8972
   157
        return -1;
slouken@8972
   158
    }
slouken@8972
   159
slouken@8972
   160
    if ((capabilities.dwFlags & needflags) != needflags) {
slouken@8972
   161
        return -1;  /* not a device we can use. */
slouken@8972
   162
    }
slouken@8972
   163
slouken@8972
   164
    item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item));
slouken@8972
   165
    if (item == NULL) {
slouken@8972
   166
        return SDL_OutOfMemory();
slouken@8972
   167
    }
slouken@8972
   168
slouken@8972
   169
    item->name = WIN_StringToUTF8(pdidInstance->tszProductName);
slouken@8972
   170
    if (!item->name) {
slouken@8972
   171
        SDL_free(item);
slouken@8972
   172
        return -1;
slouken@8972
   173
    }
slouken@8972
   174
slouken@8972
   175
    /* Copy the instance over, useful for creating devices. */
slouken@8972
   176
    SDL_memcpy(&item->instance, pdidInstance, sizeof(DIDEVICEINSTANCE));
slouken@8972
   177
    SDL_memcpy(&item->capabilities, &capabilities, sizeof(capabilities));
slouken@8972
   178
slouken@8972
   179
    return SDL_SYS_AddHapticDevice(item);
slouken@8972
   180
}
slouken@8972
   181
slouken@8972
   182
int
slouken@8972
   183
SDL_DINPUT_MaybeRemoveDevice(const DIDEVICEINSTANCE * pdidInstance)
slouken@8972
   184
{
slouken@8972
   185
    SDL_hapticlist_item *item;
slouken@8972
   186
    SDL_hapticlist_item *prev = NULL;
slouken@8972
   187
slouken@8972
   188
    if (dinput == NULL) {
slouken@8972
   189
        return -1;  /* not initialized, ignore this. */
slouken@8972
   190
    }
slouken@8972
   191
slouken@8972
   192
    for (item = SDL_hapticlist; item != NULL; item = item->next) {
slouken@8972
   193
        if (!item->bXInputHaptic && SDL_memcmp(&item->instance, pdidInstance, sizeof(*pdidInstance)) == 0) {
slouken@8972
   194
            /* found it, remove it. */
slouken@8972
   195
            return SDL_SYS_RemoveHapticDevice(prev, item);
slouken@8972
   196
        }
slouken@8972
   197
        prev = item;
slouken@8972
   198
    }
slouken@8972
   199
    return -1;
slouken@8972
   200
}
slouken@8972
   201
slouken@8972
   202
/*
slouken@8972
   203
 * Callback to get supported axes.
slouken@8972
   204
 */
slouken@8972
   205
static BOOL CALLBACK
slouken@8972
   206
DI_DeviceObjectCallback(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID pvRef)
slouken@8972
   207
{
slouken@8972
   208
    SDL_Haptic *haptic = (SDL_Haptic *) pvRef;
slouken@8972
   209
slouken@8972
   210
    if ((dev->dwType & DIDFT_AXIS) && (dev->dwFlags & DIDOI_FFACTUATOR)) {
slouken@8972
   211
        const GUID *guid = &dev->guidType;
slouken@8972
   212
        DWORD offset = 0;
icculus@10885
   213
        if (WIN_IsEqualGUID(guid, &GUID_XAxis)) {
slouken@8972
   214
            offset = DIJOFS_X;
icculus@10885
   215
        } else if (WIN_IsEqualGUID(guid, &GUID_YAxis)) {
slouken@8972
   216
            offset = DIJOFS_Y;
icculus@10885
   217
        } else if (WIN_IsEqualGUID(guid, &GUID_ZAxis)) {
slouken@8972
   218
            offset = DIJOFS_Z;
icculus@10885
   219
        } else if (WIN_IsEqualGUID(guid, &GUID_RxAxis)) {
slouken@8972
   220
            offset = DIJOFS_RX;
icculus@10885
   221
        } else if (WIN_IsEqualGUID(guid, &GUID_RyAxis)) {
slouken@8972
   222
            offset = DIJOFS_RY;
icculus@10885
   223
        } else if (WIN_IsEqualGUID(guid, &GUID_RzAxis)) {
slouken@8972
   224
            offset = DIJOFS_RZ;
slouken@8972
   225
        } else {
slouken@8972
   226
            return DIENUM_CONTINUE;   /* can't use this, go on. */
slouken@8972
   227
        }
slouken@8972
   228
slouken@8972
   229
        haptic->hwdata->axes[haptic->naxes] = offset;
slouken@8972
   230
        haptic->naxes++;
slouken@8972
   231
slouken@8972
   232
        /* Currently using the artificial limit of 3 axes. */
slouken@8972
   233
        if (haptic->naxes >= 3) {
slouken@8972
   234
            return DIENUM_STOP;
slouken@8972
   235
        }
slouken@8972
   236
    }
slouken@8972
   237
slouken@8972
   238
    return DIENUM_CONTINUE;
slouken@8972
   239
}
slouken@8972
   240
slouken@8972
   241
/*
slouken@8972
   242
 * Callback to get all supported effects.
slouken@8972
   243
 */
slouken@8972
   244
#define EFFECT_TEST(e,s)               \
icculus@10885
   245
if (WIN_IsEqualGUID(&pei->guid, &(e)))   \
slouken@8972
   246
   haptic->supported |= (s)
slouken@8972
   247
static BOOL CALLBACK
slouken@8972
   248
DI_EffectCallback(LPCDIEFFECTINFO pei, LPVOID pv)
slouken@8972
   249
{
slouken@8972
   250
    /* Prepare the haptic device. */
slouken@8972
   251
    SDL_Haptic *haptic = (SDL_Haptic *) pv;
slouken@8972
   252
slouken@8972
   253
    /* Get supported. */
slouken@8972
   254
    EFFECT_TEST(GUID_Spring, SDL_HAPTIC_SPRING);
slouken@8972
   255
    EFFECT_TEST(GUID_Damper, SDL_HAPTIC_DAMPER);
slouken@8972
   256
    EFFECT_TEST(GUID_Inertia, SDL_HAPTIC_INERTIA);
slouken@8972
   257
    EFFECT_TEST(GUID_Friction, SDL_HAPTIC_FRICTION);
slouken@8972
   258
    EFFECT_TEST(GUID_ConstantForce, SDL_HAPTIC_CONSTANT);
slouken@8972
   259
    EFFECT_TEST(GUID_CustomForce, SDL_HAPTIC_CUSTOM);
slouken@8972
   260
    EFFECT_TEST(GUID_Sine, SDL_HAPTIC_SINE);
slouken@8972
   261
    /* !!! FIXME: put this back when we have more bits in 2.1 */
slouken@8972
   262
    /* EFFECT_TEST(GUID_Square, SDL_HAPTIC_SQUARE); */
slouken@8972
   263
    EFFECT_TEST(GUID_Triangle, SDL_HAPTIC_TRIANGLE);
slouken@8972
   264
    EFFECT_TEST(GUID_SawtoothUp, SDL_HAPTIC_SAWTOOTHUP);
slouken@8972
   265
    EFFECT_TEST(GUID_SawtoothDown, SDL_HAPTIC_SAWTOOTHDOWN);
slouken@8972
   266
    EFFECT_TEST(GUID_RampForce, SDL_HAPTIC_RAMP);
slouken@8972
   267
slouken@8972
   268
    /* Check for more. */
slouken@8972
   269
    return DIENUM_CONTINUE;
slouken@8972
   270
}
slouken@8972
   271
slouken@8972
   272
/*
slouken@8972
   273
 * Opens the haptic device.
slouken@8972
   274
 *
slouken@8972
   275
 *    Steps:
slouken@8972
   276
 *       - Set cooperative level.
slouken@8972
   277
 *       - Set data format.
slouken@8972
   278
 *       - Acquire exclusiveness.
slouken@8972
   279
 *       - Reset actuators.
slouken@8972
   280
 *       - Get supported features.
slouken@8972
   281
 */
slouken@8972
   282
static int
slouken@8972
   283
SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic * haptic, LPDIRECTINPUTDEVICE8 device8, SDL_bool is_joystick)
slouken@8972
   284
{
slouken@8972
   285
    HRESULT ret;
slouken@8972
   286
    DIPROPDWORD dipdw;
slouken@8972
   287
slouken@8972
   288
    /* Allocate the hwdata */
slouken@8972
   289
    haptic->hwdata = (struct haptic_hwdata *)SDL_malloc(sizeof(*haptic->hwdata));
slouken@8972
   290
    if (haptic->hwdata == NULL) {
slouken@8972
   291
        return SDL_OutOfMemory();
slouken@8972
   292
    }
slouken@8972
   293
    SDL_memset(haptic->hwdata, 0, sizeof(*haptic->hwdata));
slouken@8972
   294
slouken@8972
   295
    /* We'll use the device8 from now on. */
slouken@8972
   296
    haptic->hwdata->device = device8;
slouken@8972
   297
    haptic->hwdata->is_joystick = is_joystick;
slouken@8972
   298
slouken@8972
   299
    /* !!! FIXME: opening a haptic device here first will make an attempt to
slouken@8972
   300
       !!! FIXME:  SDL_JoystickOpen() that same device fail later, since we
slouken@8972
   301
       !!! FIXME:  have it open in exclusive mode. But this will allow
slouken@8972
   302
       !!! FIXME:  SDL_JoystickOpen() followed by SDL_HapticOpenFromJoystick()
slouken@8972
   303
       !!! FIXME:  to work, and that's probably the common case. Still,
slouken@8972
   304
       !!! FIXME:  ideally, We need to unify the opening code. */
slouken@8972
   305
slouken@8972
   306
    if (!is_joystick) {  /* if is_joystick, we already set this up elsewhere. */
slouken@8972
   307
        /* Grab it exclusively to use force feedback stuff. */
slouken@8972
   308
        ret = IDirectInputDevice8_SetCooperativeLevel(haptic->hwdata->device,
slouken@8972
   309
                                                      SDL_HelperWindow,
slouken@8972
   310
                                                      DISCL_EXCLUSIVE |
slouken@8972
   311
                                                      DISCL_BACKGROUND);
slouken@8972
   312
        if (FAILED(ret)) {
slouken@8972
   313
            DI_SetError("Setting cooperative level to exclusive", ret);
slouken@8972
   314
            goto acquire_err;
slouken@8972
   315
        }
slouken@8972
   316
slouken@8972
   317
        /* Set data format. */
slouken@8972
   318
        ret = IDirectInputDevice8_SetDataFormat(haptic->hwdata->device,
slouken@10442
   319
                                                &SDL_c_dfDIJoystick2);
slouken@8972
   320
        if (FAILED(ret)) {
slouken@8972
   321
            DI_SetError("Setting data format", ret);
slouken@8972
   322
            goto acquire_err;
slouken@8972
   323
        }
slouken@8972
   324
slouken@8972
   325
slouken@8972
   326
        /* Acquire the device. */
slouken@8972
   327
        ret = IDirectInputDevice8_Acquire(haptic->hwdata->device);
slouken@8972
   328
        if (FAILED(ret)) {
slouken@8972
   329
            DI_SetError("Acquiring DirectInput device", ret);
slouken@8972
   330
            goto acquire_err;
slouken@8972
   331
        }
slouken@8972
   332
    }
slouken@8972
   333
slouken@10463
   334
    /* Get number of axes. */
slouken@10463
   335
    ret = IDirectInputDevice8_EnumObjects(haptic->hwdata->device,
slouken@10463
   336
                                          DI_DeviceObjectCallback,
slouken@10463
   337
                                          haptic, DIDFT_AXIS);
slouken@10463
   338
    if (FAILED(ret)) {
slouken@10463
   339
        DI_SetError("Getting device axes", ret);
slouken@10463
   340
        goto acquire_err;
slouken@10463
   341
    }
slouken@10463
   342
slouken@8972
   343
    /* Reset all actuators - just in case. */
slouken@8972
   344
    ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device,
slouken@8972
   345
                                                       DISFFC_RESET);
slouken@8972
   346
    if (FAILED(ret)) {
slouken@8972
   347
        DI_SetError("Resetting device", ret);
slouken@8972
   348
        goto acquire_err;
slouken@8972
   349
    }
slouken@8972
   350
slouken@8972
   351
    /* Enabling actuators. */
slouken@8972
   352
    ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device,
slouken@8972
   353
                                                       DISFFC_SETACTUATORSON);
slouken@8972
   354
    if (FAILED(ret)) {
slouken@8972
   355
        DI_SetError("Enabling actuators", ret);
slouken@8972
   356
        goto acquire_err;
slouken@8972
   357
    }
slouken@8972
   358
slouken@8972
   359
    /* Get supported effects. */
slouken@8972
   360
    ret = IDirectInputDevice8_EnumEffects(haptic->hwdata->device,
slouken@8972
   361
                                          DI_EffectCallback, haptic,
slouken@8972
   362
                                          DIEFT_ALL);
slouken@8972
   363
    if (FAILED(ret)) {
slouken@8972
   364
        DI_SetError("Enumerating supported effects", ret);
slouken@8972
   365
        goto acquire_err;
slouken@8972
   366
    }
slouken@8972
   367
    if (haptic->supported == 0) {       /* Error since device supports nothing. */
slouken@8972
   368
        SDL_SetError("Haptic: Internal error on finding supported effects.");
slouken@8972
   369
        goto acquire_err;
slouken@8972
   370
    }
slouken@8972
   371
slouken@8972
   372
    /* Check autogain and autocenter. */
slouken@8972
   373
    dipdw.diph.dwSize = sizeof(DIPROPDWORD);
slouken@8972
   374
    dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
slouken@8972
   375
    dipdw.diph.dwObj = 0;
slouken@8972
   376
    dipdw.diph.dwHow = DIPH_DEVICE;
slouken@8972
   377
    dipdw.dwData = 10000;
slouken@8972
   378
    ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device,
slouken@8972
   379
                                          DIPROP_FFGAIN, &dipdw.diph);
slouken@8972
   380
    if (!FAILED(ret)) {         /* Gain is supported. */
slouken@8972
   381
        haptic->supported |= SDL_HAPTIC_GAIN;
slouken@8972
   382
    }
slouken@8972
   383
    dipdw.diph.dwObj = 0;
slouken@8972
   384
    dipdw.diph.dwHow = DIPH_DEVICE;
slouken@8972
   385
    dipdw.dwData = DIPROPAUTOCENTER_OFF;
slouken@8972
   386
    ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device,
slouken@8972
   387
                                          DIPROP_AUTOCENTER, &dipdw.diph);
slouken@8972
   388
    if (!FAILED(ret)) {         /* Autocenter is supported. */
slouken@8972
   389
        haptic->supported |= SDL_HAPTIC_AUTOCENTER;
slouken@8972
   390
    }
slouken@8972
   391
slouken@8972
   392
    /* Status is always supported. */
slouken@8972
   393
    haptic->supported |= SDL_HAPTIC_STATUS | SDL_HAPTIC_PAUSE;
slouken@8972
   394
slouken@8972
   395
    /* Check maximum effects. */
slouken@8972
   396
    haptic->neffects = 128;     /* This is not actually supported as thus under windows,
slouken@8972
   397
                                   there is no way to tell the number of EFFECTS that a
slouken@8972
   398
                                   device can hold, so we'll just use a "random" number
slouken@8972
   399
                                   instead and put warnings in SDL_haptic.h */
slouken@8972
   400
    haptic->nplaying = 128;     /* Even more impossible to get this then neffects. */
slouken@8972
   401
slouken@8972
   402
    /* Prepare effects memory. */
slouken@8972
   403
    haptic->effects = (struct haptic_effect *)
slouken@8972
   404
        SDL_malloc(sizeof(struct haptic_effect) * haptic->neffects);
slouken@8972
   405
    if (haptic->effects == NULL) {
slouken@8972
   406
        SDL_OutOfMemory();
slouken@8972
   407
        goto acquire_err;
slouken@8972
   408
    }
slouken@8972
   409
    /* Clear the memory */
slouken@8972
   410
    SDL_memset(haptic->effects, 0,
slouken@8972
   411
               sizeof(struct haptic_effect) * haptic->neffects);
slouken@8972
   412
slouken@8972
   413
    return 0;
slouken@8972
   414
slouken@8972
   415
    /* Error handling */
slouken@8972
   416
  acquire_err:
slouken@8972
   417
    IDirectInputDevice8_Unacquire(haptic->hwdata->device);
slouken@8972
   418
    return -1;
slouken@8972
   419
}
slouken@8972
   420
slouken@8972
   421
int
slouken@8972
   422
SDL_DINPUT_HapticOpen(SDL_Haptic * haptic, SDL_hapticlist_item *item)
slouken@8972
   423
{
slouken@8972
   424
    HRESULT ret;
slouken@8972
   425
    LPDIRECTINPUTDEVICE8 device;
slouken@8972
   426
    LPDIRECTINPUTDEVICE8 device8;
slouken@8972
   427
slouken@8972
   428
    /* Open the device */
slouken@8972
   429
    ret = IDirectInput8_CreateDevice(dinput, &item->instance.guidInstance,
slouken@8972
   430
        &device, NULL);
slouken@8972
   431
    if (FAILED(ret)) {
slouken@8972
   432
        DI_SetError("Creating DirectInput device", ret);
slouken@8972
   433
        return -1;
slouken@8972
   434
    }
slouken@8972
   435
slouken@8972
   436
    /* Now get the IDirectInputDevice8 interface, instead. */
slouken@8972
   437
    ret = IDirectInputDevice8_QueryInterface(device,
slouken@8972
   438
        &IID_IDirectInputDevice8,
slouken@8972
   439
        (LPVOID *)&device8);
slouken@8972
   440
    /* Done with the temporary one now. */
slouken@8972
   441
    IDirectInputDevice8_Release(device);
slouken@8972
   442
    if (FAILED(ret)) {
slouken@8972
   443
        DI_SetError("Querying DirectInput interface", ret);
slouken@8972
   444
        return -1;
slouken@8972
   445
    }
slouken@8972
   446
slouken@8972
   447
    if (SDL_DINPUT_HapticOpenFromDevice(haptic, device8, SDL_FALSE) < 0) {
slouken@8972
   448
        IDirectInputDevice8_Release(device8);
slouken@8972
   449
        return -1;
slouken@8972
   450
    }
slouken@8972
   451
    return 0;
slouken@8972
   452
}
slouken@8972
   453
slouken@8972
   454
int
slouken@8972
   455
SDL_DINPUT_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
slouken@8972
   456
{
slouken@8972
   457
    HRESULT ret;
slouken@8972
   458
    DIDEVICEINSTANCE hap_instance, joy_instance;
slouken@8972
   459
slouken@8972
   460
    hap_instance.dwSize = sizeof(DIDEVICEINSTANCE);
slouken@8972
   461
    joy_instance.dwSize = sizeof(DIDEVICEINSTANCE);
slouken@8972
   462
slouken@8972
   463
    /* Get the device instances. */
slouken@8972
   464
    ret = IDirectInputDevice8_GetDeviceInfo(haptic->hwdata->device,
slouken@8972
   465
        &hap_instance);
slouken@8972
   466
    if (FAILED(ret)) {
slouken@8972
   467
        return 0;
slouken@8972
   468
    }
slouken@8972
   469
    ret = IDirectInputDevice8_GetDeviceInfo(joystick->hwdata->InputDevice,
slouken@8972
   470
        &joy_instance);
slouken@8972
   471
    if (FAILED(ret)) {
slouken@8972
   472
        return 0;
slouken@8972
   473
    }
slouken@8972
   474
icculus@10885
   475
    return WIN_IsEqualGUID(&hap_instance.guidInstance, &joy_instance.guidInstance);
slouken@8972
   476
}
slouken@8972
   477
slouken@8972
   478
int
slouken@8972
   479
SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
slouken@8972
   480
{
slouken@8972
   481
    SDL_hapticlist_item *item;
slouken@8972
   482
    int index = 0;
slouken@8972
   483
    HRESULT ret;
slouken@8972
   484
    DIDEVICEINSTANCE joy_instance;
slouken@8972
   485
slouken@8972
   486
    joy_instance.dwSize = sizeof(DIDEVICEINSTANCE);
slouken@8972
   487
    ret = IDirectInputDevice8_GetDeviceInfo(joystick->hwdata->InputDevice, &joy_instance);
slouken@8972
   488
    if (FAILED(ret)) {
slouken@8972
   489
        return -1;
slouken@8972
   490
    }
slouken@8972
   491
slouken@8972
   492
    /* Since it comes from a joystick we have to try to match it with a haptic device on our haptic list. */
slouken@8972
   493
    for (item = SDL_hapticlist; item != NULL; item = item->next) {
icculus@10885
   494
        if (!item->bXInputHaptic && WIN_IsEqualGUID(&item->instance.guidInstance, &joy_instance.guidInstance)) {
slouken@8972
   495
            haptic->index = index;
slouken@8972
   496
            return SDL_DINPUT_HapticOpenFromDevice(haptic, joystick->hwdata->InputDevice, SDL_TRUE);
slouken@8972
   497
        }
slouken@8972
   498
        ++index;
slouken@8972
   499
    }
slouken@8972
   500
slouken@8972
   501
    SDL_SetError("Couldn't find joystick in haptic device list");
slouken@8972
   502
    return -1;
slouken@8972
   503
}
slouken@8972
   504
slouken@8972
   505
void
slouken@8972
   506
SDL_DINPUT_HapticClose(SDL_Haptic * haptic)
slouken@8972
   507
{
slouken@8972
   508
    IDirectInputDevice8_Unacquire(haptic->hwdata->device);
slouken@8972
   509
slouken@8972
   510
    /* Only release if isn't grabbed by a joystick. */
slouken@8972
   511
    if (haptic->hwdata->is_joystick == 0) {
slouken@8972
   512
        IDirectInputDevice8_Release(haptic->hwdata->device);
slouken@8972
   513
    }
slouken@8972
   514
}
slouken@8972
   515
slouken@8972
   516
void
slouken@8972
   517
SDL_DINPUT_HapticQuit(void)
slouken@8972
   518
{
slouken@8972
   519
    if (dinput != NULL) {
slouken@8972
   520
        IDirectInput8_Release(dinput);
slouken@8972
   521
        dinput = NULL;
slouken@8972
   522
    }
slouken@8972
   523
slouken@8972
   524
    if (coinitialized) {
slouken@8972
   525
        WIN_CoUninitialize();
slouken@8972
   526
        coinitialized = SDL_FALSE;
slouken@8972
   527
    }
slouken@8972
   528
}
slouken@8972
   529
slouken@8972
   530
/*
slouken@8972
   531
 * Converts an SDL trigger button to an DIEFFECT trigger button.
slouken@8972
   532
 */
slouken@8972
   533
static DWORD
slouken@8972
   534
DIGetTriggerButton(Uint16 button)
slouken@8972
   535
{
slouken@8972
   536
    DWORD dwTriggerButton;
slouken@8972
   537
slouken@8972
   538
    dwTriggerButton = DIEB_NOTRIGGER;
slouken@8972
   539
slouken@8972
   540
    if (button != 0) {
slouken@8972
   541
        dwTriggerButton = DIJOFS_BUTTON(button - 1);
slouken@8972
   542
    }
slouken@8972
   543
slouken@8972
   544
    return dwTriggerButton;
slouken@8972
   545
}
slouken@8972
   546
slouken@8972
   547
slouken@8972
   548
/*
slouken@8972
   549
 * Sets the direction.
slouken@8972
   550
 */
slouken@8972
   551
static int
slouken@8972
   552
SDL_SYS_SetDirection(DIEFFECT * effect, SDL_HapticDirection * dir, int naxes)
slouken@8972
   553
{
slouken@8972
   554
    LONG *rglDir;
slouken@8972
   555
slouken@8972
   556
    /* Handle no axes a part. */
slouken@8972
   557
    if (naxes == 0) {
slouken@8972
   558
        effect->dwFlags |= DIEFF_SPHERICAL;     /* Set as default. */
slouken@8972
   559
        effect->rglDirection = NULL;
slouken@8972
   560
        return 0;
slouken@8972
   561
    }
slouken@8972
   562
slouken@8972
   563
    /* Has axes. */
slouken@8972
   564
    rglDir = SDL_malloc(sizeof(LONG) * naxes);
slouken@8972
   565
    if (rglDir == NULL) {
slouken@8972
   566
        return SDL_OutOfMemory();
slouken@8972
   567
    }
slouken@8972
   568
    SDL_memset(rglDir, 0, sizeof(LONG) * naxes);
slouken@8972
   569
    effect->rglDirection = rglDir;
slouken@8972
   570
slouken@8972
   571
    switch (dir->type) {
slouken@8972
   572
    case SDL_HAPTIC_POLAR:
slouken@8972
   573
        effect->dwFlags |= DIEFF_POLAR;
slouken@8972
   574
        rglDir[0] = dir->dir[0];
slouken@8972
   575
        return 0;
slouken@8972
   576
    case SDL_HAPTIC_CARTESIAN:
slouken@8972
   577
        effect->dwFlags |= DIEFF_CARTESIAN;
slouken@8972
   578
        rglDir[0] = dir->dir[0];
slouken@8972
   579
        if (naxes > 1)
slouken@8972
   580
            rglDir[1] = dir->dir[1];
slouken@8972
   581
        if (naxes > 2)
slouken@8972
   582
            rglDir[2] = dir->dir[2];
slouken@8972
   583
        return 0;
slouken@8972
   584
    case SDL_HAPTIC_SPHERICAL:
slouken@8972
   585
        effect->dwFlags |= DIEFF_SPHERICAL;
slouken@8972
   586
        rglDir[0] = dir->dir[0];
slouken@8972
   587
        if (naxes > 1)
slouken@8972
   588
            rglDir[1] = dir->dir[1];
slouken@8972
   589
        if (naxes > 2)
slouken@8972
   590
            rglDir[2] = dir->dir[2];
slouken@8972
   591
        return 0;
slouken@8972
   592
slouken@8972
   593
    default:
slouken@8972
   594
        return SDL_SetError("Haptic: Unknown direction type.");
slouken@8972
   595
    }
slouken@8972
   596
}
slouken@8972
   597
icculus@9071
   598
/* Clamps and converts. */
icculus@9071
   599
#define CCONVERT(x)   (((x) > 0x7FFF) ? 10000 : ((x)*10000) / 0x7FFF)
icculus@9071
   600
/* Just converts. */
icculus@9071
   601
#define CONVERT(x)    (((x)*10000) / 0x7FFF)
slouken@8972
   602
/*
slouken@8972
   603
 * Creates the DIEFFECT from a SDL_HapticEffect.
slouken@8972
   604
 */
slouken@8972
   605
static int
slouken@8972
   606
SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
slouken@8972
   607
                   SDL_HapticEffect * src)
slouken@8972
   608
{
slouken@8972
   609
    int i;
slouken@8972
   610
    DICONSTANTFORCE *constant;
slouken@8972
   611
    DIPERIODIC *periodic;
slouken@8972
   612
    DICONDITION *condition;     /* Actually an array of conditions - one per axis. */
slouken@8972
   613
    DIRAMPFORCE *ramp;
slouken@8972
   614
    DICUSTOMFORCE *custom;
slouken@8972
   615
    DIENVELOPE *envelope;
slouken@8972
   616
    SDL_HapticConstant *hap_constant;
slouken@8972
   617
    SDL_HapticPeriodic *hap_periodic;
slouken@8972
   618
    SDL_HapticCondition *hap_condition;
slouken@8972
   619
    SDL_HapticRamp *hap_ramp;
slouken@8972
   620
    SDL_HapticCustom *hap_custom;
slouken@8972
   621
    DWORD *axes;
slouken@8972
   622
slouken@8972
   623
    /* Set global stuff. */
slouken@8972
   624
    SDL_memset(dest, 0, sizeof(DIEFFECT));
slouken@8972
   625
    dest->dwSize = sizeof(DIEFFECT);    /* Set the structure size. */
slouken@8972
   626
    dest->dwSamplePeriod = 0;   /* Not used by us. */
slouken@8972
   627
    dest->dwGain = 10000;       /* Gain is set globally, not locally. */
slouken@8972
   628
    dest->dwFlags = DIEFF_OBJECTOFFSETS;        /* Seems obligatory. */
slouken@8972
   629
slouken@8972
   630
    /* Envelope. */
slouken@8972
   631
    envelope = SDL_malloc(sizeof(DIENVELOPE));
slouken@8972
   632
    if (envelope == NULL) {
slouken@8972
   633
        return SDL_OutOfMemory();
slouken@8972
   634
    }
slouken@8972
   635
    SDL_memset(envelope, 0, sizeof(DIENVELOPE));
slouken@8972
   636
    dest->lpEnvelope = envelope;
slouken@8972
   637
    envelope->dwSize = sizeof(DIENVELOPE);      /* Always should be this. */
slouken@8972
   638
slouken@8972
   639
    /* Axes. */
slouken@8972
   640
    dest->cAxes = haptic->naxes;
slouken@8972
   641
    if (dest->cAxes > 0) {
slouken@8972
   642
        axes = SDL_malloc(sizeof(DWORD) * dest->cAxes);
slouken@8972
   643
        if (axes == NULL) {
slouken@8972
   644
            return SDL_OutOfMemory();
slouken@8972
   645
        }
slouken@8972
   646
        axes[0] = haptic->hwdata->axes[0];      /* Always at least one axis. */
slouken@8972
   647
        if (dest->cAxes > 1) {
slouken@8972
   648
            axes[1] = haptic->hwdata->axes[1];
slouken@8972
   649
        }
slouken@8972
   650
        if (dest->cAxes > 2) {
slouken@8972
   651
            axes[2] = haptic->hwdata->axes[2];
slouken@8972
   652
        }
slouken@8972
   653
        dest->rgdwAxes = axes;
slouken@8972
   654
    }
slouken@8972
   655
slouken@8972
   656
    /* The big type handling switch, even bigger than Linux's version. */
slouken@8972
   657
    switch (src->type) {
slouken@8972
   658
    case SDL_HAPTIC_CONSTANT:
slouken@8972
   659
        hap_constant = &src->constant;
slouken@8972
   660
        constant = SDL_malloc(sizeof(DICONSTANTFORCE));
slouken@8972
   661
        if (constant == NULL) {
slouken@8972
   662
            return SDL_OutOfMemory();
slouken@8972
   663
        }
slouken@8972
   664
        SDL_memset(constant, 0, sizeof(DICONSTANTFORCE));
slouken@8972
   665
slouken@8972
   666
        /* Specifics */
slouken@8972
   667
        constant->lMagnitude = CONVERT(hap_constant->level);
slouken@8972
   668
        dest->cbTypeSpecificParams = sizeof(DICONSTANTFORCE);
slouken@8972
   669
        dest->lpvTypeSpecificParams = constant;
slouken@8972
   670
slouken@8972
   671
        /* Generics */
slouken@8972
   672
        dest->dwDuration = hap_constant->length * 1000; /* In microseconds. */
slouken@8972
   673
        dest->dwTriggerButton = DIGetTriggerButton(hap_constant->button);
slouken@8972
   674
        dest->dwTriggerRepeatInterval = hap_constant->interval;
slouken@8972
   675
        dest->dwStartDelay = hap_constant->delay * 1000;        /* In microseconds. */
slouken@8972
   676
slouken@8972
   677
        /* Direction. */
slouken@8972
   678
        if (SDL_SYS_SetDirection(dest, &hap_constant->direction, dest->cAxes) < 0) {
slouken@8972
   679
            return -1;
slouken@8972
   680
        }
slouken@8972
   681
slouken@8972
   682
        /* Envelope */
slouken@8972
   683
        if ((hap_constant->attack_length == 0)
slouken@8972
   684
            && (hap_constant->fade_length == 0)) {
slouken@8972
   685
            SDL_free(dest->lpEnvelope);
slouken@8972
   686
            dest->lpEnvelope = NULL;
slouken@8972
   687
        } else {
icculus@9071
   688
            envelope->dwAttackLevel = CCONVERT(hap_constant->attack_level);
slouken@8972
   689
            envelope->dwAttackTime = hap_constant->attack_length * 1000;
icculus@9071
   690
            envelope->dwFadeLevel = CCONVERT(hap_constant->fade_level);
slouken@8972
   691
            envelope->dwFadeTime = hap_constant->fade_length * 1000;
slouken@8972
   692
        }
slouken@8972
   693
slouken@8972
   694
        break;
slouken@8972
   695
slouken@8972
   696
    case SDL_HAPTIC_SINE:
slouken@8972
   697
    /* !!! FIXME: put this back when we have more bits in 2.1 */
slouken@8972
   698
    /* case SDL_HAPTIC_SQUARE: */
slouken@8972
   699
    case SDL_HAPTIC_TRIANGLE:
slouken@8972
   700
    case SDL_HAPTIC_SAWTOOTHUP:
slouken@8972
   701
    case SDL_HAPTIC_SAWTOOTHDOWN:
slouken@8972
   702
        hap_periodic = &src->periodic;
slouken@8972
   703
        periodic = SDL_malloc(sizeof(DIPERIODIC));
slouken@8972
   704
        if (periodic == NULL) {
slouken@8972
   705
            return SDL_OutOfMemory();
slouken@8972
   706
        }
slouken@8972
   707
        SDL_memset(periodic, 0, sizeof(DIPERIODIC));
slouken@8972
   708
slouken@8972
   709
        /* Specifics */
icculus@9147
   710
        periodic->dwMagnitude = CONVERT(SDL_abs(hap_periodic->magnitude));
slouken@8972
   711
        periodic->lOffset = CONVERT(hap_periodic->offset);
icculus@9147
   712
        periodic->dwPhase = 
icculus@9147
   713
                (hap_periodic->phase + (hap_periodic->magnitude < 0 ? 18000 : 0)) % 36000;
slouken@8972
   714
        periodic->dwPeriod = hap_periodic->period * 1000;
slouken@8972
   715
        dest->cbTypeSpecificParams = sizeof(DIPERIODIC);
slouken@8972
   716
        dest->lpvTypeSpecificParams = periodic;
slouken@8972
   717
slouken@8972
   718
        /* Generics */
slouken@8972
   719
        dest->dwDuration = hap_periodic->length * 1000; /* In microseconds. */
slouken@8972
   720
        dest->dwTriggerButton = DIGetTriggerButton(hap_periodic->button);
slouken@8972
   721
        dest->dwTriggerRepeatInterval = hap_periodic->interval;
slouken@8972
   722
        dest->dwStartDelay = hap_periodic->delay * 1000;        /* In microseconds. */
slouken@8972
   723
slouken@8972
   724
        /* Direction. */
slouken@8972
   725
        if (SDL_SYS_SetDirection(dest, &hap_periodic->direction, dest->cAxes)
slouken@8972
   726
            < 0) {
slouken@8972
   727
            return -1;
slouken@8972
   728
        }
slouken@8972
   729
slouken@8972
   730
        /* Envelope */
slouken@8972
   731
        if ((hap_periodic->attack_length == 0)
slouken@8972
   732
            && (hap_periodic->fade_length == 0)) {
slouken@8972
   733
            SDL_free(dest->lpEnvelope);
slouken@8972
   734
            dest->lpEnvelope = NULL;
slouken@8972
   735
        } else {
icculus@9071
   736
            envelope->dwAttackLevel = CCONVERT(hap_periodic->attack_level);
slouken@8972
   737
            envelope->dwAttackTime = hap_periodic->attack_length * 1000;
icculus@9071
   738
            envelope->dwFadeLevel = CCONVERT(hap_periodic->fade_level);
slouken@8972
   739
            envelope->dwFadeTime = hap_periodic->fade_length * 1000;
slouken@8972
   740
        }
slouken@8972
   741
slouken@8972
   742
        break;
slouken@8972
   743
slouken@8972
   744
    case SDL_HAPTIC_SPRING:
slouken@8972
   745
    case SDL_HAPTIC_DAMPER:
slouken@8972
   746
    case SDL_HAPTIC_INERTIA:
slouken@8972
   747
    case SDL_HAPTIC_FRICTION:
slouken@8972
   748
        hap_condition = &src->condition;
slouken@8972
   749
        condition = SDL_malloc(sizeof(DICONDITION) * dest->cAxes);
slouken@8972
   750
        if (condition == NULL) {
slouken@8972
   751
            return SDL_OutOfMemory();
slouken@8972
   752
        }
slouken@8972
   753
        SDL_memset(condition, 0, sizeof(DICONDITION));
slouken@8972
   754
slouken@8972
   755
        /* Specifics */
slouken@8972
   756
        for (i = 0; i < (int) dest->cAxes; i++) {
slouken@8972
   757
            condition[i].lOffset = CONVERT(hap_condition->center[i]);
slouken@8972
   758
            condition[i].lPositiveCoefficient =
slouken@8972
   759
                CONVERT(hap_condition->right_coeff[i]);
slouken@8972
   760
            condition[i].lNegativeCoefficient =
slouken@8972
   761
                CONVERT(hap_condition->left_coeff[i]);
slouken@8972
   762
            condition[i].dwPositiveSaturation =
icculus@9071
   763
                CCONVERT(hap_condition->right_sat[i] / 2);
slouken@8972
   764
            condition[i].dwNegativeSaturation =
icculus@9071
   765
                CCONVERT(hap_condition->left_sat[i] / 2);
icculus@9071
   766
            condition[i].lDeadBand = CCONVERT(hap_condition->deadband[i] / 2);
slouken@8972
   767
        }
slouken@8972
   768
        dest->cbTypeSpecificParams = sizeof(DICONDITION) * dest->cAxes;
slouken@8972
   769
        dest->lpvTypeSpecificParams = condition;
slouken@8972
   770
slouken@8972
   771
        /* Generics */
slouken@8972
   772
        dest->dwDuration = hap_condition->length * 1000;        /* In microseconds. */
slouken@8972
   773
        dest->dwTriggerButton = DIGetTriggerButton(hap_condition->button);
slouken@8972
   774
        dest->dwTriggerRepeatInterval = hap_condition->interval;
slouken@8972
   775
        dest->dwStartDelay = hap_condition->delay * 1000;       /* In microseconds. */
slouken@8972
   776
slouken@8972
   777
        /* Direction. */
slouken@8972
   778
        if (SDL_SYS_SetDirection(dest, &hap_condition->direction, dest->cAxes)
slouken@8972
   779
            < 0) {
slouken@8972
   780
            return -1;
slouken@8972
   781
        }
slouken@8972
   782
slouken@8972
   783
        /* Envelope - Not actually supported by most CONDITION implementations. */
slouken@8972
   784
        SDL_free(dest->lpEnvelope);
slouken@8972
   785
        dest->lpEnvelope = NULL;
slouken@8972
   786
slouken@8972
   787
        break;
slouken@8972
   788
slouken@8972
   789
    case SDL_HAPTIC_RAMP:
slouken@8972
   790
        hap_ramp = &src->ramp;
slouken@8972
   791
        ramp = SDL_malloc(sizeof(DIRAMPFORCE));
slouken@8972
   792
        if (ramp == NULL) {
slouken@8972
   793
            return SDL_OutOfMemory();
slouken@8972
   794
        }
slouken@8972
   795
        SDL_memset(ramp, 0, sizeof(DIRAMPFORCE));
slouken@8972
   796
slouken@8972
   797
        /* Specifics */
slouken@8972
   798
        ramp->lStart = CONVERT(hap_ramp->start);
slouken@8972
   799
        ramp->lEnd = CONVERT(hap_ramp->end);
slouken@8972
   800
        dest->cbTypeSpecificParams = sizeof(DIRAMPFORCE);
slouken@8972
   801
        dest->lpvTypeSpecificParams = ramp;
slouken@8972
   802
slouken@8972
   803
        /* Generics */
slouken@8972
   804
        dest->dwDuration = hap_ramp->length * 1000;     /* In microseconds. */
slouken@8972
   805
        dest->dwTriggerButton = DIGetTriggerButton(hap_ramp->button);
slouken@8972
   806
        dest->dwTriggerRepeatInterval = hap_ramp->interval;
slouken@8972
   807
        dest->dwStartDelay = hap_ramp->delay * 1000;    /* In microseconds. */
slouken@8972
   808
slouken@8972
   809
        /* Direction. */
slouken@8972
   810
        if (SDL_SYS_SetDirection(dest, &hap_ramp->direction, dest->cAxes) < 0) {
slouken@8972
   811
            return -1;
slouken@8972
   812
        }
slouken@8972
   813
slouken@8972
   814
        /* Envelope */
slouken@8972
   815
        if ((hap_ramp->attack_length == 0) && (hap_ramp->fade_length == 0)) {
slouken@8972
   816
            SDL_free(dest->lpEnvelope);
slouken@8972
   817
            dest->lpEnvelope = NULL;
slouken@8972
   818
        } else {
icculus@9071
   819
            envelope->dwAttackLevel = CCONVERT(hap_ramp->attack_level);
slouken@8972
   820
            envelope->dwAttackTime = hap_ramp->attack_length * 1000;
icculus@9071
   821
            envelope->dwFadeLevel = CCONVERT(hap_ramp->fade_level);
slouken@8972
   822
            envelope->dwFadeTime = hap_ramp->fade_length * 1000;
slouken@8972
   823
        }
slouken@8972
   824
slouken@8972
   825
        break;
slouken@8972
   826
slouken@8972
   827
    case SDL_HAPTIC_CUSTOM:
slouken@8972
   828
        hap_custom = &src->custom;
slouken@8972
   829
        custom = SDL_malloc(sizeof(DICUSTOMFORCE));
slouken@8972
   830
        if (custom == NULL) {
slouken@8972
   831
            return SDL_OutOfMemory();
slouken@8972
   832
        }
slouken@8972
   833
        SDL_memset(custom, 0, sizeof(DICUSTOMFORCE));
slouken@8972
   834
slouken@8972
   835
        /* Specifics */
slouken@8972
   836
        custom->cChannels = hap_custom->channels;
slouken@8972
   837
        custom->dwSamplePeriod = hap_custom->period * 1000;
slouken@8972
   838
        custom->cSamples = hap_custom->samples;
slouken@8972
   839
        custom->rglForceData =
slouken@8972
   840
            SDL_malloc(sizeof(LONG) * custom->cSamples * custom->cChannels);
slouken@8972
   841
        for (i = 0; i < hap_custom->samples * hap_custom->channels; i++) {      /* Copy data. */
icculus@9071
   842
            custom->rglForceData[i] = CCONVERT(hap_custom->data[i]);
slouken@8972
   843
        }
slouken@8972
   844
        dest->cbTypeSpecificParams = sizeof(DICUSTOMFORCE);
slouken@8972
   845
        dest->lpvTypeSpecificParams = custom;
slouken@8972
   846
slouken@8972
   847
        /* Generics */
slouken@8972
   848
        dest->dwDuration = hap_custom->length * 1000;   /* In microseconds. */
slouken@8972
   849
        dest->dwTriggerButton = DIGetTriggerButton(hap_custom->button);
slouken@8972
   850
        dest->dwTriggerRepeatInterval = hap_custom->interval;
slouken@8972
   851
        dest->dwStartDelay = hap_custom->delay * 1000;  /* In microseconds. */
slouken@8972
   852
slouken@8972
   853
        /* Direction. */
slouken@8972
   854
        if (SDL_SYS_SetDirection(dest, &hap_custom->direction, dest->cAxes) < 0) {
slouken@8972
   855
            return -1;
slouken@8972
   856
        }
slouken@8972
   857
slouken@8972
   858
        /* Envelope */
slouken@8972
   859
        if ((hap_custom->attack_length == 0)
slouken@8972
   860
            && (hap_custom->fade_length == 0)) {
slouken@8972
   861
            SDL_free(dest->lpEnvelope);
slouken@8972
   862
            dest->lpEnvelope = NULL;
slouken@8972
   863
        } else {
icculus@9071
   864
            envelope->dwAttackLevel = CCONVERT(hap_custom->attack_level);
slouken@8972
   865
            envelope->dwAttackTime = hap_custom->attack_length * 1000;
icculus@9071
   866
            envelope->dwFadeLevel = CCONVERT(hap_custom->fade_level);
slouken@8972
   867
            envelope->dwFadeTime = hap_custom->fade_length * 1000;
slouken@8972
   868
        }
slouken@8972
   869
slouken@8972
   870
        break;
slouken@8972
   871
slouken@8972
   872
    default:
slouken@8972
   873
        return SDL_SetError("Haptic: Unknown effect type.");
slouken@8972
   874
    }
slouken@8972
   875
slouken@8972
   876
    return 0;
slouken@8972
   877
}
slouken@8972
   878
slouken@8972
   879
slouken@8972
   880
/*
slouken@8972
   881
 * Frees an DIEFFECT allocated by SDL_SYS_ToDIEFFECT.
slouken@8972
   882
 */
slouken@8972
   883
static void
slouken@8972
   884
SDL_SYS_HapticFreeDIEFFECT(DIEFFECT * effect, int type)
slouken@8972
   885
{
slouken@8972
   886
    DICUSTOMFORCE *custom;
slouken@8972
   887
slouken@8972
   888
    SDL_free(effect->lpEnvelope);
slouken@8972
   889
    effect->lpEnvelope = NULL;
slouken@8972
   890
    SDL_free(effect->rgdwAxes);
slouken@8972
   891
    effect->rgdwAxes = NULL;
slouken@8972
   892
    if (effect->lpvTypeSpecificParams != NULL) {
slouken@8972
   893
        if (type == SDL_HAPTIC_CUSTOM) {        /* Must free the custom data. */
slouken@8972
   894
            custom = (DICUSTOMFORCE *) effect->lpvTypeSpecificParams;
slouken@8972
   895
            SDL_free(custom->rglForceData);
slouken@8972
   896
            custom->rglForceData = NULL;
slouken@8972
   897
        }
slouken@8972
   898
        SDL_free(effect->lpvTypeSpecificParams);
slouken@8972
   899
        effect->lpvTypeSpecificParams = NULL;
slouken@8972
   900
    }
slouken@8972
   901
    SDL_free(effect->rglDirection);
slouken@8972
   902
    effect->rglDirection = NULL;
slouken@8972
   903
}
slouken@8972
   904
slouken@8972
   905
/*
slouken@8972
   906
 * Gets the effect type from the generic SDL haptic effect wrapper.
slouken@8972
   907
 */
slouken@8972
   908
static REFGUID
slouken@8972
   909
SDL_SYS_HapticEffectType(SDL_HapticEffect * effect)
slouken@8972
   910
{
slouken@8972
   911
    switch (effect->type) {
slouken@8972
   912
    case SDL_HAPTIC_CONSTANT:
slouken@8972
   913
        return &GUID_ConstantForce;
slouken@8972
   914
slouken@8972
   915
    case SDL_HAPTIC_RAMP:
slouken@8972
   916
        return &GUID_RampForce;
slouken@8972
   917
slouken@8972
   918
    /* !!! FIXME: put this back when we have more bits in 2.1 */
slouken@8972
   919
    /* case SDL_HAPTIC_SQUARE:
slouken@8972
   920
        return &GUID_Square; */
slouken@8972
   921
slouken@8972
   922
    case SDL_HAPTIC_SINE:
slouken@8972
   923
        return &GUID_Sine;
slouken@8972
   924
slouken@8972
   925
    case SDL_HAPTIC_TRIANGLE:
slouken@8972
   926
        return &GUID_Triangle;
slouken@8972
   927
slouken@8972
   928
    case SDL_HAPTIC_SAWTOOTHUP:
slouken@8972
   929
        return &GUID_SawtoothUp;
slouken@8972
   930
slouken@8972
   931
    case SDL_HAPTIC_SAWTOOTHDOWN:
slouken@8972
   932
        return &GUID_SawtoothDown;
slouken@8972
   933
slouken@8972
   934
    case SDL_HAPTIC_SPRING:
slouken@8972
   935
        return &GUID_Spring;
slouken@8972
   936
slouken@8972
   937
    case SDL_HAPTIC_DAMPER:
slouken@8972
   938
        return &GUID_Damper;
slouken@8972
   939
slouken@8972
   940
    case SDL_HAPTIC_INERTIA:
slouken@8972
   941
        return &GUID_Inertia;
slouken@8972
   942
slouken@8972
   943
    case SDL_HAPTIC_FRICTION:
slouken@8972
   944
        return &GUID_Friction;
slouken@8972
   945
slouken@8972
   946
    case SDL_HAPTIC_CUSTOM:
slouken@8972
   947
        return &GUID_CustomForce;
slouken@8972
   948
slouken@8972
   949
    default:
slouken@8972
   950
        return NULL;
slouken@8972
   951
    }
slouken@8972
   952
}
slouken@8972
   953
int
slouken@8972
   954
SDL_DINPUT_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * base)
slouken@8972
   955
{
slouken@8972
   956
    HRESULT ret;
slouken@8972
   957
    REFGUID type = SDL_SYS_HapticEffectType(base);
slouken@8972
   958
slouken@8972
   959
    if (type == NULL) {
slouken@8972
   960
        SDL_SetError("Haptic: Unknown effect type.");
slouken@8972
   961
        return -1;
slouken@8972
   962
    }
slouken@8972
   963
slouken@8972
   964
    /* Get the effect. */
slouken@8972
   965
    if (SDL_SYS_ToDIEFFECT(haptic, &effect->hweffect->effect, base) < 0) {
slouken@8972
   966
        goto err_effectdone;
slouken@8972
   967
    }
slouken@8972
   968
slouken@8972
   969
    /* Create the actual effect. */
slouken@8972
   970
    ret = IDirectInputDevice8_CreateEffect(haptic->hwdata->device, type,
slouken@8972
   971
        &effect->hweffect->effect,
slouken@8972
   972
        &effect->hweffect->ref, NULL);
slouken@8972
   973
    if (FAILED(ret)) {
slouken@8972
   974
        DI_SetError("Unable to create effect", ret);
slouken@8972
   975
        goto err_effectdone;
slouken@8972
   976
    }
slouken@8972
   977
slouken@8972
   978
    return 0;
slouken@8972
   979
slouken@8972
   980
err_effectdone:
slouken@8972
   981
    SDL_SYS_HapticFreeDIEFFECT(&effect->hweffect->effect, base->type);
slouken@8972
   982
    return -1;
slouken@8972
   983
}
slouken@8972
   984
slouken@8972
   985
int
slouken@8972
   986
SDL_DINPUT_HapticUpdateEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * data)
slouken@8972
   987
{
slouken@8972
   988
    HRESULT ret;
slouken@8972
   989
    DWORD flags;
slouken@8972
   990
    DIEFFECT temp;
slouken@8972
   991
slouken@8972
   992
    /* Get the effect. */
slouken@8972
   993
    SDL_memset(&temp, 0, sizeof(DIEFFECT));
slouken@8972
   994
    if (SDL_SYS_ToDIEFFECT(haptic, &temp, data) < 0) {
slouken@8972
   995
        goto err_update;
slouken@8972
   996
    }
slouken@8972
   997
slouken@8972
   998
    /* Set the flags.  Might be worthwhile to diff temp with loaded effect and
slouken@8972
   999
    *  only change those parameters. */
slouken@8972
  1000
    flags = DIEP_DIRECTION |
slouken@8972
  1001
        DIEP_DURATION |
slouken@8972
  1002
        DIEP_ENVELOPE |
slouken@8972
  1003
        DIEP_STARTDELAY |
slouken@8972
  1004
        DIEP_TRIGGERBUTTON |
slouken@8972
  1005
        DIEP_TRIGGERREPEATINTERVAL | DIEP_TYPESPECIFICPARAMS;
slouken@8972
  1006
slouken@8972
  1007
    /* Create the actual effect. */
slouken@8972
  1008
    ret =
slouken@8972
  1009
        IDirectInputEffect_SetParameters(effect->hweffect->ref, &temp, flags);
slouken@10819
  1010
    if (ret == DIERR_NOTEXCLUSIVEACQUIRED) {
slouken@10819
  1011
        IDirectInputDevice8_Unacquire(haptic->hwdata->device);
slouken@10819
  1012
        ret = IDirectInputDevice8_SetCooperativeLevel(haptic->hwdata->device, SDL_HelperWindow, DISCL_EXCLUSIVE | DISCL_BACKGROUND);
slouken@10819
  1013
        if (SUCCEEDED(ret)) {
slouken@10819
  1014
            ret = DIERR_NOTACQUIRED;
slouken@10819
  1015
        }
slouken@10819
  1016
    }
slouken@10819
  1017
    if (ret == DIERR_INPUTLOST || ret == DIERR_NOTACQUIRED) {
slouken@10819
  1018
        ret = IDirectInputDevice8_Acquire(haptic->hwdata->device);
slouken@10819
  1019
        if (SUCCEEDED(ret)) {
slouken@10819
  1020
            ret = IDirectInputEffect_SetParameters(effect->hweffect->ref, &temp, flags);
slouken@10819
  1021
        }
slouken@10819
  1022
    }
slouken@8972
  1023
    if (FAILED(ret)) {
slouken@8972
  1024
        DI_SetError("Unable to update effect", ret);
slouken@8972
  1025
        goto err_update;
slouken@8972
  1026
    }
slouken@8972
  1027
slouken@8972
  1028
    /* Copy it over. */
slouken@8972
  1029
    SDL_SYS_HapticFreeDIEFFECT(&effect->hweffect->effect, data->type);
slouken@8972
  1030
    SDL_memcpy(&effect->hweffect->effect, &temp, sizeof(DIEFFECT));
slouken@8972
  1031
slouken@8972
  1032
    return 0;
slouken@8972
  1033
slouken@8972
  1034
err_update:
slouken@8972
  1035
    SDL_SYS_HapticFreeDIEFFECT(&temp, data->type);
slouken@8972
  1036
    return -1;
slouken@8972
  1037
}
slouken@8972
  1038
slouken@8972
  1039
int
slouken@8972
  1040
SDL_DINPUT_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, Uint32 iterations)
slouken@8972
  1041
{
slouken@8972
  1042
    HRESULT ret;
slouken@8972
  1043
    DWORD iter;
slouken@8972
  1044
slouken@8972
  1045
    /* Check if it's infinite. */
slouken@8972
  1046
    if (iterations == SDL_HAPTIC_INFINITY) {
slouken@8972
  1047
        iter = INFINITE;
slouken@8972
  1048
    } else {
slouken@8972
  1049
        iter = iterations;
slouken@8972
  1050
    }
slouken@8972
  1051
slouken@8972
  1052
    /* Run the effect. */
slouken@8972
  1053
    ret = IDirectInputEffect_Start(effect->hweffect->ref, iter, 0);
slouken@8972
  1054
    if (FAILED(ret)) {
slouken@8972
  1055
        return DI_SetError("Running the effect", ret);
slouken@8972
  1056
    }
slouken@8972
  1057
    return 0;
slouken@8972
  1058
}
slouken@8972
  1059
slouken@8972
  1060
int
slouken@8972
  1061
SDL_DINPUT_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
slouken@8972
  1062
{
slouken@8972
  1063
    HRESULT ret;
slouken@8972
  1064
slouken@8972
  1065
    ret = IDirectInputEffect_Stop(effect->hweffect->ref);
slouken@8972
  1066
    if (FAILED(ret)) {
slouken@8972
  1067
        return DI_SetError("Unable to stop effect", ret);
slouken@8972
  1068
    }
slouken@8972
  1069
    return 0;
slouken@8972
  1070
}
slouken@8972
  1071
slouken@8972
  1072
void
slouken@8972
  1073
SDL_DINPUT_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
slouken@8972
  1074
{
slouken@8972
  1075
    HRESULT ret;
slouken@8972
  1076
slouken@8972
  1077
    ret = IDirectInputEffect_Unload(effect->hweffect->ref);
slouken@8972
  1078
    if (FAILED(ret)) {
slouken@8972
  1079
        DI_SetError("Removing effect from the device", ret);
slouken@8972
  1080
    }
slouken@8972
  1081
    SDL_SYS_HapticFreeDIEFFECT(&effect->hweffect->effect, effect->effect.type);
slouken@8972
  1082
}
slouken@8972
  1083
slouken@8972
  1084
int
slouken@8972
  1085
SDL_DINPUT_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect *effect)
slouken@8972
  1086
{
slouken@8972
  1087
    HRESULT ret;
slouken@8972
  1088
    DWORD status;
slouken@8972
  1089
slouken@8972
  1090
    ret = IDirectInputEffect_GetEffectStatus(effect->hweffect->ref, &status);
slouken@8972
  1091
    if (FAILED(ret)) {
slouken@8972
  1092
        return DI_SetError("Getting effect status", ret);
slouken@8972
  1093
    }
slouken@8972
  1094
slouken@8972
  1095
    if (status == 0)
slouken@8972
  1096
        return SDL_FALSE;
slouken@8972
  1097
    return SDL_TRUE;
slouken@8972
  1098
}
slouken@8972
  1099
slouken@8972
  1100
int
slouken@8972
  1101
SDL_DINPUT_HapticSetGain(SDL_Haptic * haptic, int gain)
slouken@8972
  1102
{
slouken@8972
  1103
    HRESULT ret;
slouken@8972
  1104
    DIPROPDWORD dipdw;
slouken@8972
  1105
slouken@8972
  1106
    /* Create the weird structure thingy. */
slouken@8972
  1107
    dipdw.diph.dwSize = sizeof(DIPROPDWORD);
slouken@8972
  1108
    dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
slouken@8972
  1109
    dipdw.diph.dwObj = 0;
slouken@8972
  1110
    dipdw.diph.dwHow = DIPH_DEVICE;
slouken@8972
  1111
    dipdw.dwData = gain * 100;  /* 0 to 10,000 */
slouken@8972
  1112
slouken@8972
  1113
    /* Try to set the autocenter. */
slouken@8972
  1114
    ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device,
slouken@8972
  1115
        DIPROP_FFGAIN, &dipdw.diph);
slouken@8972
  1116
    if (FAILED(ret)) {
slouken@8972
  1117
        return DI_SetError("Setting gain", ret);
slouken@8972
  1118
    }
slouken@8972
  1119
    return 0;
slouken@8972
  1120
}
slouken@8972
  1121
slouken@8972
  1122
int
slouken@8972
  1123
SDL_DINPUT_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
slouken@8972
  1124
{
slouken@8972
  1125
    HRESULT ret;
slouken@8972
  1126
    DIPROPDWORD dipdw;
slouken@8972
  1127
slouken@8972
  1128
    /* Create the weird structure thingy. */
slouken@8972
  1129
    dipdw.diph.dwSize = sizeof(DIPROPDWORD);
slouken@8972
  1130
    dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
slouken@8972
  1131
    dipdw.diph.dwObj = 0;
slouken@8972
  1132
    dipdw.diph.dwHow = DIPH_DEVICE;
slouken@8972
  1133
    dipdw.dwData = (autocenter == 0) ? DIPROPAUTOCENTER_OFF :
slouken@8972
  1134
        DIPROPAUTOCENTER_ON;
slouken@8972
  1135
slouken@8972
  1136
    /* Try to set the autocenter. */
slouken@8972
  1137
    ret = IDirectInputDevice8_SetProperty(haptic->hwdata->device,
slouken@8972
  1138
        DIPROP_AUTOCENTER, &dipdw.diph);
slouken@8972
  1139
    if (FAILED(ret)) {
slouken@8972
  1140
        return DI_SetError("Setting autocenter", ret);
slouken@8972
  1141
    }
slouken@8972
  1142
    return 0;
slouken@8972
  1143
}
slouken@8972
  1144
slouken@8972
  1145
int
slouken@8972
  1146
SDL_DINPUT_HapticPause(SDL_Haptic * haptic)
slouken@8972
  1147
{
slouken@8972
  1148
    HRESULT ret;
slouken@8972
  1149
slouken@8972
  1150
    /* Pause the device. */
slouken@8972
  1151
    ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device,
slouken@8972
  1152
        DISFFC_PAUSE);
slouken@8972
  1153
    if (FAILED(ret)) {
slouken@8972
  1154
        return DI_SetError("Pausing the device", ret);
slouken@8972
  1155
    }
slouken@8972
  1156
    return 0;
slouken@8972
  1157
}
slouken@8972
  1158
slouken@8972
  1159
int
slouken@8972
  1160
SDL_DINPUT_HapticUnpause(SDL_Haptic * haptic)
slouken@8972
  1161
{
slouken@8972
  1162
    HRESULT ret;
slouken@8972
  1163
slouken@8972
  1164
    /* Unpause the device. */
slouken@8972
  1165
    ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device,
slouken@8972
  1166
        DISFFC_CONTINUE);
slouken@8972
  1167
    if (FAILED(ret)) {
slouken@8972
  1168
        return DI_SetError("Pausing the device", ret);
slouken@8972
  1169
    }
slouken@8972
  1170
    return 0;
slouken@8972
  1171
}
slouken@8972
  1172
slouken@8972
  1173
int
slouken@8972
  1174
SDL_DINPUT_HapticStopAll(SDL_Haptic * haptic)
slouken@8972
  1175
{
slouken@8972
  1176
    HRESULT ret;
slouken@8972
  1177
slouken@8972
  1178
    /* Try to stop the effects. */
slouken@8972
  1179
    ret = IDirectInputDevice8_SendForceFeedbackCommand(haptic->hwdata->device,
slouken@8972
  1180
        DISFFC_STOPALL);
slouken@8972
  1181
    if (FAILED(ret)) {
slouken@8972
  1182
        return DI_SetError("Stopping the device", ret);
slouken@8972
  1183
    }
slouken@8972
  1184
    return 0;
slouken@8972
  1185
}
slouken@8972
  1186
slouken@8972
  1187
#else /* !SDL_HAPTIC_DINPUT */
slouken@8972
  1188
icculus@9661
  1189
typedef struct DIDEVICEINSTANCE DIDEVICEINSTANCE;
icculus@9663
  1190
typedef struct SDL_hapticlist_item SDL_hapticlist_item;
icculus@9661
  1191
slouken@8972
  1192
int
slouken@8972
  1193
SDL_DINPUT_HapticInit(void)
slouken@8972
  1194
{
slouken@8972
  1195
    return 0;
slouken@8972
  1196
}
slouken@8972
  1197
slouken@8972
  1198
int
slouken@8972
  1199
SDL_DINPUT_MaybeAddDevice(const DIDEVICEINSTANCE * pdidInstance)
slouken@8972
  1200
{
slouken@8972
  1201
    return SDL_Unsupported();
slouken@8972
  1202
}
slouken@8972
  1203
slouken@8972
  1204
int
slouken@8972
  1205
SDL_DINPUT_MaybeRemoveDevice(const DIDEVICEINSTANCE * pdidInstance)
slouken@8972
  1206
{
slouken@8972
  1207
    return SDL_Unsupported();
slouken@8972
  1208
}
slouken@8972
  1209
slouken@8972
  1210
int
slouken@8972
  1211
SDL_DINPUT_HapticOpen(SDL_Haptic * haptic, SDL_hapticlist_item *item)
slouken@8972
  1212
{
slouken@8972
  1213
    return SDL_Unsupported();
slouken@8972
  1214
}
slouken@8972
  1215
slouken@8972
  1216
int
slouken@8972
  1217
SDL_DINPUT_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
slouken@8972
  1218
{
slouken@8972
  1219
    return SDL_Unsupported();
slouken@8972
  1220
}
slouken@8972
  1221
slouken@8972
  1222
int
slouken@8972
  1223
SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
slouken@8972
  1224
{
slouken@8972
  1225
    return SDL_Unsupported();
slouken@8972
  1226
}
slouken@8972
  1227
slouken@8972
  1228
void
slouken@8972
  1229
SDL_DINPUT_HapticClose(SDL_Haptic * haptic)
slouken@8972
  1230
{
slouken@8972
  1231
}
slouken@8972
  1232
slouken@8972
  1233
void
slouken@8972
  1234
SDL_DINPUT_HapticQuit(void)
slouken@8972
  1235
{
slouken@8972
  1236
}
slouken@8972
  1237
slouken@8972
  1238
int
slouken@8972
  1239
SDL_DINPUT_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * base)
slouken@8972
  1240
{
slouken@8972
  1241
    return SDL_Unsupported();
slouken@8972
  1242
}
slouken@8972
  1243
slouken@8972
  1244
int
slouken@8972
  1245
SDL_DINPUT_HapticUpdateEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * data)
slouken@8972
  1246
{
slouken@8972
  1247
    return SDL_Unsupported();
slouken@8972
  1248
}
slouken@8972
  1249
slouken@8972
  1250
int
slouken@8972
  1251
SDL_DINPUT_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, Uint32 iterations)
slouken@8972
  1252
{
slouken@8972
  1253
    return SDL_Unsupported();
slouken@8972
  1254
}
slouken@8972
  1255
slouken@8972
  1256
int
slouken@8972
  1257
SDL_DINPUT_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
slouken@8972
  1258
{
slouken@8972
  1259
    return SDL_Unsupported();
slouken@8972
  1260
}
slouken@8972
  1261
slouken@8972
  1262
void
slouken@8972
  1263
SDL_DINPUT_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
slouken@8972
  1264
{
slouken@8972
  1265
}
slouken@8972
  1266
slouken@8972
  1267
int
slouken@8972
  1268
SDL_DINPUT_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect *effect)
slouken@8972
  1269
{
slouken@8972
  1270
    return SDL_Unsupported();
slouken@8972
  1271
}
slouken@8972
  1272
slouken@8972
  1273
int
slouken@8972
  1274
SDL_DINPUT_HapticSetGain(SDL_Haptic * haptic, int gain)
slouken@8972
  1275
{
slouken@8972
  1276
    return SDL_Unsupported();
slouken@8972
  1277
}
slouken@8972
  1278
slouken@8972
  1279
int
slouken@8972
  1280
SDL_DINPUT_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
slouken@8972
  1281
{
slouken@8972
  1282
    return SDL_Unsupported();
slouken@8972
  1283
}
slouken@8972
  1284
slouken@8972
  1285
int
slouken@8972
  1286
SDL_DINPUT_HapticPause(SDL_Haptic * haptic)
slouken@8972
  1287
{
slouken@8972
  1288
    return SDL_Unsupported();
slouken@8972
  1289
}
slouken@8972
  1290
slouken@8972
  1291
int
slouken@8972
  1292
SDL_DINPUT_HapticUnpause(SDL_Haptic * haptic)
slouken@8972
  1293
{
slouken@8972
  1294
    return SDL_Unsupported();
slouken@8972
  1295
}
slouken@8972
  1296
slouken@8972
  1297
int
slouken@8972
  1298
SDL_DINPUT_HapticStopAll(SDL_Haptic * haptic)
slouken@8972
  1299
{
slouken@8972
  1300
    return SDL_Unsupported();
slouken@8972
  1301
}
slouken@8972
  1302
slouken@8972
  1303
#endif /* SDL_HAPTIC_DINPUT */
slouken@8972
  1304
slouken@8972
  1305
/* vi: set ts=4 sw=4 expandtab: */