Subversion Repositories spacemission

Rev

Rev 1 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1 Rev 4
Line 4... Line 4...
4
 
4
 
5
{$INCLUDE DelphiXcfg.inc}
5
{$INCLUDE DelphiXcfg.inc}
6
 
6
 
7
uses
7
uses
8
  Windows, Messages, SysUtils, Classes, Controls, Forms, MMSystem,
8
  Windows, Messages, SysUtils, Classes, Controls, Forms, MMSystem,
-
 
9
  DXClass, {$IFDEF VER17UP} Types, {$ENDIF}
-
 
10
{$IfDef StandardDX}
-
 
11
  {$IfDef DX9}
-
 
12
  DirectInput;
-
 
13
  {$Else}
-
 
14
    {$IfDef DX81}
9
  DirectX, DXClass;
15
  DirectInput8;
-
 
16
    {$Else}
-
 
17
  DirectInput;
-
 
18
    {$EndIf}
-
 
19
  {$EndIf}
-
 
20
{$Else}
-
 
21
  DirectX;
-
 
22
{$EndIf}
10
 
23
 
11
type
24
type
12
 
25
 
13
  {  EDXInputError  }
26
  {  EDXInputError  }
14
 
27
 
Line 763... Line 776...
763
    begin
776
    begin
764
      FFindEffectFlag := True;
777
      FFindEffectFlag := True;
765
      FFindEffectGUID := pdei.guid;
778
      FFindEffectGUID := pdei.guid;
766
    end;
779
    end;
767
 
780
 
768
    Result := DIENUM_STOP;
781
    Result := Integer(DIENUM_STOP);
769
  end;
782
  end;
770
 
783
 
771
  procedure CreateIEffectGuid(const GUID: TGUID;
784
  procedure CreateIEffectGuid(const GUID: TGUID;
772
    EffectObject: TForceFeedbackEffectObject);
785
    EffectObject: TForceFeedbackEffectObject);
773
  begin
786
  begin
774
    if EffectObject.Feff.dwSize=0 then Exit;
787
    if EffectObject.Feff.dwSize=0 then Exit;
775
 
788
 
776
    if FRoot.FInput.FDevice2<>nil then
789
    if FRoot.FInput.FDevice2<>nil then
777
      FRoot.FInput.FDevice2.CreateEffect(GUID, EffectObject.Feff, EffectObject.FEffect, nil);
790
      FRoot.FInput.FDevice2.CreateEffect(GUID, @EffectObject.Feff, EffectObject.FEffect, nil);
778
  end;
791
  end;
779
 
792
 
780
  procedure CreateIEffect(dwFlags: DWORD;
793
  procedure CreateIEffect(dwFlags: DWORD;
781
    EffectObject: TForceFeedbackEffectObject);
794
    EffectObject: TForceFeedbackEffectObject);
782
  begin
795
  begin
Line 1403... Line 1416...
1403
begin
1416
begin
1404
  FillChar(Data, dwSize, 0);
1417
  FillChar(Data, dwSize, 0);
1405
 
1418
 
1406
  if FDevice<>nil then
1419
  if FDevice<>nil then
1407
  begin
1420
  begin
1408
    hr := FDevice.GetDeviceState(dwSize, Data);
1421
    hr := FDevice.GetDeviceState(dwSize, @Data);
1409
    if (hr=DIERR_INPUTLOST) or (hr=DIERR_NOTACQUIRED) then
1422
    if (hr=DIERR_INPUTLOST) or (hr=DIERR_NOTACQUIRED) then
1410
    begin
1423
    begin
1411
      FDevice.Acquire;
1424
      FDevice.Acquire;
1412
      hr := FDevice.GetDeviceState(dwSize, Data);
1425
      hr := FDevice.GetDeviceState(dwSize, @Data);
1413
    end;
1426
    end;
1414
    Result := hr=DI_OK;
1427
    Result := hr=DI_OK;
1415
  end else
1428
  end else
1416
    Result := False;
1429
    Result := False;
1417
end;
1430
end;
Line 1419... Line 1432...
1419
function TCustomInput.SetDataFormat: Boolean;
1432
function TCustomInput.SetDataFormat: Boolean;
1420
 
1433
 
1421
  function DIEnumDeviceObjectsProc(const peff: TDIDeviceObjectInstanceA;
1434
  function DIEnumDeviceObjectsProc(const peff: TDIDeviceObjectInstanceA;
1422
    pvRef: Pointer): HRESULT; stdcall;
1435
    pvRef: Pointer): HRESULT; stdcall;
1423
  begin
1436
  begin
1424
    Result := DIENUM_CONTINUE;
1437
    Result := Integer(DIENUM_CONTINUE);
1425
 
1438
 
1426
    if CompareMem(@peff.guidType, @GUID_Unknown, SizeOf(TGUID)) then Exit;
1439
    if CompareMem(@peff.guidType, @GUID_Unknown, SizeOf(TGUID)) then Exit;
1427
 
1440
 
1428
    with TCustomInput(pvRef) do
1441
    with TCustomInput(pvRef) do
1429
    begin
1442
    begin
Line 1644... Line 1657...
1644
      DIK_LWIN         : Result := VK_LWIN;
1657
      DIK_LWIN         : Result := VK_LWIN;
1645
      DIK_RWIN         : Result := VK_RWIN;
