Reformat Windows (Resharper)

This commit is contained in:
Vladimir Kononovich 2020-12-19 23:33:11 +03:00
parent c0aabf20a1
commit 6c4907ed1d
26 changed files with 6430 additions and 5578 deletions

View file

@ -26,18 +26,23 @@ void DirectInputManager::Initialize()
// Register with the DirectInput subsystem and get a pointer to a IDirectInput interface we can use.
// Create a DInput object
if(FAILED(hr = DirectInput8Create(GetModuleHandle(nullptr), DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&_directInput, nullptr))) {
if (FAILED(
hr = DirectInput8Create(GetModuleHandle(nullptr), DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&_directInput,
nullptr)))
{
MessageManager::Log("[DInput] DirectInput8Create failed: " + std::to_string(hr));
return;
}
IDirectInputJoyConfig8* pJoyConfig = nullptr;
if(FAILED(hr = _directInput->QueryInterface(IID_IDirectInputJoyConfig8, (void**)&pJoyConfig))) {
if (FAILED(hr = _directInput->QueryInterface(IID_IDirectInputJoyConfig8, (void**)&pJoyConfig)))
{
MessageManager::Log("[DInput] QueryInterface failed: " + std::to_string(hr));
return;
}
if(pJoyConfig) {
if (pJoyConfig)
{
pJoyConfig->Release();
}
@ -48,19 +53,25 @@ bool DirectInputManager::ProcessDevice(const DIDEVICEINSTANCE* pdidInstance)
{
const GUID* deviceGuid = &pdidInstance->guidInstance;
auto comp = [=](GUID guid) {
auto comp = [=](GUID guid)
{
return guid.Data1 == deviceGuid->Data1 &&
guid.Data2 == deviceGuid->Data2 &&
guid.Data3 == deviceGuid->Data3 &&
memcmp(guid.Data4, deviceGuid->Data4, sizeof(guid.Data4)) == 0;
};
bool wasProcessedBefore = std::find_if(_processedGuids.begin(), _processedGuids.end(), comp) != _processedGuids.end();
if(wasProcessedBefore) {
bool wasProcessedBefore = std::find_if(_processedGuids.begin(), _processedGuids.end(), comp) != _processedGuids.
end();
if (wasProcessedBefore)
{
return false;
} else {
}
else
{
bool isXInput = IsXInputDevice(&pdidInstance->guidProduct);
if(isXInput) {
if (isXInput)
{
_xinputDeviceGuids.push_back(*deviceGuid);
_processedGuids.push_back(*deviceGuid);
}
@ -93,8 +104,10 @@ bool DirectInputManager::IsXInputDevice(const GUID* pGuidProductFromDirectInput)
bool bCleanupCOM = SUCCEEDED(hr);
// Create WMI
hr = CoCreateInstance(__uuidof(WbemLocator), NULL, CLSCTX_INPROC_SERVER, __uuidof(IWbemLocator), (LPVOID*)&pIWbemLocator);
if(FAILED(hr) || pIWbemLocator == NULL) {
hr = CoCreateInstance(__uuidof(WbemLocator), NULL, CLSCTX_INPROC_SERVER, __uuidof(IWbemLocator),
(LPVOID*)&pIWbemLocator);
if (FAILED(hr) || pIWbemLocator == NULL)
{
goto LCleanup;
}
@ -104,47 +117,58 @@ bool DirectInputManager::IsXInputDevice(const GUID* pGuidProductFromDirectInput)
// Connect to WMI
hr = pIWbemLocator->ConnectServer(bstrNamespace, NULL, NULL, 0L, 0L, NULL, NULL, &pIWbemServices);
if(FAILED(hr) || pIWbemServices == NULL) {
if (FAILED(hr) || pIWbemServices == NULL)
{
goto LCleanup;
}
// Switch security level to IMPERSONATE.
CoSetProxyBlanket(pIWbemServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE);
CoSetProxyBlanket(pIWbemServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL, RPC_C_AUTHN_LEVEL_CALL,
RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE);
hr = pIWbemServices->CreateInstanceEnum(bstrClassName, 0, NULL, &pEnumDevices);
if(FAILED(hr) || pEnumDevices == NULL) {
if (FAILED(hr) || pEnumDevices == NULL)
{
goto LCleanup;
}
// Loop over all devices
for(;; ) {
for (;;)
{
// Get 20 at a time
hr = pEnumDevices->Next(10000, 20, pDevices, &uReturned);
if(FAILED(hr) || uReturned == 0 || bIsXinputDevice) {
if (FAILED(hr) || uReturned == 0 || bIsXinputDevice)
{
break;
}
for(iDevice = 0; iDevice < uReturned; iDevice++) {
for (iDevice = 0; iDevice < uReturned; iDevice++)
{
// For each device, get its device ID
hr = pDevices[iDevice]->Get(bstrDeviceID, 0L, &var, NULL, NULL);
if(SUCCEEDED(hr) && var.vt == VT_BSTR && var.bstrVal != NULL) {
if (SUCCEEDED(hr) && var.vt == VT_BSTR && var.bstrVal != NULL)
{
// Check if the device ID contains "IG_". If it does, then it's an XInput device
// This information can not be found from DirectInput
if(wcsstr(var.bstrVal, L"IG_")) {
if (wcsstr(var.bstrVal, L"IG_"))
{
// If it does, then get the VID/PID from var.bstrVal
DWORD dwPid = 0, dwVid = 0;
WCHAR* strVid = wcsstr(var.bstrVal, L"VID_");
if(strVid && swscanf_s(strVid, L"VID_%4X", &dwVid) != 1) {
if (strVid && swscanf_s(strVid, L"VID_%4X", &dwVid) != 1)
{
dwVid = 0;
}
WCHAR* strPid = wcsstr(var.bstrVal, L"PID_");
if(strPid && swscanf_s(strPid, L"PID_%4X", &dwPid) != 1) {
if (strPid && swscanf_s(strPid, L"PID_%4X", &dwPid) != 1)
{
dwPid = 0;
}
// Compare the VID/PID to the DInput device
DWORD dwVidPid = MAKELONG(dwVid, dwPid);
if(dwVidPid == pGuidProductFromDirectInput->Data1) {
if (dwVidPid == pGuidProductFromDirectInput->Data1)
{
bIsXinputDevice = true;
pDevices[iDevice]->Release();
pDevices[iDevice] = nullptr;
@ -159,31 +183,40 @@ bool DirectInputManager::IsXInputDevice(const GUID* pGuidProductFromDirectInput)
}
LCleanup:
if(bstrNamespace) {
if (bstrNamespace)
{
SysFreeString(bstrNamespace);
}
if(bstrDeviceID) {
if (bstrDeviceID)
{
SysFreeString(bstrDeviceID);
}
if(bstrClassName) {
if (bstrClassName)
{
SysFreeString(bstrClassName);
}
for(iDevice = 0; iDevice < 20; iDevice++) {
if(pDevices[iDevice]) {
for (iDevice = 0; iDevice < 20; iDevice++)
{
if (pDevices[iDevice])
{
pDevices[iDevice]->Release();
}
}
if(pEnumDevices) {
if (pEnumDevices)
{
pEnumDevices->Release();
}
if(pIWbemLocator) {
if (pIWbemLocator)
{
pIWbemLocator->Release();
}
if(pIWbemServices) {
if (pIWbemServices)
{
pIWbemServices->Release();
}
if(bCleanupCOM) {
if (bCleanupCOM)
{
CoUninitialize();
}
@ -192,7 +225,8 @@ LCleanup:
void DirectInputManager::UpdateDeviceList()
{
if(_needToUpdate) {
if (_needToUpdate)
{
//An update is already pending, skip
return;
}
@ -200,15 +234,20 @@ void DirectInputManager::UpdateDeviceList()
HRESULT hr;
// Enumerate devices
if(SUCCEEDED(hr = _directInput->EnumDevices(DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, nullptr, DIEDFL_ALLDEVICES))) {
if(!_joysticksToAdd.empty()) {
if (SUCCEEDED(
hr = _directInput->EnumDevices(DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, nullptr, DIEDFL_ALLDEVICES)))
{
if (!_joysticksToAdd.empty())
{
//Sleeping apparently lets us read accurate "default" values, otherwise a PS4 controller returns all 0s, despite not doing so normally
for(DirectInputData &joystick : _joysticksToAdd) {
for (DirectInputData& joystick : _joysticksToAdd)
{
UpdateInputState(joystick);
}
std::this_thread::sleep_for(std::chrono::duration<int, std::milli>(100));
for(DirectInputData &joystick : _joysticksToAdd) {
for (DirectInputData& joystick : _joysticksToAdd)
{
UpdateInputState(joystick);
joystick.defaultState = joystick.state;
}
@ -216,7 +255,8 @@ void DirectInputManager::UpdateDeviceList()
}
}
if(_requestUpdate) {
if (_requestUpdate)
{
_requestUpdate = false;
_needToUpdate = true;
}
@ -231,14 +271,16 @@ int DirectInputManager::EnumJoysticksCallback(const DIDEVICEINSTANCE* pdidInstan
{
HRESULT hr;
if(ProcessDevice(pdidInstance)) {
if (ProcessDevice(pdidInstance))
{
_processedGuids.push_back(pdidInstance->guidInstance);
// Obtain an interface to the enumerated joystick.
LPDIRECTINPUTDEVICE8 pJoystick = nullptr;
hr = _directInput->CreateDevice(pdidInstance->guidInstance, &pJoystick, nullptr);
if(SUCCEEDED(hr)) {
if (SUCCEEDED(hr))
{
DIJOYSTATE2 state;
memset(&state, 0, sizeof(state));
DirectInputData data{pJoystick, state, state, false};
@ -247,22 +289,33 @@ int DirectInputManager::EnumJoysticksCallback(const DIDEVICEINSTANCE* pdidInstan
// Set the data format to "simple joystick" - a predefined data format
// A data format specifies which controls on a device we are interested in, and how they should be reported.
// This tells DInput that we will be passing a DIJOYSTATE2 structure to IDirectInputDevice::GetDeviceState().
if(SUCCEEDED(hr = data.joystick->SetDataFormat(&c_dfDIJoystick2))) {
if (SUCCEEDED(hr = data.joystick->SetDataFormat(&c_dfDIJoystick2)))
{
// Set the cooperative level to let DInput know how this device should interact with the system and with other DInput applications.
if(SUCCEEDED(hr = data.joystick->SetCooperativeLevel(_hWnd, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND))) {
if (SUCCEEDED(hr = data.joystick->SetCooperativeLevel(_hWnd, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND)))
{
// Enumerate the joystick objects. The callback function enabled user interface elements for objects that are found, and sets the min/max values property for discovered axes.
if(SUCCEEDED(hr = data.joystick->EnumObjects(EnumObjectsCallback, data.joystick, DIDFT_ALL))) {
if (SUCCEEDED(hr = data.joystick->EnumObjects(EnumObjectsCallback, data.joystick, DIDFT_ALL)))
{
_joysticksToAdd.push_back(data);
} else {
}
else
{
MessageManager::Log("[DInput] Failed to enumerate objects: " + std::to_string(hr));
}
} else {
}
else
{
MessageManager::Log("[DInput] Failed to set cooperative level: " + std::to_string(hr));
}
} else {
}
else
{
MessageManager::Log("[DInput] Failed to set data format: " + std::to_string(hr));
}
} else {
}
else
{
MessageManager::Log("[DInput] Failed to create directinput device" + std::to_string(hr));
}
}
@ -280,7 +333,8 @@ int DirectInputManager::EnumObjectsCallback(const DIDEVICEOBJECTINSTANCE* pdidoi
LPDIRECTINPUTDEVICE8 joystick = (LPDIRECTINPUTDEVICE8)pContext;
// For axes that are returned, set the DIPROP_RANGE property for the enumerated axis in order to scale min/max values.
if(pdidoi->dwType & DIDFT_AXIS) {
if (pdidoi->dwType & DIDFT_AXIS)
{
DIPROPRANGE diprg;
diprg.diph.dwSize = sizeof(DIPROPRANGE);
diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER);
@ -290,7 +344,8 @@ int DirectInputManager::EnumObjectsCallback(const DIDEVICEOBJECTINSTANCE* pdidoi
diprg.lMax = +1000;
// Set the range for the axis
if(FAILED(joystick->SetProperty(DIPROP_RANGE, &diprg.diph))) {
if (FAILED(joystick->SetProperty(DIPROP_RANGE, &diprg.diph)))
{
return DIENUM_STOP;
}
}
@ -301,25 +356,32 @@ int DirectInputManager::EnumObjectsCallback(const DIDEVICEOBJECTINSTANCE* pdidoi
void DirectInputManager::RefreshState()
{
if(_needToUpdate) {
if (_needToUpdate)
{
vector<DirectInputData> joysticks;
//Keep exisiting joysticks, if they still work, otherwise remove them from the list
for(DirectInputData &joystick : _joysticks) {
if(joystick.stateValid) {
for (DirectInputData& joystick : _joysticks)
{
if (joystick.stateValid)
{
joysticks.push_back(joystick);
} else {
}
else
{
MessageManager::Log("[DInput] Device lost, trying to reacquire...");
//Release the joystick, we'll try to initialize it again if it still exists
const GUID* deviceGuid = &joystick.instanceInfo.guidInstance;
auto comp = [=](GUID guid) {
auto comp = [=](GUID guid)
{
return guid.Data1 == deviceGuid->Data1 &&
guid.Data2 == deviceGuid->Data2 &&
guid.Data3 == deviceGuid->Data3 &&
memcmp(guid.Data4, deviceGuid->Data4, sizeof(guid.Data4)) == 0;
};
_processedGuids.erase(std::remove_if(_processedGuids.begin(), _processedGuids.end(), comp), _processedGuids.end());
_processedGuids.erase(std::remove_if(_processedGuids.begin(), _processedGuids.end(), comp),
_processedGuids.end());
joystick.joystick->Unacquire();
joystick.joystick->Release();
@ -327,7 +389,8 @@ void DirectInputManager::RefreshState()
}
//Add the newly-found joysticks
for(DirectInputData &joystick : _joysticksToAdd) {
for (DirectInputData& joystick : _joysticksToAdd)
{
joysticks.push_back(joystick);
}
@ -336,7 +399,8 @@ void DirectInputManager::RefreshState()
_needToUpdate = false;
}
for(DirectInputData &joystick : _joysticks) {
for (DirectInputData& joystick : _joysticks)
{
UpdateInputState(joystick);
}
}
@ -348,7 +412,8 @@ int DirectInputManager::GetJoystickCount()
bool DirectInputManager::IsPressed(int port, int button)
{
if(port >= (int)_joysticks.size() || !_joysticks[port].stateValid) {
if (port >= (int)_joysticks.size() || !_joysticks[port].stateValid)
{
return false;
}
@ -359,7 +424,8 @@ bool DirectInputManager::IsPressed(int port, int button)
int povDirection = state.rgdwPOV[0] / 4500;
bool povCentered = (LOWORD(state.rgdwPOV[0]) == 0xFFFF) || povDirection >= 8;
switch(button) {
switch (button)
{
case 0x00: return state.lY - defaultState.lY < -deadRange;
case 0x01: return state.lY - defaultState.lY > deadRange;
case 0x02: return state.lX - defaultState.lX < -deadRange;
@ -389,17 +455,20 @@ void DirectInputManager::UpdateInputState(DirectInputData &data)
// Poll the device to read the current state
hr = data.joystick->Poll();
if(FAILED(hr)) {
if (FAILED(hr))
{
// DInput is telling us that the input stream has been interrupted. We aren't tracking any state between polls, so
// we don't have any special reset that needs to be done. We just re-acquire and try again.
hr = data.joystick->Acquire();
while(hr == DIERR_INPUTLOST) {
while (hr == DIERR_INPUTLOST)
{
hr = data.joystick->Acquire();
}
// hr may be DIERR_OTHERAPPHASPRIO or other errors. This may occur when the app is minimized or in the process of
// switching, so just try again later
if(FAILED(hr)) {
if (FAILED(hr))
{
data.stateValid = false;
_requestUpdate = true;
return;
@ -407,7 +476,8 @@ void DirectInputManager::UpdateInputState(DirectInputData &data)
}
// Get the input's device state
if(FAILED(hr = data.joystick->GetDeviceState(sizeof(DIJOYSTATE2), &newState))) {
if (FAILED(hr = data.joystick->GetDeviceState(sizeof(DIJOYSTATE2), &newState)))
{
MessageManager::Log("[DInput] Failed to get device state: " + std::to_string(hr));
data.stateValid = false;
_requestUpdate = true;
@ -428,7 +498,8 @@ DirectInputManager::DirectInputManager(shared_ptr<Console> console, HWND hWnd)
DirectInputManager::~DirectInputManager()
{
for(DirectInputData &data: _joysticks) {
for (DirectInputData& data : _joysticks)
{
data.joystick->Unacquire();
data.joystick->Release();
}
@ -439,7 +510,8 @@ DirectInputManager::~DirectInputManager()
_processedGuids.clear();
_xinputDeviceGuids.clear();
if(_directInput) {
if (_directInput)
{
_directInput->Release();
_directInput = nullptr;
}

View file

@ -159,7 +159,10 @@ namespace DirectX
AudioEngine_DisableVoiceReuse = 0x40000,
};
inline AUDIO_ENGINE_FLAGS operator|(AUDIO_ENGINE_FLAGS a, AUDIO_ENGINE_FLAGS b) { return static_cast<AUDIO_ENGINE_FLAGS>( static_cast<int>(a) | static_cast<int>(b) ); }
inline AUDIO_ENGINE_FLAGS operator|(AUDIO_ENGINE_FLAGS a, AUDIO_ENGINE_FLAGS b)
{
return static_cast<AUDIO_ENGINE_FLAGS>(static_cast<int>(a) | static_cast<int>(b));
}
enum SOUND_EFFECT_INSTANCE_FLAGS
{
@ -172,7 +175,10 @@ namespace DirectX
SoundEffectInstance_UseRedirectLFE = 0x10000,
};
inline SOUND_EFFECT_INSTANCE_FLAGS operator|(SOUND_EFFECT_INSTANCE_FLAGS a, SOUND_EFFECT_INSTANCE_FLAGS b) { return static_cast<SOUND_EFFECT_INSTANCE_FLAGS>( static_cast<int>(a) | static_cast<int>(b) ); }
inline SOUND_EFFECT_INSTANCE_FLAGS operator|(SOUND_EFFECT_INSTANCE_FLAGS a, SOUND_EFFECT_INSTANCE_FLAGS b)
{
return static_cast<SOUND_EFFECT_INSTANCE_FLAGS>(static_cast<int>(a) | static_cast<int>(b));
}
enum AUDIO_ENGINE_REVERB
{
@ -222,7 +228,8 @@ namespace DirectX
class AudioEngine
{
public:
explicit AudioEngine( AUDIO_ENGINE_FLAGS flags = AudioEngine_Default, _In_opt_ const WAVEFORMATEX* wfx = nullptr, _In_opt_z_ const wchar_t* deviceId = nullptr,
explicit AudioEngine(AUDIO_ENGINE_FLAGS flags = AudioEngine_Default, _In_opt_ const WAVEFORMATEX* wfx = nullptr,
_In_opt_z_ const wchar_t* deviceId = nullptr,
AUDIO_STREAM_CATEGORY category = AudioCategory_GameEffects);
AudioEngine(AudioEngine&& moveFrom);
@ -282,7 +289,8 @@ namespace DirectX
// Releases any currently unused voices
// Internal-use functions
void __cdecl AllocateVoice( _In_ const WAVEFORMATEX* wfx, SOUND_EFFECT_INSTANCE_FLAGS flags, bool oneshot, _Outptr_result_maybenull_ IXAudio2SourceVoice** voice );
void __cdecl AllocateVoice(_In_ const WAVEFORMATEX* wfx, SOUND_EFFECT_INSTANCE_FLAGS flags, bool oneshot,
_Outptr_result_maybenull_ IXAudio2SourceVoice** voice);
void __cdecl DestroyVoice(_In_ IXAudio2SourceVoice* voice);
// Should only be called for instance voices, not one-shots
@ -333,8 +341,10 @@ namespace DirectX
void __cdecl Play(_In_z_ const char* name);
void __cdecl Play(_In_z_ const char* name, float volume, float pitch, float pan);
std::unique_ptr<SoundEffectInstance> __cdecl CreateInstance( int index, SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default );
std::unique_ptr<SoundEffectInstance> __cdecl CreateInstance( _In_z_ const char* name, SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default );
std::unique_ptr<SoundEffectInstance> __cdecl CreateInstance(
int index, SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default);
std::unique_ptr<SoundEffectInstance> __cdecl CreateInstance(
_In_z_ const char* name, SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default);
bool __cdecl IsPrepared() const;
bool __cdecl IsInUse() const;
@ -349,7 +359,8 @@ namespace DirectX
size_t __cdecl GetSampleDurationMS(int index) const;
// Returns the duration in milliseconds
const WAVEFORMATEX* __cdecl GetFormat( int index, _Out_writes_bytes_(maxsize) WAVEFORMATEX* wfx, size_t maxsize ) const;
const WAVEFORMATEX* __cdecl GetFormat(int index, _Out_writes_bytes_(maxsize) WAVEFORMATEX* wfx,
size_t maxsize) const;
int __cdecl Find(_In_z_ const char* name) const;
@ -383,16 +394,19 @@ namespace DirectX
SoundEffect(_In_ AudioEngine* engine, _In_z_ const wchar_t* waveFileName);
SoundEffect(_In_ AudioEngine* engine, _Inout_ std::unique_ptr<uint8_t[]>& wavData,
_In_ const WAVEFORMATEX* wfx, _In_reads_bytes_(audioBytes) const uint8_t* startAudio, size_t audioBytes );
_In_ const WAVEFORMATEX* wfx, _In_reads_bytes_(audioBytes) const uint8_t* startAudio,
size_t audioBytes);
SoundEffect(_In_ AudioEngine* engine, _Inout_ std::unique_ptr<uint8_t[]>& wavData,
_In_ const WAVEFORMATEX* wfx, _In_reads_bytes_(audioBytes) const uint8_t* startAudio, size_t audioBytes,
_In_ const WAVEFORMATEX* wfx, _In_reads_bytes_(audioBytes) const uint8_t* startAudio,
size_t audioBytes,
uint32_t loopStart, uint32_t loopLength);
#if defined(_XBOX_ONE) || (_WIN32_WINNT < _WIN32_WINNT_WIN8) || (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/)
SoundEffect(_In_ AudioEngine* engine, _Inout_ std::unique_ptr<uint8_t[]>& wavData,
_In_ const WAVEFORMATEX* wfx, _In_reads_bytes_(audioBytes) const uint8_t* startAudio, size_t audioBytes,
_In_ const WAVEFORMATEX* wfx, _In_reads_bytes_(audioBytes) const uint8_t* startAudio,
size_t audioBytes,
_In_reads_(seekCount) const uint32_t* seekTable, size_t seekCount);
#endif
@ -404,7 +418,8 @@ namespace DirectX
void __cdecl Play();
void __cdecl Play(float volume, float pitch, float pan);
std::unique_ptr<SoundEffectInstance> __cdecl CreateInstance( SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default );
std::unique_ptr<SoundEffectInstance> __cdecl CreateInstance(
SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default);
bool __cdecl IsInUse() const;
@ -458,6 +473,7 @@ namespace DirectX
{
XMStoreFloat3(reinterpret_cast<XMFLOAT3*>(&Position), v);
}
void __cdecl SetPosition(const XMFLOAT3& pos)
{
Position.x = pos.x;
@ -469,6 +485,7 @@ namespace DirectX
{
XMStoreFloat3(reinterpret_cast<XMFLOAT3*>(&Velocity), v);
}
void __cdecl SetVelocity(const XMFLOAT3& vel)
{
Velocity.x = vel.x;
@ -481,11 +498,15 @@ namespace DirectX
XMStoreFloat3(reinterpret_cast<XMFLOAT3*>(&OrientFront), forward);
XMStoreFloat3(reinterpret_cast<XMFLOAT3*>(&OrientTop), up);
}
void __cdecl SetOrientation(const XMFLOAT3& forward, const XMFLOAT3& up)
{
OrientFront.x = forward.x; OrientTop.x = up.x;
OrientFront.y = forward.y; OrientTop.y = up.y;
OrientFront.z = forward.z; OrientTop.z = up.z;
OrientFront.x = forward.x;
OrientTop.x = up.x;
OrientFront.y = forward.y;
OrientTop.y = up.y;
OrientFront.z = forward.z;
OrientTop.z = up.z;
}
void XM_CALLCONV SetOrientationFromQuaternion(FXMVECTOR quat)
@ -551,6 +572,7 @@ namespace DirectX
{
XMStoreFloat3(reinterpret_cast<XMFLOAT3*>(&Position), v);
}
void __cdecl SetPosition(const XMFLOAT3& pos)
{
Position.x = pos.x;
@ -562,6 +584,7 @@ namespace DirectX
{
XMStoreFloat3(reinterpret_cast<XMFLOAT3*>(&Velocity), v);
}
void __cdecl SetVelocity(const XMFLOAT3& vel)
{
Velocity.x = vel.x;
@ -574,11 +597,15 @@ namespace DirectX
XMStoreFloat3(reinterpret_cast<XMFLOAT3*>(&OrientFront), forward);
XMStoreFloat3(reinterpret_cast<XMFLOAT3*>(&OrientTop), up);
}
void __cdecl SetOrientation(const XMFLOAT3& forward, const XMFLOAT3& up)
{
OrientFront.x = forward.x; OrientTop.x = up.x;
OrientFront.y = forward.y; OrientTop.y = up.y;
OrientFront.z = forward.z; OrientTop.z = up.z;
OrientFront.x = forward.x;
OrientTop.x = up.x;
OrientFront.y = forward.y;
OrientTop.y = up.y;
OrientFront.z = forward.z;
OrientTop.z = up.z;
}
void XM_CALLCONV SetOrientationFromQuaternion(FXMVECTOR quat)
@ -651,7 +678,8 @@ namespace DirectX
// Private constructors
SoundEffectInstance(_In_ AudioEngine* engine, _In_ SoundEffect* effect, SOUND_EFFECT_INSTANCE_FLAGS flags);
SoundEffectInstance( _In_ AudioEngine* engine, _In_ WaveBank* effect, int index, SOUND_EFFECT_INSTANCE_FLAGS flags );
SoundEffectInstance(_In_ AudioEngine* engine, _In_ WaveBank* effect, int index,
SOUND_EFFECT_INSTANCE_FLAGS flags);
friend std::unique_ptr<SoundEffectInstance> __cdecl SoundEffect::CreateInstance(SOUND_EFFECT_INSTANCE_FLAGS);
friend std::unique_ptr<SoundEffectInstance> __cdecl WaveBank::CreateInstance(int, SOUND_EFFECT_INSTANCE_FLAGS);
@ -667,7 +695,8 @@ namespace DirectX
{
public:
DynamicSoundEffectInstance(_In_ AudioEngine* engine,
_In_opt_ std::function<void DIRECTX_STD_CALLCONV(DynamicSoundEffectInstance*)> bufferNeeded,
_In_opt_ std::function<void DIRECTX_STD_CALLCONV(DynamicSoundEffectInstance*)>
bufferNeeded,
int sampleRate, int channels, int sampleBits = 16,
SOUND_EFFECT_INSTANCE_FLAGS flags = SoundEffectInstance_Default);
DynamicSoundEffectInstance(DynamicSoundEffectInstance&& moveFrom);
@ -686,7 +715,8 @@ namespace DirectX
void __cdecl Apply3D(const AudioListener& listener, const AudioEmitter& emitter, bool rhcoords = true);
void __cdecl SubmitBuffer(_In_reads_bytes_(audioBytes) const uint8_t* pAudioData, size_t audioBytes);
void __cdecl SubmitBuffer( _In_reads_bytes_(audioBytes) const uint8_t* pAudioData, uint32_t offset, size_t audioBytes );
void __cdecl SubmitBuffer(_In_reads_bytes_(audioBytes) const uint8_t* pAudioData, uint32_t offset,
size_t audioBytes);
SoundState __cdecl GetState();

View file

@ -83,6 +83,7 @@ namespace DirectX
{
return reinterpret_cast<uint8_t*>(pData);
}
uint8_t* get(size_t slice) const
{
return reinterpret_cast<uint8_t*>(pData) + (slice * DepthPitch);
@ -92,6 +93,7 @@ namespace DirectX
{
return reinterpret_cast<uint8_t*>(pData) + (row * RowPitch);
}
uint8_t* scanline(size_t slice, size_t row) const
{
return reinterpret_cast<uint8_t*>(pData) + (slice * DepthPitch) + (row * RowPitch);

View file

@ -50,11 +50,14 @@ namespace DirectX
class IEffect
{
public:
virtual ~IEffect() { }
virtual ~IEffect()
{
}
virtual void __cdecl Apply(_In_ ID3D11DeviceContext* deviceContext) = 0;
virtual void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) = 0;
virtual void __cdecl GetVertexShaderBytecode(_Out_ void const** pShaderByteCode, _Out_ size_t* pByteCodeLength) =
0;
};
@ -62,7 +65,9 @@ namespace DirectX
class IEffectMatrices
{
public:
virtual ~IEffectMatrices() { }
virtual ~IEffectMatrices()
{
}
virtual void XM_CALLCONV SetWorld(FXMMATRIX value) = 0;
virtual void XM_CALLCONV SetView(FXMMATRIX value) = 0;
@ -74,7 +79,9 @@ namespace DirectX
class IEffectLights
{
public:
virtual ~IEffectLights() { }
virtual ~IEffectLights()
{
}
virtual void __cdecl SetLightingEnabled(bool value) = 0;
virtual void __cdecl SetPerPixelLighting(bool value) = 0;
@ -95,7 +102,9 @@ namespace DirectX
class IEffectFog
{
public:
virtual ~IEffectFog() { }
virtual ~IEffectFog()
{
}
virtual void __cdecl SetFogEnabled(bool value) = 0;
virtual void __cdecl SetFogStart(float value) = 0;
@ -108,7 +117,9 @@ namespace DirectX
class IEffectSkinning
{
public:
virtual ~IEffectSkinning() { }
virtual ~IEffectSkinning()
{
}
virtual void __cdecl SetWeightsPerVertex(int value) = 0;
virtual void __cdecl SetBoneTransforms(_In_reads_(count) XMMATRIX const* value, size_t count) = 0;
@ -183,7 +194,6 @@ namespace DirectX
};
// Built-in shader supports per-pixel alpha testing.
class AlphaTestEffect : public IEffect, public IEffectMatrices, public IEffectFog
{
@ -235,7 +245,6 @@ namespace DirectX
};
// Built-in shader supports two layer multitexturing (eg. for lightmaps or detail textures).
class DualTextureEffect : public IEffect, public IEffectMatrices, public IEffectFog
{
@ -284,7 +293,6 @@ namespace DirectX
};
// Built-in shader supports cubic environment mapping.
class EnvironmentMapEffect : public IEffect, public IEffectMatrices, public IEffectLights, public IEffectFog
{
@ -350,9 +358,9 @@ namespace DirectX
};
// Built-in shader supports skinned animation.
class SkinnedEffect : public IEffect, public IEffectMatrices, public IEffectLights, public IEffectFog, public IEffectSkinning
class SkinnedEffect : public IEffect, public IEffectMatrices, public IEffectLights, public IEffectFog,
public IEffectSkinning
{
public:
explicit SkinnedEffect(_In_ ID3D11Device* device);
@ -418,7 +426,6 @@ namespace DirectX
};
//----------------------------------------------------------------------------------
// Built-in effect for Visual Studio Shader Designer (DGSL) shaders
class DGSLEffect : public IEffect, public IEffectMatrices, public IEffectLights, public IEffectSkinning
@ -499,13 +506,14 @@ namespace DirectX
};
//----------------------------------------------------------------------------------
// Abstract interface to factory for sharing effects and texture resources
class IEffectFactory
{
public:
virtual ~IEffectFactory() {}
virtual ~IEffectFactory()
{
}
struct EffectInfo
{
@ -525,9 +533,11 @@ namespace DirectX
EffectInfo() { memset(this, 0, sizeof(EffectInfo)); };
};
virtual std::shared_ptr<IEffect> __cdecl CreateEffect( _In_ const EffectInfo& info, _In_opt_ ID3D11DeviceContext* deviceContext ) = 0;
virtual std::shared_ptr<IEffect> __cdecl CreateEffect(_In_ const EffectInfo& info,
_In_opt_ ID3D11DeviceContext* deviceContext) = 0;
virtual void __cdecl CreateTexture( _In_z_ const WCHAR* name, _In_opt_ ID3D11DeviceContext* deviceContext, _Outptr_ ID3D11ShaderResourceView** textureView ) = 0;
virtual void __cdecl CreateTexture(_In_z_ const WCHAR* name, _In_opt_ ID3D11DeviceContext* deviceContext,
_Outptr_ ID3D11ShaderResourceView** textureView) = 0;
};
@ -541,8 +551,10 @@ namespace DirectX
virtual ~EffectFactory();
// IEffectFactory methods.
virtual std::shared_ptr<IEffect> __cdecl CreateEffect( _In_ const EffectInfo& info, _In_opt_ ID3D11DeviceContext* deviceContext ) override;
virtual void __cdecl CreateTexture( _In_z_ const WCHAR* name, _In_opt_ ID3D11DeviceContext* deviceContext, _Outptr_ ID3D11ShaderResourceView** textureView ) override;
virtual std::shared_ptr<IEffect> __cdecl CreateEffect(_In_ const EffectInfo& info,
_In_opt_ ID3D11DeviceContext* deviceContext) override;
virtual void __cdecl CreateTexture(_In_z_ const WCHAR* name, _In_opt_ ID3D11DeviceContext* deviceContext,
_Outptr_ ID3D11ShaderResourceView** textureView) override;
// Settings.
void __cdecl ReleaseCache();
@ -573,8 +585,10 @@ namespace DirectX
virtual ~DGSLEffectFactory();
// IEffectFactory methods.
virtual std::shared_ptr<IEffect> __cdecl CreateEffect( _In_ const EffectInfo& info, _In_opt_ ID3D11DeviceContext* deviceContext ) override;
virtual void __cdecl CreateTexture( _In_z_ const WCHAR* name, _In_opt_ ID3D11DeviceContext* deviceContext, _Outptr_ ID3D11ShaderResourceView** textureView ) override;
virtual std::shared_ptr<IEffect> __cdecl CreateEffect(_In_ const EffectInfo& info,
_In_opt_ ID3D11DeviceContext* deviceContext) override;
virtual void __cdecl CreateTexture(_In_z_ const WCHAR* name, _In_opt_ ID3D11DeviceContext* deviceContext,
_Outptr_ ID3D11ShaderResourceView** textureView) override;
// DGSL methods.
struct DGSLEffectInfo : public EffectInfo
@ -585,7 +599,8 @@ namespace DirectX
DGSLEffectInfo() { memset(this, 0, sizeof(DGSLEffectInfo)); };
};
virtual std::shared_ptr<IEffect> __cdecl CreateDGSLEffect( _In_ const DGSLEffectInfo& info, _In_opt_ ID3D11DeviceContext* deviceContext );
virtual std::shared_ptr<IEffect> __cdecl CreateDGSLEffect(_In_ const DGSLEffectInfo& info,
_In_opt_ ID3D11DeviceContext* deviceContext);
virtual void __cdecl CreatePixelShader(_In_z_ const WCHAR* shader, _Outptr_ ID3D11PixelShader** pixelShader);
@ -606,7 +621,6 @@ namespace DirectX
DGSLEffectFactory(DGSLEffectFactory const&) DIRECTX_CTOR_DELETE
DGSLEffectFactory& operator=(DGSLEffectFactory const&) DIRECTX_CTOR_DELETE
};
}
#pragma warning(pop)

View file

@ -57,39 +57,78 @@ namespace DirectX
virtual ~GeometricPrimitive();
// Factory methods.
static std::unique_ptr<GeometricPrimitive> __cdecl CreateCube (_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateBox (_In_ ID3D11DeviceContext* deviceContext, const XMFLOAT3& size, bool rhcoords = true, bool invertn = false);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateSphere (_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, size_t tessellation = 16, bool rhcoords = true, bool invertn = false);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateGeoSphere (_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, size_t tessellation = 3, bool rhcoords = true);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateCylinder (_In_ ID3D11DeviceContext* deviceContext, float height = 1, float diameter = 1, size_t tessellation = 32, bool rhcoords = true);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateCone (_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, float height = 1, size_t tessellation = 32, bool rhcoords = true);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateTorus (_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, float thickness = 0.333f, size_t tessellation = 32, bool rhcoords = true);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateTetrahedron (_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateOctahedron (_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateDodecahedron (_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateIcosahedron (_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateTeapot (_In_ ID3D11DeviceContext* deviceContext, float size = 1, size_t tessellation = 8, bool rhcoords = true);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateCustom (_In_ ID3D11DeviceContext* deviceContext, const std::vector<VertexPositionNormalTexture>& vertices, const std::vector<uint16_t>& indices);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateCube(
_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateBox(_In_ ID3D11DeviceContext* deviceContext,
const XMFLOAT3& size, bool rhcoords = true,
bool invertn = false);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateSphere(
_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, size_t tessellation = 16, bool rhcoords = true,
bool invertn = false);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateGeoSphere(
_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, size_t tessellation = 3, bool rhcoords = true);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateCylinder(
_In_ ID3D11DeviceContext* deviceContext, float height = 1, float diameter = 1, size_t tessellation = 32,
bool rhcoords = true);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateCone(
_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, float height = 1, size_t tessellation = 32,
bool rhcoords = true);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateTorus(
_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, float thickness = 0.333f,
size_t tessellation = 32, bool rhcoords = true);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateTetrahedron(
_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateOctahedron(
_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateDodecahedron(
_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateIcosahedron(
_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateTeapot(
_In_ ID3D11DeviceContext* deviceContext, float size = 1, size_t tessellation = 8, bool rhcoords = true);
static std::unique_ptr<GeometricPrimitive> __cdecl CreateCustom(
_In_ ID3D11DeviceContext* deviceContext, const std::vector<VertexPositionNormalTexture>& vertices,
const std::vector<uint16_t>& indices);
static void __cdecl CreateCube (std::vector<VertexPositionNormalTexture>& vertices, std::vector<uint16_t>& indices, float size = 1, bool rhcoords = true);
static void __cdecl CreateBox (std::vector<VertexPositionNormalTexture>& vertices, std::vector<uint16_t>& indices, const XMFLOAT3& size, bool rhcoords = true, bool invertn = false);
static void __cdecl CreateSphere (std::vector<VertexPositionNormalTexture>& vertices, std::vector<uint16_t>& indices, float diameter = 1, size_t tessellation = 16, bool rhcoords = true, bool invertn = false);
static void __cdecl CreateGeoSphere (std::vector<VertexPositionNormalTexture>& vertices, std::vector<uint16_t>& indices, float diameter = 1, size_t tessellation = 3, bool rhcoords = true);
static void __cdecl CreateCylinder (std::vector<VertexPositionNormalTexture>& vertices, std::vector<uint16_t>& indices, float height = 1, float diameter = 1, size_t tessellation = 32, bool rhcoords = true);
static void __cdecl CreateCone (std::vector<VertexPositionNormalTexture>& vertices, std::vector<uint16_t>& indices, float diameter = 1, float height = 1, size_t tessellation = 32, bool rhcoords = true);
static void __cdecl CreateTorus (std::vector<VertexPositionNormalTexture>& vertices, std::vector<uint16_t>& indices, float diameter = 1, float thickness = 0.333f, size_t tessellation = 32, bool rhcoords = true);
static void __cdecl CreateTetrahedron (std::vector<VertexPositionNormalTexture>& vertices, std::vector<uint16_t>& indices, float size = 1, bool rhcoords = true);
static void __cdecl CreateOctahedron (std::vector<VertexPositionNormalTexture>& vertices, std::vector<uint16_t>& indices, float size = 1, bool rhcoords = true);
static void __cdecl CreateDodecahedron (std::vector<VertexPositionNormalTexture>& vertices, std::vector<uint16_t>& indices, float size = 1, bool rhcoords = true);
static void __cdecl CreateIcosahedron (std::vector<VertexPositionNormalTexture>& vertices, std::vector<uint16_t>& indices, float size = 1, bool rhcoords = true);
static void __cdecl CreateTeapot (std::vector<VertexPositionNormalTexture>& vertices, std::vector<uint16_t>& indices, float size = 1, size_t tessellation = 8, bool rhcoords = true);
static void __cdecl CreateCube(std::vector<VertexPositionNormalTexture>& vertices, std::vector<uint16_t>& indices,
float size = 1, bool rhcoords = true);
static void __cdecl CreateBox(std::vector<VertexPositionNormalTexture>& vertices, std::vector<uint16_t>& indices,
const XMFLOAT3& size, bool rhcoords = true, bool invertn = false);
static void __cdecl CreateSphere(std::vector<VertexPositionNormalTexture>& vertices,
std::vector<uint16_t>& indices, float diameter = 1, size_t tessellation = 16,
bool rhcoords = true, bool invertn = false);
static void __cdecl CreateGeoSphere(std::vector<VertexPositionNormalTexture>& vertices,
std::vector<uint16_t>& indices, float diameter = 1, size_t tessellation = 3,
bool rhcoords = true);
static void __cdecl CreateCylinder(std::vector<VertexPositionNormalTexture>& vertices,
std::vector<uint16_t>& indices, float height = 1, float diameter = 1,
size_t tessellation = 32, bool rhcoords = true);
static void __cdecl CreateCone(std::vector<VertexPositionNormalTexture>& vertices, std::vector<uint16_t>& indices,
float diameter = 1, float height = 1, size_t tessellation = 32,
bool rhcoords = true);
static void __cdecl CreateTorus(std::vector<VertexPositionNormalTexture>& vertices,
std::vector<uint16_t>& indices, float diameter = 1, float thickness = 0.333f,
size_t tessellation = 32, bool rhcoords = true);
static void __cdecl CreateTetrahedron(std::vector<VertexPositionNormalTexture>& vertices,
std::vector<uint16_t>& indices, float size = 1, bool rhcoords = true);
static void __cdecl CreateOctahedron(std::vector<VertexPositionNormalTexture>& vertices,
std::vector<uint16_t>& indices, float size = 1, bool rhcoords = true);
static void __cdecl CreateDodecahedron(std::vector<VertexPositionNormalTexture>& vertices,
std::vector<uint16_t>& indices, float size = 1, bool rhcoords = true);
static void __cdecl CreateIcosahedron(std::vector<VertexPositionNormalTexture>& vertices,
std::vector<uint16_t>& indices, float size = 1, bool rhcoords = true);
static void __cdecl CreateTeapot(std::vector<VertexPositionNormalTexture>& vertices,
std::vector<uint16_t>& indices, float size = 1, size_t tessellation = 8,
bool rhcoords = true);
// Draw the primitive.
void XM_CALLCONV Draw(FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection, FXMVECTOR color = Colors::White, _In_opt_ ID3D11ShaderResourceView* texture = nullptr, bool wireframe = false,
void XM_CALLCONV Draw(FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection, FXMVECTOR color = Colors::White,
_In_opt_ ID3D11ShaderResourceView* texture = nullptr, bool wireframe = false,
_In_opt_ std::function<void DIRECTX_STD_CALLCONV()> setCustomState = nullptr);
// Draw the primitive using a custom effect.
void __cdecl Draw( _In_ IEffect* effect, _In_ ID3D11InputLayout* inputLayout, bool alpha = false, bool wireframe = false,
void __cdecl Draw(_In_ IEffect* effect, _In_ ID3D11InputLayout* inputLayout, bool alpha = false,
bool wireframe = false,
_In_opt_ std::function<void DIRECTX_STD_CALLCONV()> setCustomState = nullptr);
// Create input layout for drawing with a custom effect.

View file

@ -82,14 +82,17 @@ namespace DirectX
typedef std::vector<std::unique_ptr<ModelMeshPart>> Collection;
// Draw mesh part with custom effect
void __cdecl Draw( _In_ ID3D11DeviceContext* deviceContext, _In_ IEffect* ieffect, _In_ ID3D11InputLayout* iinputLayout,
void __cdecl Draw(_In_ ID3D11DeviceContext* deviceContext, _In_ IEffect* ieffect,
_In_ ID3D11InputLayout* iinputLayout,
_In_opt_ std::function<void DIRECTX_STD_CALLCONV()> setCustomState = nullptr) const;
// Create input layout for drawing with a custom effect.
void __cdecl CreateInputLayout( _In_ ID3D11Device* d3dDevice, _In_ IEffect* ieffect, _Outptr_ ID3D11InputLayout** iinputLayout );
void __cdecl CreateInputLayout(_In_ ID3D11Device* d3dDevice, _In_ IEffect* ieffect,
_Outptr_ ID3D11InputLayout** iinputLayout);
// Change effect used by part and regenerate input layout (be sure to call Model::Modified as well)
void __cdecl ModifyEffect( _In_ ID3D11Device* d3dDevice, _In_ std::shared_ptr<IEffect>& ieffect, bool isalpha = false );
void __cdecl ModifyEffect(_In_ ID3D11Device* d3dDevice, _In_ std::shared_ptr<IEffect>& ieffect,
bool isalpha = false);
};
@ -111,11 +114,14 @@ namespace DirectX
typedef std::vector<std::shared_ptr<ModelMesh>> Collection;
// Setup states for drawing mesh
void __cdecl PrepareForRendering( _In_ ID3D11DeviceContext* deviceContext, CommonStates& states, bool alpha = false, bool wireframe = false ) const;
void __cdecl PrepareForRendering(_In_ ID3D11DeviceContext* deviceContext, CommonStates& states,
bool alpha = false, bool wireframe = false) const;
// Draw the mesh
void XM_CALLCONV Draw( _In_ ID3D11DeviceContext* deviceContext, FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection,
bool alpha = false, _In_opt_ std::function<void DIRECTX_STD_CALLCONV()> setCustomState = nullptr ) const;
void XM_CALLCONV Draw(_In_ ID3D11DeviceContext* deviceContext, FXMMATRIX world, CXMMATRIX view,
CXMMATRIX projection,
bool alpha = false,
_In_opt_ std::function<void DIRECTX_STD_CALLCONV()> setCustomState = nullptr) const;
};
@ -130,8 +136,10 @@ namespace DirectX
std::wstring name;
// Draw all the meshes in the model
void XM_CALLCONV Draw( _In_ ID3D11DeviceContext* deviceContext, CommonStates& states, FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection,
bool wireframe = false, _In_opt_ std::function<void DIRECTX_STD_CALLCONV()> setCustomState = nullptr ) const;
void XM_CALLCONV Draw(_In_ ID3D11DeviceContext* deviceContext, CommonStates& states, FXMMATRIX world,
CXMMATRIX view, CXMMATRIX projection,
bool wireframe = false,
_In_opt_ std::function<void DIRECTX_STD_CALLCONV()> setCustomState = nullptr) const;
// Notify model that effects, parts list, or mesh list has changed
void __cdecl Modified() { mEffectCache.clear(); }
@ -140,22 +148,37 @@ namespace DirectX
void __cdecl UpdateEffects(_In_ std::function<void DIRECTX_STD_CALLCONV(IEffect*)> setEffect);
// Loads a model from a Visual Studio Starter Kit .CMO file
static std::unique_ptr<Model> __cdecl CreateFromCMO( _In_ ID3D11Device* d3dDevice, _In_reads_bytes_(dataSize) const uint8_t* meshData, size_t dataSize,
_In_ IEffectFactory& fxFactory, bool ccw = true, bool pmalpha = false );
static std::unique_ptr<Model> __cdecl CreateFromCMO( _In_ ID3D11Device* d3dDevice, _In_z_ const wchar_t* szFileName,
_In_ IEffectFactory& fxFactory, bool ccw = true, bool pmalpha = false );
static std::unique_ptr<Model> __cdecl CreateFromCMO(_In_ ID3D11Device* d3dDevice,
_In_reads_bytes_(dataSize) const uint8_t* meshData,
size_t dataSize,
_In_ IEffectFactory& fxFactory, bool ccw = true,
bool pmalpha = false);
static std::unique_ptr<Model> __cdecl CreateFromCMO(_In_ ID3D11Device* d3dDevice,
_In_z_ const wchar_t* szFileName,
_In_ IEffectFactory& fxFactory, bool ccw = true,
bool pmalpha = false);
// Loads a model from a DirectX SDK .SDKMESH file
static std::unique_ptr<Model> __cdecl CreateFromSDKMESH( _In_ ID3D11Device* d3dDevice, _In_reads_bytes_(dataSize) const uint8_t* meshData, _In_ size_t dataSize,
_In_ IEffectFactory& fxFactory, bool ccw = false, bool pmalpha = false );
static std::unique_ptr<Model> __cdecl CreateFromSDKMESH( _In_ ID3D11Device* d3dDevice, _In_z_ const wchar_t* szFileName,
_In_ IEffectFactory& fxFactory, bool ccw = false, bool pmalpha = false );
static std::unique_ptr<Model> __cdecl CreateFromSDKMESH(_In_ ID3D11Device* d3dDevice,
_In_reads_bytes_(dataSize) const uint8_t* meshData,
_In_ size_t dataSize,
_In_ IEffectFactory& fxFactory, bool ccw = false,
bool pmalpha = false);
static std::unique_ptr<Model> __cdecl CreateFromSDKMESH(_In_ ID3D11Device* d3dDevice,
_In_z_ const wchar_t* szFileName,
_In_ IEffectFactory& fxFactory, bool ccw = false,
bool pmalpha = false);
// Loads a model from a .VBO file
static std::unique_ptr<Model> __cdecl CreateFromVBO( _In_ ID3D11Device* d3dDevice, _In_reads_bytes_(dataSize) const uint8_t* meshData, _In_ size_t dataSize,
_In_opt_ std::shared_ptr<IEffect> ieffect = nullptr, bool ccw = false, bool pmalpha = false );
static std::unique_ptr<Model> __cdecl CreateFromVBO( _In_ ID3D11Device* d3dDevice, _In_z_ const wchar_t* szFileName,
_In_opt_ std::shared_ptr<IEffect> ieffect = nullptr, bool ccw = false, bool pmalpha = false );
static std::unique_ptr<Model> __cdecl CreateFromVBO(_In_ ID3D11Device* d3dDevice,
_In_reads_bytes_(dataSize) const uint8_t* meshData,
_In_ size_t dataSize,
_In_opt_ std::shared_ptr<IEffect> ieffect = nullptr,
bool ccw = false, bool pmalpha = false);
static std::unique_ptr<Model> __cdecl CreateFromVBO(_In_ ID3D11Device* d3dDevice,
_In_z_ const wchar_t* szFileName,
_In_opt_ std::shared_ptr<IEffect> ieffect = nullptr,
bool ccw = false, bool pmalpha = false);
private:
std::set<IEffect*> mEffectCache;

View file

@ -47,7 +47,8 @@ namespace DirectX
class PrimitiveBatchBase
{
protected:
PrimitiveBatchBase(_In_ ID3D11DeviceContext* deviceContext, size_t maxIndices, size_t maxVertices, size_t vertexSize);
PrimitiveBatchBase(_In_ ID3D11DeviceContext* deviceContext, size_t maxIndices, size_t maxVertices,
size_t vertexSize);
PrimitiveBatchBase(PrimitiveBatchBase&& moveFrom);
PrimitiveBatchBase& operator=(PrimitiveBatchBase&& moveFrom);
virtual ~PrimitiveBatchBase();
@ -59,7 +60,9 @@ namespace DirectX
protected:
// Internal, untyped drawing method.
void __cdecl Draw(D3D11_PRIMITIVE_TOPOLOGY topology, bool isIndexed, _In_opt_count_(indexCount) uint16_t const* indices, size_t indexCount, size_t vertexCount, _Out_ void** pMappedVertices);
void __cdecl Draw(D3D11_PRIMITIVE_TOPOLOGY topology, bool isIndexed,
_In_opt_count_(indexCount) uint16_t const* indices, size_t indexCount, size_t vertexCount,
_Out_ void** pMappedVertices);
private:
// Private implementation.
@ -81,13 +84,16 @@ namespace DirectX
static const size_t DefaultBatchSize = 2048;
public:
PrimitiveBatch(_In_ ID3D11DeviceContext* deviceContext, size_t maxIndices = DefaultBatchSize * 3, size_t maxVertices = DefaultBatchSize)
PrimitiveBatch(_In_ ID3D11DeviceContext* deviceContext, size_t maxIndices = DefaultBatchSize * 3,
size_t maxVertices = DefaultBatchSize)
: PrimitiveBatchBase(deviceContext, maxIndices, maxVertices, sizeof(TVertex))
{ }
{
}
PrimitiveBatch(PrimitiveBatch&& moveFrom)
: PrimitiveBatchBase(std::move(moveFrom))
{ }
{
}
PrimitiveBatch& __cdecl operator=(PrimitiveBatch&& moveFrom)
{
@ -97,7 +103,8 @@ namespace DirectX
// Similar to the D3D9 API DrawPrimitiveUP.
void __cdecl Draw(D3D11_PRIMITIVE_TOPOLOGY topology, _In_reads_(vertexCount) TVertex const* vertices, size_t vertexCount)
void __cdecl Draw(D3D11_PRIMITIVE_TOPOLOGY topology, _In_reads_(vertexCount) TVertex const* vertices,
size_t vertexCount)
{
void* mappedVertices;
@ -108,7 +115,8 @@ namespace DirectX
// Similar to the D3D9 API DrawIndexedPrimitiveUP.
void __cdecl DrawIndexed(D3D11_PRIMITIVE_TOPOLOGY topology, _In_reads_(indexCount) uint16_t const* indices, size_t indexCount, _In_reads_(vertexCount) TVertex const* vertices, size_t vertexCount)
void __cdecl DrawIndexed(D3D11_PRIMITIVE_TOPOLOGY topology, _In_reads_(indexCount) uint16_t const* indices,
size_t indexCount, _In_reads_(vertexCount) TVertex const* vertices, size_t vertexCount)
{
void* mappedVertices;
@ -122,7 +130,8 @@ namespace DirectX
{
TVertex* mappedVertices;
PrimitiveBatchBase::Draw(D3D11_PRIMITIVE_TOPOLOGY_LINELIST, false, nullptr, 0, 2, reinterpret_cast<void**>(&mappedVertices));
PrimitiveBatchBase::Draw(D3D11_PRIMITIVE_TOPOLOGY_LINELIST, false, nullptr, 0, 2,
reinterpret_cast<void**>(&mappedVertices));
mappedVertices[0] = v1;
mappedVertices[1] = v2;
@ -133,7 +142,8 @@ namespace DirectX
{
TVertex* mappedVertices;
PrimitiveBatchBase::Draw(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, false, nullptr, 0, 3, reinterpret_cast<void**>(&mappedVertices));
PrimitiveBatchBase::Draw(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, false, nullptr, 0, 3,
reinterpret_cast<void**>(&mappedVertices));
mappedVertices[0] = v1;
mappedVertices[1] = v2;
@ -147,7 +157,8 @@ namespace DirectX
TVertex* mappedVertices;
PrimitiveBatchBase::Draw(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, true, quadIndices, 6, 4, reinterpret_cast<void**>(&mappedVertices));
PrimitiveBatchBase::Draw(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, true, quadIndices, 6, 4,
reinterpret_cast<void**>(&mappedVertices));
mappedVertices[0] = v1;
mappedVertices[1] = v2;

View file

@ -58,7 +58,8 @@ namespace DirectX
_In_ REFGUID guidContainerFormat,
_In_z_ LPCWSTR fileName,
_In_opt_ const GUID* targetFormat = nullptr,
_In_opt_ std::function<void DIRECTX_STD_CALLCONV(IPropertyBag2*)> setCustomProps = nullptr );
_In_opt_ std::function<void DIRECTX_STD_CALLCONV(IPropertyBag2*)> setCustomProps
= nullptr);
#endif
}

View file

@ -28,10 +28,8 @@
namespace DirectX
{
namespace SimpleMath
{
struct Vector4;
struct Matrix;
struct Quaternion;
@ -41,12 +39,29 @@ struct Plane;
// 2D vector
struct Vector2 : public XMFLOAT2
{
Vector2() : XMFLOAT2(0.f, 0.f) {}
explicit Vector2(float x) : XMFLOAT2( x, x ) {}
Vector2(float _x, float _y) : XMFLOAT2(_x, _y) {}
explicit Vector2(_In_reads_(2) const float *pArray) : XMFLOAT2(pArray) {}
Vector2() : XMFLOAT2(0.f, 0.f)
{
}
explicit Vector2(float x) : XMFLOAT2(x, x)
{
}
Vector2(float _x, float _y) : XMFLOAT2(_x, _y)
{
}
explicit Vector2(_In_reads_(2) const float* pArray) : XMFLOAT2(pArray)
{
}
Vector2(FXMVECTOR V) { XMStoreFloat2(this, V); }
Vector2(const XMFLOAT2& V) { this->x = V.x; this->y = V.y; }
Vector2(const XMFLOAT2& V)
{
this->x = V.x;
this->y = V.y;
}
operator XMVECTOR() const { return XMLoadFloat2(this); }
@ -55,8 +70,20 @@ struct Vector2 : public XMFLOAT2
bool operator !=(const Vector2& V) const;
// Assignment operators
Vector2& operator= (const Vector2& V) { x = V.x; y = V.y; return *this; }
Vector2& operator= (const XMFLOAT2& V) { x = V.x; y = V.y; return *this; }
Vector2& operator=(const Vector2& V)
{
x = V.x;
y = V.y;
return *this;
}
Vector2& operator=(const XMFLOAT2& V)
{
x = V.x;
y = V.y;
return *this;
}
Vector2& operator+=(const Vector2& V);
Vector2& operator-=(const Vector2& V);
Vector2& operator*=(const Vector2& V);
@ -99,13 +126,16 @@ struct Vector2 : public XMFLOAT2
static void SmoothStep(const Vector2& v1, const Vector2& v2, float t, Vector2& result);
static Vector2 SmoothStep(const Vector2& v1, const Vector2& v2, float t);
static void Barycentric( const Vector2& v1, const Vector2& v2, const Vector2& v3, float f, float g, Vector2& result );
static void Barycentric(const Vector2& v1, const Vector2& v2, const Vector2& v3, float f, float g,
Vector2& result);
static Vector2 Barycentric(const Vector2& v1, const Vector2& v2, const Vector2& v3, float f, float g);
static void CatmullRom( const Vector2& v1, const Vector2& v2, const Vector2& v3, const Vector2& v4, float t, Vector2& result );
static void CatmullRom(const Vector2& v1, const Vector2& v2, const Vector2& v3, const Vector2& v4, float t,
Vector2& result);
static Vector2 CatmullRom(const Vector2& v1, const Vector2& v2, const Vector2& v3, const Vector2& v4, float t);
static void Hermite( const Vector2& v1, const Vector2& t1, const Vector2& v2, const Vector2& t2, float t, Vector2& result );
static void Hermite(const Vector2& v1, const Vector2& t1, const Vector2& v2, const Vector2& t2, float t,
Vector2& result);
static Vector2 Hermite(const Vector2& v1, const Vector2& t1, const Vector2& v2, const Vector2& t2, float t);
static void Reflect(const Vector2& ivec, const Vector2& nvec, Vector2& result);
@ -119,14 +149,17 @@ struct Vector2 : public XMFLOAT2
static void Transform(const Vector2& v, const Matrix& m, Vector2& result);
static Vector2 Transform(const Vector2& v, const Matrix& m);
static void Transform( _In_reads_(count) const Vector2* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector2* resultArray );
static void Transform(_In_reads_(count) const Vector2* varray, size_t count, const Matrix& m,
_Out_writes_(count) Vector2* resultArray);
static void Transform(const Vector2& v, const Matrix& m, Vector4& result);
static void Transform( _In_reads_(count) const Vector2* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector4* resultArray );
static void Transform(_In_reads_(count) const Vector2* varray, size_t count, const Matrix& m,
_Out_writes_(count) Vector4* resultArray);
static void TransformNormal(const Vector2& v, const Matrix& m, Vector2& result);
static Vector2 TransformNormal(const Vector2& v, const Matrix& m);
static void TransformNormal( _In_reads_(count) const Vector2* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector2* resultArray );
static void TransformNormal(_In_reads_(count) const Vector2* varray, size_t count, const Matrix& m,
_Out_writes_(count) Vector2* resultArray);
// Constants
static const Vector2 Zero;
@ -147,12 +180,30 @@ Vector2 operator* (float S, const Vector2& V);
// 3D vector
struct Vector3 : public XMFLOAT3
{
Vector3() : XMFLOAT3(0.f, 0.f, 0.f) {}
explicit Vector3(float x) : XMFLOAT3( x, x, x ) {}
Vector3(float _x, float _y, float _z) : XMFLOAT3(_x, _y, _z) {}
explicit Vector3(_In_reads_(3) const float *pArray) : XMFLOAT3(pArray) {}
Vector3() : XMFLOAT3(0.f, 0.f, 0.f)
{
}
explicit Vector3(float x) : XMFLOAT3(x, x, x)
{
}
Vector3(float _x, float _y, float _z) : XMFLOAT3(_x, _y, _z)
{
}
explicit Vector3(_In_reads_(3) const float* pArray) : XMFLOAT3(pArray)
{
}
Vector3(FXMVECTOR V) { XMStoreFloat3(this, V); }
Vector3(const XMFLOAT3& V) { this->x = V.x; this->y = V.y; this->z = V.z; }
Vector3(const XMFLOAT3& V)
{
this->x = V.x;
this->y = V.y;
this->z = V.z;
}
operator XMVECTOR() const { return XMLoadFloat3(this); }
@ -161,8 +212,22 @@ struct Vector3 : public XMFLOAT3
bool operator !=(const Vector3& V) const;
// Assignment operators
Vector3& operator= (const Vector3& V) { x = V.x; y = V.y; z = V.z; return *this; }
Vector3& operator= (const XMFLOAT3& V) { x = V.x; y = V.y; z = V.z; return *this; }
Vector3& operator=(const Vector3& V)
{
x = V.x;
y = V.y;
z = V.z;
return *this;
}
Vector3& operator=(const XMFLOAT3& V)
{
x = V.x;
y = V.y;
z = V.z;
return *this;
}
Vector3& operator+=(const Vector3& V);
Vector3& operator-=(const Vector3& V);
Vector3& operator*=(const Vector3& V);
@ -205,13 +270,16 @@ struct Vector3 : public XMFLOAT3
static void SmoothStep(const Vector3& v1, const Vector3& v2, float t, Vector3& result);
static Vector3 SmoothStep(const Vector3& v1, const Vector3& v2, float t);
static void Barycentric( const Vector3& v1, const Vector3& v2, const Vector3& v3, float f, float g, Vector3& result );
static void Barycentric(const Vector3& v1, const Vector3& v2, const Vector3& v3, float f, float g,
Vector3& result);
static Vector3 Barycentric(const Vector3& v1, const Vector3& v2, const Vector3& v3, float f, float g);
static void CatmullRom( const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& v4, float t, Vector3& result );
static void CatmullRom(const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& v4, float t,
Vector3& result);
static Vector3 CatmullRom(const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& v4, float t);
static void Hermite( const Vector3& v1, const Vector3& t1, const Vector3& v2, const Vector3& t2, float t, Vector3& result );
static void Hermite(const Vector3& v1, const Vector3& t1, const Vector3& v2, const Vector3& t2, float t,
Vector3& result);
static Vector3 Hermite(const Vector3& v1, const Vector3& t1, const Vector3& v2, const Vector3& t2, float t);
static void Reflect(const Vector3& ivec, const Vector3& nvec, Vector3& result);
@ -225,14 +293,17 @@ struct Vector3 : public XMFLOAT3
static void Transform(const Vector3& v, const Matrix& m, Vector3& result);
static Vector3 Transform(const Vector3& v, const Matrix& m);
static void Transform( _In_reads_(count) const Vector3* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector3* resultArray );
static void Transform(_In_reads_(count) const Vector3* varray, size_t count, const Matrix& m,
_Out_writes_(count) Vector3* resultArray);
static void Transform(const Vector3& v, const Matrix& m, Vector4& result);
static void Transform( _In_reads_(count) const Vector3* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector4* resultArray );
static void Transform(_In_reads_(count) const Vector3* varray, size_t count, const Matrix& m,
_Out_writes_(count) Vector4* resultArray);
static void TransformNormal(const Vector3& v, const Matrix& m, Vector3& result);
static Vector3 TransformNormal(const Vector3& v, const Matrix& m);
static void TransformNormal( _In_reads_(count) const Vector3* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector3* resultArray );
static void TransformNormal(_In_reads_(count) const Vector3* varray, size_t count, const Matrix& m,
_Out_writes_(count) Vector3* resultArray);
// Constants
static const Vector3 Zero;
@ -260,12 +331,31 @@ Vector3 operator* (float S, const Vector3& V);
// 4D vector
struct Vector4 : public XMFLOAT4
{
Vector4() : XMFLOAT4(0.f, 0.f, 0.f, 0.f) {}
explicit Vector4(float x) : XMFLOAT4( x, x, x, x ) {}
Vector4(float _x, float _y, float _z, float _w) : XMFLOAT4(_x, _y, _z, _w) {}
explicit Vector4(_In_reads_(4) const float *pArray) : XMFLOAT4(pArray) {}
Vector4() : XMFLOAT4(0.f, 0.f, 0.f, 0.f)
{
}
explicit Vector4(float x) : XMFLOAT4(x, x, x, x)
{
}
Vector4(float _x, float _y, float _z, float _w) : XMFLOAT4(_x, _y, _z, _w)
{
}
explicit Vector4(_In_reads_(4) const float* pArray) : XMFLOAT4(pArray)
{
}
Vector4(FXMVECTOR V) { XMStoreFloat4(this, V); }
Vector4(const XMFLOAT4& V) { this->x = V.x; this->y = V.y; this->z = V.z; this->w = V.w; }
Vector4(const XMFLOAT4& V)
{
this->x = V.x;
this->y = V.y;
this->z = V.z;
this->w = V.w;
}
operator XMVECTOR() const { return XMLoadFloat4(this); }
@ -274,8 +364,24 @@ struct Vector4 : public XMFLOAT4
bool operator !=(const Vector4& V) const;
// Assignment operators
Vector4& operator= (const Vector4& V) { x = V.x; y = V.y; z = V.z; w = V.w; return *this; }
Vector4& operator= (const XMFLOAT4& V) { x = V.x; y = V.y; z = V.z; w = V.w; return *this; }
Vector4& operator=(const Vector4& V)
{
x = V.x;
y = V.y;
z = V.z;
w = V.w;
return *this;
}
Vector4& operator=(const XMFLOAT4& V)
{
x = V.x;
y = V.y;
z = V.z;
w = V.w;
return *this;
}
Vector4& operator+=(const Vector4& V);
Vector4& operator-=(const Vector4& V);
Vector4& operator*=(const Vector4& V);
@ -318,13 +424,16 @@ struct Vector4 : public XMFLOAT4
static void SmoothStep(const Vector4& v1, const Vector4& v2, float t, Vector4& result);
static Vector4 SmoothStep(const Vector4& v1, const Vector4& v2, float t);
static void Barycentric( const Vector4& v1, const Vector4& v2, const Vector4& v3, float f, float g, Vector4& result );
static void Barycentric(const Vector4& v1, const Vector4& v2, const Vector4& v3, float f, float g,
Vector4& result);
static Vector4 Barycentric(const Vector4& v1, const Vector4& v2, const Vector4& v3, float f, float g);
static void CatmullRom( const Vector4& v1, const Vector4& v2, const Vector4& v3, const Vector4& v4, float t, Vector4& result );
static void CatmullRom(const Vector4& v1, const Vector4& v2, const Vector4& v3, const Vector4& v4, float t,
Vector4& result);
static Vector4 CatmullRom(const Vector4& v1, const Vector4& v2, const Vector4& v3, const Vector4& v4, float t);
static void Hermite( const Vector4& v1, const Vector4& t1, const Vector4& v2, const Vector4& t2, float t, Vector4& result );
static void Hermite(const Vector4& v1, const Vector4& t1, const Vector4& v2, const Vector4& t2, float t,
Vector4& result);
static Vector4 Hermite(const Vector4& v1, const Vector4& t1, const Vector4& v2, const Vector4& t2, float t);
static void Reflect(const Vector4& ivec, const Vector4& nvec, Vector4& result);
@ -344,7 +453,8 @@ struct Vector4 : public XMFLOAT4
static void Transform(const Vector4& v, const Matrix& m, Vector4& result);
static Vector4 Transform(const Vector4& v, const Matrix& m);
static void Transform( _In_reads_(count) const Vector4* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector4* resultArray );
static void Transform(_In_reads_(count) const Vector4* varray, size_t count, const Matrix& m,
_Out_writes_(count) Vector4* resultArray);
// Constants
static const Vector4 Zero;
@ -370,27 +480,43 @@ struct Matrix : public XMFLOAT4X4
Matrix() : XMFLOAT4X4(1.f, 0, 0, 0,
0, 1.f, 0, 0,
0, 0, 1.f, 0,
0, 0, 0, 1.f ) {}
0, 0, 0, 1.f)
{
}
Matrix(float m00, float m01, float m02, float m03,
float m10, float m11, float m12, float m13,
float m20, float m21, float m22, float m23,
float m30, float m31, float m32, float m33) : XMFLOAT4X4(m00, m01, m02, m03,
m10, m11, m12, m13,
m20, m21, m22, m23,
m30, m31, m32, m33) {}
m30, m31, m32, m33)
{
}
explicit Matrix(const Vector3& r0, const Vector3& r1, const Vector3& r2) : XMFLOAT4X4(r0.x, r0.y, r0.z, 0,
r1.x, r1.y, r1.z, 0,
r2.x, r2.y, r2.z, 0,
0, 0, 0, 1.f ) {}
explicit Matrix( const Vector4& r0, const Vector4& r1, const Vector4& r2, const Vector4& r3 ) : XMFLOAT4X4( r0.x, r0.y, r0.z, r0.w,
0, 0, 0, 1.f)
{
}
explicit Matrix(const Vector4& r0, const Vector4& r1, const Vector4& r2, const Vector4& r3) : XMFLOAT4X4(
r0.x, r0.y, r0.z, r0.w,
r1.x, r1.y, r1.z, r1.w,
r2.x, r2.y, r2.z, r2.w,
r3.x, r3.y, r3.z, r3.w ) {}
r3.x, r3.y, r3.z, r3.w)
{
}
Matrix(const XMFLOAT4X4& M) { memcpy_s(this, sizeof(float) * 16, &M, sizeof(XMFLOAT4X4)); }
Matrix(const XMFLOAT3X3& M);
Matrix(const XMFLOAT4X3& M);
explicit Matrix(_In_reads_(16) const float *pArray) : XMFLOAT4X4(pArray) {}
explicit Matrix(_In_reads_(16) const float* pArray) : XMFLOAT4X4(pArray)
{
}
Matrix(CXMMATRIX M) { XMStoreFloat4x4(this, M); }
operator XMMATRIX() const { return XMLoadFloat4x4(this); }
@ -400,8 +526,18 @@ struct Matrix : public XMFLOAT4X4
bool operator !=(const Matrix& M) const;
// Assignment operators
Matrix& operator= (const Matrix& M) { memcpy_s( this, sizeof(float)*16, &M, sizeof(float)*16 ); return *this; }
Matrix& operator= (const XMFLOAT4X4& M) { memcpy_s( this, sizeof(float)*16, &M, sizeof(XMFLOAT4X4) ); return *this; }
Matrix& operator=(const Matrix& M)
{
memcpy_s(this, sizeof(float) * 16, &M, sizeof(float) * 16);
return *this;
}
Matrix& operator=(const XMFLOAT4X4& M)
{
memcpy_s(this, sizeof(float) * 16, &M, sizeof(XMFLOAT4X4));
return *this;
}
Matrix& operator=(const XMFLOAT3X3& M);
Matrix& operator=(const XMFLOAT4X3& M);
Matrix& operator+=(const Matrix& M);
@ -419,25 +555,67 @@ struct Matrix : public XMFLOAT4X4
// Properties
Vector3 Up() const { return Vector3(_21, _22, _23); }
void Up( const Vector3& v ) { _21 = v.x; _22 = v.y; _23 = v.z; }
void Up(const Vector3& v)
{
_21 = v.x;
_22 = v.y;
_23 = v.z;
}
Vector3 Down() const { return Vector3(-_21, -_22, -_23); }
void Down( const Vector3& v ) { _21 = -v.x; _22 = -v.y; _23 = -v.z; }
void Down(const Vector3& v)
{
_21 = -v.x;
_22 = -v.y;
_23 = -v.z;
}
Vector3 Right() const { return Vector3(_11, _12, _13); }
void Right( const Vector3& v ) { _11 = v.x; _12 = v.y; _13 = v.z; }
void Right(const Vector3& v)
{
_11 = v.x;
_12 = v.y;
_13 = v.z;
}
Vector3 Left() const { return Vector3(-_11, -_12, -_13); }
void Left( const Vector3& v ) { _11 = -v.x; _12 = -v.y; _13 = -v.z; }
void Left(const Vector3& v)
{
_11 = -v.x;
_12 = -v.y;
_13 = -v.z;
}
Vector3 Forward() const { return Vector3(-_31, -_32, -_33); }
void Forward( const Vector3& v ) { _31 = -v.x; _32 = -v.y; _33 = -v.z; }
void Forward(const Vector3& v)
{
_31 = -v.x;
_32 = -v.y;
_33 = -v.z;
}
Vector3 Backward() const { return Vector3(_31, _32, _33); }
void Backward( const Vector3& v ) { _31 = v.x; _32 = v.y; _33 = v.z; }
void Backward(const Vector3& v)
{
_31 = v.x;
_32 = v.y;
_33 = v.z;
}
Vector3 Translation() const { return Vector3(_41, _42, _43); }
void Translation( const Vector3& v ) { _41 = v.x; _42 = v.y; _43 = v.z; }
void Translation(const Vector3& v)
{
_41 = v.x;
_42 = v.y;
_43 = v.z;
}
// Matrix operations
bool Decompose(Vector3& scale, Quaternion& rotation, Vector3& translation);
@ -451,10 +629,13 @@ struct Matrix : public XMFLOAT4X4
float Determinant() const;
// Static functions
static Matrix CreateBillboard( const Vector3& object, const Vector3& cameraPosition, const Vector3& cameraUp, _In_opt_ const Vector3* cameraForward = nullptr );
static Matrix CreateBillboard(const Vector3& object, const Vector3& cameraPosition, const Vector3& cameraUp,
_In_opt_ const Vector3* cameraForward = nullptr);
static Matrix CreateConstrainedBillboard( const Vector3& object, const Vector3& cameraPosition, const Vector3& rotateAxis,
_In_opt_ const Vector3* cameraForward = nullptr, _In_opt_ const Vector3* objectForward = nullptr);
static Matrix CreateConstrainedBillboard(const Vector3& object, const Vector3& cameraPosition,
const Vector3& rotateAxis,
_In_opt_ const Vector3* cameraForward = nullptr,
_In_opt_ const Vector3* objectForward = nullptr);
static Matrix CreateTranslation(const Vector3& position);
static Matrix CreateTranslation(float x, float y, float z);
@ -471,9 +652,11 @@ struct Matrix : public XMFLOAT4X4
static Matrix CreatePerspectiveFieldOfView(float fov, float aspectRatio, float nearPlane, float farPlane);
static Matrix CreatePerspective(float width, float height, float nearPlane, float farPlane);
static Matrix CreatePerspectiveOffCenter( float left, float right, float bottom, float top, float nearPlane, float farPlane );
static Matrix CreatePerspectiveOffCenter(float left, float right, float bottom, float top, float nearPlane,
float farPlane);
static Matrix CreateOrthographic(float width, float height, float zNearPlane, float zFarPlane);
static Matrix CreateOrthographicOffCenter( float left, float right, float bottom, float top, float zNearPlane, float zFarPlane );
static Matrix CreateOrthographicOffCenter(float left, float right, float bottom, float top, float zNearPlane,
float zFarPlane);
static Matrix CreateLookAt(const Vector3& position, const Vector3& target, const Vector3& up);
static Matrix CreateWorld(const Vector3& position, const Vector3& forward, const Vector3& up);
@ -511,15 +694,38 @@ Matrix operator* (float S, const Matrix& M);
// Plane
struct Plane : public XMFLOAT4
{
Plane() : XMFLOAT4(0.f, 1.f, 0.f, 0.f) {}
Plane(float _x, float _y, float _z, float _w) : XMFLOAT4(_x, _y, _z, _w) {}
Plane(const Vector3& normal, float d) : XMFLOAT4(normal.x, normal.y, normal.z, d) {}
Plane() : XMFLOAT4(0.f, 1.f, 0.f, 0.f)
{
}
Plane(float _x, float _y, float _z, float _w) : XMFLOAT4(_x, _y, _z, _w)
{
}
Plane(const Vector3& normal, float d) : XMFLOAT4(normal.x, normal.y, normal.z, d)
{
}
Plane(const Vector3& point1, const Vector3& point2, const Vector3& point3);
Plane(const Vector3& point, const Vector3& normal);
explicit Plane(const Vector4& v) : XMFLOAT4(v.x, v.y, v.z, v.w) {}
explicit Plane(_In_reads_(4) const float *pArray) : XMFLOAT4(pArray) {}
explicit Plane(const Vector4& v) : XMFLOAT4(v.x, v.y, v.z, v.w)
{
}
explicit Plane(_In_reads_(4) const float* pArray) : XMFLOAT4(pArray)
{
}
Plane(FXMVECTOR V) { XMStoreFloat4(this, V); }
Plane(const XMFLOAT4& p) { this->x = p.x; this->y = p.y; this->z = p.z; this->w = p.w; }
Plane(const XMFLOAT4& p)
{
this->x = p.x;
this->y = p.y;
this->z = p.z;
this->w = p.w;
}
operator XMVECTOR() const { return XMLoadFloat4(this); }
@ -528,12 +734,33 @@ struct Plane : public XMFLOAT4
bool operator !=(const Plane& p) const;
// Assignment operators
Plane& operator= (const Plane& p) { x = p.x; y = p.y; z = p.z; w = p.w; return *this; }
Plane& operator= (const XMFLOAT4& p) { x = p.x; y = p.y; z = p.z; w = p.w; return *this; }
Plane& operator=(const Plane& p)
{
x = p.x;
y = p.y;
z = p.z;
w = p.w;
return *this;
}
Plane& operator=(const XMFLOAT4& p)
{
x = p.x;
y = p.y;
z = p.z;
w = p.w;
return *this;
}
// Properties
Vector3 Normal() const { return Vector3(x, y, z); }
void Normal( const Vector3& normal ) { x = normal.x; y = normal.y; z = normal.z; }
void Normal(const Vector3& normal)
{
x = normal.x;
y = normal.y;
z = normal.z;
}
float D() const { return w; }
void D(float d) { w = d; }
@ -559,13 +786,35 @@ struct Plane : public XMFLOAT4
// Quaternion
struct Quaternion : public XMFLOAT4
{
Quaternion() : XMFLOAT4(0, 0, 0, 1.f) {}
Quaternion( float _x, float _y, float _z, float _w ) : XMFLOAT4(_x, _y, _z, _w) {}
Quaternion( const Vector3& v, float scalar ) : XMFLOAT4( v.x, v.y, v.z, scalar ) {}
explicit Quaternion( const Vector4& v ) : XMFLOAT4( v.x, v.y, v.z, v.w ) {}
explicit Quaternion(_In_reads_(4) const float *pArray) : XMFLOAT4(pArray) {}
Quaternion() : XMFLOAT4(0, 0, 0, 1.f)
{
}
Quaternion(float _x, float _y, float _z, float _w) : XMFLOAT4(_x, _y, _z, _w)
{
}
Quaternion(const Vector3& v, float scalar) : XMFLOAT4(v.x, v.y, v.z, scalar)
{
}
explicit Quaternion(const Vector4& v) : XMFLOAT4(v.x, v.y, v.z, v.w)
{
}
explicit Quaternion(_In_reads_(4) const float* pArray) : XMFLOAT4(pArray)
{
}
Quaternion(FXMVECTOR V) { XMStoreFloat4(this, V); }
Quaternion(const XMFLOAT4& q) { this->x = q.x; this->y = q.y; this->z = q.z; this->w = q.w; }
Quaternion(const XMFLOAT4& q)
{
this->x = q.x;
this->y = q.y;
this->z = q.z;
this->w = q.w;
}
operator XMVECTOR() const { return XMLoadFloat4(this); }
@ -574,8 +823,24 @@ struct Quaternion : public XMFLOAT4
bool operator !=(const Quaternion& q) const;
// Assignment operators
Quaternion& operator= (const Quaternion& q) { x = q.x; y = q.y; z = q.z; w = q.w; return *this; }
Quaternion& operator= (const XMFLOAT4& q) { x = q.x; y = q.y; z = q.z; w = q.w; return *this; }
Quaternion& operator=(const Quaternion& q)
{
x = q.x;
y = q.y;
z = q.z;
w = q.w;
return *this;
}
Quaternion& operator=(const XMFLOAT4& q)
{
x = q.x;
y = q.y;
z = q.z;
w = q.w;
return *this;
}
Quaternion& operator+=(const Quaternion& q);
Quaternion& operator-=(const Quaternion& q);
Quaternion& operator*=(const Quaternion& q);
@ -630,14 +895,39 @@ Quaternion operator* (float S, const Quaternion& Q);
// Color
struct Color : public XMFLOAT4
{
Color() : XMFLOAT4(0, 0, 0, 1.f) {}
Color( float _r, float _g, float _b ) : XMFLOAT4(_r, _g, _b, 1.f) {}
Color( float _r, float _g, float _b, float _a ) : XMFLOAT4(_r, _g, _b, _a) {}
explicit Color( const Vector3& clr ) : XMFLOAT4( clr.x, clr.y, clr.z, 1.f ) {}
explicit Color( const Vector4& clr ) : XMFLOAT4( clr.x, clr.y, clr.z, clr.w ) {}
explicit Color(_In_reads_(4) const float *pArray) : XMFLOAT4(pArray) {}
Color() : XMFLOAT4(0, 0, 0, 1.f)
{
}
Color(float _r, float _g, float _b) : XMFLOAT4(_r, _g, _b, 1.f)
{
}
Color(float _r, float _g, float _b, float _a) : XMFLOAT4(_r, _g, _b, _a)
{
}
explicit Color(const Vector3& clr) : XMFLOAT4(clr.x, clr.y, clr.z, 1.f)
{
}
explicit Color(const Vector4& clr) : XMFLOAT4(clr.x, clr.y, clr.z, clr.w)
{
}
explicit Color(_In_reads_(4) const float* pArray) : XMFLOAT4(pArray)
{
}
Color(FXMVECTOR V) { XMStoreFloat4(this, V); }
Color(const XMFLOAT4& c) { this->x = c.x; this->y = c.y; this->z = c.z; this->w = c.w; }
Color(const XMFLOAT4& c)
{
this->x = c.x;
this->y = c.y;
this->z = c.z;
this->w = c.w;
}
explicit Color(const DirectX::PackedVector::XMCOLOR& Packed);
// BGRA Direct3D 9 D3DCOLOR packed color
@ -653,8 +943,24 @@ struct Color : public XMFLOAT4
bool operator !=(const Color& c) const;
// Assignment operators
Color& operator= (const Color& c) { x = c.x; y = c.y; z = c.z; w = c.w; return *this; }
Color& operator= (const XMFLOAT4& c) { x = c.x; y = c.y; z = c.z; w = c.w; return *this; }
Color& operator=(const Color& c)
{
x = c.x;
y = c.y;
z = c.z;
w = c.w;
return *this;
}
Color& operator=(const XMFLOAT4& c)
{
x = c.x;
y = c.y;
z = c.z;
w = c.w;
return *this;
}
Color& operator=(const DirectX::PackedVector::XMCOLOR& Packed);
Color& operator=(const DirectX::PackedVector::XMUBYTEN4& Packed);
Color& operator+=(const Color& c);
@ -726,8 +1032,13 @@ public:
Vector3 position;
Vector3 direction;
Ray() : position(0,0,0), direction(0,0,1) {}
Ray( const Vector3& pos, const Vector3& dir ) : position(pos), direction(dir) {}
Ray() : position(0, 0, 0), direction(0, 0, 1)
{
}
Ray(const Vector3& pos, const Vector3& dir) : position(pos), direction(dir)
{
}
// Comparison operators
bool operator ==(const Ray& r) const;
@ -753,18 +1064,29 @@ public:
float maxDepth;
Viewport() :
x(0.f), y(0.f), width(0.f), height(0.f), minDepth(0.f), maxDepth(1.f) {}
x(0.f), y(0.f), width(0.f), height(0.f), minDepth(0.f), maxDepth(1.f)
{
}
Viewport(float ix, float iy, float iw, float ih, float iminz = 0.f, float imaxz = 1.f) :
x(ix), y(iy), width(iw), height(ih), minDepth(iminz), maxDepth(imaxz) {}
x(ix), y(iy), width(iw), height(ih), minDepth(iminz), maxDepth(imaxz)
{
}
explicit Viewport(const RECT& rct) :
x(float(rct.left)), y(float(rct.top)),
width(float(rct.right - rct.left)),
height(float(rct.bottom - rct.top)),
minDepth(0.f), maxDepth(1.f) {}
minDepth(0.f), maxDepth(1.f)
{
}
explicit Viewport(const D3D11_VIEWPORT& vp) :
x(vp.TopLeftX), y(vp.TopLeftY),
width(vp.Width), height(vp.Height),
minDepth(vp.MinDepth), maxDepth(vp.MaxDepth) {}
minDepth(vp.MinDepth), maxDepth(vp.MaxDepth)
{
}
// Direct3D 11 interop
operator D3D11_VIEWPORT() { return *reinterpret_cast<D3D11_VIEWPORT*>(this); }
@ -783,28 +1105,29 @@ public:
float AspectRatio() const;
Vector3 Project(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world) const;
void Project(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world, Vector3& result ) const;
void Project(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world,
Vector3& result) const;
Vector3 Unproject(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world) const;
void Unproject(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world, Vector3& result ) const;
void Unproject(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world,
Vector3& result) const;
// Static methods
static RECT __cdecl ComputeDisplayArea(DXGI_SCALING scaling, UINT backBufferWidth, UINT backBufferHeight, int outputWidth, int outputHeight);
static RECT __cdecl ComputeDisplayArea(DXGI_SCALING scaling, UINT backBufferWidth, UINT backBufferHeight,
int outputWidth, int outputHeight);
static RECT __cdecl ComputeTitleSafeArea(UINT backBufferWidth, UINT backBufferHeight);
};
#include "SimpleMath.inl"
}; // namespace SimpleMath
}; // namespace DirectX
//------------------------------------------------------------------------------
// Support for SimpleMath and Standard C++ Library containers
namespace std
{
template<> struct less<DirectX::SimpleMath::Vector2>
template <>
struct less<DirectX::SimpleMath::Vector2>
{
bool operator()(const DirectX::SimpleMath::Vector2& V1, const DirectX::SimpleMath::Vector2& V2) const
{
@ -812,7 +1135,8 @@ namespace std
}
};
template<> struct less<DirectX::SimpleMath::Vector3>
template <>
struct less<DirectX::SimpleMath::Vector3>
{
bool operator()(const DirectX::SimpleMath::Vector3& V1, const DirectX::SimpleMath::Vector3& V2) const
{
@ -822,7 +1146,8 @@ namespace std
}
};
template<> struct less<DirectX::SimpleMath::Vector4>
template <>
struct less<DirectX::SimpleMath::Vector4>
{
bool operator()(const DirectX::SimpleMath::Vector4& V1, const DirectX::SimpleMath::Vector4& V2) const
{
@ -833,7 +1158,8 @@ namespace std
}
};
template<> struct less<DirectX::SimpleMath::Matrix>
template <>
struct less<DirectX::SimpleMath::Matrix>
{
bool operator()(const DirectX::SimpleMath::Matrix& M1, const DirectX::SimpleMath::Matrix& M2) const
{
@ -858,7 +1184,8 @@ namespace std
}
};
template<> struct less<DirectX::SimpleMath::Plane>
template <>
struct less<DirectX::SimpleMath::Plane>
{
bool operator()(const DirectX::SimpleMath::Plane& P1, const DirectX::SimpleMath::Plane& P2) const
{
@ -869,7 +1196,8 @@ namespace std
}
};
template<> struct less<DirectX::SimpleMath::Quaternion>
template <>
struct less<DirectX::SimpleMath::Quaternion>
{
bool operator()(const DirectX::SimpleMath::Quaternion& Q1, const DirectX::SimpleMath::Quaternion& Q2) const
{
@ -880,7 +1208,8 @@ namespace std
}
};
template<> struct less<DirectX::SimpleMath::Color>
template <>
struct less<DirectX::SimpleMath::Color>
{
bool operator()(const DirectX::SimpleMath::Color& C1, const DirectX::SimpleMath::Color& C2) const
{
@ -891,7 +1220,8 @@ namespace std
}
};
template<> struct less<DirectX::SimpleMath::Ray>
template <>
struct less<DirectX::SimpleMath::Ray>
{
bool operator()(const DirectX::SimpleMath::Ray& R1, const DirectX::SimpleMath::Ray& R2) const
{
@ -907,7 +1237,8 @@ namespace std
}
};
template<> struct less<DirectX::SimpleMath::Viewport>
template <>
struct less<DirectX::SimpleMath::Viewport>
{
bool operator()(const DirectX::SimpleMath::Viewport& vp1, const DirectX::SimpleMath::Viewport& vp2) const
{
@ -923,5 +1254,4 @@ namespace std
return false;
}
};
} // namespace std

View file

@ -366,7 +366,8 @@ inline Vector2 Vector2::SmoothStep( const Vector2& v1, const Vector2& v2, float
return result;
}
inline void Vector2::Barycentric( const Vector2& v1, const Vector2& v2, const Vector2& v3, float f, float g, Vector2& result )
inline void Vector2::Barycentric(const Vector2& v1, const Vector2& v2, const Vector2& v3, float f, float g,
Vector2& result)
{
using namespace DirectX;
XMVECTOR x1 = XMLoadFloat2(&v1);
@ -389,7 +390,8 @@ inline Vector2 Vector2::Barycentric( const Vector2& v1, const Vector2& v2, const
return result;
}
inline void Vector2::CatmullRom( const Vector2& v1, const Vector2& v2, const Vector2& v3, const Vector2& v4, float t, Vector2& result )
inline void Vector2::CatmullRom(const Vector2& v1, const Vector2& v2, const Vector2& v3, const Vector2& v4, float t,
Vector2& result)
{
using namespace DirectX;
XMVECTOR x1 = XMLoadFloat2(&v1);
@ -414,7 +416,8 @@ inline Vector2 Vector2::CatmullRom( const Vector2& v1, const Vector2& v2, const
return result;
}
inline void Vector2::Hermite( const Vector2& v1, const Vector2& t1, const Vector2& v2, const Vector2& t2, float t, Vector2& result )
inline void Vector2::Hermite(const Vector2& v1, const Vector2& t1, const Vector2& v2, const Vector2& t2, float t,
Vector2& result)
{
using namespace DirectX;
XMVECTOR x1 = XMLoadFloat2(&v1);
@ -524,6 +527,7 @@ inline Vector2 Vector2::Transform( const Vector2& v, const Matrix& m )
}
_Use_decl_annotations_
inline void Vector2::Transform(const Vector2* varray, size_t count, const Matrix& m, Vector2* resultArray)
{
using namespace DirectX;
@ -541,6 +545,7 @@ inline void Vector2::Transform( const Vector2& v, const Matrix& m, Vector4& resu
}
_Use_decl_annotations_
inline void Vector2::Transform(const Vector2* varray, size_t count, const Matrix& m, Vector4* resultArray)
{
using namespace DirectX;
@ -570,6 +575,7 @@ inline Vector2 Vector2::TransformNormal( const Vector2& v, const Matrix& m )
}
_Use_decl_annotations_
inline void Vector2::TransformNormal(const Vector2* varray, size_t count, const Matrix& m, Vector2* resultArray)
{
using namespace DirectX;
@ -945,7 +951,8 @@ inline Vector3 Vector3::SmoothStep( const Vector3& v1, const Vector3& v2, float
return result;
}
inline void Vector3::Barycentric( const Vector3& v1, const Vector3& v2, const Vector3& v3, float f, float g, Vector3& result )
inline void Vector3::Barycentric(const Vector3& v1, const Vector3& v2, const Vector3& v3, float f, float g,
Vector3& result)
{
using namespace DirectX;
XMVECTOR x1 = XMLoadFloat3(&v1);
@ -968,7 +975,8 @@ inline Vector3 Vector3::Barycentric( const Vector3& v1, const Vector3& v2, const
return result;
}
inline void Vector3::CatmullRom( const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& v4, float t, Vector3& result )
inline void Vector3::CatmullRom(const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& v4, float t,
Vector3& result)
{
using namespace DirectX;
XMVECTOR x1 = XMLoadFloat3(&v1);
@ -993,7 +1001,8 @@ inline Vector3 Vector3::CatmullRom( const Vector3& v1, const Vector3& v2, const
return result;
}
inline void Vector3::Hermite( const Vector3& v1, const Vector3& t1, const Vector3& v2, const Vector3& t2, float t, Vector3& result )
inline void Vector3::Hermite(const Vector3& v1, const Vector3& t1, const Vector3& v2, const Vector3& t2, float t,
Vector3& result)
{
using namespace DirectX;
XMVECTOR x1 = XMLoadFloat3(&v1);
@ -1103,6 +1112,7 @@ inline Vector3 Vector3::Transform( const Vector3& v, const Matrix& m )
}
_Use_decl_annotations_
inline void Vector3::Transform(const Vector3* varray, size_t count, const Matrix& m, Vector3* resultArray)
{
using namespace DirectX;
@ -1120,6 +1130,7 @@ inline void Vector3::Transform( const Vector3& v, const Matrix& m, Vector4& resu
}
_Use_decl_annotations_
inline void Vector3::Transform(const Vector3* varray, size_t count, const Matrix& m, Vector4* resultArray)
{
using namespace DirectX;
@ -1149,6 +1160,7 @@ inline Vector3 Vector3::TransformNormal( const Vector3& v, const Matrix& m )
}
_Use_decl_annotations_
inline void Vector3::TransformNormal(const Vector3* varray, size_t count, const Matrix& m, Vector3* resultArray)
{
using namespace DirectX;
@ -1526,7 +1538,8 @@ inline Vector4 Vector4::SmoothStep( const Vector4& v1, const Vector4& v2, float
return result;
}
inline void Vector4::Barycentric( const Vector4& v1, const Vector4& v2, const Vector4& v3, float f, float g, Vector4& result )
inline void Vector4::Barycentric(const Vector4& v1, const Vector4& v2, const Vector4& v3, float f, float g,
Vector4& result)
{
using namespace DirectX;
XMVECTOR x1 = XMLoadFloat4(&v1);
@ -1549,7 +1562,8 @@ inline Vector4 Vector4::Barycentric( const Vector4& v1, const Vector4& v2, const
return result;
}
inline void Vector4::CatmullRom( const Vector4& v1, const Vector4& v2, const Vector4& v3, const Vector4& v4, float t, Vector4& result )
inline void Vector4::CatmullRom(const Vector4& v1, const Vector4& v2, const Vector4& v3, const Vector4& v4, float t,
Vector4& result)
{
using namespace DirectX;
XMVECTOR x1 = XMLoadFloat4(&v1);
@ -1574,7 +1588,8 @@ inline Vector4 Vector4::CatmullRom( const Vector4& v1, const Vector4& v2, const
return result;
}
inline void Vector4::Hermite( const Vector4& v1, const Vector4& t1, const Vector4& v2, const Vector4& t2, float t, Vector4& result )
inline void Vector4::Hermite(const Vector4& v1, const Vector4& t1, const Vector4& v2, const Vector4& t2, float t,
Vector4& result)
{
using namespace DirectX;
XMVECTOR x1 = XMLoadFloat4(&v1);
@ -1732,6 +1747,7 @@ inline Vector4 Vector4::Transform( const Vector4& v, const Matrix& m )
}
_Use_decl_annotations_
inline void Vector4::Transform(const Vector4* varray, size_t count, const Matrix& m, Vector4* resultArray)
{
using namespace DirectX;
@ -1794,35 +1810,83 @@ inline bool Matrix::operator != ( const Matrix& M ) const
inline Matrix::Matrix(const XMFLOAT3X3& M)
{
_11 = M._11; _12 = M._12; _13 = M._13; _14 = 0.f;
_21 = M._21; _22 = M._22; _23 = M._23; _24 = 0.f;
_31 = M._31; _32 = M._32; _33 = M._33; _34 = 0.f;
_41 = 0.f; _42 = 0.f; _43 = 0.f; _44 = 1.f;
_11 = M._11;
_12 = M._12;
_13 = M._13;
_14 = 0.f;
_21 = M._21;
_22 = M._22;
_23 = M._23;
_24 = 0.f;
_31 = M._31;
_32 = M._32;
_33 = M._33;
_34 = 0.f;
_41 = 0.f;
_42 = 0.f;
_43 = 0.f;
_44 = 1.f;
}
inline Matrix::Matrix(const XMFLOAT4X3& M)
{
_11 = M._11; _12 = M._12; _13 = M._13; _14 = 0.f;
_21 = M._21; _22 = M._22; _23 = M._23; _24 = 0.f;
_31 = M._31; _32 = M._32; _33 = M._33; _34 = 0.f;
_41 = M._41; _42 = M._42; _43 = M._43; _44 = 1.f;
_11 = M._11;
_12 = M._12;
_13 = M._13;
_14 = 0.f;
_21 = M._21;
_22 = M._22;
_23 = M._23;
_24 = 0.f;
_31 = M._31;
_32 = M._32;
_33 = M._33;
_34 = 0.f;
_41 = M._41;
_42 = M._42;
_43 = M._43;
_44 = 1.f;
}
inline Matrix& Matrix::operator=(const XMFLOAT3X3& M)
{
_11 = M._11; _12 = M._12; _13 = M._13; _14 = 0.f;
_21 = M._21; _22 = M._22; _23 = M._23; _24 = 0.f;
_31 = M._31; _32 = M._32; _33 = M._33; _34 = 0.f;
_41 = 0.f; _42 = 0.f; _43 = 0.f; _44 = 1.f;
_11 = M._11;
_12 = M._12;
_13 = M._13;
_14 = 0.f;
_21 = M._21;
_22 = M._22;
_23 = M._23;
_24 = 0.f;
_31 = M._31;
_32 = M._32;
_33 = M._33;
_34 = 0.f;
_41 = 0.f;
_42 = 0.f;
_43 = 0.f;
_44 = 1.f;
return *this;
}
inline Matrix& Matrix::operator=(const XMFLOAT4X3& M)
{
_11 = M._11; _12 = M._12; _13 = M._13; _14 = 0.f;
_21 = M._21; _22 = M._22; _23 = M._23; _24 = 0.f;
_31 = M._31; _32 = M._32; _33 = M._33; _34 = 0.f;
_41 = M._41; _42 = M._42; _43 = M._43; _44 = 1.f;
_11 = M._11;
_12 = M._12;
_13 = M._13;
_14 = 0.f;
_21 = M._21;
_22 = M._22;
_23 = M._23;
_24 = 0.f;
_31 = M._31;
_32 = M._32;
_33 = M._33;
_34 = 0.f;
_41 = M._41;
_42 = M._42;
_43 = M._43;
_44 = 1.f;
return *this;
}
@ -2207,7 +2271,9 @@ inline float Matrix::Determinant() const
//------------------------------------------------------------------------------
_Use_decl_annotations_
inline Matrix Matrix::CreateBillboard( const Vector3& object, const Vector3& cameraPosition, const Vector3& cameraUp, const Vector3* cameraForward )
inline Matrix Matrix::CreateBillboard(const Vector3& object, const Vector3& cameraPosition, const Vector3& cameraUp,
const Vector3* cameraForward)
{
using namespace DirectX;
XMVECTOR O = XMLoadFloat3(&object);
@ -2248,12 +2314,15 @@ inline Matrix Matrix::CreateBillboard( const Vector3& object, const Vector3& cam
}
_Use_decl_annotations_
inline Matrix Matrix::CreateConstrainedBillboard( const Vector3& object, const Vector3& cameraPosition, const Vector3& rotateAxis,
inline Matrix Matrix::CreateConstrainedBillboard(const Vector3& object, const Vector3& cameraPosition,
const Vector3& rotateAxis,
const Vector3* cameraForward, const Vector3* objectForward)
{
using namespace DirectX;
static const XMVECTORF32 s_minAngle = { 0.99825467075f, 0.99825467075f, 0.99825467075f, 0.99825467075f }; // 1.0 - XMConvertToRadians( 0.1f );
static const XMVECTORF32 s_minAngle = {0.99825467075f, 0.99825467075f, 0.99825467075f, 0.99825467075f};
// 1.0 - XMConvertToRadians( 0.1f );
XMVECTOR O = XMLoadFloat3(&object);
XMVECTOR C = XMLoadFloat3(&cameraPosition);
@ -2412,7 +2481,8 @@ inline Matrix Matrix::CreatePerspective( float width, float height, float nearPl
return R;
}
inline Matrix Matrix::CreatePerspectiveOffCenter( float left, float right, float bottom, float top, float nearPlane, float farPlane )
inline Matrix Matrix::CreatePerspectiveOffCenter(float left, float right, float bottom, float top, float nearPlane,
float farPlane)
{
using namespace DirectX;
Matrix R;
@ -2428,7 +2498,8 @@ inline Matrix Matrix::CreateOrthographic( float width, float height, float zNear
return R;
}
inline Matrix Matrix::CreateOrthographicOffCenter( float left, float right, float bottom, float top, float zNearPlane, float zFarPlane )
inline Matrix Matrix::CreateOrthographicOffCenter(float left, float right, float bottom, float top, float zNearPlane,
float zFarPlane)
{
using namespace DirectX;
Matrix R;
@ -2460,7 +2531,9 @@ inline Matrix Matrix::CreateWorld( const Vector3& position, const Vector3& forwa
XMStoreFloat3(reinterpret_cast<XMFLOAT3*>(&R._21), yaxis);
XMStoreFloat3(reinterpret_cast<XMFLOAT3*>(&R._31), zaxis);
R._14 = R._24 = R._34 = 0.f;
R._41 = position.x; R._42 = position.y; R._43 = position.z;
R._41 = position.x;
R._42 = position.y;
R._43 = position.z;
R._44 = 1.f;
return R;
}
@ -3487,26 +3560,34 @@ inline bool Viewport::operator != ( const Viewport& vp ) const
inline Viewport& Viewport::operator=(const Viewport& vp)
{
x = vp.x; y = vp.y;
width = vp.width; height = vp.height;
minDepth = vp.minDepth; maxDepth = vp.maxDepth;
x = vp.x;
y = vp.y;
width = vp.width;
height = vp.height;
minDepth = vp.minDepth;
maxDepth = vp.maxDepth;
return *this;
}
inline Viewport& Viewport::operator=(const RECT& rct)
{
x = float(rct.left); y = float(rct.top);
x = float(rct.left);
y = float(rct.top);
width = float(rct.right - rct.left);
height = float(rct.bottom - rct.top);
minDepth = 0.f; maxDepth = 1.f;
minDepth = 0.f;
maxDepth = 1.f;
return *this;
}
inline Viewport& Viewport::operator=(const D3D11_VIEWPORT& vp)
{
x = vp.TopLeftX; y = vp.TopLeftY;
width = vp.Width; height = vp.Height;
minDepth = vp.MinDepth; maxDepth = vp.MaxDepth;
x = vp.TopLeftX;
y = vp.TopLeftY;
width = vp.Width;
height = vp.Height;
minDepth = vp.MinDepth;
maxDepth = vp.MaxDepth;
return *this;
}
@ -3533,7 +3614,8 @@ inline Vector3 Viewport::Project(const Vector3& p, const Matrix& proj, const Mat
return result;
}
inline void Viewport::Project(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world, Vector3& result) const
inline void Viewport::Project(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world,
Vector3& result) const
{
using namespace DirectX;
XMVECTOR v = XMLoadFloat3(&p);
@ -3553,7 +3635,8 @@ inline Vector3 Viewport::Unproject(const Vector3& p, const Matrix& proj, const M
return result;
}
inline void Viewport::Unproject(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world, Vector3& result) const
inline void Viewport::Unproject(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world,
Vector3& result) const
{
using namespace DirectX;
XMVECTOR v = XMLoadFloat3(&p);

View file

@ -80,23 +80,45 @@ namespace DirectX
virtual ~SpriteBatch();
// Begin/End a batch of sprite drawing operations.
void XM_CALLCONV Begin(SpriteSortMode sortMode = SpriteSortMode_Deferred, _In_opt_ ID3D11BlendState* blendState = nullptr, _In_opt_ ID3D11SamplerState* samplerState = nullptr, _In_opt_ ID3D11DepthStencilState* depthStencilState = nullptr, _In_opt_ ID3D11RasterizerState* rasterizerState = nullptr,
_In_opt_ std::function<void DIRECTX_STD_CALLCONV()> setCustomShaders = nullptr, FXMMATRIX transformMatrix = MatrixIdentity);
void XM_CALLCONV Begin(SpriteSortMode sortMode = SpriteSortMode_Deferred,
_In_opt_ ID3D11BlendState* blendState = nullptr,
_In_opt_ ID3D11SamplerState* samplerState = nullptr,
_In_opt_ ID3D11DepthStencilState* depthStencilState = nullptr,
_In_opt_ ID3D11RasterizerState* rasterizerState = nullptr,
_In_opt_ std::function<void DIRECTX_STD_CALLCONV()> setCustomShaders = nullptr,
FXMMATRIX transformMatrix = MatrixIdentity);
void __cdecl End();
// Draw overloads specifying position, origin and scale as XMFLOAT2.
void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, XMFLOAT2 const& position, FXMVECTOR color = Colors::White);
void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, XMFLOAT2 const& position, _In_opt_ RECT const* sourceRectangle, FXMVECTOR color = Colors::White, float rotation = 0, XMFLOAT2 const& origin = Float2Zero, float scale = 1, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0);
void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, XMFLOAT2 const& position, _In_opt_ RECT const* sourceRectangle, FXMVECTOR color, float rotation, XMFLOAT2 const& origin, XMFLOAT2 const& scale, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0);
void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, XMFLOAT2 const& position,
FXMVECTOR color = Colors::White);
void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, XMFLOAT2 const& position,
_In_opt_ RECT const* sourceRectangle, FXMVECTOR color = Colors::White, float rotation = 0,
XMFLOAT2 const& origin = Float2Zero, float scale = 1,
SpriteEffects effects = SpriteEffects_None, float layerDepth = 0);
void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, XMFLOAT2 const& position,
_In_opt_ RECT const* sourceRectangle, FXMVECTOR color, float rotation,
XMFLOAT2 const& origin, XMFLOAT2 const& scale, SpriteEffects effects = SpriteEffects_None,
float layerDepth = 0);
// Draw overloads specifying position, origin and scale via the first two components of an XMVECTOR.
void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, FXMVECTOR position, FXMVECTOR color = Colors::White);
void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, FXMVECTOR position, _In_opt_ RECT const* sourceRectangle, FXMVECTOR color = Colors::White, float rotation = 0, FXMVECTOR origin = g_XMZero, float scale = 1, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0);
void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, FXMVECTOR position, _In_opt_ RECT const* sourceRectangle, FXMVECTOR color, float rotation, FXMVECTOR origin, GXMVECTOR scale, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0);
void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, FXMVECTOR position,
FXMVECTOR color = Colors::White);
void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, FXMVECTOR position,
_In_opt_ RECT const* sourceRectangle, FXMVECTOR color = Colors::White, float rotation = 0,
FXMVECTOR origin = g_XMZero, float scale = 1, SpriteEffects effects = SpriteEffects_None,
float layerDepth = 0);
void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, FXMVECTOR position,
_In_opt_ RECT const* sourceRectangle, FXMVECTOR color, float rotation, FXMVECTOR origin,
GXMVECTOR scale, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0);
// Draw overloads specifying position as a RECT.
void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, RECT const& destinationRectangle, FXMVECTOR color = Colors::White);
void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, RECT const& destinationRectangle, _In_opt_ RECT const* sourceRectangle, FXMVECTOR color = Colors::White, float rotation = 0, XMFLOAT2 const& origin = Float2Zero, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0);
void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, RECT const& destinationRectangle,
FXMVECTOR color = Colors::White);
void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, RECT const& destinationRectangle,
_In_opt_ RECT const* sourceRectangle, FXMVECTOR color = Colors::White, float rotation = 0,
XMFLOAT2 const& origin = Float2Zero, SpriteEffects effects = SpriteEffects_None,
float layerDepth = 0);
// Rotation mode to be applied to the sprite transformation
void __cdecl SetRotation(DXGI_MODE_ROTATION mode);

View file

@ -36,16 +36,27 @@ namespace DirectX
SpriteFont(_In_ ID3D11Device* device, _In_z_ wchar_t const* fileName);
SpriteFont(_In_ ID3D11Device* device, _In_reads_bytes_(dataSize) uint8_t const* dataBlob, _In_ size_t dataSize);
SpriteFont(_In_ ID3D11ShaderResourceView* texture, _In_reads_(glyphCount) Glyph const* glyphs, _In_ size_t glyphCount, _In_ float lineSpacing);
SpriteFont(_In_ ID3D11ShaderResourceView* texture, _In_reads_(glyphCount) Glyph const* glyphs,
_In_ size_t glyphCount, _In_ float lineSpacing);
SpriteFont(SpriteFont&& moveFrom);
SpriteFont& operator=(SpriteFont&& moveFrom);
virtual ~SpriteFont();
void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, XMFLOAT2 const& position, FXMVECTOR color = Colors::White, float rotation = 0, XMFLOAT2 const& origin = Float2Zero, float scale = 1, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const;
void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, XMFLOAT2 const& position, FXMVECTOR color, float rotation, XMFLOAT2 const& origin, XMFLOAT2 const& scale, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const;
void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, FXMVECTOR position, FXMVECTOR color = Colors::White, float rotation = 0, FXMVECTOR origin = g_XMZero, float scale = 1, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const;
void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, FXMVECTOR position, FXMVECTOR color, float rotation, FXMVECTOR origin, GXMVECTOR scale, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const;
void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, XMFLOAT2 const& position,
FXMVECTOR color = Colors::White, float rotation = 0,
XMFLOAT2 const& origin = Float2Zero, float scale = 1,
SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const;
void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, XMFLOAT2 const& position,
FXMVECTOR color, float rotation, XMFLOAT2 const& origin, XMFLOAT2 const& scale,
SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const;
void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, FXMVECTOR position,
FXMVECTOR color = Colors::White, float rotation = 0, FXMVECTOR origin = g_XMZero,
float scale = 1, SpriteEffects effects = SpriteEffects_None,
float layerDepth = 0) const;
void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, FXMVECTOR position,
FXMVECTOR color, float rotation, FXMVECTOR origin, GXMVECTOR scale,
SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const;
XMVECTOR XM_CALLCONV MeasureString(_In_z_ wchar_t const* text) const;

View file

@ -49,7 +49,8 @@ namespace DirectX
VertexPositionColor(XMFLOAT3 const& position, XMFLOAT4 const& color)
: position(position),
color(color)
{ }
{
}
VertexPositionColor(FXMVECTOR position, FXMVECTOR color)
{
@ -73,7 +74,8 @@ namespace DirectX
VertexPositionTexture(XMFLOAT3 const& position, XMFLOAT2 const& textureCoordinate)
: position(position),
textureCoordinate(textureCoordinate)
{ }
{
}
VertexPositionTexture(FXMVECTOR position, FXMVECTOR textureCoordinate)
{
@ -97,7 +99,8 @@ namespace DirectX
VertexPositionNormal(XMFLOAT3 const& position, XMFLOAT3 const& normal)
: position(position),
normal(normal)
{ }
{
}
VertexPositionNormal(FXMVECTOR position, FXMVECTOR normal)
{
@ -122,7 +125,8 @@ namespace DirectX
: position(position),
color(color),
textureCoordinate(textureCoordinate)
{ }
{
}
VertexPositionColorTexture(FXMVECTOR position, FXMVECTOR color, FXMVECTOR textureCoordinate)
{
@ -149,7 +153,8 @@ namespace DirectX
: position(position),
normal(normal),
color(color)
{ }
{
}
VertexPositionNormalColor(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR color)
{
@ -176,7 +181,8 @@ namespace DirectX
: position(position),
normal(normal),
textureCoordinate(textureCoordinate)
{ }
{
}
VertexPositionNormalTexture(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR textureCoordinate)
{
@ -199,14 +205,17 @@ namespace DirectX
{
VertexPositionNormalColorTexture() DIRECTX_CTOR_DEFAULT
VertexPositionNormalColorTexture(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& color, XMFLOAT2 const& textureCoordinate)
VertexPositionNormalColorTexture(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& color,
XMFLOAT2 const& textureCoordinate)
: position(position),
normal(normal),
color(color),
textureCoordinate(textureCoordinate)
{ }
{
}
VertexPositionNormalColorTexture(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR color, CXMVECTOR textureCoordinate)
VertexPositionNormalColorTexture(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR color,
CXMVECTOR textureCoordinate)
{
XMStoreFloat3(&this->position, position);
XMStoreFloat3(&this->normal, normal);
@ -236,7 +245,8 @@ namespace DirectX
uint32_t color;
XMFLOAT2 textureCoordinate;
VertexPositionNormalTangentColorTexture(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& tangent, uint32_t rgba, XMFLOAT2 const& textureCoordinate)
VertexPositionNormalTangentColorTexture(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& tangent,
uint32_t rgba, XMFLOAT2 const& textureCoordinate)
: position(position),
normal(normal),
tangent(tangent),
@ -245,7 +255,8 @@ namespace DirectX
{
}
VertexPositionNormalTangentColorTexture(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR tangent, uint32_t rgba, CXMVECTOR textureCoordinate)
VertexPositionNormalTangentColorTexture(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR tangent, uint32_t rgba,
CXMVECTOR textureCoordinate)
: color(rgba)
{
XMStoreFloat3(&this->position, position);
@ -254,7 +265,8 @@ namespace DirectX
XMStoreFloat2(&this->textureCoordinate, textureCoordinate);
}
VertexPositionNormalTangentColorTexture(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& tangent, XMFLOAT4 const& color, XMFLOAT2 const& textureCoordinate)
VertexPositionNormalTangentColorTexture(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& tangent,
XMFLOAT4 const& color, XMFLOAT2 const& textureCoordinate)
: position(position),
normal(normal),
tangent(tangent),
@ -263,7 +275,8 @@ namespace DirectX
SetColor(color);
}
VertexPositionNormalTangentColorTexture(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR tangent, CXMVECTOR color, CXMVECTOR textureCoordinate)
VertexPositionNormalTangentColorTexture(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR tangent, CXMVECTOR color,
CXMVECTOR textureCoordinate)
{
XMStoreFloat3(&this->position, position);
XMStoreFloat3(&this->normal, normal);
@ -290,15 +303,18 @@ namespace DirectX
uint32_t indices;
uint32_t weights;
VertexPositionNormalTangentColorTextureSkinning(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& tangent, uint32_t rgba,
XMFLOAT2 const& textureCoordinate, XMUINT4 const& indices, XMFLOAT4 const& weights)
VertexPositionNormalTangentColorTextureSkinning(XMFLOAT3 const& position, XMFLOAT3 const& normal,
XMFLOAT4 const& tangent, uint32_t rgba,
XMFLOAT2 const& textureCoordinate, XMUINT4 const& indices,
XMFLOAT4 const& weights)
: VertexPositionNormalTangentColorTexture(position, normal, tangent, rgba, textureCoordinate)
{
SetBlendIndices(indices);
SetBlendWeights(weights);
}
VertexPositionNormalTangentColorTextureSkinning(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR tangent, uint32_t rgba, CXMVECTOR textureCoordinate,
VertexPositionNormalTangentColorTextureSkinning(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR tangent,
uint32_t rgba, CXMVECTOR textureCoordinate,
XMUINT4 const& indices, CXMVECTOR weights)
: VertexPositionNormalTangentColorTexture(position, normal, tangent, rgba, textureCoordinate)
{
@ -306,15 +322,18 @@ namespace DirectX
SetBlendWeights(weights);
}
VertexPositionNormalTangentColorTextureSkinning(XMFLOAT3 const& position, XMFLOAT3 const& normal, XMFLOAT4 const& tangent, XMFLOAT4 const& color,
XMFLOAT2 const& textureCoordinate, XMUINT4 const& indices, XMFLOAT4 const& weights)
VertexPositionNormalTangentColorTextureSkinning(XMFLOAT3 const& position, XMFLOAT3 const& normal,
XMFLOAT4 const& tangent, XMFLOAT4 const& color,
XMFLOAT2 const& textureCoordinate, XMUINT4 const& indices,
XMFLOAT4 const& weights)
: VertexPositionNormalTangentColorTexture(position, normal, tangent, color, textureCoordinate)
{
SetBlendIndices(indices);
SetBlendWeights(weights);
}
VertexPositionNormalTangentColorTextureSkinning(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR tangent, CXMVECTOR color, CXMVECTOR textureCoordinate,
VertexPositionNormalTangentColorTextureSkinning(FXMVECTOR position, FXMVECTOR normal, FXMVECTOR tangent,
CXMVECTOR color, CXMVECTOR textureCoordinate,
XMUINT4 const& indices, CXMVECTOR weights)
: VertexPositionNormalTangentColorTexture(position, normal, tangent, color, textureCoordinate)
{

View file

@ -13,7 +13,8 @@
using namespace DirectX;
Renderer::Renderer(shared_ptr<Console> console, HWND hWnd, bool registerAsMessageManager) : BaseRenderer(console, registerAsMessageManager)
Renderer::Renderer(shared_ptr<Console> console, HWND hWnd, bool registerAsMessageManager) : BaseRenderer(
console, registerAsMessageManager)
{
_hWnd = hWnd;
@ -23,7 +24,8 @@ Renderer::Renderer(shared_ptr<Console> console, HWND hWnd, bool registerAsMessag
Renderer::~Renderer()
{
shared_ptr<VideoRenderer> videoRenderer = _console->GetVideoRenderer();
if(videoRenderer) {
if (videoRenderer)
{
videoRenderer->UnregisterRenderingDevice(this);
}
CleanupDevice();
@ -31,7 +33,8 @@ Renderer::~Renderer()
void Renderer::SetFullscreenMode(bool fullscreen, void* windowHandle, uint32_t monitorWidth, uint32_t monitorHeight)
{
if(fullscreen != _fullscreen || _hWnd != (HWND)windowHandle) {
if (fullscreen != _fullscreen || _hWnd != (HWND)windowHandle)
{
_hWnd = (HWND)windowHandle;
_monitorWidth = monitorWidth;
_monitorHeight = monitorHeight;
@ -43,11 +46,17 @@ void Renderer::SetScreenSize(uint32_t width, uint32_t height)
{
ScreenSize screenSize = _console->GetVideoDecoder()->GetScreenSize(false);
VideoConfig cfg = _console->GetSettings()->GetVideoConfig();
if(_screenHeight != screenSize.Height || _screenWidth != screenSize.Width || _nesFrameHeight != height || _nesFrameWidth != width || _newFullscreen != _fullscreen || _useBilinearInterpolation != cfg.UseBilinearInterpolation) {
if (_screenHeight != screenSize.Height || _screenWidth != screenSize.Width || _nesFrameHeight != height ||
_nesFrameWidth != width || _newFullscreen != _fullscreen || _useBilinearInterpolation != cfg.
UseBilinearInterpolation)
{
auto frameLock = _frameLock.AcquireSafe();
auto textureLock = _textureLock.AcquireSafe();
screenSize = _console->GetVideoDecoder()->GetScreenSize(false);
if(_screenHeight != screenSize.Height || _screenWidth != screenSize.Width || _nesFrameHeight != height || _nesFrameWidth != width || _newFullscreen != _fullscreen || _useBilinearInterpolation != cfg.UseBilinearInterpolation) {
if (_screenHeight != screenSize.Height || _screenWidth != screenSize.Width || _nesFrameHeight != height ||
_nesFrameWidth != width || _newFullscreen != _fullscreen || _useBilinearInterpolation != cfg.
UseBilinearInterpolation)
{
_nesFrameHeight = height;
_nesFrameWidth = width;
_newFrameBufferSize = width * height;
@ -55,9 +64,11 @@ void Renderer::SetScreenSize(uint32_t width, uint32_t height)
bool needReset = _fullscreen != _newFullscreen || _useBilinearInterpolation != cfg.UseBilinearInterpolation;
bool fullscreenResizeMode = _fullscreen && _newFullscreen;
if(_pSwapChain && _fullscreen && !_newFullscreen) {
if (_pSwapChain && _fullscreen && !_newFullscreen)
{
HRESULT hr = _pSwapChain->SetFullscreenState(FALSE, NULL);
if(FAILED(hr)) {
if (FAILED(hr))
{
MessageManager::Log("SetFullscreenState(FALSE) failed - Error:" + std::to_string(hr));
}
}
@ -67,21 +78,26 @@ void Renderer::SetScreenSize(uint32_t width, uint32_t height)
_screenHeight = screenSize.Height;
_screenWidth = screenSize.Width;
if(_fullscreen) {
if (_fullscreen)
{
_realScreenHeight = _monitorHeight;
_realScreenWidth = _monitorWidth;
//Ensure the screen width/height is smaller or equal to the fullscreen resolution, no matter the requested scale
if(_monitorHeight < _screenHeight || _monitorWidth < _screenWidth) {
if (_monitorHeight < _screenHeight || _monitorWidth < _screenWidth)
{
double scale = (double)screenSize.Width / (double)screenSize.Height;
_screenHeight = _monitorHeight;
_screenWidth = (uint32_t)(scale * _screenHeight);
if(_monitorWidth < _screenWidth) {
if (_monitorWidth < _screenWidth)
{
_screenWidth = _monitorWidth;
_screenHeight = (uint32_t)(_screenWidth / scale);
}
}
} else {
}
else
{
_realScreenHeight = screenSize.Height;
_realScreenWidth = screenSize.Width;
}
@ -91,13 +107,19 @@ void Renderer::SetScreenSize(uint32_t width, uint32_t height)
_screenBufferSize = _realScreenHeight * _realScreenWidth;
if(!_pSwapChain || needReset) {
if (!_pSwapChain || needReset)
{
Reset();
} else {
if(fullscreenResizeMode) {
}
else
{
if (fullscreenResizeMode)
{
ResetNesBuffers();
CreateNesBuffers();
} else {
}
else
{
ResetNesBuffers();
ReleaseRenderTargetView();
_pSwapChain->ResizeBuffers(1, _realScreenWidth, _realScreenHeight, DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, 0);
@ -113,9 +135,12 @@ void Renderer::Reset()
{
auto lock = _frameLock.AcquireSafe();
CleanupDevice();
if(FAILED(InitDevice())) {
if (FAILED(InitDevice()))
{
CleanupDevice();
} else {
}
else
{
_console->GetVideoRenderer()->RegisterRenderingDevice(this);
}
}
@ -124,28 +149,34 @@ void Renderer::CleanupDevice()
{
ResetNesBuffers();
ReleaseRenderTargetView();
if(_pAlphaEnableBlendingState) {
if (_pAlphaEnableBlendingState)
{
_pAlphaEnableBlendingState->Release();
_pAlphaEnableBlendingState = nullptr;
}
if(_pDepthDisabledStencilState) {
if (_pDepthDisabledStencilState)
{
_pDepthDisabledStencilState->Release();
_pDepthDisabledStencilState = nullptr;
}
if(_samplerState) {
if (_samplerState)
{
_samplerState->Release();
_samplerState = nullptr;
}
if(_pSwapChain) {
if (_pSwapChain)
{
_pSwapChain->SetFullscreenState(false, nullptr);
_pSwapChain->Release();
_pSwapChain = nullptr;
}
if(_pDeviceContext) {
if (_pDeviceContext)
{
_pDeviceContext->Release();
_pDeviceContext = nullptr;
}
if(_pd3dDevice) {
if (_pd3dDevice)
{
_pd3dDevice->Release();
_pd3dDevice = nullptr;
}
@ -153,19 +184,23 @@ void Renderer::CleanupDevice()
void Renderer::ResetNesBuffers()
{
if(_pTexture) {
if (_pTexture)
{
_pTexture->Release();
_pTexture = nullptr;
}
if(_overlayTexture) {
if (_overlayTexture)
{
_overlayTexture->Release();
_overlayTexture = nullptr;
}
if(_pTextureSrv) {
if (_pTextureSrv)
{
_pTextureSrv->Release();
_pTextureSrv = nullptr;
}
if(_pOverlaySrv) {
if (_pOverlaySrv)
{
_pOverlaySrv->Release();
_pOverlaySrv = nullptr;
}
@ -178,7 +213,8 @@ void Renderer::ResetNesBuffers()
void Renderer::ReleaseRenderTargetView()
{
if(_pRenderTargetView) {
if (_pRenderTargetView)
{
_pRenderTargetView->Release();
_pRenderTargetView = nullptr;
}
@ -189,14 +225,16 @@ HRESULT Renderer::CreateRenderTargetView()
// Create a render target view
ID3D11Texture2D* pBackBuffer = nullptr;
HRESULT hr = _pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer);
if(FAILED(hr)) {
if (FAILED(hr))
{
MessageManager::Log("SwapChain::GetBuffer() failed - Error:" + std::to_string(hr));
return hr;
}
hr = _pd3dDevice->CreateRenderTargetView(pBackBuffer, nullptr, &_pRenderTargetView);
pBackBuffer->Release();
if(FAILED(hr)) {
if (FAILED(hr))
{
MessageManager::Log("D3DDevice::CreateRenderTargetView() failed - Error:" + std::to_string(hr));
return hr;
}
@ -224,19 +262,23 @@ HRESULT Renderer::CreateNesBuffers()
memset(_textureBuffer[1], 0, _nesFrameWidth * _nesFrameHeight * 4);
_pTexture = CreateTexture(_nesFrameWidth, _nesFrameHeight);
if(!_pTexture) {
if (!_pTexture)
{
return S_FALSE;
}
_overlayTexture = CreateTexture(8, 8);
if(!_overlayTexture) {
if (!_overlayTexture)
{
return S_FALSE;
}
_pTextureSrv = GetShaderResourceView(_pTexture);
if(!_pTextureSrv) {
if (!_pTextureSrv)
{
return S_FALSE;
}
_pOverlaySrv = GetShaderResourceView(_overlayTexture);
if(!_pOverlaySrv) {
if (!_pOverlaySrv)
{
return S_FALSE;
}
@ -296,38 +338,49 @@ HRESULT Renderer::InitDevice()
D3D_DRIVER_TYPE driverType = D3D_DRIVER_TYPE_NULL;
D3D_FEATURE_LEVEL featureLevel = D3D_FEATURE_LEVEL_11_1;
for(UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++) {
for (UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++)
{
driverType = driverTypes[driverTypeIndex];
featureLevel = D3D_FEATURE_LEVEL_11_1;
hr = D3D11CreateDeviceAndSwapChain(nullptr, driverType, nullptr, createDeviceFlags, featureLevels, numFeatureLevels, D3D11_SDK_VERSION, &sd, &_pSwapChain, &_pd3dDevice, &featureLevel, &_pDeviceContext);
hr = D3D11CreateDeviceAndSwapChain(nullptr, driverType, nullptr, createDeviceFlags, featureLevels,
numFeatureLevels, D3D11_SDK_VERSION, &sd, &_pSwapChain, &_pd3dDevice,
&featureLevel, &_pDeviceContext);
/*if(FAILED(hr)) {
MessageManager::Log("D3D11CreateDeviceAndSwapChain() failed - Error:" + std::to_string(hr));
}*/
if(hr == E_INVALIDARG) {
if (hr == E_INVALIDARG)
{
// DirectX 11.0 platforms will not recognize D3D_FEATURE_LEVEL_11_1 so we need to retry without it
featureLevel = D3D_FEATURE_LEVEL_11_0;
hr = D3D11CreateDeviceAndSwapChain(nullptr, driverType, nullptr, createDeviceFlags, &featureLevels[1], numFeatureLevels - 1, D3D11_SDK_VERSION, &sd, &_pSwapChain, &_pd3dDevice, &featureLevel, &_pDeviceContext);
hr = D3D11CreateDeviceAndSwapChain(nullptr, driverType, nullptr, createDeviceFlags, &featureLevels[1],
numFeatureLevels - 1, D3D11_SDK_VERSION, &sd, &_pSwapChain, &_pd3dDevice,
&featureLevel, &_pDeviceContext);
}
if(SUCCEEDED(hr)) {
if (SUCCEEDED(hr))
{
break;
}
}
if(FAILED(hr)) {
if (FAILED(hr))
{
MessageManager::Log("D3D11CreateDeviceAndSwapChain() failed - Error:" + std::to_string(hr));
return hr;
}
if(_fullscreen) {
if (_fullscreen)
{
hr = _pSwapChain->SetFullscreenState(TRUE, NULL);
if(FAILED(hr)) {
if (FAILED(hr))
{
MessageManager::Log("SetFullscreenState(true) failed - Error:" + std::to_string(hr));
MessageManager::Log("Switching back to windowed mode");
hr = _pSwapChain->SetFullscreenState(FALSE, NULL);
if(FAILED(hr)) {
if (FAILED(hr))
{
MessageManager::Log("SetFullscreenState(false) failed - Error:" + std::to_string(hr));
return hr;
}
@ -335,7 +388,8 @@ HRESULT Renderer::InitDevice()
}
hr = CreateRenderTargetView();
if(FAILED(hr)) {
if (FAILED(hr))
{
return hr;
}
@ -358,7 +412,8 @@ HRESULT Renderer::InitDevice()
// Create the state using the device.
hr = _pd3dDevice->CreateDepthStencilState(&depthDisabledStencilDesc, &_pDepthDisabledStencilState);
if(FAILED(hr)) {
if (FAILED(hr))
{
MessageManager::Log("D3DDevice::CreateDepthStencilState() failed - Error:" + std::to_string(hr));
return hr;
}
@ -379,7 +434,8 @@ HRESULT Renderer::InitDevice()
// Create the blend state using the description.
hr = _pd3dDevice->CreateBlendState(&blendStateDescription, &_pAlphaEnableBlendingState);
if(FAILED(hr)) {
if (FAILED(hr))
{
MessageManager::Log("D3DDevice::CreateBlendState() failed - Error:" + std::to_string(hr));
return hr;
}
@ -394,12 +450,14 @@ HRESULT Renderer::InitDevice()
_pDeviceContext->OMSetDepthStencilState(_pDepthDisabledStencilState, 1);
hr = CreateNesBuffers();
if(FAILED(hr)) {
if (FAILED(hr))
{
return hr;
}
hr = CreateSamplerState();
if(FAILED(hr)) {
if (FAILED(hr))
{
return hr;
}
@ -425,7 +483,8 @@ HRESULT Renderer::CreateSamplerState()
samplerDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
HRESULT hr = _pd3dDevice->CreateSamplerState(&samplerDesc, &_samplerState);
if(FAILED(hr)) {
if (FAILED(hr))
{
MessageManager::Log("D3DDevice::CreateSamplerState() failed - Error:" + std::to_string(hr));
}
@ -452,7 +511,8 @@ ID3D11Texture2D* Renderer::CreateTexture(uint32_t width, uint32_t height)
desc.MiscFlags = 0;
HRESULT hr = _pd3dDevice->CreateTexture2D(&desc, nullptr, &texture);
if(FAILED(hr)) {
if (FAILED(hr))
{
MessageManager::Log("D3DDevice::CreateTexture() failed - Error:" + std::to_string(hr));
return nullptr;
}
@ -463,7 +523,8 @@ ID3D11ShaderResourceView* Renderer::GetShaderResourceView(ID3D11Texture2D* textu
{
ID3D11ShaderResourceView* shaderResourceView = nullptr;
HRESULT hr = _pd3dDevice->CreateShaderResourceView(texture, nullptr, &shaderResourceView);
if(FAILED(hr)) {
if (FAILED(hr))
{
MessageManager::Log("D3DDevice::CreateShaderResourceView() failed - Error:" + std::to_string(hr));
return nullptr;
}
@ -477,14 +538,17 @@ void Renderer::DrawString(string message, float x, float y, DirectX::FXMVECTOR c
DrawString(textStr, x, y, color, scale, font);
}
void Renderer::DrawString(std::wstring message, float x, float y, DirectX::FXMVECTOR color, float scale, SpriteFont* font)
void Renderer::DrawString(std::wstring message, float x, float y, DirectX::FXMVECTOR color, float scale,
SpriteFont* font)
{
const wchar_t* text = message.c_str();
if(font == nullptr) {
if (font == nullptr)
{
font = _font.get();
}
font->DrawString(_spriteBatch.get(), text, XMFLOAT2(x+_leftMargin, y+_topMargin), color, 0.0f, XMFLOAT2(0, 0), scale);
font->DrawString(_spriteBatch.get(), text, XMFLOAT2(x + _leftMargin, y + _topMargin), color, 0.0f, XMFLOAT2(0, 0),
scale);
}
void Renderer::UpdateFrame(void* frameBuffer, uint32_t width, uint32_t height)
@ -493,7 +557,8 @@ void Renderer::UpdateFrame(void *frameBuffer, uint32_t width, uint32_t height)
uint32_t bpp = 4;
auto lock = _textureLock.AcquireSafe();
if(_textureBuffer[0]) {
if (_textureBuffer[0])
{
//_textureBuffer[0] may be null if directx failed to initialize properly
memcpy(_textureBuffer[0], frameBuffer, width * height * bpp);
_needFlip = true;
@ -504,14 +569,16 @@ void Renderer::UpdateFrame(void *frameBuffer, uint32_t width, uint32_t height)
void Renderer::DrawScreen()
{
//Swap buffers - emulator always writes to _textureBuffer[0], screen always draws _textureBuffer[1]
if(_needFlip) {
if (_needFlip)
{
auto lock = _textureLock.AcquireSafe();
uint8_t* textureBuffer = _textureBuffer[0];
_textureBuffer[0] = _textureBuffer[1];
_textureBuffer[1] = textureBuffer;
_needFlip = false;
if(_frameChanged) {
if (_frameChanged)
{
_frameChanged = false;
_renderedFrameCount++;
}
@ -522,13 +589,15 @@ void Renderer::DrawScreen()
uint32_t rowPitch = _nesFrameWidth * bpp;
D3D11_MAPPED_SUBRESOURCE dd;
HRESULT hr = _pDeviceContext->Map(_pTexture, 0, D3D11_MAP_WRITE_DISCARD, 0, &dd);
if(FAILED(hr)) {
if (FAILED(hr))
{
MessageManager::Log("DeviceContext::Map() failed - Error:" + std::to_string(hr));
return;
}
uint8_t* surfacePointer = (uint8_t*)dd.pData;
uint8_t* videoBuffer = _textureBuffer[1];
for(uint32_t i = 0, iMax = _nesFrameHeight; i < iMax; i++) {
for (uint32_t i = 0, iMax = _nesFrameHeight; i < iMax; i++)
{
memcpy(surfacePointer, videoBuffer, rowPitch);
videoBuffer += rowPitch;
surfacePointer += dd.RowPitch;
@ -555,18 +624,22 @@ void Renderer::Render()
{
bool paused = _console->IsPaused();
if(_noUpdateCount > 10 || _frameChanged || paused || IsMessageShown()) {
if (_noUpdateCount > 10 || _frameChanged || paused || IsMessageShown())
{
_noUpdateCount = 0;
auto lock = _frameLock.AcquireSafe();
if(_newFullscreen != _fullscreen) {
if (_newFullscreen != _fullscreen)
{
SetScreenSize(_nesFrameWidth, _nesFrameHeight);
}
if(_pDeviceContext == nullptr) {
if (_pDeviceContext == nullptr)
{
//DirectX failed to initialize, try to init
Reset();
if(_pDeviceContext == nullptr) {
if (_pDeviceContext == nullptr)
{
//Can't init, prevent crash
return;
}
@ -580,8 +653,10 @@ void Renderer::Render()
//Draw screen
DrawScreen();
if(_console->IsRunning()) {
if(paused) {
if (_console->IsRunning())
{
if (paused)
{
DrawPauseScreen();
}
DrawCounters();
@ -595,15 +670,20 @@ void Renderer::Render()
bool waitVSync = _console->GetSettings()->GetVideoConfig().VerticalSync;
HRESULT hr = _pSwapChain->Present(waitVSync ? 1 : 0, 0);
if(FAILED(hr)) {
if (FAILED(hr))
{
MessageManager::Log("SwapChain::Present() failed - Error:" + std::to_string(hr));
if(hr == DXGI_ERROR_DEVICE_REMOVED) {
MessageManager::Log("D3DDevice: GetDeviceRemovedReason: " + std::to_string(_pd3dDevice->GetDeviceRemovedReason()));
if (hr == DXGI_ERROR_DEVICE_REMOVED)
{
MessageManager::Log(
"D3DDevice: GetDeviceRemovedReason: " + std::to_string(_pd3dDevice->GetDeviceRemovedReason()));
}
MessageManager::Log("Trying to reset DX...");
Reset();
}
} else {
}
else
{
_noUpdateCount++;
}
}
@ -611,7 +691,8 @@ void Renderer::Render()
void Renderer::DrawString(std::wstring message, int x, int y, uint8_t r, uint8_t g, uint8_t b, uint8_t opacity)
{
XMVECTORF32 color = {(float)r / 255.0f, (float)g / 255.0f, (float)b / 255.0f, (float)opacity / 255.0f};
_font->DrawString(_spriteBatch.get(), message.c_str(), XMFLOAT2((float)x+_leftMargin, (float)y+_topMargin), color);
_font->DrawString(_spriteBatch.get(), message.c_str(), XMFLOAT2((float)x + _leftMargin, (float)y + _topMargin),
color);
}
float Renderer::MeasureString(std::wstring text)

View file

@ -12,7 +12,8 @@ using namespace DirectX;
class Console;
namespace DirectX {
namespace DirectX
{
class SpriteBatch;
class SpriteFont;
}
@ -79,7 +80,8 @@ private:
void DrawPauseScreen();
void DrawString(string message, float x, float y, DirectX::FXMVECTOR color, float scale, SpriteFont* font = nullptr);
void DrawString(std::wstring message, float x, float y, DirectX::FXMVECTOR color, float scale, SpriteFont* font = nullptr);
void DrawString(std::wstring message, float x, float y, DirectX::FXMVECTOR color, float scale,
SpriteFont* font = nullptr);
void DrawString(std::wstring message, int x, int y, uint8_t r, uint8_t g, uint8_t b, uint8_t opacity);
float MeasureString(std::wstring text);

View file

@ -15,16 +15,20 @@ SoundManager::SoundManager(shared_ptr<Console> console, HWND hwnd)
memset(&_audioDeviceID, 0, sizeof(_audioDeviceID));
if(InitializeDirectSound(44100, true)) {
if (InitializeDirectSound(44100, true))
{
_console->GetSoundMixer()->RegisterAudioDevice(this);
} else {
}
else
{
MessageManager::DisplayMessage("Error", "CouldNotInitializeAudioSystem");
}
}
SoundManager::~SoundManager()
{
if(_console && _console->GetSoundMixer()) {
if (_console && _console->GetSoundMixer())
{
_console->GetSoundMixer()->RegisterAudioDevice(nullptr);
}
Release();
@ -36,9 +40,12 @@ bool CALLBACK SoundManager::DirectSoundEnumProc(LPGUID lpGUID, LPCWSTR lpszDesc,
SoundDeviceInfo deviceInfo;
deviceInfo.description = utf8::utf8::encode(lpszDesc);
if(lpGUID != nullptr) {
if (lpGUID != nullptr)
{
memcpy((void*)&deviceInfo.guid, lpGUID, 16);
} else {
}
else
{
memset((void*)&deviceInfo.guid, 0, 16);
}
devices->push_back(deviceInfo);
@ -56,7 +63,8 @@ vector<SoundDeviceInfo> SoundManager::GetAvailableDeviceInfo()
string SoundManager::GetAvailableDevices()
{
string deviceString;
for(SoundDeviceInfo device : GetAvailableDeviceInfo()) {
for (SoundDeviceInfo device : GetAvailableDeviceInfo())
{
deviceString += device.description + "||"s;
}
return deviceString;
@ -64,11 +72,15 @@ string SoundManager::GetAvailableDevices()
void SoundManager::SetAudioDevice(string deviceName)
{
if(_audioDeviceName != deviceName) {
for(SoundDeviceInfo device : GetAvailableDeviceInfo()) {
if(device.description.compare(deviceName) == 0) {
if (_audioDeviceName != deviceName)
{
for (SoundDeviceInfo device : GetAvailableDeviceInfo())
{
if (device.description.compare(deviceName) == 0)
{
_audioDeviceName = deviceName;
if(memcmp(&_audioDeviceID, &device.guid, 16) != 0) {
if (memcmp(&_audioDeviceID, &device.guid, 16) != 0)
{
memcpy(&_audioDeviceID, &device.guid, 16);
_needReset = true;
}
@ -86,14 +98,16 @@ bool SoundManager::InitializeDirectSound(uint32_t sampleRate, bool isStereo)
// Initialize the direct sound interface pointer for the default sound device.
result = DirectSoundCreate8(&_audioDeviceID, &_directSound, NULL);
if(FAILED(result)) {
if (FAILED(result))
{
MessageManager::Log("[Audio] Failed to create direct sound device.");
return false;
}
// Set the cooperative level to priority so the format of the primary sound buffer can be modified.
result = _directSound->SetCooperativeLevel(_hWnd, DSSCL_PRIORITY);
if(FAILED(result)) {
if (FAILED(result))
{
MessageManager::Log("[Audio] Failed to set cooperative level.");
return false;
}
@ -108,7 +122,8 @@ bool SoundManager::InitializeDirectSound(uint32_t sampleRate, bool isStereo)
// Get control of the primary sound buffer on the default sound device.
result = _directSound->CreateSoundBuffer(&bufferDesc, &_primaryBuffer, NULL);
if(FAILED(result)) {
if (FAILED(result))
{
MessageManager::Log("[Audio] Failed to create primary sound buffer.");
return false;
}
@ -127,7 +142,8 @@ bool SoundManager::InitializeDirectSound(uint32_t sampleRate, bool isStereo)
// Set the primary buffer to be the wave format specified.
result = _primaryBuffer->SetFormat(&waveFormat);
if(FAILED(result)) {
if (FAILED(result))
{
MessageManager::Log("[Audio] Failed to set the sound format.");
return false;
}
@ -138,7 +154,8 @@ bool SoundManager::InitializeDirectSound(uint32_t sampleRate, bool isStereo)
// Set the buffer description of the secondary sound buffer that the wave file will be loaded onto.
bufferDesc.dwSize = sizeof(DSBUFFERDESC);
bufferDesc.dwFlags = DSBCAPS_CTRLPOSITIONNOTIFY | DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS | DSBCAPS_LOCSOFTWARE | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY;
bufferDesc.dwFlags = DSBCAPS_CTRLPOSITIONNOTIFY | DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS |
DSBCAPS_LOCSOFTWARE | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY;
bufferDesc.dwBufferBytes = _bufferSize;
bufferDesc.dwReserved = 0;
bufferDesc.lpwfxFormat = &waveFormat;
@ -147,21 +164,24 @@ bool SoundManager::InitializeDirectSound(uint32_t sampleRate, bool isStereo)
// Create a temporary sound buffer with the specific buffer settings.
IDirectSoundBuffer* tempBuffer;
result = _directSound->CreateSoundBuffer(&bufferDesc, &tempBuffer, NULL);
if(FAILED(result)) {
if (FAILED(result))
{
MessageManager::Log("[Audio] Failed to create temporary sound buffer.");
return false;
}
// Test the buffer format against the direct sound 8 interface and create the secondary buffer.
result = tempBuffer->QueryInterface(IID_IDirectSoundBuffer8, (LPVOID*)&_secondaryBuffer);
if(FAILED(result)) {
if (FAILED(result))
{
MessageManager::Log("[Audio] Failed to obtain secondary sound buffer.");
return false;
}
// Set volume of the buffer to 100%.
result = _secondaryBuffer->SetVolume(DSBVOLUME_MAX);
if(FAILED(result)) {
if (FAILED(result))
{
MessageManager::Log("[Audio] Failed to set volume of the secondary sound buffer.");
return false;
}
@ -180,17 +200,20 @@ void SoundManager::Release()
_needReset = false;
_lastWriteOffset = 0;
if(_secondaryBuffer) {
if (_secondaryBuffer)
{
_secondaryBuffer->Release();
_secondaryBuffer = nullptr;
}
if(_primaryBuffer) {
if (_primaryBuffer)
{
_primaryBuffer->Release();
_primaryBuffer = nullptr;
}
if(_directSound) {
if (_directSound)
{
_directSound->Release();
_directSound = nullptr;
}
@ -215,11 +238,13 @@ void SoundManager::CopyToSecondaryBuffer(uint8_t *data, uint32_t size)
DWORD bufferASize;
DWORD bufferBSize;
_secondaryBuffer->Lock(_lastWriteOffset, size, (void**)&bufferPtrA, (DWORD*)&bufferASize, (void**)&bufferPtrB, (DWORD*)&bufferBSize, 0);
_secondaryBuffer->Lock(_lastWriteOffset, size, (void**)&bufferPtrA, (DWORD*)&bufferASize, (void**)&bufferPtrB,
(DWORD*)&bufferBSize, 0);
_lastWriteOffset = (_lastWriteOffset + size) % _bufferSize;
memcpy(bufferPtrA, data, bufferASize);
if(bufferPtrB && bufferBSize > 0) {
if (bufferPtrB && bufferBSize > 0)
{
memcpy(bufferPtrB, data + bufferASize, bufferBSize);
}
@ -228,7 +253,8 @@ void SoundManager::CopyToSecondaryBuffer(uint8_t *data, uint32_t size)
void SoundManager::Pause()
{
if(_secondaryBuffer) {
if (_secondaryBuffer)
{
_secondaryBuffer->Stop();
}
_playing = false;
@ -236,7 +262,8 @@ void SoundManager::Pause()
void SoundManager::Stop()
{
if(_secondaryBuffer) {
if (_secondaryBuffer)
{
_secondaryBuffer->Stop();
ClearSecondaryBuffer();
}
@ -247,7 +274,8 @@ void SoundManager::Stop()
void SoundManager::Play()
{
if(_secondaryBuffer) {
if (_secondaryBuffer)
{
_secondaryBuffer->Play(0, 0, DSBPLAY_LOOPING);
_playing = true;
}
@ -256,9 +284,12 @@ void SoundManager::Play()
void SoundManager::ValidateWriteCursor(DWORD safeWriteCursor)
{
int32_t writeGap = _lastWriteOffset - safeWriteCursor;
if(writeGap < -10000) {
if (writeGap < -10000)
{
writeGap += _bufferSize;
} else if(writeGap < 0) {
}
else if (writeGap < 0)
{
_bufferUnderrunEventCount++;
_lastWriteOffset = safeWriteCursor;
}
@ -273,7 +304,8 @@ void SoundManager::ProcessEndOfFrame()
uint32_t emulationSpeed = _console->GetSettings()->GetEmulationSpeed();
uint32_t targetRate = _sampleRate;
if(emulationSpeed > 0 && emulationSpeed < 100) {
if (emulationSpeed > 0 && emulationSpeed < 100)
{
//Slow down playback when playing at less than 100%
targetRate = (uint32_t)(targetRate * ((double)emulationSpeed / 100.0));
}
@ -284,7 +316,9 @@ void SoundManager::ProcessEndOfFrame()
AudioConfig cfg = _console->GetSettings()->GetAudioConfig();
SetAudioDevice(cfg.AudioDevice);
if(_averageLatency > 0 && emulationSpeed <= 100 && emulationSpeed > 0 && std::abs(_averageLatency - cfg.AudioLatency) > 50) {
if (_averageLatency > 0 && emulationSpeed <= 100 && emulationSpeed > 0 && std::abs(
_averageLatency - cfg.AudioLatency) > 50)
{
//Latency is way off (over 50ms gap), stop audio & start again
Stop();
}
@ -294,7 +328,8 @@ void SoundManager::PlayBuffer(int16_t *soundBuffer, uint32_t sampleCount, uint32
{
uint32_t bytesPerSample = 2 * (isStereo ? 2 : 1);
uint32_t latency = _console->GetSettings()->GetAudioConfig().AudioLatency;
if(_sampleRate != sampleRate || _isStereo != isStereo || _needReset || latency != _previousLatency) {
if (_sampleRate != sampleRate || _isStereo != isStereo || _needReset || latency != _previousLatency)
{
_previousLatency = latency;
Release();
InitializeDirectSound(sampleRate, isStereo);
@ -308,9 +343,11 @@ void SoundManager::PlayBuffer(int16_t *soundBuffer, uint32_t sampleCount, uint32
uint32_t soundBufferSize = sampleCount * bytesPerSample;
CopyToSecondaryBuffer((uint8_t*)soundBuffer, soundBufferSize);
if(!_playing) {
if (!_playing)
{
DWORD byteLatency = (int32_t)((float)(sampleRate * latency) / 1000.0f * bytesPerSample);
if(_lastWriteOffset >= byteLatency / 2) {
if (_lastWriteOffset >= byteLatency / 2)
{
Play();
}
}

View file

@ -182,10 +182,18 @@ static vector<KeyDefinition> _keyDefinitions = {
//{ "-", 0xE3 - E4, "OEM specific", "" },
{"VK_PROCESSKEY", 0xE5, "IME PROCESS", ""},
//{ "-", 0xE6, "OEM specific", "" },
{ "VK_PACKET", 0xE7, "Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KEYUP", "" },
{
"VK_PACKET", 0xE7,
"Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KEYUP",
""
},
//{ "-", 0xE8, "Unassigned", "" },
// {"-",0xE6,"OEM specific"},
{ "VK_PACKET", 0xE7, "Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KEYUP", "" },
{
"VK_PACKET", 0xE7,
"Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KEYUP",
""
},
// {"-",0xE8,"Unassigned"},
//{ "-", 0xE9 - F5, "OEM specific", "" },
{"VK_ATTN", 0xF6, "Attn", ""},
@ -207,31 +215,53 @@ WindowsKeyManager::WindowsKeyManager(shared_ptr<Console> console, HWND hWnd)
ResetKeyState();
//Init XInput buttons
vector<string> buttonNames = { "Up", "Down", "Left", "Right", "Start", "Back", "L3", "R3", "L1", "R1", "?", "?", "A", "B", "X", "Y", "L2", "R2", "RT Up", "RT Down", "RT Left", "RT Right", "LT Up", "LT Down", "LT Left", "LT Right" };
for(int i = 0; i < 4; i++) {
for(int j = 0; j < (int)buttonNames.size(); j++) {
_keyDefinitions.push_back({ "", (uint32_t)(0xFFFF + i * 0x100 + j + 1), "Pad" + std::to_string(i + 1) + " " + buttonNames[j] });
vector<string> buttonNames = {
"Up", "Down", "Left", "Right", "Start", "Back", "L3", "R3", "L1", "R1", "?", "?", "A", "B", "X", "Y", "L2", "R2",
"RT Up", "RT Down", "RT Left", "RT Right", "LT Up", "LT Down", "LT Left", "LT Right"
};
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < (int)buttonNames.size(); j++)
{
_keyDefinitions.push_back({
"", (uint32_t)(0xFFFF + i * 0x100 + j + 1), "Pad" + std::to_string(i + 1) + " " + buttonNames[j]
});
}
}
//Init DirectInput buttons
vector<string> diButtonNames = { "Y+", "Y-", "X-", "X+", "Y2+", "Y2-", "X2-", "X2+", "Z+", "Z-", "Z2+", "Z2-", "DPad Up", "DPad Down", "DPad Right", "DPad Left" };
for(int i = 0; i < 16; i++) {
for(int j = 0; j < (int)diButtonNames.size(); j++) {
_keyDefinitions.push_back({ "", (uint32_t)(0x11000 + i * 0x100 + j), "Joy" + std::to_string(i + 1) + " " + diButtonNames[j] });
vector<string> diButtonNames = {
"Y+", "Y-", "X-", "X+", "Y2+", "Y2-", "X2-", "X2+", "Z+", "Z-", "Z2+", "Z2-", "DPad Up", "DPad Down",
"DPad Right", "DPad Left"
};
for (int i = 0; i < 16; i++)
{
for (int j = 0; j < (int)diButtonNames.size(); j++)
{
_keyDefinitions.push_back({
"", (uint32_t)(0x11000 + i * 0x100 + j), "Joy" + std::to_string(i + 1) + " " + diButtonNames[j]
});
}
for(int j = 0; j < 128; j++) {
_keyDefinitions.push_back({ "", (uint32_t)(0x11000 + i * 0x100 + j + 0x10), "Joy" + std::to_string(i + 1) + " But" + std::to_string(j+1)});
for (int j = 0; j < 128; j++)
{
_keyDefinitions.push_back({
"", (uint32_t)(0x11000 + i * 0x100 + j + 0x10),
"Joy" + std::to_string(i + 1) + " But" + std::to_string(j + 1)
});
}
}
for(KeyDefinition& keyDef : _keyDefinitions) {
for (KeyDefinition& keyDef : _keyDefinitions)
{
_keyNames[keyDef.keyCode] = keyDef.description;
_keyExtendedNames[keyDef.keyCode | 0x100] = keyDef.extDescription.empty() ? "Ext " + keyDef.description : keyDef.extDescription;
_keyExtendedNames[keyDef.keyCode | 0x100] = keyDef.extDescription.empty()
? "Ext " + keyDef.description
: keyDef.extDescription;
_keyCodes[keyDef.description] = keyDef.keyCode;
if(!keyDef.extDescription.empty()) {
if (!keyDef.extDescription.empty())
{
_keyCodes[keyDef.extDescription] = 0x100 | (keyDef.keyCode);
}
}
@ -248,14 +278,17 @@ WindowsKeyManager::~WindowsKeyManager()
void WindowsKeyManager::StartUpdateDeviceThread()
{
_updateDeviceThread = std::thread([=]() {
_updateDeviceThread = std::thread([=]()
{
_xInput.reset(new XInputManager(_console));
_directInput.reset(new DirectInputManager(_console, _hWnd));
while(!_stopUpdateDeviceThread) {
while (!_stopUpdateDeviceThread)
{
//Check for newly plugged in XInput controllers every 5 secs
//Do not check for DirectInput controllers because this takes more time and sometimes causes issues/freezes
if(_xInput->NeedToUpdate()) {
if (_xInput->NeedToUpdate())
{
_xInput->UpdateDeviceList();
}
_stopSignal.Wait(5000);
@ -265,7 +298,8 @@ void WindowsKeyManager::StartUpdateDeviceThread()
void WindowsKeyManager::RefreshState()
{
if(!_xInput || !_directInput) {
if (!_xInput || !_directInput)
{
return;
}
@ -275,27 +309,35 @@ void WindowsKeyManager::RefreshState()
bool WindowsKeyManager::IsKeyPressed(uint32_t key)
{
if(_disableAllKeys) {
if (_disableAllKeys)
{
return false;
}
if(key >= 0x10000) {
if(!_xInput || !_directInput) {
if (key >= 0x10000)
{
if (!_xInput || !_directInput)
{
return false;
}
if(key >= 0x11000) {
if (key >= 0x11000)
{
//Directinput key
uint8_t gamepadPort = (key - 0x11000) / 0x100;
uint8_t gamepadButton = (key - 0x11000) % 0x100;
return _directInput->IsPressed(gamepadPort, gamepadButton);
} else {
}
else
{
//XInput key
uint8_t gamepadPort = (key - 0xFFFF) / 0x100;
uint8_t gamepadButton = (key - 0xFFFF) % 0x100;
return _xInput->IsPressed(gamepadPort, gamepadButton);
}
} else if(key < 0x200) {
}
else if (key < 0x200)
{
return _keyState[key] != 0;
}
return false;
@ -303,7 +345,8 @@ bool WindowsKeyManager::IsKeyPressed(uint32_t key)
bool WindowsKeyManager::IsMouseButtonPressed(MouseButton button)
{
switch(button) {
switch (button)
{
case MouseButton::LeftButton: return _mouseState[0];
case MouseButton::RightButton: return _mouseState[1];
case MouseButton::MiddleButton: return _mouseState[2];
@ -315,30 +358,39 @@ bool WindowsKeyManager::IsMouseButtonPressed(MouseButton button)
vector<uint32_t> WindowsKeyManager::GetPressedKeys()
{
vector<uint32_t> result;
if(!_xInput || !_directInput) {
if (!_xInput || !_directInput)
{
return result;
}
_xInput->RefreshState();
for(int i = 0; i < XUSER_MAX_COUNT; i++) {
for(int j = 1; j <= 26; j++) {
if(_xInput->IsPressed(i, j)) {
for (int i = 0; i < XUSER_MAX_COUNT; i++)
{
for (int j = 1; j <= 26; j++)
{
if (_xInput->IsPressed(i, j))
{
result.push_back(0xFFFF + i * 0x100 + j);
}
}
}
_directInput->RefreshState();
for(int i = _directInput->GetJoystickCount() - 1; i >= 0; i--) {
for(int j = 0; j < 16+128; j++) {
if(_directInput->IsPressed(i, j)) {
for (int i = _directInput->GetJoystickCount() - 1; i >= 0; i--)
{
for (int j = 0; j < 16 + 128; j++)
{
if (_directInput->IsPressed(i, j))
{
result.push_back(0x11000 + i * 0x100 + j);
}
}
}
for(int i = 0; i < 0x200; i++) {
if(_keyState[i]) {
for (int i = 0; i < 0x200; i++)
{
if (_keyState[i])
{
result.push_back(i);
}
}
@ -349,7 +401,8 @@ string WindowsKeyManager::GetKeyName(uint32_t keyCode)
{
bool extendedKey = (keyCode <= 0xFFFF && (keyCode & 0x100));
auto keyDef = (extendedKey ? _keyExtendedNames : _keyNames).find(keyCode);
if(keyDef != (extendedKey ? _keyExtendedNames : _keyNames).end()) {
if (keyDef != (extendedKey ? _keyExtendedNames : _keyNames).end())
{
return keyDef->second;
}
return "";
@ -358,7 +411,8 @@ string WindowsKeyManager::GetKeyName(uint32_t keyCode)
uint32_t WindowsKeyManager::GetKeyCode(string keyName)
{
auto keyDef = _keyCodes.find(keyName);
if(keyDef != _keyCodes.end()) {
if (keyDef != _keyCodes.end())
{
return keyDef->second;
}
return 0;
@ -366,7 +420,8 @@ uint32_t WindowsKeyManager::GetKeyCode(string keyName)
void WindowsKeyManager::UpdateDevices()
{
if(!_xInput || !_directInput) {
if (!_xInput || !_directInput)
{
return;
}
@ -376,11 +431,15 @@ void WindowsKeyManager::UpdateDevices()
void WindowsKeyManager::SetKeyState(uint16_t scanCode, bool state)
{
if(scanCode > 0x1FF) {
if (scanCode > 0x1FF)
{
_mouseState[scanCode & 0x03] = state;
} else {
}
else
{
uint32_t keyCode = MapVirtualKeyEx(scanCode & 0xFF, MAPVK_VSC_TO_VK, GetKeyboardLayout(0));
if(keyCode >= 0x10 && keyCode <= 0x12) {
if (keyCode >= 0x10 && keyCode <= 0x12)
{
//Ignore "ext" flag for alt, ctrl & shift
scanCode = MapVirtualKeyEx(keyCode, MAPVK_VK_TO_VSC, GetKeyboardLayout(0));
}

View file

@ -8,7 +8,8 @@
#include "XInputManager.h"
#include "DirectInputManager.h"
struct KeyDefinition {
struct KeyDefinition
{
string name;
uint32_t keyCode;
string description;

View file

@ -6,7 +6,8 @@
XInputManager::XInputManager(shared_ptr<Console> console)
{
_console = console;
for(int i = 0; i < XUSER_MAX_COUNT; i++) {
for (int i = 0; i < XUSER_MAX_COUNT; i++)
{
_gamePadStates.push_back(shared_ptr<XINPUT_STATE>(new XINPUT_STATE()));
_gamePadConnected.push_back(true);
}
@ -15,13 +16,18 @@ XInputManager::XInputManager(shared_ptr<Console> console)
void XInputManager::RefreshState()
{
XINPUT_STATE state;
for(DWORD i = 0; i < XUSER_MAX_COUNT; i++) {
if(_gamePadConnected[i]) {
if(XInputGetState(i, &state) != ERROR_SUCCESS) {
for (DWORD i = 0; i < XUSER_MAX_COUNT; i++)
{
if (_gamePadConnected[i])
{
if (XInputGetState(i, &state) != ERROR_SUCCESS)
{
//XInputGetState is incredibly slow when no controller is plugged in
ZeroMemory(_gamePadStates[i].get(), sizeof(XINPUT_STATE));
_gamePadConnected[i] = false;
} else {
}
else
{
*_gamePadStates[i] = state;
}
}
@ -30,10 +36,13 @@ void XInputManager::RefreshState()
bool XInputManager::NeedToUpdate()
{
for(int i = 0; i < XUSER_MAX_COUNT; i++) {
if(!_gamePadConnected[i]) {
for (int i = 0; i < XUSER_MAX_COUNT; i++)
{
if (!_gamePadConnected[i])
{
XINPUT_STATE state;
if(XInputGetState(i, &state) == ERROR_SUCCESS) {
if (XInputGetState(i, &state) == ERROR_SUCCESS)
{
return true;
}
}
@ -44,22 +53,28 @@ bool XInputManager::NeedToUpdate()
void XInputManager::UpdateDeviceList()
{
//Periodically detect if a controller has been plugged in to allow controllers to be plugged in after the emu is started
for(int i = 0; i < XUSER_MAX_COUNT; i++) {
for (int i = 0; i < XUSER_MAX_COUNT; i++)
{
_gamePadConnected[i] = true;
}
}
bool XInputManager::IsPressed(uint8_t gamepadPort, uint8_t button)
{
if(_gamePadConnected[gamepadPort]) {
if (_gamePadConnected[gamepadPort])
{
XINPUT_GAMEPAD& gamepad = _gamePadStates[gamepadPort]->Gamepad;
if(button <= 16) {
if (button <= 16)
{
WORD xinputButton = 1 << (button - 1);
return (_gamePadStates[gamepadPort]->Gamepad.wButtons & xinputButton) != 0;
} else {
}
else
{
double ratio = _console->GetSettings()->GetControllerDeadzoneRatio() * 2;
switch(button) {
switch (button)
{
case 17: return gamepad.bLeftTrigger > (XINPUT_GAMEPAD_TRIGGER_THRESHOLD * ratio);
case 18: return gamepad.bRightTrigger > (XINPUT_GAMEPAD_TRIGGER_THRESHOLD * ratio);
case 19: return gamepad.sThumbRY > (XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE * ratio);