Skip to content

Commit

Permalink
Updated for DirectX Tool Kit February 2017 releases
Browse files Browse the repository at this point in the history
  • Loading branch information
walbourn committed Feb 15, 2017
1 parent c8776e2 commit 46a3295
Show file tree
Hide file tree
Showing 21 changed files with 628 additions and 185 deletions.
5 changes: 5 additions & 0 deletions Kits/DirectXTK/DirectXTK_Windows10.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -639,4 +639,9 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
<Target Name="ATGEnsureShaders" BeforeTargets="PrepareForBuild">
<Exec Condition="!Exists('src/Shaders/Compiled/SpriteEffect_SpriteVertexShader.inc')"
WorkingDirectory="$(ProjectDir)src/Shaders"
Command="CompileShaders" />
</Target>
</Project>
2 changes: 1 addition & 1 deletion Kits/DirectXTK/Inc/Keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ namespace DirectX

bool __cdecl IsKeyDown(Keys key) const
{
if (key >= 0 && key <= 0xff)
if (key >= 0 && key <= 0xfe)
{
auto ptr = reinterpret_cast<const uint32_t*>(this);
unsigned int bf = 1u << (key & 0x1f);
Expand Down
8 changes: 7 additions & 1 deletion Kits/DirectXTK/Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ DirectXTK - the DirectX Tool Kit for DirectX 11

Copyright (c) Microsoft Corporation. All rights reserved.

December 5, 2016
February 10, 2017

This package contains the "DirectX Tool Kit", a collection of helper classes for
writing Direct3D 11 C++ code for Universal Windows Platform (UWP) apps for Windows 10,
Expand Down Expand Up @@ -79,6 +79,12 @@ https://opensource.microsoft.com/codeofconduct/
RELEASE HISTORY
---------------

February 10, 2017
GamePad now supports special value of -1 for 'most recently connected controller'
WIC format 40bppCMYKAlpha should be converted to RGBA8 rather than RGBA16
DDS support for L8A8 with bitcount 8 rather than 16
Minor code cleanup

December 5, 2016
Mouse and Keyboard classes updated with IsConnected method
Windows10 project /ZW switch removed to support use in C++/WinRT projection apps
Expand Down
101 changes: 87 additions & 14 deletions Kits/DirectXTK/Src/GamePad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ class GamePad::Impl
Impl(GamePad* owner) :
mOwner(owner),
mCtrlChanged(INVALID_HANDLE_VALUE),
mUserChanged(INVALID_HANDLE_VALUE)
mUserChanged(INVALID_HANDLE_VALUE),
mMostRecentGamepad(0)
{
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
Expand Down Expand Up @@ -169,6 +170,9 @@ class GamePad::Impl
ScanGamePads();
}

if (player == -1)
player = mMostRecentGamepad;

if ( ( player >= 0 ) && ( player < MAX_PLAYER_COUNT ) )
{
if ( mGamePad[ player ] )
Expand Down Expand Up @@ -201,11 +205,11 @@ class GamePad::Impl

ApplyStickDeadZone( static_cast<float>(reading.LeftThumbstickX), static_cast<float>(reading.LeftThumbstickY),
deadZoneMode, 1.f, .24f /* Recommended Xbox One deadzone */,
static_cast<float>(state.thumbSticks.leftX), static_cast<float>(state.thumbSticks.leftY) );
state.thumbSticks.leftX, state.thumbSticks.leftY );

ApplyStickDeadZone( static_cast<float>(reading.RightThumbstickX), static_cast<float>(reading.RightThumbstickY),
deadZoneMode, 1.f, .24f /* Recommended Xbox One deadzone */,
static_cast<float>(state.thumbSticks.rightX), static_cast<float>(state.thumbSticks.rightY) );
state.thumbSticks.rightX, state.thumbSticks.rightY );

state.triggers.left = static_cast<float>(reading.LeftTrigger);
state.triggers.right = static_cast<float>(reading.RightTrigger);
Expand All @@ -229,6 +233,9 @@ class GamePad::Impl
ScanGamePads();
}

if (player == -1)
player = mMostRecentGamepad;

