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