mirror of
https://github.com/izzy2lost/dolphin.git
synced 2026-06-19 01:16:48 -07:00
boring svn:eol-style native again...
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5771 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
+187
-187
@@ -1,187 +1,187 @@
|
||||
#include "../ControllerInterface.h"
|
||||
|
||||
#ifdef CIFACE_USE_DIRECTINPUT_KEYBOARD
|
||||
|
||||
#include "DirectInputKeyboard.h"
|
||||
#include "DirectInput.h"
|
||||
|
||||
// TODO: maybe add a ClearInputState function to this device
|
||||
|
||||
namespace ciface
|
||||
{
|
||||
namespace DirectInput
|
||||
{
|
||||
|
||||
struct
|
||||
{
|
||||
const BYTE code;
|
||||
const char* const name;
|
||||
} named_keys[] =
|
||||
{
|
||||
#include "NamedKeys.h"
|
||||
};
|
||||
|
||||
struct
|
||||
{
|
||||
const BYTE code;
|
||||
const char* const name;
|
||||
} named_lights[] =
|
||||
{
|
||||
{ VK_NUMLOCK, "NUM LOCK" },
|
||||
{ VK_CAPITAL, "CAPS LOCK" },
|
||||
{ VK_SCROLL, "SCROLL LOCK" }
|
||||
};
|
||||
|
||||
void InitKeyboard(IDirectInput8* const idi8, std::vector<ControllerInterface::Device*>& devices)
|
||||
{
|
||||
LPDIRECTINPUTDEVICE8 kb_device;
|
||||
|
||||
unsigned int kb_count = 0;
|
||||
|
||||
std::list<DIDEVICEINSTANCE> keyboards;
|
||||
idi8->EnumDevices(DI8DEVCLASS_KEYBOARD, DIEnumDevicesCallback, (LPVOID)&keyboards, DIEDFL_ATTACHEDONLY);
|
||||
|
||||
// add other keyboard devices
|
||||
std::list<DIDEVICEINSTANCE>::iterator
|
||||
i = keyboards.begin(),
|
||||
e = keyboards.end();
|
||||
for (; i!=e; ++i)
|
||||
{
|
||||
if (SUCCEEDED(idi8->CreateDevice(i->guidInstance, &kb_device, NULL)))
|
||||
{
|
||||
if (SUCCEEDED(kb_device->SetDataFormat(&c_dfDIKeyboard)))
|
||||
if (SUCCEEDED(kb_device->SetCooperativeLevel(NULL, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)))
|
||||
{
|
||||
devices.push_back(new Keyboard(kb_device, kb_count++));
|
||||
return;
|
||||
}
|
||||
}
|
||||
kb_device->Release();
|
||||
}
|
||||
}
|
||||
|
||||
Keyboard::~Keyboard()
|
||||
{
|
||||
// kb
|
||||
m_kb_device->Unacquire();
|
||||
m_kb_device->Release();
|
||||
|
||||
}
|
||||
|
||||
Keyboard::Keyboard(const LPDIRECTINPUTDEVICE8 kb_device, const int index)
|
||||
: m_kb_device(kb_device)
|
||||
, m_index(index)
|
||||
{
|
||||
m_kb_device->Acquire();
|
||||
|
||||
ZeroMemory(&m_state_in, sizeof(m_state_in));
|
||||
ZeroMemory(m_state_out, sizeof(m_state_out));
|
||||
ZeroMemory(&m_current_state_out, sizeof(m_current_state_out));
|
||||
|
||||
// KEYBOARD
|
||||
// add keys
|
||||
for (unsigned int i = 0; i < sizeof(named_keys)/sizeof(*named_keys); ++i)
|
||||
AddInput(new Key(i));
|
||||
// add lights
|
||||
for (unsigned int i = 0; i < sizeof(named_lights)/sizeof(*named_lights); ++i)
|
||||
AddOutput(new Light(i));
|
||||
}
|
||||
|
||||
bool Keyboard::UpdateInput()
|
||||
{
|
||||
HRESULT hr = m_kb_device->GetDeviceState(sizeof(m_state_in), m_state_in);
|
||||
|
||||
if (DIERR_INPUTLOST == hr || DIERR_NOTACQUIRED == hr)
|
||||
m_kb_device->Acquire();
|
||||
|
||||
return SUCCEEDED(hr);
|
||||
}
|
||||
|
||||
bool Keyboard::UpdateOutput()
|
||||
{
|
||||
class KInput : public INPUT
|
||||
{
|
||||
public:
|
||||
KInput( const unsigned char key, const bool up = false )
|
||||
{
|
||||
memset( this, 0, sizeof(*this) );
|
||||
type = INPUT_KEYBOARD;
|
||||
ki.wVk = key;
|
||||
if (up) ki.dwFlags = KEYEVENTF_KEYUP;
|
||||
}
|
||||
};
|
||||
|
||||
std::vector< KInput > kbinputs;
|
||||
for ( unsigned int i = 0; i < sizeof(m_state_out)/sizeof(*m_state_out); ++i )
|
||||
{
|
||||
bool want_on = false;
|
||||
if ( m_state_out[i] )
|
||||
want_on = m_state_out[i] > wxGetLocalTimeMillis() % 255 ; // light should flash when output is 0.5
|
||||
|
||||
// lights are set to their original state when output is zero
|
||||
if ( want_on ^ m_current_state_out[i] )
|
||||
{
|
||||
kbinputs.push_back( KInput( named_lights[i].code ) ); // press
|
||||
kbinputs.push_back( KInput( named_lights[i].code, true ) ); // release
|
||||
|
||||
m_current_state_out[i] ^= 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (kbinputs.size())
|
||||
return ( kbinputs.size() == SendInput( (UINT)kbinputs.size(), &kbinputs[0], sizeof( kbinputs[0] ) ) );
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string Keyboard::GetName() const
|
||||
{
|
||||
return "Keyboard";
|
||||
}
|
||||
|
||||
int Keyboard::GetId() const
|
||||
{
|
||||
return m_index;
|
||||
}
|
||||
|
||||
std::string Keyboard::GetSource() const
|
||||
{
|
||||
return DINPUT_SOURCE_NAME;
|
||||
}
|
||||
|
||||
ControlState Keyboard::GetInputState(const ControllerInterface::Device::Input* const input) const
|
||||
{
|
||||
return (((Input*)input)->GetState(m_state_in));
|
||||
}
|
||||
|
||||
void Keyboard::SetOutputState(const ControllerInterface::Device::Output* const output, const ControlState state)
|
||||
{
|
||||
((Output*)output)->SetState(state, m_state_out);
|
||||
}
|
||||
|
||||
// names
|
||||
std::string Keyboard::Key::GetName() const
|
||||
{
|
||||
return named_keys[m_index].name;
|
||||
}
|
||||
|
||||
std::string Keyboard::Light::GetName() const
|
||||
{
|
||||
return named_lights[ m_index ].name;
|
||||
}
|
||||
|
||||
// get/set state
|
||||
ControlState Keyboard::Key::GetState(const BYTE keys[]) const
|
||||
{
|
||||
return (keys[named_keys[m_index].code] != 0);
|
||||
}
|
||||
|
||||
void Keyboard::Light::SetState( const ControlState state, unsigned char* const state_out )
|
||||
{
|
||||
state_out[m_index] = state * 255;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#include "../ControllerInterface.h"
|
||||
|
||||
#ifdef CIFACE_USE_DIRECTINPUT_KEYBOARD
|
||||
|
||||
#include "DirectInputKeyboard.h"
|
||||
#include "DirectInput.h"
|
||||
|
||||
// TODO: maybe add a ClearInputState function to this device
|
||||
|
||||
namespace ciface
|
||||
{
|
||||
namespace DirectInput
|
||||
{
|
||||
|
||||
struct
|
||||
{
|
||||
const BYTE code;
|
||||
const char* const name;
|
||||
} named_keys[] =
|
||||
{
|
||||
#include "NamedKeys.h"
|
||||
};
|
||||
|
||||
struct
|
||||
{
|
||||
const BYTE code;
|
||||
const char* const name;
|
||||
} named_lights[] =
|
||||
{
|
||||
{ VK_NUMLOCK, "NUM LOCK" },
|
||||
{ VK_CAPITAL, "CAPS LOCK" },
|
||||
{ VK_SCROLL, "SCROLL LOCK" }
|
||||
};
|
||||
|
||||
void InitKeyboard(IDirectInput8* const idi8, std::vector<ControllerInterface::Device*>& devices)
|
||||
{
|
||||
LPDIRECTINPUTDEVICE8 kb_device;
|
||||
|
||||
unsigned int kb_count = 0;
|
||||
|
||||
std::list<DIDEVICEINSTANCE> keyboards;
|
||||
idi8->EnumDevices(DI8DEVCLASS_KEYBOARD, DIEnumDevicesCallback, (LPVOID)&keyboards, DIEDFL_ATTACHEDONLY);
|
||||
|
||||
// add other keyboard devices
|
||||
std::list<DIDEVICEINSTANCE>::iterator
|
||||
i = keyboards.begin(),
|
||||
e = keyboards.end();
|
||||
for (; i!=e; ++i)
|
||||
{
|
||||
if (SUCCEEDED(idi8->CreateDevice(i->guidInstance, &kb_device, NULL)))
|
||||
{
|
||||
if (SUCCEEDED(kb_device->SetDataFormat(&c_dfDIKeyboard)))
|
||||
if (SUCCEEDED(kb_device->SetCooperativeLevel(NULL, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)))
|
||||
{
|
||||
devices.push_back(new Keyboard(kb_device, kb_count++));
|
||||
return;
|
||||
}
|
||||
}
|
||||
kb_device->Release();
|
||||
}
|
||||
}
|
||||
|
||||
Keyboard::~Keyboard()
|
||||
{
|
||||
// kb
|
||||
m_kb_device->Unacquire();
|
||||
m_kb_device->Release();
|
||||
|
||||
}
|
||||
|
||||
Keyboard::Keyboard(const LPDIRECTINPUTDEVICE8 kb_device, const int index)
|
||||
: m_kb_device(kb_device)
|
||||
, m_index(index)
|
||||
{
|
||||
m_kb_device->Acquire();
|
||||
|
||||
ZeroMemory(&m_state_in, sizeof(m_state_in));
|
||||
ZeroMemory(m_state_out, sizeof(m_state_out));
|
||||
ZeroMemory(&m_current_state_out, sizeof(m_current_state_out));
|
||||
|
||||
// KEYBOARD
|
||||
// add keys
|
||||
for (unsigned int i = 0; i < sizeof(named_keys)/sizeof(*named_keys); ++i)
|
||||
AddInput(new Key(i));
|
||||
// add lights
|
||||
for (unsigned int i = 0; i < sizeof(named_lights)/sizeof(*named_lights); ++i)
|
||||
AddOutput(new Light(i));
|
||||
}
|
||||
|
||||
bool Keyboard::UpdateInput()
|
||||
{
|
||||
HRESULT hr = m_kb_device->GetDeviceState(sizeof(m_state_in), m_state_in);
|
||||
|
||||
if (DIERR_INPUTLOST == hr || DIERR_NOTACQUIRED == hr)
|
||||
m_kb_device->Acquire();
|
||||
|
||||
return SUCCEEDED(hr);
|
||||
}
|
||||
|
||||
bool Keyboard::UpdateOutput()
|
||||
{
|
||||
class KInput : public INPUT
|
||||
{
|
||||
public:
|
||||
KInput( const unsigned char key, const bool up = false )
|
||||
{
|
||||
memset( this, 0, sizeof(*this) );
|
||||
type = INPUT_KEYBOARD;
|
||||
ki.wVk = key;
|
||||
if (up) ki.dwFlags = KEYEVENTF_KEYUP;
|
||||
}
|
||||
};
|
||||
|
||||
std::vector< KInput > kbinputs;
|
||||
for ( unsigned int i = 0; i < sizeof(m_state_out)/sizeof(*m_state_out); ++i )
|
||||
{
|
||||
bool want_on = false;
|
||||
if ( m_state_out[i] )
|
||||
want_on = m_state_out[i] > wxGetLocalTimeMillis() % 255 ; // light should flash when output is 0.5
|
||||
|
||||
// lights are set to their original state when output is zero
|
||||
if ( want_on ^ m_current_state_out[i] )
|
||||
{
|
||||
kbinputs.push_back( KInput( named_lights[i].code ) ); // press
|
||||
kbinputs.push_back( KInput( named_lights[i].code, true ) ); // release
|
||||
|
||||
m_current_state_out[i] ^= 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (kbinputs.size())
|
||||
return ( kbinputs.size() == SendInput( (UINT)kbinputs.size(), &kbinputs[0], sizeof( kbinputs[0] ) ) );
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string Keyboard::GetName() const
|
||||
{
|
||||
return "Keyboard";
|
||||
}
|
||||
|
||||
int Keyboard::GetId() const
|
||||
{
|
||||
return m_index;
|
||||
}
|
||||
|
||||
std::string Keyboard::GetSource() const
|
||||
{
|
||||
return DINPUT_SOURCE_NAME;
|
||||
}
|
||||
|
||||
ControlState Keyboard::GetInputState(const ControllerInterface::Device::Input* const input) const
|
||||
{
|
||||
return (((Input*)input)->GetState(m_state_in));
|
||||
}
|
||||
|
||||
void Keyboard::SetOutputState(const ControllerInterface::Device::Output* const output, const ControlState state)
|
||||
{
|
||||
((Output*)output)->SetState(state, m_state_out);
|
||||
}
|
||||
|
||||
// names
|
||||
std::string Keyboard::Key::GetName() const
|
||||
{
|
||||
return named_keys[m_index].name;
|
||||
}
|
||||
|
||||
std::string Keyboard::Light::GetName() const
|
||||
{
|
||||
return named_lights[ m_index ].name;
|
||||
}
|
||||
|
||||
// get/set state
|
||||
ControlState Keyboard::Key::GetState(const BYTE keys[]) const
|
||||
{
|
||||
return (keys[named_keys[m_index].code] != 0);
|
||||
}
|
||||
|
||||
void Keyboard::Light::SetState( const ControlState state, unsigned char* const state_out )
|
||||
{
|
||||
state_out[m_index] = state * 255;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,99 +1,99 @@
|
||||
#ifndef _CIFACE_DIRECTINPUT_KEYBOARD_H_
|
||||
#define _CIFACE_DIRECTINPUT_KEYBOARD_H_
|
||||
|
||||
#include "../ControllerInterface.h"
|
||||
|
||||
#define DIRECTINPUT_VERSION 0x0800
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOMINMAX
|
||||
#include <Windows.h>
|
||||
#include <dinput.h>
|
||||
|
||||
#include <wx/stopwatch.h>
|
||||
#include <wx/utils.h>
|
||||
|
||||
namespace ciface
|
||||
{
|
||||
namespace DirectInput
|
||||
{
|
||||
|
||||
void InitKeyboard(IDirectInput8* const idi8, std::vector<ControllerInterface::Device*>& devices);
|
||||
|
||||
class Keyboard : public ControllerInterface::Device
|
||||
{
|
||||
friend class ControllerInterface;
|
||||
friend class ControllerInterface::ControlReference;
|
||||
|
||||
protected:
|
||||
|
||||
struct State
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
class Input : public ControllerInterface::Device::Input
|
||||
{
|
||||
friend class Keyboard;
|
||||
protected:
|
||||
virtual ControlState GetState(const BYTE keys[]) const = 0;
|
||||
};
|
||||
|
||||
class Output : public ControllerInterface::Device::Output
|
||||
{
|
||||
friend class Keyboard;
|
||||
protected:
|
||||
virtual void SetState(const ControlState state, unsigned char* const state_out) = 0;
|
||||
};
|
||||
|
||||
class Key : public Input
|
||||
{
|
||||
friend class Keyboard;
|
||||
public:
|
||||
std::string GetName() const;
|
||||
protected:
|
||||
Key(const unsigned int index) : m_index(index) {}
|
||||
ControlState GetState(const BYTE keys[]) const;
|
||||
private:
|
||||
const unsigned int m_index;
|
||||
};
|
||||
|
||||
class Light : public Output
|
||||
{
|
||||
friend class Keyboard;
|
||||
public:
|
||||
std::string GetName() const;
|
||||
protected:
|
||||
Light(const unsigned int index) : m_index(index) {}
|
||||
void SetState(const ControlState state, unsigned char* const state_out);
|
||||
private:
|
||||
const unsigned int m_index;
|
||||
};
|
||||
|
||||
bool UpdateInput();
|
||||
bool UpdateOutput();
|
||||
|
||||
ControlState GetInputState( const ControllerInterface::Device::Input* const input ) const;
|
||||
void SetOutputState( const ControllerInterface::Device::Output* const input, const ControlState state );
|
||||
|
||||
public:
|
||||
Keyboard(const LPDIRECTINPUTDEVICE8 kb_device, const int index);
|
||||
~Keyboard();
|
||||
|
||||
std::string GetName() const;
|
||||
int GetId() const;
|
||||
std::string GetSource() const;
|
||||
|
||||
private:
|
||||
const LPDIRECTINPUTDEVICE8 m_kb_device;
|
||||
const int m_index;
|
||||
|
||||
wxLongLong m_last_update;
|
||||
BYTE m_state_in[256];
|
||||
unsigned char m_state_out[3]; // NUM CAPS SCROLL
|
||||
bool m_current_state_out[3]; // NUM CAPS SCROLL
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#ifndef _CIFACE_DIRECTINPUT_KEYBOARD_H_
|
||||
#define _CIFACE_DIRECTINPUT_KEYBOARD_H_
|
||||
|
||||
#include "../ControllerInterface.h"
|
||||
|
||||
#define DIRECTINPUT_VERSION 0x0800
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOMINMAX
|
||||
#include <Windows.h>
|
||||
#include <dinput.h>
|
||||
|
||||
#include <wx/stopwatch.h>
|
||||
#include <wx/utils.h>
|
||||
|
||||
namespace ciface
|
||||
{
|
||||
namespace DirectInput
|
||||
{
|
||||
|
||||
void InitKeyboard(IDirectInput8* const idi8, std::vector<ControllerInterface::Device*>& devices);
|
||||
|
||||
class Keyboard : public ControllerInterface::Device
|
||||
{
|
||||
friend class ControllerInterface;
|
||||
friend class ControllerInterface::ControlReference;
|
||||
|
||||
protected:
|
||||
|
||||
struct State
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
class Input : public ControllerInterface::Device::Input
|
||||
{
|
||||
friend class Keyboard;
|
||||
protected:
|
||||
virtual ControlState GetState(const BYTE keys[]) const = 0;
|
||||
};
|
||||
|
||||
class Output : public ControllerInterface::Device::Output
|
||||
{
|
||||
friend class Keyboard;
|
||||
protected:
|
||||
virtual void SetState(const ControlState state, unsigned char* const state_out) = 0;
|
||||
};
|
||||
|
||||
class Key : public Input
|
||||
{
|
||||
friend class Keyboard;
|
||||
public:
|
||||
std::string GetName() const;
|
||||
protected:
|
||||
Key(const unsigned int index) : m_index(index) {}
|
||||
ControlState GetState(const BYTE keys[]) const;
|
||||
private:
|
||||
const unsigned int m_index;
|
||||
};
|
||||
|
||||
class Light : public Output
|
||||
{
|
||||
friend class Keyboard;
|
||||
public:
|
||||
std::string GetName() const;
|
||||
protected:
|
||||
Light(const unsigned int index) : m_index(index) {}
|
||||
void SetState(const ControlState state, unsigned char* const state_out);
|
||||
private:
|
||||
const unsigned int m_index;
|
||||
};
|
||||
|
||||
bool UpdateInput();
|
||||
bool UpdateOutput();
|
||||
|
||||
ControlState GetInputState( const ControllerInterface::Device::Input* const input ) const;
|
||||
void SetOutputState( const ControllerInterface::Device::Output* const input, const ControlState state );
|
||||
|
||||
public:
|
||||
Keyboard(const LPDIRECTINPUTDEVICE8 kb_device, const int index);
|
||||
~Keyboard();
|
||||
|
||||
std::string GetName() const;
|
||||
int GetId() const;
|
||||
std::string GetSource() const;
|
||||
|
||||
private:
|
||||
const LPDIRECTINPUTDEVICE8 m_kb_device;
|
||||
const int m_index;
|
||||
|
||||
wxLongLong m_last_update;
|
||||
BYTE m_state_in[256];
|
||||
unsigned char m_state_out[3]; // NUM CAPS SCROLL
|
||||
bool m_current_state_out[3]; // NUM CAPS SCROLL
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+175
-175
@@ -1,175 +1,175 @@
|
||||
#include "../ControllerInterface.h"
|
||||
|
||||
#ifdef CIFACE_USE_DIRECTINPUT_MOUSE
|
||||
|
||||
#include "DirectInputMouse.h"
|
||||
#include "DirectInput.h"
|
||||
|
||||
// TODO: maybe add a ClearInputState function to this device
|
||||
|
||||
// (lower would be more sensitive) user can lower sensitivity by setting range
|
||||
// seems decent here ( at 8 ), I dont think anyone would need more sensitive than this
|
||||
// and user can lower it much farther than they would want to with the range
|
||||
#define MOUSE_AXIS_SENSITIVITY 8
|
||||
|
||||
// if input hasn't been received for this many ms, mouse input will be skipped
|
||||
// otherwise it is just some crazy value
|
||||
#define DROP_INPUT_TIME 250
|
||||
|
||||
namespace ciface
|
||||
{
|
||||
namespace DirectInput
|
||||
{
|
||||
|
||||
void InitMouse( IDirectInput8* const idi8, std::vector<ControllerInterface::Device*>& devices )
|
||||
{
|
||||
LPDIRECTINPUTDEVICE8 mo_device;
|
||||
|
||||
unsigned int mo_count = 0;
|
||||
|
||||
std::list<DIDEVICEINSTANCE> mice;
|
||||
idi8->EnumDevices(DI8DEVCLASS_POINTER, DIEnumDevicesCallback, (LPVOID)&mice, DIEDFL_ATTACHEDONLY);
|
||||
|
||||
// add other keyboard devices
|
||||
std::list<DIDEVICEINSTANCE>::iterator
|
||||
i = mice.begin(),
|
||||
e = mice.end();
|
||||
for (; i!=e; ++i)
|
||||
{
|
||||
if (SUCCEEDED(idi8->CreateDevice(i->guidInstance, &mo_device, NULL)))
|
||||
{
|
||||
if (SUCCEEDED(mo_device->SetDataFormat(&c_dfDIMouse2)))
|
||||
if (SUCCEEDED(mo_device->SetCooperativeLevel(NULL, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)))
|
||||
{
|
||||
devices.push_back(new Mouse(mo_device, mo_count++));
|
||||
return;
|
||||
}
|
||||
}
|
||||
mo_device->Release();
|
||||
}
|
||||
}
|
||||
|
||||
Mouse::~Mouse()
|
||||
{
|
||||
// mouse
|
||||
m_mo_device->Unacquire();
|
||||
m_mo_device->Release();
|
||||
}
|
||||
|
||||
Mouse::Mouse(const LPDIRECTINPUTDEVICE8 mo_device, const int index)
|
||||
: m_mo_device(mo_device)
|
||||
, m_index(index)
|
||||
{
|
||||
m_mo_device->Acquire();
|
||||
|
||||
m_last_update = GetTickCount();
|
||||
ZeroMemory(&m_state_in, sizeof(m_state_in));
|
||||
|
||||
// MOUSE
|
||||
// get caps
|
||||
DIDEVCAPS mouse_caps;
|
||||
ZeroMemory( &mouse_caps, sizeof(mouse_caps) );
|
||||
mouse_caps.dwSize = sizeof(mouse_caps);
|
||||
m_mo_device->GetCapabilities(&mouse_caps);
|
||||
// mouse buttons
|
||||
for (unsigned int i = 0; i < mouse_caps.dwButtons; ++i)
|
||||
AddInput(new Button(i));
|
||||
// mouse axes
|
||||
for (unsigned int i = 0; i < mouse_caps.dwAxes; ++i)
|
||||
{
|
||||
// each axis gets a negative and a positive input instance associated with it
|
||||
AddInput(new Axis(i, (2==i) ? -1 : -MOUSE_AXIS_SENSITIVITY));
|
||||
AddInput(new Axis(i, -(2==i) ? 1 : MOUSE_AXIS_SENSITIVITY));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool Mouse::UpdateInput()
|
||||
{
|
||||
DIMOUSESTATE2 tmp_mouse;
|
||||
HRESULT hr = m_mo_device->GetDeviceState(sizeof(tmp_mouse), &tmp_mouse);
|
||||
|
||||
// if mouse position hasn't been updated in a short while, skip a dev state
|
||||
const DWORD cur_time = GetTickCount();
|
||||
if (cur_time - m_last_update > DROP_INPUT_TIME)
|
||||
{
|
||||
// set buttons/axes to zero
|
||||
// skip this input state
|
||||
ZeroMemory(&m_state_in, sizeof(m_state_in));
|
||||
}
|
||||
else if (SUCCEEDED(hr))
|
||||
{
|
||||
// need to smooth out the axes, otherwise it doesnt work for shit
|
||||
for (unsigned int i = 0; i < 3; ++i)
|
||||
((&m_state_in.lX)[i] += (&tmp_mouse.lX)[i]) /= 2;
|
||||
|
||||
// copy over the buttons
|
||||
memcpy(m_state_in.rgbButtons, tmp_mouse.rgbButtons, sizeof(m_state_in.rgbButtons));
|
||||
}
|
||||
|
||||
m_last_update = cur_time;
|
||||
|
||||
if (DIERR_INPUTLOST == hr || DIERR_NOTACQUIRED == hr)
|
||||
m_mo_device->Acquire();
|
||||
|
||||
return SUCCEEDED(hr);
|
||||
}
|
||||
|
||||
bool Mouse::UpdateOutput()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string Mouse::GetName() const
|
||||
{
|
||||
return "Mouse";
|
||||
}
|
||||
|
||||
int Mouse::GetId() const
|
||||
{
|
||||
return m_index;
|
||||
}
|
||||
|
||||
std::string Mouse::GetSource() const
|
||||
{
|
||||
return DINPUT_SOURCE_NAME;
|
||||
}
|
||||
|
||||
ControlState Mouse::GetInputState( const ControllerInterface::Device::Input* const input ) const
|
||||
{
|
||||
return (((Input*)input)->GetState(&m_state_in));
|
||||
}
|
||||
|
||||
void Mouse::SetOutputState(const ControllerInterface::Device::Output* const output, const ControlState state)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// names
|
||||
std::string Mouse::Button::GetName() const
|
||||
{
|
||||
return std::string("Button ") + char('0'+m_index);
|
||||
}
|
||||
|
||||
std::string Mouse::Axis::GetName() const
|
||||
{
|
||||
std::string tmpstr("Axis ");
|
||||
tmpstr += "XYZ"[m_index]; tmpstr += ( m_range>0 ? '+' : '-' );
|
||||
return tmpstr;
|
||||
}
|
||||
|
||||
// get/set state
|
||||
ControlState Mouse::Button::GetState(const DIMOUSESTATE2* const state) const
|
||||
{
|
||||
return (state->rgbButtons[m_index] != 0);
|
||||
}
|
||||
|
||||
ControlState Mouse::Axis::GetState(const DIMOUSESTATE2* const state) const
|
||||
{
|
||||
return std::max(0.0f, ControlState((&state->lX)[m_index]) / m_range);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#include "../ControllerInterface.h"
|
||||
|
||||
#ifdef CIFACE_USE_DIRECTINPUT_MOUSE
|
||||
|
||||
#include "DirectInputMouse.h"
|
||||
#include "DirectInput.h"
|
||||
|
||||
// TODO: maybe add a ClearInputState function to this device
|
||||
|
||||
// (lower would be more sensitive) user can lower sensitivity by setting range
|
||||
// seems decent here ( at 8 ), I dont think anyone would need more sensitive than this
|
||||
// and user can lower it much farther than they would want to with the range
|
||||
#define MOUSE_AXIS_SENSITIVITY 8
|
||||
|
||||
// if input hasn't been received for this many ms, mouse input will be skipped
|
||||
// otherwise it is just some crazy value
|
||||
#define DROP_INPUT_TIME 250
|
||||
|
||||
namespace ciface
|
||||
{
|
||||
namespace DirectInput
|
||||
{
|
||||
|
||||
void InitMouse( IDirectInput8* const idi8, std::vector<ControllerInterface::Device*>& devices )
|
||||
{
|
||||
LPDIRECTINPUTDEVICE8 mo_device;
|
||||
|
||||
unsigned int mo_count = 0;
|
||||
|
||||
std::list<DIDEVICEINSTANCE> mice;
|
||||
idi8->EnumDevices(DI8DEVCLASS_POINTER, DIEnumDevicesCallback, (LPVOID)&mice, DIEDFL_ATTACHEDONLY);
|
||||
|
||||
// add other keyboard devices
|
||||
std::list<DIDEVICEINSTANCE>::iterator
|
||||
i = mice.begin(),
|
||||
e = mice.end();
|
||||
for (; i!=e; ++i)
|
||||
{
|
||||
if (SUCCEEDED(idi8->CreateDevice(i->guidInstance, &mo_device, NULL)))
|
||||
{
|
||||
if (SUCCEEDED(mo_device->SetDataFormat(&c_dfDIMouse2)))
|
||||
if (SUCCEEDED(mo_device->SetCooperativeLevel(NULL, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)))
|
||||
{
|
||||
devices.push_back(new Mouse(mo_device, mo_count++));
|
||||
return;
|
||||
}
|
||||
}
|
||||
mo_device->Release();
|
||||
}
|
||||
}
|
||||
|
||||
Mouse::~Mouse()
|
||||
{
|
||||
// mouse
|
||||
m_mo_device->Unacquire();
|
||||
m_mo_device->Release();
|
||||
}
|
||||
|
||||
Mouse::Mouse(const LPDIRECTINPUTDEVICE8 mo_device, const int index)
|
||||
: m_mo_device(mo_device)
|
||||
, m_index(index)
|
||||
{
|
||||
m_mo_device->Acquire();
|
||||
|
||||
m_last_update = GetTickCount();
|
||||
ZeroMemory(&m_state_in, sizeof(m_state_in));
|
||||
|
||||
// MOUSE
|
||||
// get caps
|
||||
DIDEVCAPS mouse_caps;
|
||||
ZeroMemory( &mouse_caps, sizeof(mouse_caps) );
|
||||
mouse_caps.dwSize = sizeof(mouse_caps);
|
||||
m_mo_device->GetCapabilities(&mouse_caps);
|
||||
// mouse buttons
|
||||
for (unsigned int i = 0; i < mouse_caps.dwButtons; ++i)
|
||||
AddInput(new Button(i));
|
||||
// mouse axes
|
||||
for (unsigned int i = 0; i < mouse_caps.dwAxes; ++i)
|
||||
{
|
||||
// each axis gets a negative and a positive input instance associated with it
|
||||
AddInput(new Axis(i, (2==i) ? -1 : -MOUSE_AXIS_SENSITIVITY));
|
||||
AddInput(new Axis(i, -(2==i) ? 1 : MOUSE_AXIS_SENSITIVITY));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool Mouse::UpdateInput()
|
||||
{
|
||||
DIMOUSESTATE2 tmp_mouse;
|
||||
HRESULT hr = m_mo_device->GetDeviceState(sizeof(tmp_mouse), &tmp_mouse);
|
||||
|
||||
// if mouse position hasn't been updated in a short while, skip a dev state
|
||||
const DWORD cur_time = GetTickCount();
|
||||
if (cur_time - m_last_update > DROP_INPUT_TIME)
|
||||
{
|
||||
// set buttons/axes to zero
|
||||
// skip this input state
|
||||
ZeroMemory(&m_state_in, sizeof(m_state_in));
|
||||
}
|
||||
else if (SUCCEEDED(hr))
|
||||
{
|
||||
// need to smooth out the axes, otherwise it doesnt work for shit
|
||||
for (unsigned int i = 0; i < 3; ++i)
|
||||
((&m_state_in.lX)[i] += (&tmp_mouse.lX)[i]) /= 2;
|
||||
|
||||
// copy over the buttons
|
||||
memcpy(m_state_in.rgbButtons, tmp_mouse.rgbButtons, sizeof(m_state_in.rgbButtons));
|
||||
}
|
||||
|
||||
m_last_update = cur_time;
|
||||
|
||||
if (DIERR_INPUTLOST == hr || DIERR_NOTACQUIRED == hr)
|
||||
m_mo_device->Acquire();
|
||||
|
||||
return SUCCEEDED(hr);
|
||||
}
|
||||
|
||||
bool Mouse::UpdateOutput()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string Mouse::GetName() const
|
||||
{
|
||||
return "Mouse";
|
||||
}
|
||||
|
||||
int Mouse::GetId() const
|
||||
{
|
||||
return m_index;
|
||||
}
|
||||
|
||||
std::string Mouse::GetSource() const
|
||||
{
|
||||
return DINPUT_SOURCE_NAME;
|
||||
}
|
||||
|
||||
ControlState Mouse::GetInputState( const ControllerInterface::Device::Input* const input ) const
|
||||
{
|
||||
return (((Input*)input)->GetState(&m_state_in));
|
||||
}
|
||||
|
||||
void Mouse::SetOutputState(const ControllerInterface::Device::Output* const output, const ControlState state)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// names
|
||||
std::string Mouse::Button::GetName() const
|
||||
{
|
||||
return std::string("Button ") + char('0'+m_index);
|
||||
}
|
||||
|
||||
std::string Mouse::Axis::GetName() const
|
||||
{
|
||||
std::string tmpstr("Axis ");
|
||||
tmpstr += "XYZ"[m_index]; tmpstr += ( m_range>0 ? '+' : '-' );
|
||||
return tmpstr;
|
||||
}
|
||||
|
||||
// get/set state
|
||||
ControlState Mouse::Button::GetState(const DIMOUSESTATE2* const state) const
|
||||
{
|
||||
return (state->rgbButtons[m_index] != 0);
|
||||
}
|
||||
|
||||
ControlState Mouse::Axis::GetState(const DIMOUSESTATE2* const state) const
|
||||
{
|
||||
return std::max(0.0f, ControlState((&state->lX)[m_index]) / m_range);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,83 +1,83 @@
|
||||
#ifndef _CIFACE_DIRECTINPUT_MOUSE_H_
|
||||
#define _CIFACE_DIRECTINPUT_MOUSE_H_
|
||||
|
||||
#include "../ControllerInterface.h"
|
||||
|
||||
#define DIRECTINPUT_VERSION 0x0800
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOMINMAX
|
||||
#include <Windows.h>
|
||||
#include <dinput.h>
|
||||
|
||||
namespace ciface
|
||||
{
|
||||
namespace DirectInput
|
||||
{
|
||||
|
||||
void InitMouse(IDirectInput8* const idi8, std::vector<ControllerInterface::Device*>& devices);
|
||||
|
||||
class Mouse : public ControllerInterface::Device
|
||||
{
|
||||
friend class ControllerInterface;
|
||||
friend class ControllerInterface::ControlReference;
|
||||
|
||||
protected:
|
||||
|
||||
class Input : public ControllerInterface::Device::Input
|
||||
{
|
||||
friend class Mouse;
|
||||
protected:
|
||||
virtual ControlState GetState(const DIMOUSESTATE2* const boardstate) const = 0;
|
||||
};
|
||||
|
||||
class Button : public Input
|
||||
{
|
||||
friend class Mouse;
|
||||
public:
|
||||
std::string GetName() const;
|
||||
protected:
|
||||
Button(const unsigned int index) : m_index(index) {}
|
||||
ControlState GetState(const DIMOUSESTATE2* const state) const;
|
||||
private:
|
||||
const unsigned int m_index;
|
||||
};
|
||||
|
||||
class Axis : public Input
|
||||
{
|
||||
friend class Mouse;
|
||||
public:
|
||||
std::string GetName() const;
|
||||
protected:
|
||||
Axis(const unsigned int index, const LONG range) : m_index(index), m_range(range) {}
|
||||
ControlState GetState(const DIMOUSESTATE2* const state) const;
|
||||
private:
|
||||
const unsigned int m_index;
|
||||
const LONG m_range;
|
||||
};
|
||||
|
||||
bool UpdateInput();
|
||||
bool UpdateOutput();
|
||||
|
||||
ControlState GetInputState( const ControllerInterface::Device::Input* const input ) const;
|
||||
void SetOutputState( const ControllerInterface::Device::Output* const input, const ControlState state );
|
||||
|
||||
public:
|
||||
Mouse(const LPDIRECTINPUTDEVICE8 mo_device, const int index);
|
||||
~Mouse();
|
||||
|
||||
std::string GetName() const;
|
||||
int GetId() const;
|
||||
std::string GetSource() const;
|
||||
|
||||
private:
|
||||
const LPDIRECTINPUTDEVICE8 m_mo_device;
|
||||
const int m_index;
|
||||
|
||||
DWORD m_last_update;
|
||||
DIMOUSESTATE2 m_state_in;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#ifndef _CIFACE_DIRECTINPUT_MOUSE_H_
|
||||
#define _CIFACE_DIRECTINPUT_MOUSE_H_
|
||||
|
||||
#include "../ControllerInterface.h"
|
||||
|
||||
#define DIRECTINPUT_VERSION 0x0800
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOMINMAX
|
||||
#include <Windows.h>
|
||||
#include <dinput.h>
|
||||
|
||||
namespace ciface
|
||||
{
|
||||
namespace DirectInput
|
||||
{
|
||||
|
||||
void InitMouse(IDirectInput8* const idi8, std::vector<ControllerInterface::Device*>& devices);
|
||||
|
||||
class Mouse : public ControllerInterface::Device
|
||||
{
|
||||
friend class ControllerInterface;
|
||||
friend class ControllerInterface::ControlReference;
|
||||
|
||||
protected:
|
||||
|
||||
class Input : public ControllerInterface::Device::Input
|
||||
{
|
||||
friend class Mouse;
|
||||
protected:
|
||||
virtual ControlState GetState(const DIMOUSESTATE2* const boardstate) const = 0;
|
||||
};
|
||||
|
||||
class Button : public Input
|
||||
{
|
||||
friend class Mouse;
|
||||
public:
|
||||
std::string GetName() const;
|
||||
protected:
|
||||
Button(const unsigned int index) : m_index(index) {}
|
||||
ControlState GetState(const DIMOUSESTATE2* const state) const;
|
||||
private:
|
||||
const unsigned int m_index;
|
||||
};
|
||||
|
||||
class Axis : public Input
|
||||
{
|
||||
friend class Mouse;
|
||||
public:
|
||||
std::string GetName() const;
|
||||
protected:
|
||||
Axis(const unsigned int index, const LONG range) : m_index(index), m_range(range) {}
|
||||
ControlState GetState(const DIMOUSESTATE2* const state) const;
|
||||
private:
|
||||
const unsigned int m_index;
|
||||
const LONG m_range;
|
||||
};
|
||||
|
||||
bool UpdateInput();
|
||||
bool UpdateOutput();
|
||||
|
||||
ControlState GetInputState( const ControllerInterface::Device::Input* const input ) const;
|
||||
void SetOutputState( const ControllerInterface::Device::Output* const input, const ControlState state );
|
||||
|
||||
public:
|
||||
Mouse(const LPDIRECTINPUTDEVICE8 mo_device, const int index);
|
||||
~Mouse();
|
||||
|
||||
std::string GetName() const;
|
||||
int GetId() const;
|
||||
std::string GetSource() const;
|
||||
|
||||
private:
|
||||
const LPDIRECTINPUTDEVICE8 m_mo_device;
|
||||
const int m_index;
|
||||
|
||||
DWORD m_last_update;
|
||||
DIMOUSESTATE2 m_state_in;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,63 +1,63 @@
|
||||
// Copyright (C) 2003 Dolphin Project.
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, version 2.0.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "D3DBlob.h"
|
||||
|
||||
D3DBlob::D3DBlob(unsigned int blob_size, const u8* init_data) : ref(1), size(blob_size), blob(NULL)
|
||||
{
|
||||
data = new u8[blob_size];
|
||||
if (init_data) memcpy(data, init_data, size);
|
||||
}
|
||||
|
||||
D3DBlob::D3DBlob(ID3D10Blob* d3dblob) : ref(1)
|
||||
{
|
||||
blob = d3dblob;
|
||||
data = (u8*)blob->GetBufferPointer();
|
||||
size = blob->GetBufferSize();
|
||||
d3dblob->AddRef();
|
||||
}
|
||||
|
||||
D3DBlob::~D3DBlob()
|
||||
{
|
||||
if (blob) blob->Release();
|
||||
else delete[] data;
|
||||
}
|
||||
|
||||
void D3DBlob::AddRef()
|
||||
{
|
||||
++ref;
|
||||
}
|
||||
|
||||
unsigned int D3DBlob::Release()
|
||||
{
|
||||
if (--ref == 0)
|
||||
{
|
||||
delete this;
|
||||
return 0;
|
||||
}
|
||||
return ref;
|
||||
}
|
||||
|
||||
unsigned int D3DBlob::Size()
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
u8* D3DBlob::Data()
|
||||
{
|
||||
return data;
|
||||
}
|
||||
// Copyright (C) 2003 Dolphin Project.
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, version 2.0.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "D3DBlob.h"
|
||||
|
||||
D3DBlob::D3DBlob(unsigned int blob_size, const u8* init_data) : ref(1), size(blob_size), blob(NULL)
|
||||
{
|
||||
data = new u8[blob_size];
|
||||
if (init_data) memcpy(data, init_data, size);
|
||||
}
|
||||
|
||||
D3DBlob::D3DBlob(ID3D10Blob* d3dblob) : ref(1)
|
||||
{
|
||||
blob = d3dblob;
|
||||
data = (u8*)blob->GetBufferPointer();
|
||||
size = blob->GetBufferSize();
|
||||
d3dblob->AddRef();
|
||||
}
|
||||
|
||||
D3DBlob::~D3DBlob()
|
||||
{
|
||||
if (blob) blob->Release();
|
||||
else delete[] data;
|
||||
}
|
||||
|
||||
void D3DBlob::AddRef()
|
||||
{
|
||||
++ref;
|
||||
}
|
||||
|
||||
unsigned int D3DBlob::Release()
|
||||
{
|
||||
if (--ref == 0)
|
||||
{
|
||||
delete this;
|
||||
return 0;
|
||||
}
|
||||
return ref;
|
||||
}
|
||||
|
||||
unsigned int D3DBlob::Size()
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
u8* D3DBlob::Data()
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -1,47 +1,47 @@
|
||||
// Copyright (C) 2003 Dolphin Project.
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, version 2.0.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <d3d11.h>
|
||||
#include "Common.h"
|
||||
|
||||
// use this class instead ID3D10Blob or ID3D11Blob whenever possible
|
||||
class D3DBlob
|
||||
{
|
||||
public:
|
||||
// memory will be copied into an own buffer
|
||||
D3DBlob(unsigned int blob_size, const u8* init_data = NULL);
|
||||
|
||||
// d3dblob will be AddRef'd
|
||||
D3DBlob(ID3D10Blob* d3dblob);
|
||||
|
||||
void AddRef();
|
||||
unsigned int Release();
|
||||
|
||||
unsigned int Size();
|
||||
u8* Data();
|
||||
|
||||
private:
|
||||
~D3DBlob();
|
||||
|
||||
unsigned int ref;
|
||||
unsigned int size;
|
||||
|
||||
u8* data;
|
||||
ID3D10Blob* blob;
|
||||
};
|
||||
// Copyright (C) 2003 Dolphin Project.
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, version 2.0.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <d3d11.h>
|
||||
#include "Common.h"
|
||||
|
||||
// use this class instead ID3D10Blob or ID3D11Blob whenever possible
|
||||
class D3DBlob
|
||||
{
|
||||
public:
|
||||
// memory will be copied into an own buffer
|
||||
D3DBlob(unsigned int blob_size, const u8* init_data = NULL);
|
||||
|
||||
// d3dblob will be AddRef'd
|
||||
D3DBlob(ID3D10Blob* d3dblob);
|
||||
|
||||
void AddRef();
|
||||
unsigned int Release();
|
||||
|
||||
unsigned int Size();
|
||||
u8* Data();
|
||||
|
||||
private:
|
||||
~D3DBlob();
|
||||
|
||||
unsigned int ref;
|
||||
unsigned int size;
|
||||
|
||||
u8* data;
|
||||
ID3D10Blob* blob;
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,132 +1,132 @@
|
||||
// Copyright (C) 2003 Dolphin Project.
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, version 2.0.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "D3DBase.h"
|
||||
#include <stack>
|
||||
|
||||
using std::stack;
|
||||
|
||||
namespace D3D
|
||||
{
|
||||
|
||||
// stores the pipeline state to use when calling VertexManager::Flush()
|
||||
class EmuGfxState
|
||||
{
|
||||
public:
|
||||
EmuGfxState();
|
||||
~EmuGfxState();
|
||||
|
||||
void SetVShader(ID3D11VertexShader* shader, D3DBlob* bcode);
|
||||
void SetPShader(ID3D11PixelShader* shader);
|
||||
void SetInputElements(const D3D11_INPUT_ELEMENT_DESC* elems, UINT num);
|
||||
void SetShaderResource(unsigned int stage, ID3D11ShaderResourceView* srv);
|
||||
|
||||
void ApplyState(); // apply current state
|
||||
void AlphaPass(); // only modify the current state to enable the alpha pass
|
||||
void Reset();
|
||||
|
||||
// blend state
|
||||
void SetAlphaBlendEnable(bool enable);
|
||||
void SetRenderTargetWriteMask(UINT8 mask);
|
||||
void SetSrcBlend(D3D11_BLEND val);
|
||||
void SetDestBlend(D3D11_BLEND val);
|
||||
void SetBlendOp(D3D11_BLEND_OP val);
|
||||
|
||||
// sampler states
|
||||
void SetSamplerFilter(DWORD stage, D3D11_FILTER filter);
|
||||
|
||||
// TODO: add methods for changing the other states instead of modifying them directly
|
||||
|
||||
D3D11_SAMPLER_DESC samplerdesc[8];
|
||||
D3D11_RASTERIZER_DESC rastdesc;
|
||||
D3D11_DEPTH_STENCIL_DESC depthdesc;
|
||||
|
||||
float psconstants[116];
|
||||
float vsconstants[952];
|
||||
bool vscbufchanged;
|
||||
bool pscbufchanged;
|
||||
|
||||
private:
|
||||
ID3D11VertexShader* vertexshader;
|
||||
D3DBlob* vsbytecode;
|
||||
ID3D11PixelShader* pixelshader;
|
||||
D3DBlob* psbytecode;
|
||||
bool vshaderchanged;
|
||||
|
||||
ID3D11Buffer* vscbuf;
|
||||
ID3D11Buffer* pscbuf;
|
||||
|
||||
ID3D11InputLayout* inp_layout;
|
||||
D3D11_INPUT_ELEMENT_DESC inp_elems[32];
|
||||
int num_inp_elems;
|
||||
|
||||
ID3D11ShaderResourceView* shader_resources[8];
|
||||
D3D11_BLEND_DESC blenddesc;
|
||||
|
||||
bool apply_called;
|
||||
};
|
||||
|
||||
template<typename T> class AutoState
|
||||
{
|
||||
public:
|
||||
AutoState(const T* object);
|
||||
AutoState(const AutoState<T> &source);
|
||||
~AutoState();
|
||||
|
||||
const inline T* GetPtr() const { return state; }
|
||||
|
||||
private:
|
||||
const T* state;
|
||||
};
|
||||
|
||||
typedef AutoState<ID3D11BlendState> AutoBlendState;
|
||||
typedef AutoState<ID3D11DepthStencilState> AutoDepthStencilState;
|
||||
typedef AutoState<ID3D11RasterizerState> AutoRasterizerState;
|
||||
|
||||
class StateManager
|
||||
{
|
||||
public:
|
||||
StateManager();
|
||||
|
||||
// call any of these to change the affected states
|
||||
void PushBlendState(const ID3D11BlendState* state);
|
||||
void PushDepthState(const ID3D11DepthStencilState* state);
|
||||
void PushRasterizerState(const ID3D11RasterizerState* state);
|
||||
|
||||
// call these after drawing
|
||||
void PopBlendState();
|
||||
void PopDepthState();
|
||||
void PopRasterizerState();
|
||||
|
||||
// call this before any drawing operation if states could have changed meanwhile
|
||||
void Apply();
|
||||
|
||||
private:
|
||||
stack<AutoBlendState> blendstates;
|
||||
stack<AutoDepthStencilState> depthstates;
|
||||
stack<AutoRasterizerState> raststates;
|
||||
ID3D11BlendState* cur_blendstate;
|
||||
ID3D11DepthStencilState* cur_depthstate;
|
||||
ID3D11RasterizerState* cur_raststate;
|
||||
};
|
||||
|
||||
extern EmuGfxState* gfxstate;
|
||||
extern StateManager* stateman;
|
||||
|
||||
} // namespace
|
||||
// Copyright (C) 2003 Dolphin Project.
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, version 2.0.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "D3DBase.h"
|
||||
#include <stack>
|
||||
|
||||
using std::stack;
|
||||
|
||||
namespace D3D
|
||||
{
|
||||
|
||||
// stores the pipeline state to use when calling VertexManager::Flush()
|
||||
class EmuGfxState
|
||||
{
|
||||
public:
|
||||
EmuGfxState();
|
||||
~EmuGfxState();
|
||||
|
||||
void SetVShader(ID3D11VertexShader* shader, D3DBlob* bcode);
|
||||
void SetPShader(ID3D11PixelShader* shader);
|
||||
void SetInputElements(const D3D11_INPUT_ELEMENT_DESC* elems, UINT num);
|
||||
void SetShaderResource(unsigned int stage, ID3D11ShaderResourceView* srv);
|
||||
|
||||
void ApplyState(); // apply current state
|
||||
void AlphaPass(); // only modify the current state to enable the alpha pass
|
||||
void Reset();
|
||||
|
||||
// blend state
|
||||
void SetAlphaBlendEnable(bool enable);
|
||||
void SetRenderTargetWriteMask(UINT8 mask);
|
||||
void SetSrcBlend(D3D11_BLEND val);
|
||||
void SetDestBlend(D3D11_BLEND val);
|
||||
void SetBlendOp(D3D11_BLEND_OP val);
|
||||
|
||||
// sampler states
|
||||
void SetSamplerFilter(DWORD stage, D3D11_FILTER filter);
|
||||
|
||||
// TODO: add methods for changing the other states instead of modifying them directly
|
||||
|
||||
D3D11_SAMPLER_DESC samplerdesc[8];
|
||||
D3D11_RASTERIZER_DESC rastdesc;
|
||||
D3D11_DEPTH_STENCIL_DESC depthdesc;
|
||||
|
||||
float psconstants[116];
|
||||
float vsconstants[952];
|
||||
bool vscbufchanged;
|
||||
bool pscbufchanged;
|
||||
|
||||
private:
|
||||
ID3D11VertexShader* vertexshader;
|
||||
D3DBlob* vsbytecode;
|
||||
ID3D11PixelShader* pixelshader;
|
||||
D3DBlob* psbytecode;
|
||||
bool vshaderchanged;
|
||||
|
||||
ID3D11Buffer* vscbuf;
|
||||
ID3D11Buffer* pscbuf;
|
||||
|
||||
ID3D11InputLayout* inp_layout;
|
||||
D3D11_INPUT_ELEMENT_DESC inp_elems[32];
|
||||
int num_inp_elems;
|
||||
|
||||
ID3D11ShaderResourceView* shader_resources[8];
|
||||
D3D11_BLEND_DESC blenddesc;
|
||||
|
||||
bool apply_called;
|
||||
};
|
||||
|
||||
template<typename T> class AutoState
|
||||
{
|
||||
public:
|
||||
AutoState(const T* object);
|
||||
AutoState(const AutoState<T> &source);
|
||||
~AutoState();
|
||||
|
||||
const inline T* GetPtr() const { return state; }
|
||||
|
||||
private:
|
||||
const T* state;
|
||||
};
|
||||
|
||||
typedef AutoState<ID3D11BlendState> AutoBlendState;
|
||||
typedef AutoState<ID3D11DepthStencilState> AutoDepthStencilState;
|
||||
typedef AutoState<ID3D11RasterizerState> AutoRasterizerState;
|
||||
|
||||
class StateManager
|
||||
{
|
||||
public:
|
||||
StateManager();
|
||||
|
||||
// call any of these to change the affected states
|
||||
void PushBlendState(const ID3D11BlendState* state);
|
||||
void PushDepthState(const ID3D11DepthStencilState* state);
|
||||
void PushRasterizerState(const ID3D11RasterizerState* state);
|
||||
|
||||
// call these after drawing
|
||||
void PopBlendState();
|
||||
void PopDepthState();
|
||||
void PopRasterizerState();
|
||||
|
||||
// call this before any drawing operation if states could have changed meanwhile
|
||||
void Apply();
|
||||
|
||||
private:
|
||||
stack<AutoBlendState> blendstates;
|
||||
stack<AutoDepthStencilState> depthstates;
|
||||
stack<AutoRasterizerState> raststates;
|
||||
ID3D11BlendState* cur_blendstate;
|
||||
ID3D11DepthStencilState* cur_depthstate;
|
||||
ID3D11RasterizerState* cur_raststate;
|
||||
};
|
||||
|
||||
extern EmuGfxState* gfxstate;
|
||||
extern StateManager* stateman;
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user