if ( ( player >= 0 ) && ( player < MAX_PLAYER_COUNT ) )
{
if ( mGamePad[ player ] )
Expand Down Expand Up @@ -265,6 +272,9 @@ class GamePad::Impl
{
using namespace ABI::Windows::Gaming::Input;

if (player == -1)
player = mMostRecentGamepad;

if ( ( player >= 0 ) && ( player < MAX_PLAYER_COUNT ) )
{
if ( mGamePad[ player ] )
Expand Down Expand Up @@ -306,6 +316,8 @@ class GamePad::Impl
HANDLE mUserChanged;

private:
int mMostRecentGamepad;

void ScanGamePads()
{
using namespace Microsoft::WRL;
Expand Down Expand Up @@ -362,6 +374,8 @@ class GamePad::Impl
{
if ( mGamePad[ k ] == pad )
{
if (j == (count - 1))
mMostRecentGamepad = static_cast<int>(k);
break;
}
else if ( !mGamePad[ k ] )
Expand All @@ -377,6 +391,8 @@ class GamePad::Impl
if ( empty < MAX_PLAYER_COUNT )
{
mGamePad[ empty ] = pad;
if (j == (count - 1))
mMostRecentGamepad = static_cast<int>(empty);

ComPtr<IGameController> ctrl;
hr = pad.As(&ctrl);
Expand Down Expand Up @@ -526,7 +542,8 @@ class GamePad::Impl
Impl(GamePad *owner) :
mOwner(owner),
mCtrlChanged(INVALID_HANDLE_VALUE),
mUserChanged(INVALID_HANDLE_VALUE)
mUserChanged(INVALID_HANDLE_VALUE),
mMostRecentGamepad(0)
{
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
Expand Down Expand Up @@ -596,6 +613,9 @@ class GamePad::Impl
ScanGamePads();
}

if (player == -1)
player = mMostRecentGamepad;

if ( ( player >= 0 ) && ( player < MAX_PLAYER_COUNT ) )
{
if ( mGamePad[ player ] )
Expand Down Expand Up @@ -655,6 +675,9 @@ class GamePad::Impl
ScanGamePads();
}

if (player == -1)
player = mMostRecentGamepad;

if ( ( player >= 0 ) && ( player < MAX_PLAYER_COUNT ) )
{
if ( mGamePad[ player ] )
Expand Down Expand Up @@ -703,6 +726,9 @@ class GamePad::Impl
{
using namespace ABI::Windows::Xbox::Input;

if (player == -1)
player = mMostRecentGamepad;

if ( ( player >= 0 ) && ( player < MAX_PLAYER_COUNT ) )
{
if ( mGamePad[ player ] )
Expand Down Expand Up @@ -753,6 +779,8 @@ class GamePad::Impl
HANDLE mUserChanged;

private:
int mMostRecentGamepad;

void ScanGamePads()
{
using namespace ABI::Windows::Foundation::Collections;
Expand Down Expand Up @@ -800,6 +828,8 @@ class GamePad::Impl
{
if ( mGamePad[ k ] == pad )
{
if (!j)
mMostRecentGamepad = static_cast<int>(k);
break;
}
else if ( !mGamePad[ k ] )
Expand All @@ -817,6 +847,8 @@ class GamePad::Impl
}

mGamePad[ empty ] = pad;
if (!j)
mMostRecentGamepad = static_cast<int>(empty);
}
}
}
Expand Down Expand Up @@ -941,7 +973,12 @@ class GamePad::Impl

void GetState( int player, _Out_ State& state, DeadZone deadZoneMode )
{
if ( !ThrottleRetry(player) )
if (player == -1)
player = GetMostRecent();

ULONGLONG time = GetTickCount64();

if ( !ThrottleRetry(player, time) )
{
#if (_WIN32_WINNT < _WIN32_WINNT_WIN8)
if ( mSuspended )
Expand All @@ -956,10 +993,13 @@ class GamePad::Impl
DWORD result = XInputGetState( DWORD(player), &xstate );
if ( result == ERROR_DEVICE_NOT_CONNECTED )
{
ClearSlot( player, GetTickCount64() );
ClearSlot( player, time );
}
else
{
if (!mConnected[player])
mLastReadTime[player] = time;

mConnected[ player ] = true;

state.connected = true;
Expand Down Expand Up @@ -1010,16 +1050,24 @@ class GamePad::Impl

void GetCapabilities( int player, _Out_ Capabilities& caps )
{
if ( !ThrottleRetry(player) )
if (player == -1)
player = GetMostRecent();

ULONGLONG time = GetTickCount64();

if ( !ThrottleRetry(player, time) )
{
XINPUT_CAPABILITIES xcaps;
DWORD result = XInputGetCapabilities( DWORD(player), 0, &xcaps );
if ( result == ERROR_DEVICE_NOT_CONNECTED )
{
ClearSlot( player, GetTickCount64() );
ClearSlot( player, time );
}
else
{
if (!mConnected[player])
mLastReadTime[player] = time;

mConnected[ player ] = true;

caps.connected = true;
Expand Down Expand Up @@ -1051,7 +1099,12 @@ class GamePad::Impl

bool SetVibration( int player, float leftMotor, float rightMotor, float leftTrigger, float rightTrigger )
{
if ( ThrottleRetry(player) )
if (player == -1)
player = GetMostRecent();

ULONGLONG time = GetTickCount64();

if ( ThrottleRetry(player, time) )
{
return false;
}
Expand All @@ -1075,11 +1128,14 @@ class GamePad::Impl
DWORD result = XInputSetState( DWORD(player), &xvibration );
if ( result == ERROR_DEVICE_NOT_CONNECTED )
{
ClearSlot( player, GetTickCount64() );
ClearSlot( player, time );
return false;
}
else
{
if (!mConnected[player])
mLastReadTime[player] = time;

mConnected[ player ] = true;
return (result == ERROR_SUCCESS);
}
Expand Down Expand Up @@ -1116,6 +1172,8 @@ class GamePad::Impl
// For XInput 9.1.0, we have to emulate the behavior of XInputEnable( TRUE )
if ( mSuspended )
{
ULONGLONG time = GetTickCount64();

for( int j = 0; j < XUSER_MAX_COUNT; ++j )
{
if ( mConnected[ j ] )
Expand All @@ -1126,7 +1184,7 @@ class GamePad::Impl
DWORD result = XInputSetState( DWORD(j), &xvibration );
if ( result == ERROR_DEVICE_NOT_CONNECTED )
{
ClearSlot( j, GetTickCount64() );
ClearSlot( j, time );
}
}
}
Expand All @@ -1151,7 +1209,7 @@ class GamePad::Impl
bool mSuspended;
#endif

bool ThrottleRetry( int player )
bool ThrottleRetry( int player, ULONGLONG time )
{
// This function minimizes a potential performance issue with XInput on Windows when
// checking a disconnected controller slot which requires device enumeration.
Expand All @@ -1163,8 +1221,6 @@ class GamePad::Impl
if ( mConnected[ player ] )
return false;

ULONGLONG time = GetTickCount64();

for( size_t j = 0; j < XUSER_MAX_COUNT; ++j )
{
if ( !mConnected[j] )
Expand All @@ -1191,6 +1247,23 @@ class GamePad::Impl
mLeftMotor[ player ] = mRightMotor[ player ] = 0.f;
#endif
}

int GetMostRecent()
{
int player = -1;
ULONGLONG time = 0;

for (size_t j = 0; j < XUSER_MAX_COUNT; ++j)
{
if (mConnected[j] && (mLastReadTime[j] > time))
{
time = mLastReadTime[j];
player = static_cast<int>(j);
}
}

return player;
}
};

GamePad::Impl* GamePad::Impl::s_gamePad = nullptr;
Expand Down
5 changes: 5 additions & 0 deletions Kits/DirectXTK/Src/LoaderHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,11 @@ namespace DirectX
}

// No DXGI format maps to ISBITMASK(0x0f,0x00,0x00,0xf0) aka D3DFMT_A4L4

if (ISBITMASK(0x000000ff, 0x00000000, 0x00000000, 0x0000ff00))
{
return DXGI_FORMAT_R8G8_UNORM; // Some DDS writers assume the bitcount should be 8 instead of 16
}
}

if (16 == ddpf.RGBBitCount)
Expand Down
4 changes: 2 additions & 2 deletions Kits/DirectXTK/Src/ScreenGrab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ HRESULT DirectX::SaveWICTextureToFile( ID3D11DeviceContext* pContext,
{
// Opt-in to the WIC2 support for writing 32-bit Windows BMP files with an alpha channel
PROPBAG2 option = {};
option.pstrName = L"EnableV5Header32bppBGRA";
option.pstrName = const_cast<wchar_t*>(L"EnableV5Header32bppBGRA");

VARIANT varValue;
varValue.vt = VT_BOOL;
Expand Down Expand Up @@ -517,7 +517,7 @@ HRESULT DirectX::SaveWICTextureToFile( ID3D11DeviceContext* pContext,
PropVariantInit( &value );

value.vt = VT_LPSTR;
value.pszVal = "DirectXTK";
value.pszVal = const_cast<char*>("DirectXTK");

if ( memcmp( &guidContainerFormat, &GUID_ContainerFormatPng, sizeof(GUID) ) == 0 )
{
Expand Down
Loading

0 comments on commit 46a3295

Please sign in to comment.