1658
      DIK_RWIN         : Result := VK_RWIN;
1646
      DIK_APPS         : Result := VK_APPS;
1659
      DIK_APPS         : Result := VK_APPS;
1647
    end;
1660
    end;
1648
  end;
1661
  end;
-
 
1662
{$IFDEF StandardDX}
1649
 
1663
type
-
 
1664
  TDIKeyboardState = array[0..255] of Byte;
-
 
1665
{$ENDIF}
1650
var      
1666
var
1651
  j: Integer;
1667
  j: Integer;
1652
  i: TDXInputState;
1668
  i: TDXInputState;
1653
  dikb: TDIKeyboardState;
1669
  dikb: TDIKeyboardState;
1654
begin
1670
begin
Line 1846... Line 1862...
1846
end;
1862
end;
1847
                                                       
1863
                                                       
1848
function TJoystick_EnumJoysticksCallback(const lpddi: TDIDeviceInstanceA;
1864
function TJoystick_EnumJoysticksCallback(const lpddi: TDIDeviceInstanceA;
1849
  pvRef: Pointer): HRESULT; stdcall;
1865
  pvRef: Pointer): HRESULT; stdcall;
1850
begin
1866
begin
1851
  Result := DIENUM_CONTINUE;
1867
  Result := Integer(DIENUM_CONTINUE);
1852
 
1868
 
1853
  with TJoystick(pvRef) do
1869
  with TJoystick(pvRef) do
1854
  begin
1870
  begin
1855
    if FEnumIndex=FID then
1871
    if FEnumIndex=FID then
1856
    begin
1872
    begin
1857
      FDeviceGUID := lpddi.guidInstance;
1873
      FDeviceGUID := lpddi.guidInstance;
1858
      FEnumFlag := True;
1874
      FEnumFlag := True;
1859
      Result := DIENUM_STOP;
1875
      Result := Integer(DIENUM_STOP);
1860
      Exit;
1876
      Exit;
1861
    end;
1877
    end;
1862
    Inc(FEnumIndex);
1878
    Inc(FEnumIndex);
1863
  end;
1879
  end;
1864
end;
1880
end;
Line 1878... Line 1894...
1878
      begin
1894
      begin
1879
        {  Device search.  }
1895
        {  Device search.  }
1880
        FEnumFlag := False;
1896
        FEnumFlag := False;
1881
        FEnumIndex := 0;
1897
        FEnumIndex := 0;
1882
 
1898
 
1883
        FDXInput.FDInput.EnumDevices(DIDEVTYPE_JOYSTICK, @TJoystick_EnumJoysticksCallback,
1899
        FDXInput.FDInput.EnumDevices({DIDEVTYPE_JOYSTICK}4, @TJoystick_EnumJoysticksCallback,
1884
          Self, DIEDFL_ATTACHEDONLY);
1900
          Self, DIEDFL_ATTACHEDONLY);
1885
 
1901
 
1886
        if not FEnumFlag then Exit;
1902
        if not FEnumFlag then Exit;
1887
 
1903
 
1888
        {  Device making.  }
1904
        {  Device making.  }
Line 1894... Line 1910...
1894
          FButtonCount := devcaps.dwButtons;
1910
          FButtonCount := devcaps.dwButtons;
1895
          if devcaps.dwFlags and DIDC_FORCEFEEDBACK<>0 then
1911
          if devcaps.dwFlags and DIDC_FORCEFEEDBACK<>0 then
1896
            FForceFeedbackDevice := True;
1912
            FForceFeedbackDevice := True;
1897
        end;
1913
        end;
1898
 
1914
 
1899
        if FDXInput.FDInput.CreateDevice(GUID_Joystick, FDevice, nil)<>DI_OK then Exit;
1915
        //if FDXInput.FDInput.CreateDevice(GUID_Joystick, FDevice, nil)<>DI_OK then Exit;   get out by Paul van Dinther
1900
 
1916
 
1901
        {  Device data format (TDIDataFormat) making.  }
1917
        {  Device data format (TDIDataFormat) making.  }
1902
 
1918
 
1903
        with FDataFormat do
1919
        with FDataFormat do
1904
        begin
1920
        begin
Line 2120... Line 2136...
2120
  FDirectInputCount: Integer;
2136
  FDirectInputCount: Integer;
2121
 
2137
 
2122
procedure InitDirectInput(out DI: IDirectInput);
2138
procedure InitDirectInput(out DI: IDirectInput);
2123
type
2139
type
2124
  TDirectInputCreate = function(hinst: THandle; dwVersion: DWORD;
2140
  TDirectInputCreate = function(hinst: THandle; dwVersion: DWORD;
2125
    out ppDI: IDirectInputA; punkOuter: IUnknown): HRESULT; stdcall;
2141
    out ppDI: {$IFDEF UNICODE}IDirectInputW{$ELSE}IDirectInputA{$ENDIF}; punkOuter: IUnknown): HRESULT; stdcall;
2126
begin
2142
begin
2127
  if FDirectInput=nil then
2143
  if FDirectInput=nil then
2128
  begin
2144
  begin
2129
    try
2145
    try
2130
      TDirectInputCreate(DXLoadLibrary('DInput.dll', 'DirectInputCreateA'))
2146
      TDirectInputCreate(DXLoadLibrary('DInput.dll', 'DirectInputCreateA'))