A few changes to the GCPadNew needed to compile in linux, and put GCPadNew back into the linux build. Also changed file properties to eol-style native.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5268 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
9e1d956e98
commit
2742be1c2e
|
@ -77,16 +77,12 @@ dirs = [
|
||||||
'Source/Plugins/Plugin_DSP_HLE/Src',
|
'Source/Plugins/Plugin_DSP_HLE/Src',
|
||||||
'Source/Plugins/Plugin_DSP_LLE/Src',
|
'Source/Plugins/Plugin_DSP_LLE/Src',
|
||||||
'Source/Plugins/Plugin_GCPad/Src',
|
'Source/Plugins/Plugin_GCPad/Src',
|
||||||
|
'Source/Plugins/Plugin_GCPadNew/Src',
|
||||||
'Source/Plugins/Plugin_Wiimote/Src',
|
'Source/Plugins/Plugin_Wiimote/Src',
|
||||||
'Source/Core/DolphinWX/Src',
|
'Source/Core/DolphinWX/Src',
|
||||||
'Source/Core/DebuggerWX/Src',
|
'Source/Core/DebuggerWX/Src',
|
||||||
]
|
]
|
||||||
|
|
||||||
if sys.platform == 'darwin':
|
|
||||||
dirs += [
|
|
||||||
'Source/Plugins/Plugin_GCPadNew/Src'
|
|
||||||
]
|
|
||||||
|
|
||||||
builders = {}
|
builders = {}
|
||||||
if sys.platform == 'darwin':
|
if sys.platform == 'darwin':
|
||||||
from plistlib import writePlist
|
from plistlib import writePlist
|
||||||
|
|
|
@ -1,54 +1,54 @@
|
||||||
|
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
|
||||||
Plugin::Plugin()
|
Plugin::Plugin()
|
||||||
{
|
{
|
||||||
// GCPads
|
// GCPads
|
||||||
for ( unsigned int i = 0; i<4; ++i )
|
for ( unsigned int i = 0; i<4; ++i )
|
||||||
controllers.push_back( new GCPad( i ) );
|
controllers.push_back( new GCPad( i ) );
|
||||||
// Wiimotes / disabled, cause it only the GUI half is done
|
// Wiimotes / disabled, cause it only the GUI half is done
|
||||||
//for ( unsigned int i = 0; i<4; ++i )
|
//for ( unsigned int i = 0; i<4; ++i )
|
||||||
// controllers.push_back( new Wiimote( i ) );
|
// controllers.push_back( new Wiimote( i ) );
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugin::~Plugin()
|
Plugin::~Plugin()
|
||||||
{
|
{
|
||||||
// delete pads
|
// delete pads
|
||||||
std::vector<ControllerEmu*>::const_iterator i = controllers.begin(),
|
std::vector<ControllerEmu*>::const_iterator i = controllers.begin(),
|
||||||
e = controllers.end();
|
e = controllers.end();
|
||||||
for ( ; i != e; ++i )
|
for ( ; i != e; ++i )
|
||||||
delete *i;
|
delete *i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Plugin::LoadConfig()
|
void Plugin::LoadConfig()
|
||||||
{
|
{
|
||||||
IniFile inifile;
|
IniFile inifile;
|
||||||
|
|
||||||
std::ifstream file;
|
std::ifstream file;
|
||||||
file.open( (std::string(File::GetUserPath(D_CONFIG_IDX)) + CONFIG_FILE_NAME ).c_str() );
|
file.open( (std::string(File::GetUserPath(D_CONFIG_IDX)) + CONFIG_FILE_NAME ).c_str() );
|
||||||
inifile.Load( file );
|
inifile.Load( file );
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
std::vector< ControllerEmu* >::const_iterator i = controllers.begin(),
|
std::vector< ControllerEmu* >::const_iterator i = controllers.begin(),
|
||||||
e = controllers.end();
|
e = controllers.end();
|
||||||
for ( ; i!=e; ++i )
|
for ( ; i!=e; ++i )
|
||||||
(*i)->LoadConfig( inifile[ (*i)->GetName() ] );
|
(*i)->LoadConfig( inifile[ (*i)->GetName() ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Plugin::SaveConfig()
|
void Plugin::SaveConfig()
|
||||||
{
|
{
|
||||||
IniFile inifile;
|
IniFile inifile;
|
||||||
|
|
||||||
std::vector< ControllerEmu* >::const_iterator i = controllers.begin(),
|
std::vector< ControllerEmu* >::const_iterator i = controllers.begin(),
|
||||||
e = controllers.end();
|
e = controllers.end();
|
||||||
for ( ; i!=e; ++i )
|
for ( ; i!=e; ++i )
|
||||||
(*i)->SaveConfig( inifile[ (*i)->GetName() ] );
|
(*i)->SaveConfig( inifile[ (*i)->GetName() ] );
|
||||||
|
|
||||||
// dont need to save empty values
|
// dont need to save empty values
|
||||||
inifile.Clean();
|
inifile.Clean();
|
||||||
|
|
||||||
std::ofstream file;
|
std::ofstream file;
|
||||||
file.open( (std::string(File::GetUserPath(D_CONFIG_IDX)) + CONFIG_FILE_NAME ).c_str() );
|
file.open( (std::string(File::GetUserPath(D_CONFIG_IDX)) + CONFIG_FILE_NAME ).c_str() );
|
||||||
inifile.Save( file );
|
inifile.Save( file );
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,36 +1,36 @@
|
||||||
#ifndef _CONFIG_H_
|
#ifndef _CONFIG_H_
|
||||||
#define _CONFIG_H_
|
#define _CONFIG_H_
|
||||||
|
|
||||||
#define CONFIG_FILE_NAME "GCPadNew.ini"
|
#define CONFIG_FILE_NAME "GCPadNew.ini"
|
||||||
|
|
||||||
#include "ControllerInterface/ControllerInterface.h"
|
#include "ControllerInterface/ControllerInterface.h"
|
||||||
#include "Thread.h"
|
#include "Thread.h"
|
||||||
#include "FileUtil.h"
|
#include "FileUtil.h"
|
||||||
#include "IniFile.h"
|
#include "IniFile.h"
|
||||||
|
|
||||||
#include "ControllerEmu.h"
|
#include "ControllerEmu.h"
|
||||||
#include "ControllerEmu/GCPad/GCPad.h"
|
#include "ControllerEmu/GCPad/GCPad.h"
|
||||||
#include "ControllerEmu/Wiimote/Wiimote.h"
|
#include "ControllerEmu/Wiimote/Wiimote.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
class Plugin
|
class Plugin
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Plugin();
|
Plugin();
|
||||||
~Plugin();
|
~Plugin();
|
||||||
|
|
||||||
void LoadConfig();
|
void LoadConfig();
|
||||||
void SaveConfig();
|
void SaveConfig();
|
||||||
|
|
||||||
std::vector< ControllerEmu* > controllers;
|
std::vector< ControllerEmu* > controllers;
|
||||||
|
|
||||||
Common::CriticalSection controls_crit, interface_crit; // lock controls first
|
Common::CriticalSection controls_crit, interface_crit; // lock controls first
|
||||||
ControllerInterface controller_interface;
|
ControllerInterface controller_interface;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,166 +1,166 @@
|
||||||
#ifndef _CONFIGBOX_H_
|
#ifndef _CONFIGBOX_H_
|
||||||
#define _CONFIGBOX_H_
|
#define _CONFIGBOX_H_
|
||||||
|
|
||||||
#define SLIDER_TICK_COUNT 100
|
#define SLIDER_TICK_COUNT 100
|
||||||
#define DETECT_WAIT_TIME 1500
|
#define DETECT_WAIT_TIME 1500
|
||||||
#define PREVIEW_UPDATE_TIME 25
|
#define PREVIEW_UPDATE_TIME 25
|
||||||
|
|
||||||
// might have to change this setup for wiimote
|
// might have to change this setup for wiimote
|
||||||
#define PROFILES_PATH "Profiles/GCPad/"
|
#define PROFILES_PATH "Profiles/GCPad/"
|
||||||
|
|
||||||
#include <wx/wx.h>
|
#include <wx/wx.h>
|
||||||
#include <wx/listbox.h>
|
#include <wx/listbox.h>
|
||||||
#include <wx/textctrl.h>
|
#include <wx/textctrl.h>
|
||||||
#include <wx/button.h>
|
#include <wx/button.h>
|
||||||
#include <wx/stattext.h>
|
#include <wx/stattext.h>
|
||||||
#include <wx/combobox.h>
|
#include <wx/combobox.h>
|
||||||
#include <wx/checkbox.h>
|
#include <wx/checkbox.h>
|
||||||
#include <wx/notebook.h>
|
#include <wx/notebook.h>
|
||||||
#include <wx/panel.h>
|
#include <wx/panel.h>
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "ControllerInterface/ControllerInterface.h"
|
#include "ControllerInterface/ControllerInterface.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "FileSearch.h"
|
#include "FileSearch.h"
|
||||||
|
|
||||||
class SettingCBox : public wxChoice
|
class SettingCBox : public wxChoice
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SettingCBox( wxWindow* const parent, ControlState& _value, int min, int max );
|
SettingCBox( wxWindow* const parent, ControlState& _value, int min, int max );
|
||||||
|
|
||||||
ControlState& value;
|
ControlState& value;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ControlChooser : public wxStaticBoxSizer
|
class ControlChooser : public wxStaticBoxSizer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ControlChooser( wxWindow* const parent, ControllerInterface::ControlReference* const ref, wxWindow* const eventsink );
|
ControlChooser( wxWindow* const parent, ControllerInterface::ControlReference* const ref, wxWindow* const eventsink );
|
||||||
|
|
||||||
void UpdateGUI();
|
void UpdateGUI();
|
||||||
|
|
||||||
ControllerInterface::ControlReference* control_reference;
|
ControllerInterface::ControlReference* control_reference;
|
||||||
|
|
||||||
wxTextCtrl* textctrl;
|
wxTextCtrl* textctrl;
|
||||||
wxListBox* control_lbox;
|
wxListBox* control_lbox;
|
||||||
wxChoice* mode_cbox;
|
wxChoice* mode_cbox;
|
||||||
wxSlider* range_slider;
|
wxSlider* range_slider;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxStaticText* m_bound_label;
|
wxStaticText* m_bound_label;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ControlList : public wxDialog
|
class ControlList : public wxDialog
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ControlList( wxWindow* const parent, ControllerInterface::ControlReference* const ref, ControlChooser* const chooser );
|
ControlList( wxWindow* const parent, ControllerInterface::ControlReference* const ref, ControlChooser* const chooser );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ControlChooser* const m_control_chooser;
|
ControlChooser* const m_control_chooser;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ControlDialog : public wxDialog
|
class ControlDialog : public wxDialog
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ControlDialog( wxWindow* const parent, ControllerInterface::ControlReference* const ref, const std::vector<ControllerInterface::Device*>& devs );
|
ControlDialog( wxWindow* const parent, ControllerInterface::ControlReference* const ref, const std::vector<ControllerInterface::Device*>& devs );
|
||||||
void SelectControl( wxCommandEvent& event );
|
void SelectControl( wxCommandEvent& event );
|
||||||
|
|
||||||
ControllerInterface::ControlReference* const control_reference;
|
ControllerInterface::ControlReference* const control_reference;
|
||||||
wxComboBox* device_cbox;
|
wxComboBox* device_cbox;
|
||||||
ControlChooser* control_chooser;
|
ControlChooser* control_chooser;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ControlButton : public wxButton
|
class ControlButton : public wxButton
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ControlButton( wxWindow* const parent, ControllerInterface::ControlReference* const _ref, const unsigned int width, const std::string& label = "" );
|
ControlButton( wxWindow* const parent, ControllerInterface::ControlReference* const _ref, const unsigned int width, const std::string& label = "" );
|
||||||
|
|
||||||
ControllerInterface::ControlReference* const control_reference;
|
ControllerInterface::ControlReference* const control_reference;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ControlGroupBox : public wxStaticBoxSizer
|
class ControlGroupBox : public wxStaticBoxSizer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ControlGroupBox( ControllerEmu::ControlGroup* const group, wxWindow* const parent );
|
ControlGroupBox( ControllerEmu::ControlGroup* const group, wxWindow* const parent );
|
||||||
|
|
||||||
ControllerEmu::ControlGroup* control_group;
|
ControllerEmu::ControlGroup* control_group;
|
||||||
wxStaticBitmap* static_bitmap;
|
wxStaticBitmap* static_bitmap;
|
||||||
std::vector< SettingCBox* > options;
|
std::vector< SettingCBox* > options;
|
||||||
std::vector< wxButton* > controls;
|
std::vector< wxButton* > controls;
|
||||||
std::vector<ControlButton*> control_buttons;
|
std::vector<ControlButton*> control_buttons;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ConfigDialog;
|
class ConfigDialog;
|
||||||
|
|
||||||
class GamepadPage : public wxNotebookPage
|
class GamepadPage : public wxNotebookPage
|
||||||
{
|
{
|
||||||
friend class ConfigDialog;
|
friend class ConfigDialog;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GamepadPage( wxWindow* parent, Plugin& plugin, const unsigned int pad_num, ConfigDialog* const config_dialog );
|
GamepadPage( wxWindow* parent, Plugin& plugin, const unsigned int pad_num, ConfigDialog* const config_dialog );
|
||||||
|
|
||||||
void UpdateGUI();
|
void UpdateGUI();
|
||||||
|
|
||||||
void RefreshDevices( wxCommandEvent& event );
|
void RefreshDevices( wxCommandEvent& event );
|
||||||
|
|
||||||
void LoadProfile( wxCommandEvent& event );
|
void LoadProfile( wxCommandEvent& event );
|
||||||
void SaveProfile( wxCommandEvent& event );
|
void SaveProfile( wxCommandEvent& event );
|
||||||
void DeleteProfile( wxCommandEvent& event );
|
void DeleteProfile( wxCommandEvent& event );
|
||||||
|
|
||||||
void ConfigControl( wxCommandEvent& event );
|
void ConfigControl( wxCommandEvent& event );
|
||||||
void ConfigDetectControl( wxCommandEvent& event );
|
void ConfigDetectControl( wxCommandEvent& event );
|
||||||
void DetectControl( wxCommandEvent& event );
|
void DetectControl( wxCommandEvent& event );
|
||||||
void ClearControl( wxCommandEvent& event );
|
void ClearControl( wxCommandEvent& event );
|
||||||
|
|
||||||
void SetDevice( wxCommandEvent& event );
|
void SetDevice( wxCommandEvent& event );
|
||||||
void SetControl( wxCommandEvent& event );
|
void SetControl( wxCommandEvent& event );
|
||||||
|
|
||||||
void ClearAll( wxCommandEvent& event );
|
void ClearAll( wxCommandEvent& event );
|
||||||
|
|
||||||
void AdjustControlOption( wxCommandEvent& event );
|
void AdjustControlOption( wxCommandEvent& event );
|
||||||
void AdjustSetting( wxCommandEvent& event );
|
void AdjustSetting( wxCommandEvent& event );
|
||||||
|
|
||||||
wxComboBox* profile_cbox;
|
wxComboBox* profile_cbox;
|
||||||
wxComboBox* device_cbox;
|
wxComboBox* device_cbox;
|
||||||
|
|
||||||
std::vector<ControlGroupBox*> control_groups;
|
std::vector<ControlGroupBox*> control_groups;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
ControllerEmu* const controller;
|
ControllerEmu* const controller;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
ControlDialog* m_control_dialog;
|
ControlDialog* m_control_dialog;
|
||||||
Plugin& m_plugin;
|
Plugin& m_plugin;
|
||||||
ConfigDialog* const m_config_dialog;
|
ConfigDialog* const m_config_dialog;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ConfigDialog : public wxDialog
|
class ConfigDialog : public wxDialog
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ConfigDialog( wxWindow* const parent, Plugin& plugin, const std::string& name, const bool _is_game_running );
|
ConfigDialog( wxWindow* const parent, Plugin& plugin, const std::string& name, const bool _is_game_running );
|
||||||
~ConfigDialog();
|
~ConfigDialog();
|
||||||
|
|
||||||
void ClickSave( wxCommandEvent& event );
|
void ClickSave( wxCommandEvent& event );
|
||||||
|
|
||||||
void UpdateDeviceComboBox();
|
void UpdateDeviceComboBox();
|
||||||
void UpdateProfileComboBox();
|
void UpdateProfileComboBox();
|
||||||
|
|
||||||
void UpdateControlReferences();
|
void UpdateControlReferences();
|
||||||
void UpdateBitmaps(wxTimerEvent&);
|
void UpdateBitmaps(wxTimerEvent&);
|
||||||
|
|
||||||
const bool is_game_running;
|
const bool is_game_running;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
wxNotebook* m_pad_notebook;
|
wxNotebook* m_pad_notebook;
|
||||||
std::vector<GamepadPage*> m_padpages;
|
std::vector<GamepadPage*> m_padpages;
|
||||||
Plugin& m_plugin;
|
Plugin& m_plugin;
|
||||||
wxTimer* m_update_timer;
|
wxTimer* m_update_timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,186 +1,186 @@
|
||||||
|
|
||||||
#include "ConfigDiag.h"
|
#include "ConfigDiag.h"
|
||||||
|
|
||||||
void ConfigDialog::UpdateBitmaps(wxTimerEvent& WXUNUSED(event))
|
void ConfigDialog::UpdateBitmaps(wxTimerEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
|
|
||||||
GamepadPage* const current_page = (GamepadPage*)m_pad_notebook->GetPage( m_pad_notebook->GetSelection() );
|
GamepadPage* const current_page = (GamepadPage*)m_pad_notebook->GetPage( m_pad_notebook->GetSelection() );
|
||||||
|
|
||||||
std::vector< ControlGroupBox* >::iterator g = current_page->control_groups.begin(),
|
std::vector< ControlGroupBox* >::iterator g = current_page->control_groups.begin(),
|
||||||
ge = current_page->control_groups.end();
|
ge = current_page->control_groups.end();
|
||||||
for ( ; g != ge; ++g )
|
for ( ; g != ge; ++g )
|
||||||
{
|
{
|
||||||
|
|
||||||
if ( (*g)->static_bitmap )
|
if ( (*g)->static_bitmap )
|
||||||
{
|
{
|
||||||
|
|
||||||
// don't want game thread updating input when we are using it here
|
// don't want game thread updating input when we are using it here
|
||||||
if ( false == m_plugin.interface_crit.TryEnter() )
|
if ( false == m_plugin.interface_crit.TryEnter() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( false == is_game_running )
|
if ( false == is_game_running )
|
||||||
m_plugin.controller_interface.UpdateInput();
|
m_plugin.controller_interface.UpdateInput();
|
||||||
|
|
||||||
switch ( (*g)->control_group->type )
|
switch ( (*g)->control_group->type )
|
||||||
{
|
{
|
||||||
case GROUP_TYPE_STICK :
|
case GROUP_TYPE_STICK :
|
||||||
{
|
{
|
||||||
float x, y;
|
float x, y;
|
||||||
float xx, yy;
|
float xx, yy;
|
||||||
((ControllerEmu::AnalogStick*)(*g)->control_group)->GetState( &x, &y, 32.0, 32-1.5 );
|
((ControllerEmu::AnalogStick*)(*g)->control_group)->GetState( &x, &y, 32.0, 32-1.5 );
|
||||||
|
|
||||||
xx = ((ControllerEmu::AnalogStick*)(*g)->control_group)->controls[3]->control_ref->State();
|
xx = ((ControllerEmu::AnalogStick*)(*g)->control_group)->controls[3]->control_ref->State();
|
||||||
xx -= ((ControllerEmu::AnalogStick*)(*g)->control_group)->controls[2]->control_ref->State();
|
xx -= ((ControllerEmu::AnalogStick*)(*g)->control_group)->controls[2]->control_ref->State();
|
||||||
yy = ((ControllerEmu::AnalogStick*)(*g)->control_group)->controls[1]->control_ref->State();
|
yy = ((ControllerEmu::AnalogStick*)(*g)->control_group)->controls[1]->control_ref->State();
|
||||||
yy -= ((ControllerEmu::AnalogStick*)(*g)->control_group)->controls[0]->control_ref->State();
|
yy -= ((ControllerEmu::AnalogStick*)(*g)->control_group)->controls[0]->control_ref->State();
|
||||||
xx *= 32 - 1; xx += 32;
|
xx *= 32 - 1; xx += 32;
|
||||||
yy *= 32 - 1; yy += 32;
|
yy *= 32 - 1; yy += 32;
|
||||||
|
|
||||||
// setup
|
// setup
|
||||||
wxBitmap bitmap(64, 64);
|
wxBitmap bitmap(64, 64);
|
||||||
wxMemoryDC dc;
|
wxMemoryDC dc;
|
||||||
dc.SelectObject(bitmap);
|
dc.SelectObject(bitmap);
|
||||||
dc.Clear();
|
dc.Clear();
|
||||||
|
|
||||||
// draw the shit
|
// draw the shit
|
||||||
|
|
||||||
// circle for visual aid for diagonal adjustment
|
// circle for visual aid for diagonal adjustment
|
||||||
dc.SetPen(*wxLIGHT_GREY_PEN);
|
dc.SetPen(*wxLIGHT_GREY_PEN);
|
||||||
dc.SetBrush(*wxTRANSPARENT_BRUSH);
|
dc.SetBrush(*wxTRANSPARENT_BRUSH);
|
||||||
dc.DrawCircle( 32, 32, 32);
|
dc.DrawCircle( 32, 32, 32);
|
||||||
|
|
||||||
// deadzone circle
|
// deadzone circle
|
||||||
dc.SetBrush(*wxLIGHT_GREY_BRUSH);
|
dc.SetBrush(*wxLIGHT_GREY_BRUSH);
|
||||||
dc.DrawCircle( 32, 32, ((ControllerEmu::AnalogStick*)(*g)->control_group)->settings[0]->value * 32 );
|
dc.DrawCircle( 32, 32, ((ControllerEmu::AnalogStick*)(*g)->control_group)->settings[0]->value * 32 );
|
||||||
|
|
||||||
// raw dot
|
// raw dot
|
||||||
dc.SetPen(*wxGREY_PEN);
|
dc.SetPen(*wxGREY_PEN);
|
||||||
dc.SetBrush(*wxGREY_BRUSH);
|
dc.SetBrush(*wxGREY_BRUSH);
|
||||||
// i like the dot better than the cross i think
|
// i like the dot better than the cross i think
|
||||||
dc.DrawRectangle( xx - 2, yy - 2, 4, 4 );
|
dc.DrawRectangle( xx - 2, yy - 2, 4, 4 );
|
||||||
//dc.DrawRectangle( xx-1, 64-yy-4, 2, 8 );
|
//dc.DrawRectangle( xx-1, 64-yy-4, 2, 8 );
|
||||||
//dc.DrawRectangle( xx-4, 64-yy-1, 8, 2 );
|
//dc.DrawRectangle( xx-4, 64-yy-1, 8, 2 );
|
||||||
|
|
||||||
// adjusted dot
|
// adjusted dot
|
||||||
if ( x!=32 || y!=32 )
|
if ( x!=32 || y!=32 )
|
||||||
{
|
{
|
||||||
dc.SetPen(*wxRED_PEN);
|
dc.SetPen(*wxRED_PEN);
|
||||||
dc.SetBrush(*wxRED_BRUSH);
|
dc.SetBrush(*wxRED_BRUSH);
|
||||||
dc.DrawRectangle( x-2, 64-y-2, 4, 4 );
|
dc.DrawRectangle( x-2, 64-y-2, 4, 4 );
|
||||||
// i like the dot better than the cross i think
|
// i like the dot better than the cross i think
|
||||||
//dc.DrawRectangle( x-1, 64-y-4, 2, 8 );
|
//dc.DrawRectangle( x-1, 64-y-4, 2, 8 );
|
||||||
//dc.DrawRectangle( x-4, 64-y-1, 8, 2 );
|
//dc.DrawRectangle( x-4, 64-y-1, 8, 2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
// box outline
|
// box outline
|
||||||
// Windows XP color
|
// Windows XP color
|
||||||
dc.SetPen(wxPen(_T("#7f9db9")));
|
dc.SetPen(wxPen(_T("#7f9db9")));
|
||||||
dc.SetBrush(*wxTRANSPARENT_BRUSH);
|
dc.SetBrush(*wxTRANSPARENT_BRUSH);
|
||||||
dc.DrawRectangle(0, 0, 64, 64);
|
dc.DrawRectangle(0, 0, 64, 64);
|
||||||
|
|
||||||
// done drawing
|
// done drawing
|
||||||
dc.SelectObject(wxNullBitmap);
|
dc.SelectObject(wxNullBitmap);
|
||||||
|
|
||||||
// set the shit
|
// set the shit
|
||||||
(*g)->static_bitmap->SetBitmap( bitmap );
|
(*g)->static_bitmap->SetBitmap( bitmap );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GROUP_TYPE_BUTTONS :
|
case GROUP_TYPE_BUTTONS :
|
||||||
{
|
{
|
||||||
const unsigned int button_count = ((unsigned int)(*g)->control_group->controls.size());
|
const unsigned int button_count = ((unsigned int)(*g)->control_group->controls.size());
|
||||||
// setup
|
// setup
|
||||||
wxBitmap bitmap(12*button_count+1, 12);
|
wxBitmap bitmap(12*button_count+1, 12);
|
||||||
wxMemoryDC dc;
|
wxMemoryDC dc;
|
||||||
dc.SelectObject(bitmap);
|
dc.SelectObject(bitmap);
|
||||||
dc.Clear();
|
dc.Clear();
|
||||||
|
|
||||||
// draw the shit
|
// draw the shit
|
||||||
dc.SetPen(*wxGREY_PEN);
|
dc.SetPen(*wxGREY_PEN);
|
||||||
|
|
||||||
unsigned int * const bitmasks = new unsigned int[ button_count ];
|
unsigned int * const bitmasks = new unsigned int[ button_count ];
|
||||||
for ( unsigned int n = 0; n<button_count; ++n )
|
for ( unsigned int n = 0; n<button_count; ++n )
|
||||||
bitmasks[n] = ( 1 << n );
|
bitmasks[n] = ( 1 << n );
|
||||||
|
|
||||||
unsigned int buttons = 0;
|
unsigned int buttons = 0;
|
||||||
((ControllerEmu::Buttons*)(*g)->control_group)->GetState( &buttons, bitmasks );
|
((ControllerEmu::Buttons*)(*g)->control_group)->GetState( &buttons, bitmasks );
|
||||||
|
|
||||||
for ( unsigned int n = 0; n<button_count; ++n )
|
for ( unsigned int n = 0; n<button_count; ++n )
|
||||||
{
|
{
|
||||||
// TODO: threshold stuff, actually redo this crap with the GetState func
|
// TODO: threshold stuff, actually redo this crap with the GetState func
|
||||||
if ( buttons & bitmasks[n] )
|
if ( buttons & bitmasks[n] )
|
||||||
dc.SetBrush( *wxRED_BRUSH );
|
dc.SetBrush( *wxRED_BRUSH );
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
unsigned char amt = 255 - (*g)->control_group->controls[n]->control_ref->State() * 128;
|
unsigned char amt = 255 - (*g)->control_group->controls[n]->control_ref->State() * 128;
|
||||||
dc.SetBrush( wxBrush( wxColor( amt, amt, amt ) ) );
|
dc.SetBrush( wxBrush( wxColor( amt, amt, amt ) ) );
|
||||||
}
|
}
|
||||||
dc.DrawRectangle(n*12, 0, 14, 12);
|
dc.DrawRectangle(n*12, 0, 14, 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete bitmasks;
|
delete bitmasks;
|
||||||
|
|
||||||
// box outline
|
// box outline
|
||||||
// Windows XP color
|
// Windows XP color
|
||||||
dc.SetPen(wxPen(_T("#7f9db9")));
|
dc.SetPen(wxPen(_T("#7f9db9")));
|
||||||
dc.SetBrush(*wxTRANSPARENT_BRUSH);
|
dc.SetBrush(*wxTRANSPARENT_BRUSH);
|
||||||
dc.DrawRectangle(0, 0, bitmap.GetWidth(), bitmap.GetHeight());
|
dc.DrawRectangle(0, 0, bitmap.GetWidth(), bitmap.GetHeight());
|
||||||
|
|
||||||
// done drawing
|
// done drawing
|
||||||
dc.SelectObject(wxNullBitmap);
|
dc.SelectObject(wxNullBitmap);
|
||||||
|
|
||||||
// set the shit
|
// set the shit
|
||||||
(*g)->static_bitmap->SetBitmap( bitmap );
|
(*g)->static_bitmap->SetBitmap( bitmap );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GROUP_TYPE_MIXED_TRIGGERS :
|
case GROUP_TYPE_MIXED_TRIGGERS :
|
||||||
{
|
{
|
||||||
const unsigned int trigger_count = ((unsigned int)((*g)->control_group->controls.size() / 2));
|
const unsigned int trigger_count = ((unsigned int)((*g)->control_group->controls.size() / 2));
|
||||||
// setup
|
// setup
|
||||||
wxBitmap bitmap( 64+12+1, 12*trigger_count+1);
|
wxBitmap bitmap( 64+12+1, 12*trigger_count+1);
|
||||||
wxMemoryDC dc;
|
wxMemoryDC dc;
|
||||||
dc.SelectObject(bitmap);
|
dc.SelectObject(bitmap);
|
||||||
dc.Clear();
|
dc.Clear();
|
||||||
|
|
||||||
// draw the shit
|
// draw the shit
|
||||||
dc.SetPen(*wxGREY_PEN);
|
dc.SetPen(*wxGREY_PEN);
|
||||||
ControlState thresh = (*g)->control_group->settings[0]->value;
|
ControlState thresh = (*g)->control_group->settings[0]->value;
|
||||||
|
|
||||||
for ( unsigned int n = 0; n < trigger_count; ++n )
|
for ( unsigned int n = 0; n < trigger_count; ++n )
|
||||||
{
|
{
|
||||||
dc.SetBrush(*wxRED_BRUSH);
|
dc.SetBrush(*wxRED_BRUSH);
|
||||||
ControlState trig_d = (*g)->control_group->controls[n]->control_ref->State();
|
ControlState trig_d = (*g)->control_group->controls[n]->control_ref->State();
|
||||||
|
|
||||||
ControlState trig_a = trig_d > thresh ? 1
|
ControlState trig_a = trig_d > thresh ? 1
|
||||||
: (*g)->control_group->controls[n+trigger_count]->control_ref->State();
|
: (*g)->control_group->controls[n+trigger_count]->control_ref->State();
|
||||||
|
|
||||||
dc.DrawRectangle(0, n*12, 64+20, 14);
|
dc.DrawRectangle(0, n*12, 64+20, 14);
|
||||||
if ( trig_d <= thresh )
|
if ( trig_d <= thresh )
|
||||||
dc.SetBrush(*wxWHITE_BRUSH);
|
dc.SetBrush(*wxWHITE_BRUSH);
|
||||||
dc.DrawRectangle(trig_a*64, n*12, 64+20, 14);
|
dc.DrawRectangle(trig_a*64, n*12, 64+20, 14);
|
||||||
dc.DrawRectangle(64, n*12, 32, 14);
|
dc.DrawRectangle(64, n*12, 32, 14);
|
||||||
}
|
}
|
||||||
dc.SetBrush(*wxTRANSPARENT_BRUSH);
|
dc.SetBrush(*wxTRANSPARENT_BRUSH);
|
||||||
dc.DrawRectangle(thresh*64, 0, 128, trigger_count*14);
|
dc.DrawRectangle(thresh*64, 0, 128, trigger_count*14);
|
||||||
|
|
||||||
// box outline
|
// box outline
|
||||||
// Windows XP color
|
// Windows XP color
|
||||||
dc.SetPen(wxPen(_T("#7f9db9")));
|
dc.SetPen(wxPen(_T("#7f9db9")));
|
||||||
dc.DrawRectangle(0, 0, bitmap.GetWidth(), bitmap.GetHeight());
|
dc.DrawRectangle(0, 0, bitmap.GetWidth(), bitmap.GetHeight());
|
||||||
|
|
||||||
// done drawing
|
// done drawing
|
||||||
dc.SelectObject(wxNullBitmap);
|
dc.SelectObject(wxNullBitmap);
|
||||||
|
|
||||||
// set the shit
|
// set the shit
|
||||||
(*g)->static_bitmap->SetBitmap( bitmap );
|
(*g)->static_bitmap->SetBitmap( bitmap );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default :
|
default :
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_plugin.interface_crit.Leave();
|
m_plugin.interface_crit.Leave();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,138 +1,138 @@
|
||||||
#include "ControllerEmu.h"
|
#include "ControllerEmu.h"
|
||||||
|
|
||||||
#include "ControllerEmu/GCPad/GCPad.h"
|
#include "ControllerEmu/GCPad/GCPad.h"
|
||||||
|
|
||||||
const char modifier[] = "Modifier";
|
const char modifier[] = "Modifier";
|
||||||
|
|
||||||
// TODO: make this use iterators
|
// TODO: make this use iterators
|
||||||
ControllerEmu::~ControllerEmu()
|
ControllerEmu::~ControllerEmu()
|
||||||
{
|
{
|
||||||
for ( unsigned int g = 0; g<groups.size(); ++g )
|
for ( unsigned int g = 0; g<groups.size(); ++g )
|
||||||
delete groups[g];
|
delete groups[g];
|
||||||
}
|
}
|
||||||
// TODO: make this use iterators
|
// TODO: make this use iterators
|
||||||
ControllerEmu::ControlGroup::~ControlGroup()
|
ControllerEmu::ControlGroup::~ControlGroup()
|
||||||
{
|
{
|
||||||
for ( unsigned int i = 0; i < controls.size(); ++i )
|
for ( unsigned int i = 0; i < controls.size(); ++i )
|
||||||
delete controls[i];
|
delete controls[i];
|
||||||
for ( unsigned int i = 0; i < settings.size(); ++i )
|
for ( unsigned int i = 0; i < settings.size(); ++i )
|
||||||
delete settings[i];
|
delete settings[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: make this use iterators
|
// TODO: make this use iterators
|
||||||
void ControllerEmu::UpdateReferences( ControllerInterface& devi )
|
void ControllerEmu::UpdateReferences( ControllerInterface& devi )
|
||||||
{
|
{
|
||||||
for ( unsigned int g = 0; g<groups.size(); ++g )
|
for ( unsigned int g = 0; g<groups.size(); ++g )
|
||||||
for ( unsigned int i = 0; i < groups[g]->controls.size(); ++i )
|
for ( unsigned int i = 0; i < groups[g]->controls.size(); ++i )
|
||||||
devi.UpdateReference( groups[g]->controls[i]->control_ref );
|
devi.UpdateReference( groups[g]->controls[i]->control_ref );
|
||||||
}
|
}
|
||||||
|
|
||||||
void ControllerEmu::UpdateDefaultDevice()
|
void ControllerEmu::UpdateDefaultDevice()
|
||||||
{
|
{
|
||||||
std::vector<ControlGroup*>::const_iterator i = groups.begin(),
|
std::vector<ControlGroup*>::const_iterator i = groups.begin(),
|
||||||
e = groups.end();
|
e = groups.end();
|
||||||
for ( ; i!=e; ++i )
|
for ( ; i!=e; ++i )
|
||||||
{
|
{
|
||||||
std::vector<ControlGroup::Control*>::const_iterator ci = (*i)->controls.begin(),
|
std::vector<ControlGroup::Control*>::const_iterator ci = (*i)->controls.begin(),
|
||||||
ce = (*i)->controls.end();
|
ce = (*i)->controls.end();
|
||||||
for ( ; ci!=ce; ++ci )
|
for ( ; ci!=ce; ++ci )
|
||||||
(*ci)->control_ref->device_qualifier = default_device;
|
(*ci)->control_ref->device_qualifier = default_device;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ControllerEmu::LoadConfig( IniFile::Section& sec )
|
void ControllerEmu::LoadConfig( IniFile::Section& sec )
|
||||||
{
|
{
|
||||||
const std::string default_dev = sec[ "Device" ];
|
const std::string default_dev = sec[ "Device" ];
|
||||||
default_device.FromString( default_dev );
|
default_device.FromString( default_dev );
|
||||||
|
|
||||||
std::vector<ControlGroup*>::const_iterator i = groups.begin(),
|
std::vector<ControlGroup*>::const_iterator i = groups.begin(),
|
||||||
e = groups.end();
|
e = groups.end();
|
||||||
for ( ; i!=e; ++i )
|
for ( ; i!=e; ++i )
|
||||||
{
|
{
|
||||||
std::string group( (*i)->name ); group += "/";
|
std::string group( (*i)->name ); group += "/";
|
||||||
|
|
||||||
// settings
|
// settings
|
||||||
std::vector<ControlGroup::Setting*>::const_iterator si = (*i)->settings.begin(),
|
std::vector<ControlGroup::Setting*>::const_iterator si = (*i)->settings.begin(),
|
||||||
se = (*i)->settings.end();
|
se = (*i)->settings.end();
|
||||||
for ( ; si!=se; ++si )
|
for ( ; si!=se; ++si )
|
||||||
(*si)->value = sec.Get(group+(*si)->name, (*si)->default_value*100) / 100;
|
(*si)->value = sec.Get(group+(*si)->name, (*si)->default_value*100) / 100;
|
||||||
|
|
||||||
// controls
|
// controls
|
||||||
std::vector<ControlGroup::Control*>::const_iterator ci = (*i)->controls.begin(),
|
std::vector<ControlGroup::Control*>::const_iterator ci = (*i)->controls.begin(),
|
||||||
ce = (*i)->controls.end();
|
ce = (*i)->controls.end();
|
||||||
for ( ; ci!=ce; ++ci )
|
for ( ; ci!=ce; ++ci )
|
||||||
{
|
{
|
||||||
// control and dev qualifier
|
// control and dev qualifier
|
||||||
(*ci)->control_ref->control_qualifier.name = sec[group + (*ci)->name];
|
(*ci)->control_ref->control_qualifier.name = sec[group + (*ci)->name];
|
||||||
(*ci)->control_ref->device_qualifier.FromString( sec.Get( group+(*ci)->name+"/Device", default_dev ) );
|
(*ci)->control_ref->device_qualifier.FromString( sec.Get( group+(*ci)->name+"/Device", default_dev ) );
|
||||||
|
|
||||||
// range
|
// range
|
||||||
(*ci)->control_ref->range = sec.Get( group+(*ci)->name+"/Range", 100.0f ) / 100;
|
(*ci)->control_ref->range = sec.Get( group+(*ci)->name+"/Range", 100.0f ) / 100;
|
||||||
|
|
||||||
// input mode
|
// input mode
|
||||||
if ( (*ci)->control_ref->is_input )
|
if ( (*ci)->control_ref->is_input )
|
||||||
((ControllerInterface::InputReference*)((*ci)->control_ref))->mode
|
((ControllerInterface::InputReference*)((*ci)->control_ref))->mode
|
||||||
= sec.Get( group+(*ci)->name+"/Mode", 0 );
|
= sec.Get( group+(*ci)->name+"/Mode", 0 );
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ControllerEmu::SaveConfig( IniFile::Section& sec )
|
void ControllerEmu::SaveConfig( IniFile::Section& sec )
|
||||||
{
|
{
|
||||||
const std::string default_dev = default_device.ToString();
|
const std::string default_dev = default_device.ToString();
|
||||||
sec[ " Device" ] = default_dev;
|
sec[ " Device" ] = default_dev;
|
||||||
|
|
||||||
std::vector<ControlGroup*>::const_iterator i = groups.begin(),
|
std::vector<ControlGroup*>::const_iterator i = groups.begin(),
|
||||||
e = groups.end();
|
e = groups.end();
|
||||||
for ( ; i!=e; ++i )
|
for ( ; i!=e; ++i )
|
||||||
{
|
{
|
||||||
std::string group( (*i)->name ); group += "/";
|
std::string group( (*i)->name ); group += "/";
|
||||||
|
|
||||||
// settings
|
// settings
|
||||||
std::vector<ControlGroup::Setting*>::const_iterator si = (*i)->settings.begin(),
|
std::vector<ControlGroup::Setting*>::const_iterator si = (*i)->settings.begin(),
|
||||||
se = (*i)->settings.end();
|
se = (*i)->settings.end();
|
||||||
for ( ; si!=se; ++si )
|
for ( ; si!=se; ++si )
|
||||||
sec.Set( group+(*si)->name, (*si)->value*100, (*si)->default_value*100 );
|
sec.Set( group+(*si)->name, (*si)->value*100, (*si)->default_value*100 );
|
||||||
|
|
||||||
// controls
|
// controls
|
||||||
std::vector<ControlGroup::Control*>::const_iterator ci = (*i)->controls.begin(),
|
std::vector<ControlGroup::Control*>::const_iterator ci = (*i)->controls.begin(),
|
||||||
ce = (*i)->controls.end();
|
ce = (*i)->controls.end();
|
||||||
for ( ; ci!=ce; ++ci )
|
for ( ; ci!=ce; ++ci )
|
||||||
{
|
{
|
||||||
// control and dev qualifier
|
// control and dev qualifier
|
||||||
sec[group + (*ci)->name] = (*ci)->control_ref->control_qualifier.name;
|
sec[group + (*ci)->name] = (*ci)->control_ref->control_qualifier.name;
|
||||||
sec.Set( group+(*ci)->name+"/Device", (*ci)->control_ref->device_qualifier.ToString(), default_dev );
|
sec.Set( group+(*ci)->name+"/Device", (*ci)->control_ref->device_qualifier.ToString(), default_dev );
|
||||||
|
|
||||||
// range
|
// range
|
||||||
sec.Set( group+(*ci)->name+"/Range", (*ci)->control_ref->range*100, 100 );
|
sec.Set( group+(*ci)->name+"/Range", (*ci)->control_ref->range*100, 100 );
|
||||||
|
|
||||||
// input mode
|
// input mode
|
||||||
if ( (*ci)->control_ref->is_input )
|
if ( (*ci)->control_ref->is_input )
|
||||||
sec.Set( group+(*ci)->name+"/Mode",
|
sec.Set( group+(*ci)->name+"/Mode",
|
||||||
((ControllerInterface::InputReference*)((*ci)->control_ref))->mode, (unsigned int)0 );
|
((ControllerInterface::InputReference*)((*ci)->control_ref))->mode, (unsigned int)0 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ControllerEmu::AnalogStick::AnalogStick( const char* const _name ) : ControlGroup( _name, GROUP_TYPE_STICK )
|
ControllerEmu::AnalogStick::AnalogStick( const char* const _name ) : ControlGroup( _name, GROUP_TYPE_STICK )
|
||||||
{
|
{
|
||||||
for ( unsigned int i = 0; i < 4; ++i )
|
for ( unsigned int i = 0; i < 4; ++i )
|
||||||
controls.push_back( new Input( named_directions[i] ) );
|
controls.push_back( new Input( named_directions[i] ) );
|
||||||
|
|
||||||
controls.push_back( new Input( modifier ) );
|
controls.push_back( new Input( modifier ) );
|
||||||
|
|
||||||
settings.push_back( new Setting("Dead Zone", 0 ) );
|
settings.push_back( new Setting("Dead Zone", 0 ) );
|
||||||
settings.push_back( new Setting("Square Stick", 0 ) );
|
settings.push_back( new Setting("Square Stick", 0 ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ControllerEmu::Buttons::Buttons( const char* const _name ) : ControlGroup( _name, GROUP_TYPE_BUTTONS )
|
ControllerEmu::Buttons::Buttons( const char* const _name ) : ControlGroup( _name, GROUP_TYPE_BUTTONS )
|
||||||
{
|
{
|
||||||
settings.push_back( new Setting("Threshold", 0.5f ) );
|
settings.push_back( new Setting("Threshold", 0.5f ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
ControllerEmu::MixedTriggers::MixedTriggers( const char* const _name ) : ControlGroup( _name, GROUP_TYPE_MIXED_TRIGGERS )
|
ControllerEmu::MixedTriggers::MixedTriggers( const char* const _name ) : ControlGroup( _name, GROUP_TYPE_MIXED_TRIGGERS )
|
||||||
{
|
{
|
||||||
settings.push_back( new Setting("Threshold", 0.9f ) );
|
settings.push_back( new Setting("Threshold", 0.9f ) );
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,226 +1,226 @@
|
||||||
#ifndef _CONTROLLEREMU_H_
|
#ifndef _CONTROLLEREMU_H_
|
||||||
#define _CONTROLLEREMU_H_
|
#define _CONTROLLEREMU_H_
|
||||||
|
|
||||||
// windows crap
|
// windows crap
|
||||||
#define NOMINMAX
|
#define NOMINMAX
|
||||||
|
|
||||||
#include "pluginspecs_pad.h"
|
#include "pluginspecs_pad.h"
|
||||||
#include "pluginspecs_wiimote.h"
|
#include "pluginspecs_wiimote.h"
|
||||||
//#include <CommonTypes.h>
|
//#include <CommonTypes.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include "ControllerInterface/ControllerInterface.h"
|
#include "ControllerInterface/ControllerInterface.h"
|
||||||
#include "IniFile.h"
|
#include "IniFile.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#define sign(x) ((x)?(x)<0?-1:1:0)
|
#define sign(x) ((x)?(x)<0?-1:1:0)
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
GROUP_TYPE_OTHER
|
GROUP_TYPE_OTHER
|
||||||
,GROUP_TYPE_STICK
|
,GROUP_TYPE_STICK
|
||||||
,GROUP_TYPE_MIXED_TRIGGERS
|
,GROUP_TYPE_MIXED_TRIGGERS
|
||||||
,GROUP_TYPE_BUTTONS
|
,GROUP_TYPE_BUTTONS
|
||||||
};
|
};
|
||||||
|
|
||||||
const char * const named_directions[] =
|
const char * const named_directions[] =
|
||||||
{
|
{
|
||||||
"Up",
|
"Up",
|
||||||
"Down",
|
"Down",
|
||||||
"Left",
|
"Left",
|
||||||
"Right"
|
"Right"
|
||||||
};
|
};
|
||||||
|
|
||||||
class ControllerEmu
|
class ControllerEmu
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
class ControlGroup
|
class ControlGroup
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
class Control
|
class Control
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
Control( ControllerInterface::ControlReference* const _ref, const char * const _name )
|
Control( ControllerInterface::ControlReference* const _ref, const char * const _name )
|
||||||
: control_ref(_ref), name(_name){}
|
: control_ref(_ref), name(_name){}
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
//virtual std::string GetName() const = 0;
|
//virtual std::string GetName() const = 0;
|
||||||
|
|
||||||
ControllerInterface::ControlReference* const control_ref;
|
ControllerInterface::ControlReference* const control_ref;
|
||||||
const char * const name;
|
const char * const name;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Input : public Control
|
class Input : public Control
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Input( const char * const _name )
|
Input( const char * const _name )
|
||||||
: Control( new ControllerInterface::InputReference, _name ) {}
|
: Control( new ControllerInterface::InputReference, _name ) {}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Output : public Control
|
class Output : public Control
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Output( const char * const _name )
|
Output( const char * const _name )
|
||||||
: Control( new ControllerInterface::OutputReference, _name ) {}
|
: Control( new ControllerInterface::OutputReference, _name ) {}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Setting
|
class Setting
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Setting(const char* const _name, const float def_value ) : name(_name), value(def_value), default_value(def_value) {}
|
Setting(const char* const _name, const float def_value ) : name(_name), value(def_value), default_value(def_value) {}
|
||||||
|
|
||||||
const char* const name;
|
const char* const name;
|
||||||
ControlState value;
|
ControlState value;
|
||||||
const ControlState default_value;
|
const ControlState default_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
ControlGroup( const char* const _name, const unsigned int _type = GROUP_TYPE_OTHER ) : name(_name), type(_type) {}
|
ControlGroup( const char* const _name, const unsigned int _type = GROUP_TYPE_OTHER ) : name(_name), type(_type) {}
|
||||||
virtual ~ControlGroup();
|
virtual ~ControlGroup();
|
||||||
|
|
||||||
//ControlGroup( const ControlGroup& ctrl );
|
//ControlGroup( const ControlGroup& ctrl );
|
||||||
|
|
||||||
//const unsigned int type;
|
//const unsigned int type;
|
||||||
const char* const name;
|
const char* const name;
|
||||||
const unsigned int type;
|
const unsigned int type;
|
||||||
|
|
||||||
std::vector< Control* > controls;
|
std::vector< Control* > controls;
|
||||||
std::vector< Setting* > settings;
|
std::vector< Setting* > settings;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class AnalogStick : public ControlGroup
|
class AnalogStick : public ControlGroup
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
template <typename C>
|
template <typename C>
|
||||||
void GetState( C* const x, C* const y, const unsigned int base, const unsigned int range )
|
void GetState( C* const x, C* const y, const unsigned int base, const unsigned int range )
|
||||||
{
|
{
|
||||||
// this is all a mess
|
// this is all a mess
|
||||||
|
|
||||||
ControlState yy = controls[0]->control_ref->State() - controls[1]->control_ref->State();
|
ControlState yy = controls[0]->control_ref->State() - controls[1]->control_ref->State();
|
||||||
ControlState xx = controls[3]->control_ref->State() - controls[2]->control_ref->State();
|
ControlState xx = controls[3]->control_ref->State() - controls[2]->control_ref->State();
|
||||||
|
|
||||||
ControlState deadzone = settings[0]->value;
|
ControlState deadzone = settings[0]->value;
|
||||||
ControlState square = settings[1]->value;
|
ControlState square = settings[1]->value;
|
||||||
ControlState m = controls[4]->control_ref->State();
|
ControlState m = controls[4]->control_ref->State();
|
||||||
|
|
||||||
// modifier code
|
// modifier code
|
||||||
if ( m )
|
if ( m )
|
||||||
{
|
{
|
||||||
yy = (abs(yy)>deadzone) * sign(yy) * m;
|
yy = (abs(yy)>deadzone) * sign(yy) * m;
|
||||||
xx = (abs(xx)>deadzone) * sign(xx) * m;
|
xx = (abs(xx)>deadzone) * sign(xx) * m;
|
||||||
}
|
}
|
||||||
|
|
||||||
// deadzone / square stick code
|
// deadzone / square stick code
|
||||||
if ( deadzone || square )
|
if ( deadzone || square )
|
||||||
{
|
{
|
||||||
// this section might be all wrong, but its working good enough, i think
|
// this section might be all wrong, but its working good enough, i think
|
||||||
|
|
||||||
ControlState ang = atan2( yy, xx );
|
ControlState ang = atan2( yy, xx );
|
||||||
ControlState ang_sin = sin(ang);
|
ControlState ang_sin = sin(ang);
|
||||||
ControlState ang_cos = cos(ang);
|
ControlState ang_cos = cos(ang);
|
||||||
|
|
||||||
// the amt a full square stick would have at current angle
|
// the amt a full square stick would have at current angle
|
||||||
ControlState square_full = std::min( 1/abs(ang_sin), 1/abs(ang_cos) );
|
ControlState square_full = std::min( 1/abs(ang_sin), 1/abs(ang_cos) );
|
||||||
|
|
||||||
// the amt a full stick would have that was ( user setting squareness) at current angle
|
// the amt a full stick would have that was ( user setting squareness) at current angle
|
||||||
// i think this is more like a pointed circle rather than a rounded square like it should be
|
// i think this is more like a pointed circle rather than a rounded square like it should be
|
||||||
ControlState stick_full = ( 1 + ( square_full - 1 ) * square );
|
ControlState stick_full = ( 1 + ( square_full - 1 ) * square );
|
||||||
|
|
||||||
ControlState dist = sqrt(xx*xx + yy*yy);
|
ControlState dist = sqrt(xx*xx + yy*yy);
|
||||||
|
|
||||||
// dead zone code
|
// dead zone code
|
||||||
dist = std::max( 0.0f, dist - deadzone * stick_full );
|
dist = std::max( 0.0f, dist - deadzone * stick_full );
|
||||||
dist /= ( 1 - deadzone );
|
dist /= ( 1 - deadzone );
|
||||||
|
|
||||||
// square stick code
|
// square stick code
|
||||||
ControlState amt = ( dist ) / stick_full;
|
ControlState amt = ( dist ) / stick_full;
|
||||||
dist -= ((square_full - 1) * amt * square);
|
dist -= ((square_full - 1) * amt * square);
|
||||||
|
|
||||||
yy = std::max( -1.0f, std::min( 1.0f, ang_sin * dist ) );
|
yy = std::max( -1.0f, std::min( 1.0f, ang_sin * dist ) );
|
||||||
xx = std::max( -1.0f, std::min( 1.0f, ang_cos * dist ) );
|
xx = std::max( -1.0f, std::min( 1.0f, ang_cos * dist ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
*y = C( yy * range + base );
|
*y = C( yy * range + base );
|
||||||
*x = C( xx * range + base );
|
*x = C( xx * range + base );
|
||||||
}
|
}
|
||||||
|
|
||||||
AnalogStick( const char* const _name );
|
AnalogStick( const char* const _name );
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Buttons : public ControlGroup
|
class Buttons : public ControlGroup
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Buttons( const char* const _name );
|
Buttons( const char* const _name );
|
||||||
|
|
||||||
template <typename C>
|
template <typename C>
|
||||||
void GetState( C* const buttons, const C* bitmasks )
|
void GetState( C* const buttons, const C* bitmasks )
|
||||||
{
|
{
|
||||||
std::vector<Control*>::iterator i = controls.begin(),
|
std::vector<Control*>::iterator i = controls.begin(),
|
||||||
e = controls.end();
|
e = controls.end();
|
||||||
for ( ; i!=e; ++i, ++bitmasks )
|
for ( ; i!=e; ++i, ++bitmasks )
|
||||||
if ( (*i)->control_ref->State() > settings[0]->value ) // threshold
|
if ( (*i)->control_ref->State() > settings[0]->value ) // threshold
|
||||||
*buttons |= *bitmasks;
|
*buttons |= *bitmasks;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class MixedTriggers : public ControlGroup
|
class MixedTriggers : public ControlGroup
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
template <typename C, typename S>
|
template <typename C, typename S>
|
||||||
void GetState( C* const digital, const C* bitmasks, S* analog, const unsigned int range )
|
void GetState( C* const digital, const C* bitmasks, S* analog, const unsigned int range )
|
||||||
{
|
{
|
||||||
const unsigned int trig_count = ((unsigned int) (controls.size() / 2));
|
const unsigned int trig_count = ((unsigned int) (controls.size() / 2));
|
||||||
for ( unsigned int i=0; i<trig_count; ++i,++bitmasks,++analog )
|
for ( unsigned int i=0; i<trig_count; ++i,++bitmasks,++analog )
|
||||||
{
|
{
|
||||||
if ( controls[i]->control_ref->State() > settings[0]->value ) //threshold
|
if ( controls[i]->control_ref->State() > settings[0]->value ) //threshold
|
||||||
{
|
{
|
||||||
*analog = range;
|
*analog = range;
|
||||||
*digital |= *bitmasks;
|
*digital |= *bitmasks;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
*analog = S(controls[i+trig_count]->control_ref->State() * range);
|
*analog = S(controls[i+trig_count]->control_ref->State() * range);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MixedTriggers( const char* const _name );
|
MixedTriggers( const char* const _name );
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual ~ControllerEmu();
|
virtual ~ControllerEmu();
|
||||||
|
|
||||||
virtual std::string GetName() const = 0;
|
virtual std::string GetName() const = 0;
|
||||||
|
|
||||||
void LoadConfig( IniFile::Section& sec );
|
void LoadConfig( IniFile::Section& sec );
|
||||||
void SaveConfig( IniFile::Section& sec );
|
void SaveConfig( IniFile::Section& sec );
|
||||||
void UpdateDefaultDevice();
|
void UpdateDefaultDevice();
|
||||||
|
|
||||||
void UpdateReferences( ControllerInterface& devi );
|
void UpdateReferences( ControllerInterface& devi );
|
||||||
|
|
||||||
std::vector< ControlGroup* > groups;
|
std::vector< ControlGroup* > groups;
|
||||||
|
|
||||||
|
|
||||||
ControllerInterface::DeviceQualifier default_device;
|
ControllerInterface::DeviceQualifier default_device;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,97 +1,97 @@
|
||||||
|
|
||||||
#include "GCPad.h"
|
#include "GCPad.h"
|
||||||
|
|
||||||
// this is all temporary, but sticking with the padspecs ...for now
|
// this is all temporary, but sticking with the padspecs ...for now
|
||||||
const u16 button_bitmasks[] =
|
const u16 button_bitmasks[] =
|
||||||
{
|
{
|
||||||
PAD_BUTTON_A,
|
PAD_BUTTON_A,
|
||||||
PAD_BUTTON_B,
|
PAD_BUTTON_B,
|
||||||
PAD_BUTTON_X,
|
PAD_BUTTON_X,
|
||||||
PAD_BUTTON_Y,
|
PAD_BUTTON_Y,
|
||||||
PAD_TRIGGER_Z,
|
PAD_TRIGGER_Z,
|
||||||
PAD_BUTTON_START
|
PAD_BUTTON_START
|
||||||
};
|
};
|
||||||
|
|
||||||
const u16 trigger_bitmasks[] =
|
const u16 trigger_bitmasks[] =
|
||||||
{
|
{
|
||||||
PAD_TRIGGER_L,
|
PAD_TRIGGER_L,
|
||||||
PAD_TRIGGER_R,
|
PAD_TRIGGER_R,
|
||||||
};
|
};
|
||||||
|
|
||||||
const u16 dpad_bitmasks[] =
|
const u16 dpad_bitmasks[] =
|
||||||
{
|
{
|
||||||
PAD_BUTTON_UP, PAD_BUTTON_DOWN, PAD_BUTTON_LEFT, PAD_BUTTON_RIGHT
|
PAD_BUTTON_UP, PAD_BUTTON_DOWN, PAD_BUTTON_LEFT, PAD_BUTTON_RIGHT
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* const named_buttons[] =
|
const char* const named_buttons[] =
|
||||||
{
|
{
|
||||||
"A",
|
"A",
|
||||||
"B",
|
"B",
|
||||||
"X",
|
"X",
|
||||||
"Y",
|
"Y",
|
||||||
"Z",
|
"Z",
|
||||||
"Start",
|
"Start",
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* const named_triggers[] =
|
const char* const named_triggers[] =
|
||||||
{
|
{
|
||||||
"L", "R", "L-Analog", "R-Analog"
|
"L", "R", "L-Analog", "R-Analog"
|
||||||
};
|
};
|
||||||
|
|
||||||
GCPad::GCPad( const unsigned int index ) : m_index(index)
|
GCPad::GCPad( const unsigned int index ) : m_index(index)
|
||||||
{
|
{
|
||||||
|
|
||||||
// buttons
|
// buttons
|
||||||
groups.push_back( m_buttons = new Buttons( "Buttons" ) );
|
groups.push_back( m_buttons = new Buttons( "Buttons" ) );
|
||||||
for ( unsigned int i=0; i < sizeof(named_buttons)/sizeof(*named_buttons); ++i )
|
for ( unsigned int i=0; i < sizeof(named_buttons)/sizeof(*named_buttons); ++i )
|
||||||
m_buttons->controls.push_back( new ControlGroup::Input( named_buttons[i] ) );
|
m_buttons->controls.push_back( new ControlGroup::Input( named_buttons[i] ) );
|
||||||
|
|
||||||
// sticks
|
// sticks
|
||||||
groups.push_back( m_main_stick = new AnalogStick( "Main Stick" ) );
|
groups.push_back( m_main_stick = new AnalogStick( "Main Stick" ) );
|
||||||
groups.push_back( m_c_stick = new AnalogStick( "C-Stick" ) );
|
groups.push_back( m_c_stick = new AnalogStick( "C-Stick" ) );
|
||||||
|
|
||||||
// triggers
|
// triggers
|
||||||
groups.push_back( m_triggers = new MixedTriggers( "Triggers" ) );
|
groups.push_back( m_triggers = new MixedTriggers( "Triggers" ) );
|
||||||
for ( unsigned int i=0; i < sizeof(named_triggers)/sizeof(*named_triggers); ++i )
|
for ( unsigned int i=0; i < sizeof(named_triggers)/sizeof(*named_triggers); ++i )
|
||||||
m_triggers->controls.push_back( new ControlGroup::Input( named_triggers[i] ) );
|
m_triggers->controls.push_back( new ControlGroup::Input( named_triggers[i] ) );
|
||||||
|
|
||||||
// dpad
|
// dpad
|
||||||
groups.push_back( m_dpad = new Buttons( "D-Pad" ) );
|
groups.push_back( m_dpad = new Buttons( "D-Pad" ) );
|
||||||
for ( unsigned int i=0; i < 4; ++i )
|
for ( unsigned int i=0; i < 4; ++i )
|
||||||
m_dpad->controls.push_back( new ControlGroup::Input( named_directions[i] ) );
|
m_dpad->controls.push_back( new ControlGroup::Input( named_directions[i] ) );
|
||||||
|
|
||||||
// rumble
|
// rumble
|
||||||
groups.push_back( m_rumble = new ControlGroup( "Rumble" ) );
|
groups.push_back( m_rumble = new ControlGroup( "Rumble" ) );
|
||||||
m_rumble->controls.push_back( new ControlGroup::Output( "Motor" ) );
|
m_rumble->controls.push_back( new ControlGroup::Output( "Motor" ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GCPad::GetName() const
|
std::string GCPad::GetName() const
|
||||||
{
|
{
|
||||||
return std::string("GCPad") + char('1'+m_index);
|
return std::string("GCPad") + char('1'+m_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GCPad::GetInput( SPADStatus* const pad )
|
void GCPad::GetInput( SPADStatus* const pad )
|
||||||
{
|
{
|
||||||
std::vector< ControlGroup::Control* >::iterator i,e;
|
std::vector< ControlGroup::Control* >::iterator i,e;
|
||||||
|
|
||||||
// buttons
|
// buttons
|
||||||
m_buttons->GetState( &pad->button, button_bitmasks );
|
m_buttons->GetState( &pad->button, button_bitmasks );
|
||||||
|
|
||||||
// TODO: set analog A/B to full or w/e
|
// TODO: set analog A/B to full or w/e
|
||||||
|
|
||||||
// dpad
|
// dpad
|
||||||
m_dpad->GetState( &pad->button, dpad_bitmasks );
|
m_dpad->GetState( &pad->button, dpad_bitmasks );
|
||||||
|
|
||||||
// sticks
|
// sticks
|
||||||
m_main_stick->GetState( &pad->stickX, &pad->stickY, 0x80, 127 );
|
m_main_stick->GetState( &pad->stickX, &pad->stickY, 0x80, 127 );
|
||||||
m_c_stick->GetState( &pad->substickX, &pad->substickY, 0x80, 127 );
|
m_c_stick->GetState( &pad->substickX, &pad->substickY, 0x80, 127 );
|
||||||
|
|
||||||
// triggers
|
// triggers
|
||||||
m_triggers->GetState( &pad->button, trigger_bitmasks, &pad->triggerLeft, 0xFF );
|
m_triggers->GetState( &pad->button, trigger_bitmasks, &pad->triggerLeft, 0xFF );
|
||||||
}
|
}
|
||||||
|
|
||||||
void GCPad::SetOutput( const bool on )
|
void GCPad::SetOutput( const bool on )
|
||||||
{
|
{
|
||||||
m_rumble->controls[0]->control_ref->State( on );
|
m_rumble->controls[0]->control_ref->State( on );
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,31 +1,31 @@
|
||||||
#ifndef _CONEMU_GCPAD_H_
|
#ifndef _CONEMU_GCPAD_H_
|
||||||
#define _CONEMU_GCPAD_H_
|
#define _CONEMU_GCPAD_H_
|
||||||
|
|
||||||
#include "../../ControllerEmu.h"
|
#include "../../ControllerEmu.h"
|
||||||
|
|
||||||
class GCPad : public ControllerEmu
|
class GCPad : public ControllerEmu
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
GCPad( const unsigned int index );
|
GCPad( const unsigned int index );
|
||||||
void GetInput( SPADStatus* const pad );
|
void GetInput( SPADStatus* const pad );
|
||||||
void SetOutput( const bool on );
|
void SetOutput( const bool on );
|
||||||
|
|
||||||
std::string GetName() const;
|
std::string GetName() const;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Buttons* m_buttons;
|
Buttons* m_buttons;
|
||||||
AnalogStick* m_main_stick;
|
AnalogStick* m_main_stick;
|
||||||
AnalogStick* m_c_stick;
|
AnalogStick* m_c_stick;
|
||||||
Buttons* m_dpad;
|
Buttons* m_dpad;
|
||||||
MixedTriggers* m_triggers;
|
MixedTriggers* m_triggers;
|
||||||
ControlGroup* m_rumble;
|
ControlGroup* m_rumble;
|
||||||
|
|
||||||
const unsigned int m_index;
|
const unsigned int m_index;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,257 +1,257 @@
|
||||||
|
|
||||||
#include "Wiimote.h"
|
#include "Wiimote.h"
|
||||||
|
|
||||||
// buttons
|
// buttons
|
||||||
|
|
||||||
#define WIIMOTE_PAD_LEFT 0x01
|
#define WIIMOTE_PAD_LEFT 0x01
|
||||||
#define WIIMOTE_PAD_RIGHT 0x02
|
#define WIIMOTE_PAD_RIGHT 0x02
|
||||||
#define WIIMOTE_PAD_DOWN 0x04
|
#define WIIMOTE_PAD_DOWN 0x04
|
||||||
#define WIIMOTE_PAD_UP 0x08
|
#define WIIMOTE_PAD_UP 0x08
|
||||||
#define WIIMOTE_PLUS 0x10
|
#define WIIMOTE_PLUS 0x10
|
||||||
|
|
||||||
#define WIIMOTE_TWO 0x0100
|
#define WIIMOTE_TWO 0x0100
|
||||||
#define WIIMOTE_ONE 0x0200
|
#define WIIMOTE_ONE 0x0200
|
||||||
#define WIIMOTE_B 0x0400
|
#define WIIMOTE_B 0x0400
|
||||||
#define WIIMOTE_A 0x0800
|
#define WIIMOTE_A 0x0800
|
||||||
#define WIIMOTE_MINUS 0x1000
|
#define WIIMOTE_MINUS 0x1000
|
||||||
#define WIIMOTE_HOME 0x8000
|
#define WIIMOTE_HOME 0x8000
|
||||||
|
|
||||||
// reports
|
// reports
|
||||||
|
|
||||||
#define REPORT_UNKNOWN 0x10
|
#define REPORT_UNKNOWN 0x10
|
||||||
#define REPORT_LEDS 0x11
|
#define REPORT_LEDS 0x11
|
||||||
#define REPORT_DATA_MODE 0x12
|
#define REPORT_DATA_MODE 0x12
|
||||||
#define REPORT_IR_ENABLE 0x13
|
#define REPORT_IR_ENABLE 0x13
|
||||||
#define REPORT_SPEAKER_ENABLE 0x14
|
#define REPORT_SPEAKER_ENABLE 0x14
|
||||||
#define REPORT_STATUS_REQUEST 0x15
|
#define REPORT_STATUS_REQUEST 0x15
|
||||||
#define REPORT_WRITE_MEMORY 0x16
|
#define REPORT_WRITE_MEMORY 0x16
|
||||||
#define REPORT_READ_MEMORY 0x17
|
#define REPORT_READ_MEMORY 0x17
|
||||||
#define REPORT_SPEAKER_DATA 0x18
|
#define REPORT_SPEAKER_DATA 0x18
|
||||||
#define REPORT_SPEAKER_MUTE 0x19
|
#define REPORT_SPEAKER_MUTE 0x19
|
||||||
#define REPORT_IR_ENABLE_2 0x1a
|
#define REPORT_IR_ENABLE_2 0x1a
|
||||||
#define REPORT_STATUS 0x20
|
#define REPORT_STATUS 0x20
|
||||||
#define REPORT_READ_MEMORY_DATA 0x21
|
#define REPORT_READ_MEMORY_DATA 0x21
|
||||||
#define REPORT_ACKNOWLEDGE_OUTPUT 0x22
|
#define REPORT_ACKNOWLEDGE_OUTPUT 0x22
|
||||||
//#define REPORT_DATA_REPORTS 0x30-0x3f
|
//#define REPORT_DATA_REPORTS 0x30-0x3f
|
||||||
|
|
||||||
// reporting modes
|
// reporting modes
|
||||||
|
|
||||||
#define REPORT_MODE_CORE 0x30
|
#define REPORT_MODE_CORE 0x30
|
||||||
#define REPORT_MODE_CORE_ACCEL 0x31
|
#define REPORT_MODE_CORE_ACCEL 0x31
|
||||||
#define REPORT_MODE_CORE_EXTEN8 0x32
|
#define REPORT_MODE_CORE_EXTEN8 0x32
|
||||||
#define REPORT_MODE_CORE_ACCEL_IR12 0x33
|
#define REPORT_MODE_CORE_ACCEL_IR12 0x33
|
||||||
#define REPORT_MODE_CORE_EXTEN19 0x34
|
#define REPORT_MODE_CORE_EXTEN19 0x34
|
||||||
#define REPORT_MODE_CORE_ACCEL_EXTEN16 0x35
|
#define REPORT_MODE_CORE_ACCEL_EXTEN16 0x35
|
||||||
#define REPORT_MODE_CORE_IR10_EXTEN9 0x36
|
#define REPORT_MODE_CORE_IR10_EXTEN9 0x36
|
||||||
#define REPORT_MODE_CORE_ACCEL_IR10_EXTEN6 0x37
|
#define REPORT_MODE_CORE_ACCEL_IR10_EXTEN6 0x37
|
||||||
#define REPORT_MODE_EXTEN21 0x3d
|
#define REPORT_MODE_EXTEN21 0x3d
|
||||||
#define REPORT_MODE_IL_CORE_ACCEL_IR36_1 0x3e
|
#define REPORT_MODE_IL_CORE_ACCEL_IR36_1 0x3e
|
||||||
#define REPORT_MODE_IL_CORE_ACCEL_IR36_2 0x3f
|
#define REPORT_MODE_IL_CORE_ACCEL_IR36_2 0x3f
|
||||||
|
|
||||||
// this is all temporary, but sticking with the padspecs ...for now
|
// this is all temporary, but sticking with the padspecs ...for now
|
||||||
const u16 button_bitmasks[] =
|
const u16 button_bitmasks[] =
|
||||||
{
|
{
|
||||||
WIIMOTE_A, WIIMOTE_B, WIIMOTE_ONE, WIIMOTE_TWO, WIIMOTE_MINUS, WIIMOTE_PLUS, WIIMOTE_HOME
|
WIIMOTE_A, WIIMOTE_B, WIIMOTE_ONE, WIIMOTE_TWO, WIIMOTE_MINUS, WIIMOTE_PLUS, WIIMOTE_HOME
|
||||||
};
|
};
|
||||||
|
|
||||||
const u16 dpad_bitmasks[] =
|
const u16 dpad_bitmasks[] =
|
||||||
{
|
{
|
||||||
WIIMOTE_PAD_UP, WIIMOTE_PAD_DOWN, WIIMOTE_PAD_LEFT, WIIMOTE_PAD_RIGHT
|
WIIMOTE_PAD_UP, WIIMOTE_PAD_DOWN, WIIMOTE_PAD_LEFT, WIIMOTE_PAD_RIGHT
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* const named_buttons[] =
|
const char* const named_buttons[] =
|
||||||
{
|
{
|
||||||
"A",
|
"A",
|
||||||
"B",
|
"B",
|
||||||
"One",
|
"One",
|
||||||
"Two",
|
"Two",
|
||||||
"Minus",
|
"Minus",
|
||||||
"Plus",
|
"Plus",
|
||||||
"Home",
|
"Home",
|
||||||
};
|
};
|
||||||
|
|
||||||
const char * const named_groups[] =
|
const char * const named_groups[] =
|
||||||
{
|
{
|
||||||
"Buttons", "D-Pad"
|
"Buttons", "D-Pad"
|
||||||
};
|
};
|
||||||
|
|
||||||
Wiimote::Wiimote( const unsigned int index ) : m_index(index), m_report_mode(REPORT_MODE_CORE)
|
Wiimote::Wiimote( const unsigned int index ) : m_index(index), m_report_mode(REPORT_MODE_CORE)
|
||||||
{
|
{
|
||||||
|
|
||||||
// buttons
|
// buttons
|
||||||
groups.push_back( m_buttons = new Buttons( named_groups[0] ) );
|
groups.push_back( m_buttons = new Buttons( named_groups[0] ) );
|
||||||
for ( unsigned int i=0; i < sizeof(named_buttons)/sizeof(*named_buttons); ++i )
|
for ( unsigned int i=0; i < sizeof(named_buttons)/sizeof(*named_buttons); ++i )
|
||||||
m_buttons->controls.push_back( new ControlGroup::Input( named_buttons[i] ) );
|
m_buttons->controls.push_back( new ControlGroup::Input( named_buttons[i] ) );
|
||||||
|
|
||||||
// dpad
|
// dpad
|
||||||
groups.push_back( m_dpad = new Buttons( named_groups[1] ) );
|
groups.push_back( m_dpad = new Buttons( named_groups[1] ) );
|
||||||
for ( unsigned int i=0; i < 4; ++i )
|
for ( unsigned int i=0; i < 4; ++i )
|
||||||
m_dpad->controls.push_back( new ControlGroup::Input( named_directions[i] ) );
|
m_dpad->controls.push_back( new ControlGroup::Input( named_directions[i] ) );
|
||||||
|
|
||||||
// rumble
|
// rumble
|
||||||
groups.push_back( m_rumble = new ControlGroup( "Rumble" ) );
|
groups.push_back( m_rumble = new ControlGroup( "Rumble" ) );
|
||||||
m_rumble->controls.push_back( new ControlGroup::Output( "Motor" ) );
|
m_rumble->controls.push_back( new ControlGroup::Output( "Motor" ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Wiimote::GetName() const
|
std::string Wiimote::GetName() const
|
||||||
{
|
{
|
||||||
return std::string("Wiimote") + char('1'+m_index);
|
return std::string("Wiimote") + char('1'+m_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Wiimote::Cycle()
|
void Wiimote::Cycle()
|
||||||
{
|
{
|
||||||
|
|
||||||
HIDReport rpt;
|
HIDReport rpt;
|
||||||
rpt << (u8)m_report_mode;
|
rpt << (u8)m_report_mode;
|
||||||
|
|
||||||
switch ( m_report_mode )
|
switch ( m_report_mode )
|
||||||
{
|
{
|
||||||
//(a1) 30 BB BB
|
//(a1) 30 BB BB
|
||||||
case REPORT_MODE_CORE :
|
case REPORT_MODE_CORE :
|
||||||
{
|
{
|
||||||
u16 buttons;
|
u16 buttons;
|
||||||
m_buttons->GetState( &buttons, button_bitmasks );
|
m_buttons->GetState( &buttons, button_bitmasks );
|
||||||
m_dpad->GetState( &buttons, dpad_bitmasks );
|
m_dpad->GetState( &buttons, dpad_bitmasks );
|
||||||
rpt << buttons;
|
rpt << buttons;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//(a1) 31 BB BB AA AA AA
|
//(a1) 31 BB BB AA AA AA
|
||||||
case REPORT_MODE_CORE_ACCEL :
|
case REPORT_MODE_CORE_ACCEL :
|
||||||
{
|
{
|
||||||
u16 buttons;
|
u16 buttons;
|
||||||
m_buttons->GetState( &buttons, button_bitmasks );
|
m_buttons->GetState( &buttons, button_bitmasks );
|
||||||
m_dpad->GetState( &buttons, dpad_bitmasks );
|
m_dpad->GetState( &buttons, dpad_bitmasks );
|
||||||
rpt << buttons << (u16)0 << (u8)0;
|
rpt << buttons << (u16)0 << (u8)0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//(a1) 32 BB BB EE EE EE EE EE EE EE EE
|
//(a1) 32 BB BB EE EE EE EE EE EE EE EE
|
||||||
case REPORT_MODE_CORE_EXTEN8 :
|
case REPORT_MODE_CORE_EXTEN8 :
|
||||||
{
|
{
|
||||||
u16 buttons;
|
u16 buttons;
|
||||||
m_buttons->GetState( &buttons, button_bitmasks );
|
m_buttons->GetState( &buttons, button_bitmasks );
|
||||||
m_dpad->GetState( &buttons, dpad_bitmasks );
|
m_dpad->GetState( &buttons, dpad_bitmasks );
|
||||||
rpt << buttons << (u64)0;
|
rpt << buttons << (u64)0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//(a1) 33 BB BB AA AA AA II II II II II II II II II II II II
|
//(a1) 33 BB BB AA AA AA II II II II II II II II II II II II
|
||||||
case REPORT_MODE_CORE_ACCEL_IR12 :
|
case REPORT_MODE_CORE_ACCEL_IR12 :
|
||||||
{
|
{
|
||||||
u16 buttons;
|
u16 buttons;
|
||||||
m_buttons->GetState( &buttons, button_bitmasks );
|
m_buttons->GetState( &buttons, button_bitmasks );
|
||||||
m_dpad->GetState( &buttons, dpad_bitmasks );
|
m_dpad->GetState( &buttons, dpad_bitmasks );
|
||||||
rpt << buttons << (u64)0 << (u32)0 << (u16)0 << (u8)0;
|
rpt << buttons << (u64)0 << (u32)0 << (u16)0 << (u8)0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//(a1) 34 BB BB EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE
|
//(a1) 34 BB BB EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE
|
||||||
case REPORT_MODE_CORE_EXTEN19 :
|
case REPORT_MODE_CORE_EXTEN19 :
|
||||||
{
|
{
|
||||||
u16 buttons;
|
u16 buttons;
|
||||||
m_buttons->GetState( &buttons, button_bitmasks );
|
m_buttons->GetState( &buttons, button_bitmasks );
|
||||||
m_dpad->GetState( &buttons, dpad_bitmasks );
|
m_dpad->GetState( &buttons, dpad_bitmasks );
|
||||||
rpt << buttons << (u64)0 << (u64)0 << (u16)0 << (u8)0;
|
rpt << buttons << (u64)0 << (u64)0 << (u16)0 << (u8)0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//(a1) 35 BB BB AA AA AA EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE
|
//(a1) 35 BB BB AA AA AA EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE
|
||||||
case REPORT_MODE_CORE_ACCEL_EXTEN16 :
|
case REPORT_MODE_CORE_ACCEL_EXTEN16 :
|
||||||
{
|
{
|
||||||
u16 buttons;
|
u16 buttons;
|
||||||
m_buttons->GetState( &buttons, button_bitmasks );
|
m_buttons->GetState( &buttons, button_bitmasks );
|
||||||
m_dpad->GetState( &buttons, dpad_bitmasks );
|
m_dpad->GetState( &buttons, dpad_bitmasks );
|
||||||
rpt << buttons << (u64)0 << (u64)0 << (u16)0 << (u8)0;
|
rpt << buttons << (u64)0 << (u64)0 << (u16)0 << (u8)0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//(a1) 36 BB BB II II II II II II II II II II EE EE EE EE EE EE EE EE EE
|
//(a1) 36 BB BB II II II II II II II II II II EE EE EE EE EE EE EE EE EE
|
||||||
case REPORT_MODE_CORE_IR10_EXTEN9 :
|
case REPORT_MODE_CORE_IR10_EXTEN9 :
|
||||||
{
|
{
|
||||||
u16 buttons;
|
u16 buttons;
|
||||||
m_buttons->GetState( &buttons, button_bitmasks );
|
m_buttons->GetState( &buttons, button_bitmasks );
|
||||||
m_dpad->GetState( &buttons, dpad_bitmasks );
|
m_dpad->GetState( &buttons, dpad_bitmasks );
|
||||||
rpt << buttons << (u64)0 << (u64)0 << (u16)0 << (u8)0;
|
rpt << buttons << (u64)0 << (u64)0 << (u16)0 << (u8)0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//(a1) 37 BB BB AA AA AA II II II II II II II II II II EE EE EE EE EE EE
|
//(a1) 37 BB BB AA AA AA II II II II II II II II II II EE EE EE EE EE EE
|
||||||
case REPORT_MODE_CORE_ACCEL_IR10_EXTEN6 :
|
case REPORT_MODE_CORE_ACCEL_IR10_EXTEN6 :
|
||||||
{
|
{
|
||||||
u16 buttons;
|
u16 buttons;
|
||||||
m_buttons->GetState( &buttons, button_bitmasks );
|
m_buttons->GetState( &buttons, button_bitmasks );
|
||||||
m_dpad->GetState( &buttons, dpad_bitmasks );
|
m_dpad->GetState( &buttons, dpad_bitmasks );
|
||||||
rpt << buttons << (u64)0 << (u64)0 << (u16)0 << (u8)0;
|
rpt << buttons << (u64)0 << (u64)0 << (u16)0 << (u8)0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//(a1) 3d EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE
|
//(a1) 3d EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE
|
||||||
case REPORT_MODE_EXTEN21 :
|
case REPORT_MODE_EXTEN21 :
|
||||||
{
|
{
|
||||||
u16 buttons;
|
u16 buttons;
|
||||||
m_buttons->GetState( &buttons, button_bitmasks );
|
m_buttons->GetState( &buttons, button_bitmasks );
|
||||||
m_dpad->GetState( &buttons, dpad_bitmasks );
|
m_dpad->GetState( &buttons, dpad_bitmasks );
|
||||||
rpt << buttons << (u64)0 << (u64)0 << (u16)0 << (u8)0;
|
rpt << buttons << (u64)0 << (u64)0 << (u16)0 << (u8)0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//(a1) 3e/3f BB BB AA II II II II II II II II II II II II II II II II II II
|
//(a1) 3e/3f BB BB AA II II II II II II II II II II II II II II II II II II
|
||||||
case REPORT_MODE_IL_CORE_ACCEL_IR36_1 :
|
case REPORT_MODE_IL_CORE_ACCEL_IR36_1 :
|
||||||
case REPORT_MODE_IL_CORE_ACCEL_IR36_2 :
|
case REPORT_MODE_IL_CORE_ACCEL_IR36_2 :
|
||||||
{
|
{
|
||||||
u16 buttons;
|
u16 buttons;
|
||||||
m_buttons->GetState( &buttons, button_bitmasks );
|
m_buttons->GetState( &buttons, button_bitmasks );
|
||||||
m_dpad->GetState( &buttons, dpad_bitmasks );
|
m_dpad->GetState( &buttons, dpad_bitmasks );
|
||||||
//rpt << buttons << (u64)0 << (u64)0 << (u64)0 << (u64)0 << (u32)0 << (u8)0;
|
//rpt << buttons << (u64)0 << (u64)0 << (u64)0 << (u64)0 << (u32)0 << (u8)0;
|
||||||
rpt << buttons << (u64)0 << (u64)0 << (u16)0 << (u8)0;
|
rpt << buttons << (u64)0 << (u64)0 << (u16)0 << (u8)0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default :
|
default :
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Wiimote& Wiimote::operator<<( HIDReport& rpt_in )
|
Wiimote& Wiimote::operator<<( HIDReport& rpt_in )
|
||||||
{
|
{
|
||||||
const u8 report_id = rpt_in.front(); rpt_in.pop();
|
const u8 report_id = rpt_in.front(); rpt_in.pop();
|
||||||
|
|
||||||
HIDReport rpt_out;
|
HIDReport rpt_out;
|
||||||
|
|
||||||
switch ( report_id )
|
switch ( report_id )
|
||||||
{
|
{
|
||||||
case REPORT_LEDS :
|
case REPORT_LEDS :
|
||||||
break;
|
break;
|
||||||
case REPORT_DATA_MODE :
|
case REPORT_DATA_MODE :
|
||||||
{
|
{
|
||||||
rpt_in.pop(); // continuous
|
rpt_in.pop(); // continuous
|
||||||
m_report_mode = rpt_in.front();
|
m_report_mode = rpt_in.front();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case REPORT_IR_ENABLE :
|
case REPORT_IR_ENABLE :
|
||||||
break;
|
break;
|
||||||
case REPORT_SPEAKER_ENABLE :
|
case REPORT_SPEAKER_ENABLE :
|
||||||
break;
|
break;
|
||||||
case REPORT_STATUS_REQUEST :
|
case REPORT_STATUS_REQUEST :
|
||||||
{
|
{
|
||||||
u16 buttons;
|
u16 buttons;
|
||||||
m_buttons->GetState( &buttons, button_bitmasks );
|
m_buttons->GetState( &buttons, button_bitmasks );
|
||||||
m_dpad->GetState( &buttons, dpad_bitmasks );
|
m_dpad->GetState( &buttons, dpad_bitmasks );
|
||||||
rpt_out << (u8)REPORT_STATUS << buttons << (u16)0 << (u8)0 << (u8)0xFF;
|
rpt_out << (u8)REPORT_STATUS << buttons << (u16)0 << (u8)0 << (u8)0xFF;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case REPORT_WRITE_MEMORY :
|
case REPORT_WRITE_MEMORY :
|
||||||
break;
|
break;
|
||||||
case REPORT_READ_MEMORY :
|
case REPORT_READ_MEMORY :
|
||||||
break;
|
break;
|
||||||
case REPORT_SPEAKER_DATA :
|
case REPORT_SPEAKER_DATA :
|
||||||
break;
|
break;
|
||||||
case REPORT_SPEAKER_MUTE :
|
case REPORT_SPEAKER_MUTE :
|
||||||
break;
|
break;
|
||||||
case REPORT_IR_ENABLE_2 :
|
case REPORT_IR_ENABLE_2 :
|
||||||
break;
|
break;
|
||||||
case REPORT_STATUS :
|
case REPORT_STATUS :
|
||||||
break;
|
break;
|
||||||
case REPORT_READ_MEMORY_DATA :
|
case REPORT_READ_MEMORY_DATA :
|
||||||
break;
|
break;
|
||||||
case REPORT_ACKNOWLEDGE_OUTPUT :
|
case REPORT_ACKNOWLEDGE_OUTPUT :
|
||||||
break;
|
break;
|
||||||
default :
|
default :
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,46 +1,46 @@
|
||||||
#ifndef _CONEMU_WIIMOTE_H_
|
#ifndef _CONEMU_WIIMOTE_H_
|
||||||
#define _CONEMU_WIIMOTE_H_
|
#define _CONEMU_WIIMOTE_H_
|
||||||
|
|
||||||
#include "../../ControllerEmu.h"
|
#include "../../ControllerEmu.h"
|
||||||
|
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
class HIDReport : public std::queue<u8>
|
class HIDReport : public std::queue<u8>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
template <typename T>
|
template <typename T>
|
||||||
HIDReport& operator<<( const T& t )
|
HIDReport& operator<<( const T& t )
|
||||||
{
|
{
|
||||||
const u8* const e = ((u8*)&t) + sizeof(t);
|
const u8* const e = ((u8*)&t) + sizeof(t);
|
||||||
const u8* i = (u8*)&t;
|
const u8* i = (u8*)&t;
|
||||||
for ( ;i<e; ++i )
|
for ( ;i<e; ++i )
|
||||||
push(*i);
|
push(*i);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Wiimote : public ControllerEmu
|
class Wiimote : public ControllerEmu
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Wiimote( const unsigned int index );
|
Wiimote( const unsigned int index );
|
||||||
void Cycle();
|
void Cycle();
|
||||||
Wiimote& operator<<( HIDReport& );
|
Wiimote& operator<<( HIDReport& );
|
||||||
|
|
||||||
std::string GetName() const;
|
std::string GetName() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Buttons* m_buttons;
|
Buttons* m_buttons;
|
||||||
Buttons* m_dpad;
|
Buttons* m_dpad;
|
||||||
ControlGroup* m_rumble;
|
ControlGroup* m_rumble;
|
||||||
// TODO: add forces
|
// TODO: add forces
|
||||||
// TODO: add ir
|
// TODO: add ir
|
||||||
|
|
||||||
const unsigned int m_index;
|
const unsigned int m_index;
|
||||||
unsigned int m_report_mode;
|
unsigned int m_report_mode;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,249 +1,249 @@
|
||||||
#ifndef _DEVICEINTERFACE_H_
|
#ifndef _DEVICEINTERFACE_H_
|
||||||
#define _DEVICEINTERFACE_H_
|
#define _DEVICEINTERFACE_H_
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
// enable disable sources
|
// enable disable sources
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define CIFACE_USE_XINPUT
|
#define CIFACE_USE_XINPUT
|
||||||
#define CIFACE_USE_DIRECTINPUT_JOYSTICK
|
#define CIFACE_USE_DIRECTINPUT_JOYSTICK
|
||||||
#define CIFACE_USE_DIRECTINPUT_KBM
|
#define CIFACE_USE_DIRECTINPUT_KBM
|
||||||
#define CIFACE_USE_DIRECTINPUT
|
#define CIFACE_USE_DIRECTINPUT
|
||||||
#endif
|
#endif
|
||||||
#if defined(HAVE_X11) && HAVE_X11
|
#if defined(HAVE_X11) && HAVE_X11
|
||||||
// Xlib is not tested at all currently, it is like 80% complete at least though
|
// Xlib is not tested at all currently, it is like 80% complete at least though
|
||||||
#define CIFACE_USE_XLIB
|
#define CIFACE_USE_XLIB
|
||||||
#endif
|
#endif
|
||||||
#ifndef CIFACE_USE_DIRECTINPUT_JOYSTICK
|
#ifndef CIFACE_USE_DIRECTINPUT_JOYSTICK
|
||||||
#define CIFACE_USE_SDL
|
#define CIFACE_USE_SDL
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// idk in case i wanted to change it to double or somethin, idk what's best
|
// idk in case i wanted to change it to double or somethin, idk what's best
|
||||||
typedef float ControlState;
|
typedef float ControlState;
|
||||||
|
|
||||||
//
|
//
|
||||||
// ControllerInterface
|
// ControllerInterface
|
||||||
//
|
//
|
||||||
// some crazy shit i made to control different device inputs and outputs
|
// some crazy shit i made to control different device inputs and outputs
|
||||||
// from lots of different sources, hopefully more easily
|
// from lots of different sources, hopefully more easily
|
||||||
//
|
//
|
||||||
class ControllerInterface
|
class ControllerInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//
|
//
|
||||||
// Device
|
// Device
|
||||||
//
|
//
|
||||||
// Pretty obviously, a device class
|
// Pretty obviously, a device class
|
||||||
//
|
//
|
||||||
class Device
|
class Device
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//
|
//
|
||||||
// Control
|
// Control
|
||||||
//
|
//
|
||||||
// control includes inputs and outputs
|
// control includes inputs and outputs
|
||||||
//
|
//
|
||||||
class Control // input or output
|
class Control // input or output
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual std::string GetName() const = 0;
|
virtual std::string GetName() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
// Input
|
// Input
|
||||||
//
|
//
|
||||||
// an input on a device
|
// an input on a device
|
||||||
//
|
//
|
||||||
class Input : public Control
|
class Input : public Control
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~Input() {}
|
virtual ~Input() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
// Output
|
// Output
|
||||||
//
|
//
|
||||||
// guess wut it is, yup and output
|
// guess wut it is, yup and output
|
||||||
//
|
//
|
||||||
class Output : public Control
|
class Output : public Control
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~Output() {}
|
virtual ~Output() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual ~Device();
|
virtual ~Device();
|
||||||
|
|
||||||
virtual std::string GetName() const = 0;
|
virtual std::string GetName() const = 0;
|
||||||
virtual int GetId() const = 0;
|
virtual int GetId() const = 0;
|
||||||
virtual std::string GetSource() const = 0;
|
virtual std::string GetSource() const = 0;
|
||||||
|
|
||||||
virtual ControlState GetInputState( const Input* const input ) = 0;
|
virtual ControlState GetInputState( const Input* const input ) = 0;
|
||||||
virtual void SetOutputState( const Output* const output, const ControlState state ) = 0;
|
virtual void SetOutputState( const Output* const output, const ControlState state ) = 0;
|
||||||
|
|
||||||
virtual bool UpdateInput() = 0;
|
virtual bool UpdateInput() = 0;
|
||||||
virtual bool UpdateOutput() = 0;
|
virtual bool UpdateOutput() = 0;
|
||||||
|
|
||||||
virtual void ClearInputState();
|
virtual void ClearInputState();
|
||||||
|
|
||||||
const std::vector< Input* >& Inputs();
|
const std::vector< Input* >& Inputs();
|
||||||
const std::vector< Output* >& Outputs();
|
const std::vector< Output* >& Outputs();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::vector<Input*> inputs;
|
std::vector<Input*> inputs;
|
||||||
std::vector<Output*> outputs;
|
std::vector<Output*> outputs;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
// DeviceQualifier
|
// DeviceQualifier
|
||||||
//
|
//
|
||||||
// device qualifier used to match devices
|
// device qualifier used to match devices
|
||||||
// currently has ( source, id, name ) properties which match a device
|
// currently has ( source, id, name ) properties which match a device
|
||||||
//
|
//
|
||||||
class DeviceQualifier
|
class DeviceQualifier
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DeviceQualifier() : id(-1){}
|
DeviceQualifier() : id(-1){}
|
||||||
DeviceQualifier( const std::string& _source, const int _id, const std::string& _name )
|
DeviceQualifier( const std::string& _source, const int _id, const std::string& _name )
|
||||||
: source(_source), id(_id), name(_name) {}
|
: source(_source), id(_id), name(_name) {}
|
||||||
bool operator==(const Device* const dev) const;
|
bool operator==(const Device* const dev) const;
|
||||||
void FromDevice(const Device* const dev);
|
void FromDevice(const Device* const dev);
|
||||||
void FromString(const std::string& str);
|
void FromString(const std::string& str);
|
||||||
std::string ToString() const;
|
std::string ToString() const;
|
||||||
|
|
||||||
std::string source;
|
std::string source;
|
||||||
int id;
|
int id;
|
||||||
std::string name;
|
std::string name;
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
// ControlQualifier
|
// ControlQualifier
|
||||||
//
|
//
|
||||||
// control qualifier includes input and output qualifiers
|
// control qualifier includes input and output qualifiers
|
||||||
// used to match controls on devices, only has name property
|
// used to match controls on devices, only has name property
|
||||||
// |input1|input2| form as well, || matches anything, might change this to * or something
|
// |input1|input2| form as well, || matches anything, might change this to * or something
|
||||||
//
|
//
|
||||||
class ControlQualifier
|
class ControlQualifier
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ControlQualifier() {};
|
ControlQualifier() {};
|
||||||
ControlQualifier( const std::string& _name ) : name(_name) {}
|
ControlQualifier( const std::string& _name ) : name(_name) {}
|
||||||
virtual bool operator==(const Device::Control* const in) const;
|
virtual bool operator==(const Device::Control* const in) const;
|
||||||
void FromControl(const Device::Control* const in);
|
void FromControl(const Device::Control* const in);
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
// InputQualifier
|
// InputQualifier
|
||||||
//
|
//
|
||||||
// ControlQualifier for inputs
|
// ControlQualifier for inputs
|
||||||
//
|
//
|
||||||
class InputQualifier : public ControlQualifier
|
class InputQualifier : public ControlQualifier
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
InputQualifier() {};
|
InputQualifier() {};
|
||||||
InputQualifier( const std::string& _name ) : ControlQualifier(_name) {}
|
InputQualifier( const std::string& _name ) : ControlQualifier(_name) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
// OutputQualifier
|
// OutputQualifier
|
||||||
//
|
//
|
||||||
// ControlQualifier for outputs
|
// ControlQualifier for outputs
|
||||||
//
|
//
|
||||||
class OutputQualifier : public ControlQualifier
|
class OutputQualifier : public ControlQualifier
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OutputQualifier() {};
|
OutputQualifier() {};
|
||||||
OutputQualifier( const std::string& _name ) : ControlQualifier(_name) {}
|
OutputQualifier( const std::string& _name ) : ControlQualifier(_name) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
// ControlReference
|
// ControlReference
|
||||||
//
|
//
|
||||||
// these are what you create to actually use the inputs, InputReference or OutputReference
|
// these are what you create to actually use the inputs, InputReference or OutputReference
|
||||||
// they have a vector < struct { device , vector < controls > } >
|
// they have a vector < struct { device , vector < controls > } >
|
||||||
//
|
//
|
||||||
// after being binded to devices and controls with ControllerInterface::UpdateReference,
|
// after being binded to devices and controls with ControllerInterface::UpdateReference,
|
||||||
// each one can binded to a devices, and 0+ controls the device
|
// each one can binded to a devices, and 0+ controls the device
|
||||||
// ControlReference can update its own controls when you change its control qualifier
|
// ControlReference can update its own controls when you change its control qualifier
|
||||||
// using ControlReference::UpdateControls but when you change its device qualifer
|
// using ControlReference::UpdateControls but when you change its device qualifer
|
||||||
// you must use ControllerInterface::UpdateReference
|
// you must use ControllerInterface::UpdateReference
|
||||||
//
|
//
|
||||||
class ControlReference
|
class ControlReference
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ControlReference( const bool _is_input ) : range(1), is_input(_is_input), device(NULL) {}
|
ControlReference( const bool _is_input ) : range(1), is_input(_is_input), device(NULL) {}
|
||||||
|
|
||||||
virtual ControlState State( const ControlState state = 0 ) = 0;
|
virtual ControlState State( const ControlState state = 0 ) = 0;
|
||||||
virtual bool Detect( const unsigned int ms, const unsigned int count = 1 ) = 0;
|
virtual bool Detect( const unsigned int ms, const unsigned int count = 1 ) = 0;
|
||||||
virtual void UpdateControls() = 0;
|
virtual void UpdateControls() = 0;
|
||||||
|
|
||||||
ControlState range;
|
ControlState range;
|
||||||
|
|
||||||
DeviceQualifier device_qualifier;
|
DeviceQualifier device_qualifier;
|
||||||
ControlQualifier control_qualifier;
|
ControlQualifier control_qualifier;
|
||||||
|
|
||||||
const bool is_input;
|
const bool is_input;
|
||||||
Device* device;
|
Device* device;
|
||||||
|
|
||||||
std::vector<Device::Control*> controls;
|
std::vector<Device::Control*> controls;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
// InputReference
|
// InputReference
|
||||||
//
|
//
|
||||||
// control reference for inputs
|
// control reference for inputs
|
||||||
//
|
//
|
||||||
class InputReference : public ControlReference
|
class InputReference : public ControlReference
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
InputReference() : ControlReference( true ) {}
|
InputReference() : ControlReference( true ) {}
|
||||||
ControlState State( const ControlState state );
|
ControlState State( const ControlState state );
|
||||||
bool Detect( const unsigned int ms, const unsigned int count );
|
bool Detect( const unsigned int ms, const unsigned int count );
|
||||||
void UpdateControls();
|
void UpdateControls();
|
||||||
|
|
||||||
unsigned int mode;
|
unsigned int mode;
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
// OutputReference
|
// OutputReference
|
||||||
//
|
//
|
||||||
// control reference for outputs
|
// control reference for outputs
|
||||||
//
|
//
|
||||||
class OutputReference : public ControlReference
|
class OutputReference : public ControlReference
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OutputReference() : ControlReference( false ) {}
|
OutputReference() : ControlReference( false ) {}
|
||||||
ControlState State( const ControlState state );
|
ControlState State( const ControlState state );
|
||||||
bool Detect( const unsigned int ms, const unsigned int count );
|
bool Detect( const unsigned int ms, const unsigned int count );
|
||||||
void UpdateControls();
|
void UpdateControls();
|
||||||
};
|
};
|
||||||
|
|
||||||
ControllerInterface() : m_is_init(false) {}
|
ControllerInterface() : m_is_init(false) {}
|
||||||
|
|
||||||
void SetHwnd( void* const hwnd );
|
void SetHwnd( void* const hwnd );
|
||||||
void Init();
|
void Init();
|
||||||
void DeInit();
|
void DeInit();
|
||||||
bool IsInit();
|
bool IsInit();
|
||||||
|
|
||||||
void UpdateReference( ControlReference* control );
|
void UpdateReference( ControlReference* control );
|
||||||
bool UpdateInput();
|
bool UpdateInput();
|
||||||
bool UpdateOutput();
|
bool UpdateOutput();
|
||||||
|
|
||||||
const std::vector<Device*>& Devices();
|
const std::vector<Device*>& Devices();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_is_init;
|
bool m_is_init;
|
||||||
std::vector<Device*> m_devices;
|
std::vector<Device*> m_devices;
|
||||||
void* m_hwnd;
|
void* m_hwnd;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,35 +1,35 @@
|
||||||
#include "../ControllerInterface.h"
|
#include "../ControllerInterface.h"
|
||||||
|
|
||||||
#ifdef CIFACE_USE_DIRECTINPUT
|
#ifdef CIFACE_USE_DIRECTINPUT
|
||||||
|
|
||||||
#include "DirectInput.h"
|
#include "DirectInput.h"
|
||||||
|
|
||||||
#pragma comment(lib, "Dinput8.lib")
|
#pragma comment(lib, "Dinput8.lib")
|
||||||
#pragma comment(lib, "dxguid.lib")
|
#pragma comment(lib, "dxguid.lib")
|
||||||
|
|
||||||
namespace ciface
|
namespace ciface
|
||||||
{
|
{
|
||||||
namespace DirectInput
|
namespace DirectInput
|
||||||
{
|
{
|
||||||
|
|
||||||
void Init( std::vector<ControllerInterface::Device*>& devices/*, HWND hwnd*/ )
|
void Init( std::vector<ControllerInterface::Device*>& devices/*, HWND hwnd*/ )
|
||||||
{
|
{
|
||||||
IDirectInput8* idi8;
|
IDirectInput8* idi8;
|
||||||
if ( DI_OK != DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (LPVOID*)&idi8, NULL ) )
|
if ( DI_OK != DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (LPVOID*)&idi8, NULL ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#ifdef CIFACE_USE_DIRECTINPUT_KBM
|
#ifdef CIFACE_USE_DIRECTINPUT_KBM
|
||||||
InitKeyboardMouse( idi8, devices );
|
InitKeyboardMouse( idi8, devices );
|
||||||
#endif
|
#endif
|
||||||
#ifdef CIFACE_USE_DIRECTINPUT_JOYSTICK
|
#ifdef CIFACE_USE_DIRECTINPUT_JOYSTICK
|
||||||
InitJoystick( idi8, devices/*, hwnd*/ );
|
InitJoystick( idi8, devices/*, hwnd*/ );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
idi8->Release();
|
idi8->Release();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,29 +1,29 @@
|
||||||
#ifndef _CIFACE_DIRECTINPUT_H_
|
#ifndef _CIFACE_DIRECTINPUT_H_
|
||||||
#define _CIFACE_DIRECTINPUT_H_
|
#define _CIFACE_DIRECTINPUT_H_
|
||||||
|
|
||||||
#include "../ControllerInterface.h"
|
#include "../ControllerInterface.h"
|
||||||
|
|
||||||
#define DIRECTINPUT_VERSION 0x0800
|
#define DIRECTINPUT_VERSION 0x0800
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#define NOMINMAX
|
#define NOMINMAX
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <dinput.h>
|
#include <dinput.h>
|
||||||
|
|
||||||
#ifdef CIFACE_USE_DIRECTINPUT_JOYSTICK
|
#ifdef CIFACE_USE_DIRECTINPUT_JOYSTICK
|
||||||
#include "DirectInputJoystick.h"
|
#include "DirectInputJoystick.h"
|
||||||
#endif
|
#endif
|
||||||
#ifdef CIFACE_USE_DIRECTINPUT_KBM
|
#ifdef CIFACE_USE_DIRECTINPUT_KBM
|
||||||
#include "DirectInputKeyboardMouse.h"
|
#include "DirectInputKeyboardMouse.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace ciface
|
namespace ciface
|
||||||
{
|
{
|
||||||
namespace DirectInput
|
namespace DirectInput
|
||||||
{
|
{
|
||||||
|
|
||||||
void Init( std::vector<ControllerInterface::Device*>& devices/*, HWND hwnd*/ );
|
void Init( std::vector<ControllerInterface::Device*>& devices/*, HWND hwnd*/ );
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,137 +1,137 @@
|
||||||
#ifndef _CIFACE_DIRECTINPUT_JOYSTICK_H_
|
#ifndef _CIFACE_DIRECTINPUT_JOYSTICK_H_
|
||||||
#define _CIFACE_DIRECTINPUT_JOYSTICK_H_
|
#define _CIFACE_DIRECTINPUT_JOYSTICK_H_
|
||||||
|
|
||||||
#include "../ControllerInterface.h"
|
#include "../ControllerInterface.h"
|
||||||
|
|
||||||
#define DIRECTINPUT_VERSION 0x0800
|
#define DIRECTINPUT_VERSION 0x0800
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#define NOMINMAX
|
#define NOMINMAX
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <dinput.h>
|
#include <dinput.h>
|
||||||
|
|
||||||
#ifdef CIFACE_USE_XINPUT
|
#ifdef CIFACE_USE_XINPUT
|
||||||
// this takes so long, idk if it should be enabled :(
|
// this takes so long, idk if it should be enabled :(
|
||||||
#define NO_DUPLICATE_DINPUT_XINPUT
|
#define NO_DUPLICATE_DINPUT_XINPUT
|
||||||
#include <wbemidl.h>
|
#include <wbemidl.h>
|
||||||
#include <oleauto.h>
|
#include <oleauto.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace ciface
|
namespace ciface
|
||||||
{
|
{
|
||||||
namespace DirectInput
|
namespace DirectInput
|
||||||
{
|
{
|
||||||
|
|
||||||
void InitJoystick( IDirectInput8* const idi8, std::vector<ControllerInterface::Device*>& devices/*, HWND hwnd*/ );
|
void InitJoystick( IDirectInput8* const idi8, std::vector<ControllerInterface::Device*>& devices/*, HWND hwnd*/ );
|
||||||
|
|
||||||
class Joystick : public ControllerInterface::Device
|
class Joystick : public ControllerInterface::Device
|
||||||
{
|
{
|
||||||
friend class ControllerInterface;
|
friend class ControllerInterface;
|
||||||
friend class ControllerInterface::ControlReference;
|
friend class ControllerInterface::ControlReference;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
struct EffectState
|
struct EffectState
|
||||||
{
|
{
|
||||||
EffectState( LPDIRECTINPUTEFFECT eff ) : changed(0), iface(eff) {}
|
EffectState( LPDIRECTINPUTEFFECT eff ) : changed(0), iface(eff) {}
|
||||||
LPDIRECTINPUTEFFECT iface;
|
LPDIRECTINPUTEFFECT iface;
|
||||||
ControlState magnitude;
|
ControlState magnitude;
|
||||||
bool changed;
|
bool changed;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Input : public ControllerInterface::Device::Input
|
class Input : public ControllerInterface::Device::Input
|
||||||
{
|
{
|
||||||
friend class Joystick;
|
friend class Joystick;
|
||||||
protected:
|
protected:
|
||||||
virtual ControlState GetState( const DIJOYSTATE* const joystate ) = 0;
|
virtual ControlState GetState( const DIJOYSTATE* const joystate ) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
// can probably eliminate this base class
|
// can probably eliminate this base class
|
||||||
class Output : public ControllerInterface::Device::Output
|
class Output : public ControllerInterface::Device::Output
|
||||||
{
|
{
|
||||||
friend class Joystick;
|
friend class Joystick;
|
||||||
protected:
|
protected:
|
||||||
virtual void SetState( const ControlState state, EffectState* const joystate ) = 0;
|
virtual void SetState( const ControlState state, EffectState* const joystate ) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Button : public Input
|
class Button : public Input
|
||||||
{
|
{
|
||||||
friend class Joystick;
|
friend class Joystick;
|
||||||
public:
|
public:
|
||||||
std::string GetName() const;
|
std::string GetName() const;
|
||||||
protected:
|
protected:
|
||||||
Button( const unsigned int index ) : m_index(index) {}
|
Button( const unsigned int index ) : m_index(index) {}
|
||||||
ControlState GetState( const DIJOYSTATE* const joystate );
|
ControlState GetState( const DIJOYSTATE* const joystate );
|
||||||
private:
|
private:
|
||||||
const unsigned int m_index;
|
const unsigned int m_index;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Axis : public Input
|
class Axis : public Input
|
||||||
{
|
{
|
||||||
friend class Joystick;
|
friend class Joystick;
|
||||||
public:
|
public:
|
||||||
std::string GetName() const;
|
std::string GetName() const;
|
||||||
protected:
|
protected:
|
||||||
Axis( const unsigned int index, const LONG base, const LONG range ) : m_index(index), m_base(base), m_range(range) {}
|
Axis( const unsigned int index, const LONG base, const LONG range ) : m_index(index), m_base(base), m_range(range) {}
|
||||||
ControlState GetState( const DIJOYSTATE* const joystate );
|
ControlState GetState( const DIJOYSTATE* const joystate );
|
||||||
private:
|
private:
|
||||||
const unsigned int m_index;
|
const unsigned int m_index;
|
||||||
const LONG m_base;
|
const LONG m_base;
|
||||||
const LONG m_range;
|
const LONG m_range;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Hat : public Input
|
class Hat : public Input
|
||||||
{
|
{
|
||||||
friend class Joystick;
|
friend class Joystick;
|
||||||
public:
|
public:
|
||||||
std::string GetName() const;
|
std::string GetName() const;
|
||||||
protected:
|
protected:
|
||||||
Hat( const unsigned int index, const unsigned int direction ) : m_index(index), m_direction(direction) {}
|
Hat( const unsigned int index, const unsigned int direction ) : m_index(index), m_direction(direction) {}
|
||||||
ControlState GetState( const DIJOYSTATE* const joystate );
|
ControlState GetState( const DIJOYSTATE* const joystate );
|
||||||
private:
|
private:
|
||||||
const unsigned int m_index;
|
const unsigned int m_index;
|
||||||
const unsigned int m_direction;
|
const unsigned int m_direction;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Force : public Output
|
class Force : public Output
|
||||||
{
|
{
|
||||||
friend class Joystick;
|
friend class Joystick;
|
||||||
public:
|
public:
|
||||||
std::string GetName() const;
|
std::string GetName() const;
|
||||||
protected:
|
protected:
|
||||||
Force( const unsigned int index ) : m_index(index) {}
|
Force( const unsigned int index ) : m_index(index) {}
|
||||||
void SetState( const ControlState state, EffectState* const joystate );
|
void SetState( const ControlState state, EffectState* const joystate );
|
||||||
private:
|
private:
|
||||||
const unsigned int m_index;
|
const unsigned int m_index;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool UpdateInput();
|
bool UpdateInput();
|
||||||
bool UpdateOutput();
|
bool UpdateOutput();
|
||||||
|
|
||||||
ControlState GetInputState( const ControllerInterface::Device::Input* const input );
|
ControlState GetInputState( const ControllerInterface::Device::Input* const input );
|
||||||
void SetOutputState( const ControllerInterface::Device::Output* const input, const ControlState state );
|
void SetOutputState( const ControllerInterface::Device::Output* const input, const ControlState state );
|
||||||
|
|
||||||
void ClearInputState();
|
void ClearInputState();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Joystick( /*const LPCDIDEVICEINSTANCE lpddi, */const LPDIRECTINPUTDEVICE8 device, const unsigned int index );
|
Joystick( /*const LPCDIDEVICEINSTANCE lpddi, */const LPDIRECTINPUTDEVICE8 device, const unsigned int index );
|
||||||
~Joystick();
|
~Joystick();
|
||||||
|
|
||||||
std::string GetName() const;
|
std::string GetName() const;
|
||||||
int GetId() const;
|
int GetId() const;
|
||||||
std::string GetSource() const;
|
std::string GetSource() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const LPDIRECTINPUTDEVICE8 m_device;
|
const LPDIRECTINPUTDEVICE8 m_device;
|
||||||
const unsigned int m_index;
|
const unsigned int m_index;
|
||||||
//const std::string m_name;
|
//const std::string m_name;
|
||||||
|
|
||||||
DIJOYSTATE m_state_in;
|
DIJOYSTATE m_state_in;
|
||||||
std::vector<EffectState> m_state_out;
|
std::vector<EffectState> m_state_out;
|
||||||
|
|
||||||
bool m_must_poll;
|
bool m_must_poll;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,269 +1,269 @@
|
||||||
#include "../ControllerInterface.h"
|
#include "../ControllerInterface.h"
|
||||||
|
|
||||||
#ifdef CIFACE_USE_DIRECTINPUT_KBM
|
#ifdef CIFACE_USE_DIRECTINPUT_KBM
|
||||||
|
|
||||||
#include "DirectInputKeyboardMouse.h"
|
#include "DirectInputKeyboardMouse.h"
|
||||||
|
|
||||||
// TODO: maybe add a ClearInputState function to this device
|
// TODO: maybe add a ClearInputState function to this device
|
||||||
|
|
||||||
// (lower would be more sensitive) user can lower sensitivity by setting range
|
// (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
|
// 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
|
// and user can lower it much farther than they would want to with the range
|
||||||
#define MOUSE_AXIS_SENSITIVITY 8
|
#define MOUSE_AXIS_SENSITIVITY 8
|
||||||
|
|
||||||
// if input hasn't been received for this many ms, mouse input will be skipped
|
// if input hasn't been received for this many ms, mouse input will be skipped
|
||||||
// otherwise it is just some crazy value
|
// otherwise it is just some crazy value
|
||||||
#define DROP_INPUT_TIME 250
|
#define DROP_INPUT_TIME 250
|
||||||
|
|
||||||
namespace ciface
|
namespace ciface
|
||||||
{
|
{
|
||||||
namespace DirectInput
|
namespace DirectInput
|
||||||
{
|
{
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
const BYTE code;
|
const BYTE code;
|
||||||
const char* const name;
|
const char* const name;
|
||||||
} named_keys[] =
|
} named_keys[] =
|
||||||
{
|
{
|
||||||
#include "NamedKeys.h"
|
#include "NamedKeys.h"
|
||||||
};
|
};
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
const BYTE code;
|
const BYTE code;
|
||||||
const char* const name;
|
const char* const name;
|
||||||
} named_lights[] =
|
} named_lights[] =
|
||||||
{
|
{
|
||||||
{ VK_NUMLOCK, "NUM LOCK" },
|
{ VK_NUMLOCK, "NUM LOCK" },
|
||||||
{ VK_CAPITAL, "CAPS LOCK" },
|
{ VK_CAPITAL, "CAPS LOCK" },
|
||||||
{ VK_SCROLL, "SCROLL LOCK" }
|
{ VK_SCROLL, "SCROLL LOCK" }
|
||||||
};
|
};
|
||||||
|
|
||||||
void InitKeyboardMouse( IDirectInput8* const idi8, std::vector<ControllerInterface::Device*>& devices )
|
void InitKeyboardMouse( IDirectInput8* const idi8, std::vector<ControllerInterface::Device*>& devices )
|
||||||
{
|
{
|
||||||
// mouse and keyboard are a combined device, to allow shift+click and stuff
|
// mouse and keyboard are a combined device, to allow shift+click and stuff
|
||||||
// if thats dumb, i will make a VirtualDevice class that just uses ranges of inputs/outputs from other devices
|
// if thats dumb, i will make a VirtualDevice class that just uses ranges of inputs/outputs from other devices
|
||||||
// so there can be a separated Keyboard and mouse, as well as combined KeyboardMouse
|
// so there can be a separated Keyboard and mouse, as well as combined KeyboardMouse
|
||||||
|
|
||||||
// TODO: this has potential to not release devices if set datafmt or cooplevel fails
|
// TODO: this has potential to not release devices if set datafmt or cooplevel fails
|
||||||
|
|
||||||
LPDIRECTINPUTDEVICE8 kb_device;
|
LPDIRECTINPUTDEVICE8 kb_device;
|
||||||
LPDIRECTINPUTDEVICE8 mo_device;
|
LPDIRECTINPUTDEVICE8 mo_device;
|
||||||
|
|
||||||
if ( DI_OK == idi8->CreateDevice( GUID_SysKeyboard, &kb_device, NULL ) )
|
if ( DI_OK == idi8->CreateDevice( GUID_SysKeyboard, &kb_device, NULL ) )
|
||||||
if ( DI_OK == kb_device->SetDataFormat( &c_dfDIKeyboard ) )
|
if ( DI_OK == kb_device->SetDataFormat( &c_dfDIKeyboard ) )
|
||||||
if ( DI_OK == kb_device->SetCooperativeLevel( NULL, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE) )
|
if ( DI_OK == kb_device->SetCooperativeLevel( NULL, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE) )
|
||||||
if ( DI_OK == kb_device->Acquire() )
|
if ( DI_OK == kb_device->Acquire() )
|
||||||
{
|
{
|
||||||
|
|
||||||
if ( DI_OK == idi8->CreateDevice( GUID_SysMouse, &mo_device, NULL ) )
|
if ( DI_OK == idi8->CreateDevice( GUID_SysMouse, &mo_device, NULL ) )
|
||||||
if ( DI_OK == mo_device->SetDataFormat( &c_dfDIMouse2 ) )
|
if ( DI_OK == mo_device->SetDataFormat( &c_dfDIMouse2 ) )
|
||||||
if ( DI_OK == mo_device->SetCooperativeLevel( NULL, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE) )
|
if ( DI_OK == mo_device->SetCooperativeLevel( NULL, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE) )
|
||||||
if ( DI_OK == mo_device->Acquire() )
|
if ( DI_OK == mo_device->Acquire() )
|
||||||
{
|
{
|
||||||
devices.push_back( new KeyboardMouse( kb_device, mo_device ) );
|
devices.push_back( new KeyboardMouse( kb_device, mo_device ) );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
goto release_mouse;
|
goto release_mouse;
|
||||||
|
|
||||||
goto unacquire_kb;
|
goto unacquire_kb;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
goto release_kb;
|
goto release_kb;
|
||||||
|
|
||||||
release_mouse:
|
release_mouse:
|
||||||
mo_device->Release();
|
mo_device->Release();
|
||||||
unacquire_kb:
|
unacquire_kb:
|
||||||
kb_device->Unacquire();
|
kb_device->Unacquire();
|
||||||
release_kb:
|
release_kb:
|
||||||
kb_device->Release();
|
kb_device->Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyboardMouse::~KeyboardMouse()
|
KeyboardMouse::~KeyboardMouse()
|
||||||
{
|
{
|
||||||
// kb
|
// kb
|
||||||
m_kb_device->Unacquire();
|
m_kb_device->Unacquire();
|
||||||
m_kb_device->Release();
|
m_kb_device->Release();
|
||||||
// mouse
|
// mouse
|
||||||
m_mo_device->Unacquire();
|
m_mo_device->Unacquire();
|
||||||
m_mo_device->Release();
|
m_mo_device->Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyboardMouse::KeyboardMouse( const LPDIRECTINPUTDEVICE8 kb_device, const LPDIRECTINPUTDEVICE8 mo_device )
|
KeyboardMouse::KeyboardMouse( const LPDIRECTINPUTDEVICE8 kb_device, const LPDIRECTINPUTDEVICE8 mo_device )
|
||||||
: m_kb_device(kb_device)
|
: m_kb_device(kb_device)
|
||||||
, m_mo_device(mo_device)
|
, m_mo_device(mo_device)
|
||||||
{
|
{
|
||||||
m_last_update = wxGetLocalTimeMillis();
|
m_last_update = wxGetLocalTimeMillis();
|
||||||
|
|
||||||
ZeroMemory( &m_state_in, sizeof(m_state_in) );
|
ZeroMemory( &m_state_in, sizeof(m_state_in) );
|
||||||
ZeroMemory( m_state_out, sizeof(m_state_out) );
|
ZeroMemory( m_state_out, sizeof(m_state_out) );
|
||||||
ZeroMemory( &m_current_state_out, sizeof(m_current_state_out) );
|
ZeroMemory( &m_current_state_out, sizeof(m_current_state_out) );
|
||||||
|
|
||||||
// KEYBOARD
|
// KEYBOARD
|
||||||
// add keys
|
// add keys
|
||||||
for ( unsigned int i = 0; i < sizeof(named_keys)/sizeof(*named_keys); ++i )
|
for ( unsigned int i = 0; i < sizeof(named_keys)/sizeof(*named_keys); ++i )
|
||||||
inputs.push_back( new Key( i ) );
|
inputs.push_back( new Key( i ) );
|
||||||
// add lights
|
// add lights
|
||||||
for ( unsigned int i = 0; i < sizeof(named_lights)/sizeof(*named_lights); ++i )
|
for ( unsigned int i = 0; i < sizeof(named_lights)/sizeof(*named_lights); ++i )
|
||||||
outputs.push_back( new Light( i ) );
|
outputs.push_back( new Light( i ) );
|
||||||
|
|
||||||
// MOUSE
|
// MOUSE
|
||||||
// get caps
|
// get caps
|
||||||
DIDEVCAPS mouse_caps;
|
DIDEVCAPS mouse_caps;
|
||||||
ZeroMemory( &mouse_caps, sizeof(mouse_caps) );
|
ZeroMemory( &mouse_caps, sizeof(mouse_caps) );
|
||||||
mouse_caps.dwSize = sizeof(mouse_caps);
|
mouse_caps.dwSize = sizeof(mouse_caps);
|
||||||
m_mo_device->GetCapabilities(&mouse_caps);
|
m_mo_device->GetCapabilities(&mouse_caps);
|
||||||
// mouse buttons
|
// mouse buttons
|
||||||
for ( unsigned int i = 0; i < mouse_caps.dwButtons; ++i )
|
for ( unsigned int i = 0; i < mouse_caps.dwButtons; ++i )
|
||||||
inputs.push_back( new Button( i ) );
|
inputs.push_back( new Button( i ) );
|
||||||
// mouse axes
|
// mouse axes
|
||||||
for ( unsigned int i = 0; i < mouse_caps.dwAxes; ++i )
|
for ( unsigned int i = 0; i < mouse_caps.dwAxes; ++i )
|
||||||
{
|
{
|
||||||
// each axis gets a negative and a positive input instance associated with it
|
// each axis gets a negative and a positive input instance associated with it
|
||||||
inputs.push_back( new Axis( i, (2==i) ? -1 : -MOUSE_AXIS_SENSITIVITY ) );
|
inputs.push_back( new Axis( i, (2==i) ? -1 : -MOUSE_AXIS_SENSITIVITY ) );
|
||||||
inputs.push_back( new Axis( i, -(2==i) ? 1 : MOUSE_AXIS_SENSITIVITY ) );
|
inputs.push_back( new Axis( i, -(2==i) ? 1 : MOUSE_AXIS_SENSITIVITY ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KeyboardMouse::UpdateInput()
|
bool KeyboardMouse::UpdateInput()
|
||||||
{
|
{
|
||||||
DIMOUSESTATE2 tmp_mouse;
|
DIMOUSESTATE2 tmp_mouse;
|
||||||
|
|
||||||
// if mouse position hasn't been updated in a short while, skip a dev state
|
// if mouse position hasn't been updated in a short while, skip a dev state
|
||||||
wxLongLong cur_time = wxGetLocalTimeMillis();
|
wxLongLong cur_time = wxGetLocalTimeMillis();
|
||||||
if ( cur_time - m_last_update > DROP_INPUT_TIME )
|
if ( cur_time - m_last_update > DROP_INPUT_TIME )
|
||||||
{
|
{
|
||||||
// set axes to zero
|
// set axes to zero
|
||||||
ZeroMemory( &m_state_in.mouse, sizeof(m_state_in.mouse) );
|
ZeroMemory( &m_state_in.mouse, sizeof(m_state_in.mouse) );
|
||||||
// skip this input state
|
// skip this input state
|
||||||
m_mo_device->GetDeviceState( sizeof(tmp_mouse), &tmp_mouse );
|
m_mo_device->GetDeviceState( sizeof(tmp_mouse), &tmp_mouse );
|
||||||
}
|
}
|
||||||
|
|
||||||
m_last_update = cur_time;
|
m_last_update = cur_time;
|
||||||
|
|
||||||
if ( DI_OK == m_kb_device->GetDeviceState( sizeof(m_state_in.keyboard), &m_state_in.keyboard )
|
if ( DI_OK == m_kb_device->GetDeviceState( sizeof(m_state_in.keyboard), &m_state_in.keyboard )
|
||||||
&& DI_OK == m_mo_device->GetDeviceState( sizeof(tmp_mouse), &tmp_mouse ) )
|
&& DI_OK == m_mo_device->GetDeviceState( sizeof(tmp_mouse), &tmp_mouse ) )
|
||||||
{
|
{
|
||||||
// need to smooth out the axes, otherwise it doesnt work for shit
|
// need to smooth out the axes, otherwise it doesnt work for shit
|
||||||
for ( unsigned int i = 0; i < 3; ++i )
|
for ( unsigned int i = 0; i < 3; ++i )
|
||||||
((&m_state_in.mouse.lX)[i] += (&tmp_mouse.lX)[i]) /= 2;
|
((&m_state_in.mouse.lX)[i] += (&tmp_mouse.lX)[i]) /= 2;
|
||||||
|
|
||||||
// copy over the buttons
|
// copy over the buttons
|
||||||
memcpy( m_state_in.mouse.rgbButtons, tmp_mouse.rgbButtons, sizeof(m_state_in.mouse.rgbButtons) );
|
memcpy( m_state_in.mouse.rgbButtons, tmp_mouse.rgbButtons, sizeof(m_state_in.mouse.rgbButtons) );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KeyboardMouse::UpdateOutput()
|
bool KeyboardMouse::UpdateOutput()
|
||||||
{
|
{
|
||||||
class KInput : public INPUT
|
class KInput : public INPUT
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
KInput( const unsigned char key, const bool up = false )
|
KInput( const unsigned char key, const bool up = false )
|
||||||
{
|
{
|
||||||
memset( this, 0, sizeof(*this) );
|
memset( this, 0, sizeof(*this) );
|
||||||
type = INPUT_KEYBOARD;
|
type = INPUT_KEYBOARD;
|
||||||
ki.wVk = key;
|
ki.wVk = key;
|
||||||
if (up) ki.dwFlags = KEYEVENTF_KEYUP;
|
if (up) ki.dwFlags = KEYEVENTF_KEYUP;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector< KInput > kbinputs;
|
std::vector< KInput > kbinputs;
|
||||||
for ( unsigned int i = 0; i < sizeof(m_state_out)/sizeof(*m_state_out); ++i )
|
for ( unsigned int i = 0; i < sizeof(m_state_out)/sizeof(*m_state_out); ++i )
|
||||||
{
|
{
|
||||||
bool want_on = false;
|
bool want_on = false;
|
||||||
if ( m_state_out[i] )
|
if ( m_state_out[i] )
|
||||||
want_on = m_state_out[i] > wxGetLocalTimeMillis() % 255 ; // light should flash when output is 0.5
|
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
|
// lights are set to their original state when output is zero
|
||||||
if ( want_on ^ m_current_state_out[i] )
|
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 ) ); // press
|
||||||
kbinputs.push_back( KInput( named_lights[i].code, true ) ); // release
|
kbinputs.push_back( KInput( named_lights[i].code, true ) ); // release
|
||||||
|
|
||||||
m_current_state_out[i] ^= 1;
|
m_current_state_out[i] ^= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ( kbinputs.size() == SendInput( (UINT)kbinputs.size(), &kbinputs[0], sizeof( kbinputs[0] ) ) );
|
return ( kbinputs.size() == SendInput( (UINT)kbinputs.size(), &kbinputs[0], sizeof( kbinputs[0] ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string KeyboardMouse::GetName() const
|
std::string KeyboardMouse::GetName() const
|
||||||
{
|
{
|
||||||
return "Keyboard Mouse";
|
return "Keyboard Mouse";
|
||||||
}
|
}
|
||||||
|
|
||||||
int KeyboardMouse::GetId() const
|
int KeyboardMouse::GetId() const
|
||||||
{
|
{
|
||||||
// should this be -1, idk
|
// should this be -1, idk
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string KeyboardMouse::GetSource() const
|
std::string KeyboardMouse::GetSource() const
|
||||||
{
|
{
|
||||||
return "DirectInput";
|
return "DirectInput";
|
||||||
}
|
}
|
||||||
|
|
||||||
ControlState KeyboardMouse::GetInputState( const ControllerInterface::Device::Input* const input )
|
ControlState KeyboardMouse::GetInputState( const ControllerInterface::Device::Input* const input )
|
||||||
{
|
{
|
||||||
return ( ((Input*)input)->GetState( &m_state_in ) );
|
return ( ((Input*)input)->GetState( &m_state_in ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyboardMouse::SetOutputState( const ControllerInterface::Device::Output* const output, const ControlState state )
|
void KeyboardMouse::SetOutputState( const ControllerInterface::Device::Output* const output, const ControlState state )
|
||||||
{
|
{
|
||||||
((Output*)output)->SetState( state, m_state_out );
|
((Output*)output)->SetState( state, m_state_out );
|
||||||
}
|
}
|
||||||
|
|
||||||
// names
|
// names
|
||||||
std::string KeyboardMouse::Key::GetName() const
|
std::string KeyboardMouse::Key::GetName() const
|
||||||
{
|
{
|
||||||
return named_keys[m_index].name;
|
return named_keys[m_index].name;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string KeyboardMouse::Button::GetName() const
|
std::string KeyboardMouse::Button::GetName() const
|
||||||
{
|
{
|
||||||
return std::string("Button ") + char('0'+m_index);
|
return std::string("Button ") + char('0'+m_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string KeyboardMouse::Axis::GetName() const
|
std::string KeyboardMouse::Axis::GetName() const
|
||||||
{
|
{
|
||||||
std::string tmpstr("Mouse ");
|
std::string tmpstr("Mouse ");
|
||||||
tmpstr += "XYZ"[m_index]; tmpstr += ( m_range>0 ? '+' : '-' );
|
tmpstr += "XYZ"[m_index]; tmpstr += ( m_range>0 ? '+' : '-' );
|
||||||
return tmpstr;
|
return tmpstr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string KeyboardMouse::Light::GetName() const
|
std::string KeyboardMouse::Light::GetName() const
|
||||||
{
|
{
|
||||||
return named_lights[ m_index ].name;
|
return named_lights[ m_index ].name;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get/set state
|
// get/set state
|
||||||
ControlState KeyboardMouse::Key::GetState( const State* const state )
|
ControlState KeyboardMouse::Key::GetState( const State* const state )
|
||||||
{
|
{
|
||||||
return ( state->keyboard[named_keys[m_index].code] > 0 );
|
return ( state->keyboard[named_keys[m_index].code] > 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
ControlState KeyboardMouse::Button::GetState( const State* const state )
|
ControlState KeyboardMouse::Button::GetState( const State* const state )
|
||||||
{
|
{
|
||||||
return ( state->mouse.rgbButtons[m_index] > 0 );
|
return ( state->mouse.rgbButtons[m_index] > 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
ControlState KeyboardMouse::Axis::GetState( const State* const state )
|
ControlState KeyboardMouse::Axis::GetState( const State* const state )
|
||||||
{
|
{
|
||||||
return std::max( 0.0f, ControlState((&state->mouse.lX)[m_index]) / m_range );
|
return std::max( 0.0f, ControlState((&state->mouse.lX)[m_index]) / m_range );
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyboardMouse::Light::SetState( const ControlState state, unsigned char* const state_out )
|
void KeyboardMouse::Light::SetState( const ControlState state, unsigned char* const state_out )
|
||||||
{
|
{
|
||||||
state_out[ m_index ] = state * 255;
|
state_out[ m_index ] = state * 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,125 +1,125 @@
|
||||||
#ifndef _CIFACE_DIRECTINPUT_KBM_H_
|
#ifndef _CIFACE_DIRECTINPUT_KBM_H_
|
||||||
#define _CIFACE_DIRECTINPUT_KBM_H_
|
#define _CIFACE_DIRECTINPUT_KBM_H_
|
||||||
|
|
||||||
#include "../ControllerInterface.h"
|
#include "../ControllerInterface.h"
|
||||||
|
|
||||||
#define DIRECTINPUT_VERSION 0x0800
|
#define DIRECTINPUT_VERSION 0x0800
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#define NOMINMAX
|
#define NOMINMAX
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <dinput.h>
|
#include <dinput.h>
|
||||||
|
|
||||||
#include <wx/stopwatch.h>
|
#include <wx/stopwatch.h>
|
||||||
#include <wx/utils.h>
|
#include <wx/utils.h>
|
||||||
|
|
||||||
namespace ciface
|
namespace ciface
|
||||||
{
|
{
|
||||||
namespace DirectInput
|
namespace DirectInput
|
||||||
{
|
{
|
||||||
|
|
||||||
void InitKeyboardMouse( IDirectInput8* const idi8, std::vector<ControllerInterface::Device*>& devices );
|
void InitKeyboardMouse( IDirectInput8* const idi8, std::vector<ControllerInterface::Device*>& devices );
|
||||||
|
|
||||||
class KeyboardMouse : public ControllerInterface::Device
|
class KeyboardMouse : public ControllerInterface::Device
|
||||||
{
|
{
|
||||||
friend class ControllerInterface;
|
friend class ControllerInterface;
|
||||||
friend class ControllerInterface::ControlReference;
|
friend class ControllerInterface::ControlReference;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
struct State
|
struct State
|
||||||
{
|
{
|
||||||
BYTE keyboard[256];
|
BYTE keyboard[256];
|
||||||
DIMOUSESTATE2 mouse;
|
DIMOUSESTATE2 mouse;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Input : public ControllerInterface::Device::Input
|
class Input : public ControllerInterface::Device::Input
|
||||||
{
|
{
|
||||||
friend class KeyboardMouse;
|
friend class KeyboardMouse;
|
||||||
protected:
|
protected:
|
||||||
virtual ControlState GetState( const State* const boardstate ) = 0;
|
virtual ControlState GetState( const State* const boardstate ) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Output : public ControllerInterface::Device::Output
|
class Output : public ControllerInterface::Device::Output
|
||||||
{
|
{
|
||||||
friend class KeyboardMouse;
|
friend class KeyboardMouse;
|
||||||
protected:
|
protected:
|
||||||
virtual void SetState( const ControlState state, unsigned char* const state_out ) = 0;
|
virtual void SetState( const ControlState state, unsigned char* const state_out ) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Key : public Input
|
class Key : public Input
|
||||||
{
|
{
|
||||||
friend class KeyboardMouse;
|
friend class KeyboardMouse;
|
||||||
public:
|
public:
|
||||||
std::string GetName() const;
|
std::string GetName() const;
|
||||||
protected:
|
protected:
|
||||||
Key( const unsigned int index ) : m_index(index) {}
|
Key( const unsigned int index ) : m_index(index) {}
|
||||||
ControlState GetState( const State* const state );
|
ControlState GetState( const State* const state );
|
||||||
private:
|
private:
|
||||||
const unsigned int m_index;
|
const unsigned int m_index;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Button : public Input
|
class Button : public Input
|
||||||
{
|
{
|
||||||
friend class KeyboardMouse;
|
friend class KeyboardMouse;
|
||||||
public:
|
public:
|
||||||
std::string GetName() const;
|
std::string GetName() const;
|
||||||
protected:
|
protected:
|
||||||
Button( const unsigned int index ) : m_index(index) {}
|
Button( const unsigned int index ) : m_index(index) {}
|
||||||
ControlState GetState( const State* const state );
|
ControlState GetState( const State* const state );
|
||||||
private:
|
private:
|
||||||
const unsigned int m_index;
|
const unsigned int m_index;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Axis : public Input
|
class Axis : public Input
|
||||||
{
|
{
|
||||||
friend class KeyboardMouse;
|
friend class KeyboardMouse;
|
||||||
public:
|
public:
|
||||||
std::string GetName() const;
|
std::string GetName() const;
|
||||||
protected:
|
protected:
|
||||||
Axis( const unsigned int index, const LONG range ) : m_index(index), m_range(range) {}
|
Axis( const unsigned int index, const LONG range ) : m_index(index), m_range(range) {}
|
||||||
ControlState GetState( const State* const state );
|
ControlState GetState( const State* const state );
|
||||||
private:
|
private:
|
||||||
const unsigned int m_index;
|
const unsigned int m_index;
|
||||||
const LONG m_range;
|
const LONG m_range;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Light : public Output
|
class Light : public Output
|
||||||
{
|
{
|
||||||
friend class KeyboardMouse;
|
friend class KeyboardMouse;
|
||||||
public:
|
public:
|
||||||
std::string GetName() const;
|
std::string GetName() const;
|
||||||
protected:
|
protected:
|
||||||
Light( const unsigned int index ) : m_index(index) {}
|
Light( const unsigned int index ) : m_index(index) {}
|
||||||
void SetState( const ControlState state, unsigned char* const state_out );
|
void SetState( const ControlState state, unsigned char* const state_out );
|
||||||
private:
|
private:
|
||||||
const unsigned int m_index;
|
const unsigned int m_index;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool UpdateInput();
|
bool UpdateInput();
|
||||||
bool UpdateOutput();
|
bool UpdateOutput();
|
||||||
|
|
||||||
ControlState GetInputState( const ControllerInterface::Device::Input* const input );
|
ControlState GetInputState( const ControllerInterface::Device::Input* const input );
|
||||||
void SetOutputState( const ControllerInterface::Device::Output* const input, const ControlState state );
|
void SetOutputState( const ControllerInterface::Device::Output* const input, const ControlState state );
|
||||||
|
|
||||||
public:
|
public:
|
||||||
KeyboardMouse( const LPDIRECTINPUTDEVICE8 kb_device, const LPDIRECTINPUTDEVICE8 mo_device );
|
KeyboardMouse( const LPDIRECTINPUTDEVICE8 kb_device, const LPDIRECTINPUTDEVICE8 mo_device );
|
||||||
~KeyboardMouse();
|
~KeyboardMouse();
|
||||||
|
|
||||||
std::string GetName() const;
|
std::string GetName() const;
|
||||||
int GetId() const;
|
int GetId() const;
|
||||||
std::string GetSource() const;
|
std::string GetSource() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const LPDIRECTINPUTDEVICE8 m_kb_device;
|
const LPDIRECTINPUTDEVICE8 m_kb_device;
|
||||||
const LPDIRECTINPUTDEVICE8 m_mo_device;
|
const LPDIRECTINPUTDEVICE8 m_mo_device;
|
||||||
|
|
||||||
wxLongLong m_last_update;
|
wxLongLong m_last_update;
|
||||||
State m_state_in;
|
State m_state_in;
|
||||||
unsigned char m_state_out[3]; // NUM CAPS SCROLL
|
unsigned char m_state_out[3]; // NUM CAPS SCROLL
|
||||||
bool m_current_state_out[3]; // NUM CAPS SCROLL
|
bool m_current_state_out[3]; // NUM CAPS SCROLL
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,144 +1,144 @@
|
||||||
{ DIK_A, "A" },
|
{ DIK_A, "A" },
|
||||||
{ DIK_B, "B" },
|
{ DIK_B, "B" },
|
||||||
{ DIK_C, "C" },
|
{ DIK_C, "C" },
|
||||||
{ DIK_D, "D" },
|
{ DIK_D, "D" },
|
||||||
{ DIK_E, "E" },
|
{ DIK_E, "E" },
|
||||||
{ DIK_F, "F" },
|
{ DIK_F, "F" },
|
||||||
{ DIK_G, "G" },
|
{ DIK_G, "G" },
|
||||||
{ DIK_H, "H" },
|
{ DIK_H, "H" },
|
||||||
{ DIK_I, "I" },
|
{ DIK_I, "I" },
|
||||||
{ DIK_J, "J" },
|
{ DIK_J, "J" },
|
||||||
{ DIK_K, "K" },
|
{ DIK_K, "K" },
|
||||||
{ DIK_L, "L" },
|
{ DIK_L, "L" },
|
||||||
{ DIK_M, "M" },
|
{ DIK_M, "M" },
|
||||||
{ DIK_N, "N" },
|
{ DIK_N, "N" },
|
||||||
{ DIK_O, "O" },
|
{ DIK_O, "O" },
|
||||||
{ DIK_P, "P" },
|
{ DIK_P, "P" },
|
||||||
{ DIK_Q, "Q" },
|
{ DIK_Q, "Q" },
|
||||||
{ DIK_R, "R" },
|
{ DIK_R, "R" },
|
||||||
{ DIK_S, "S" },
|
{ DIK_S, "S" },
|
||||||
{ DIK_T, "T" },
|
{ DIK_T, "T" },
|
||||||
{ DIK_U, "U" },
|
{ DIK_U, "U" },
|
||||||
{ DIK_V, "V" },
|
{ DIK_V, "V" },
|
||||||
{ DIK_W, "W" },
|
{ DIK_W, "W" },
|
||||||
{ DIK_X, "X" },
|
{ DIK_X, "X" },
|
||||||
{ DIK_Y, "Y" },
|
{ DIK_Y, "Y" },
|
||||||
{ DIK_Z, "Z" },
|
{ DIK_Z, "Z" },
|
||||||
{ DIK_0, "0" },
|
{ DIK_0, "0" },
|
||||||
{ DIK_1, "1" },
|
{ DIK_1, "1" },
|
||||||
{ DIK_2, "2" },
|
{ DIK_2, "2" },
|
||||||
{ DIK_3, "3" },
|
{ DIK_3, "3" },
|
||||||
{ DIK_4, "4" },
|
{ DIK_4, "4" },
|
||||||
{ DIK_5, "5" },
|
{ DIK_5, "5" },
|
||||||
{ DIK_6, "6" },
|
{ DIK_6, "6" },
|
||||||
{ DIK_7, "7" },
|
{ DIK_7, "7" },
|
||||||
{ DIK_8, "8" },
|
{ DIK_8, "8" },
|
||||||
{ DIK_9, "9" },
|
{ DIK_9, "9" },
|
||||||
{ DIK_UP, "UP" },
|
{ DIK_UP, "UP" },
|
||||||
{ DIK_DOWN, "DOWN" },
|
{ DIK_DOWN, "DOWN" },
|
||||||
{ DIK_LEFT, "LEFT" },
|
{ DIK_LEFT, "LEFT" },
|
||||||
{ DIK_RIGHT, "RIGHT" },
|
{ DIK_RIGHT, "RIGHT" },
|
||||||
{ DIK_ABNT_C1, "ABNT_C1" },
|
{ DIK_ABNT_C1, "ABNT_C1" },
|
||||||
{ DIK_ABNT_C2, "ABNT_C2" },
|
{ DIK_ABNT_C2, "ABNT_C2" },
|
||||||
{ DIK_ADD, "ADD" },
|
{ DIK_ADD, "ADD" },
|
||||||
{ DIK_APOSTROPHE, "APOSTROPHE" },
|
{ DIK_APOSTROPHE, "APOSTROPHE" },
|
||||||
{ DIK_APPS, "APPS" },
|
{ DIK_APPS, "APPS" },
|
||||||
{ DIK_AT, "AT" },
|
{ DIK_AT, "AT" },
|
||||||
{ DIK_AX, "AX" },
|
{ DIK_AX, "AX" },
|
||||||
{ DIK_BACK, "BACK" },
|
{ DIK_BACK, "BACK" },
|
||||||
{ DIK_BACKSLASH, "BACKSLASH" },
|
{ DIK_BACKSLASH, "BACKSLASH" },
|
||||||
{ DIK_CALCULATOR, "CALCULATOR" },
|
{ DIK_CALCULATOR, "CALCULATOR" },
|
||||||
{ DIK_CAPITAL, "CAPITAL" },
|
{ DIK_CAPITAL, "CAPITAL" },
|
||||||
{ DIK_COLON, "COLON" },
|
{ DIK_COLON, "COLON" },
|
||||||
{ DIK_COMMA, "COMMA" },
|
{ DIK_COMMA, "COMMA" },
|
||||||
{ DIK_CONVERT, "CONVERT" },
|
{ DIK_CONVERT, "CONVERT" },
|
||||||
{ DIK_DECIMAL, "DECIMAL" },
|
{ DIK_DECIMAL, "DECIMAL" },
|
||||||
{ DIK_DELETE, "DELETE" },
|
{ DIK_DELETE, "DELETE" },
|
||||||
{ DIK_DIVIDE, "DIVIDE" },
|
{ DIK_DIVIDE, "DIVIDE" },
|
||||||
{ DIK_EQUALS, "EQUALS" },
|
{ DIK_EQUALS, "EQUALS" },
|
||||||
{ DIK_ESCAPE, "ESCAPE" },
|
{ DIK_ESCAPE, "ESCAPE" },
|
||||||
{ DIK_F1, "F1" },
|
{ DIK_F1, "F1" },
|
||||||
{ DIK_F2, "F2" },
|
{ DIK_F2, "F2" },
|
||||||
{ DIK_F3, "F3" },
|
{ DIK_F3, "F3" },
|
||||||
{ DIK_F4, "F4" },
|
{ DIK_F4, "F4" },
|
||||||
{ DIK_F5, "F5" },
|
{ DIK_F5, "F5" },
|
||||||
{ DIK_F6, "F6" },
|
{ DIK_F6, "F6" },
|
||||||
{ DIK_F7, "F7" },
|
{ DIK_F7, "F7" },
|
||||||
{ DIK_F8, "F8" },
|
{ DIK_F8, "F8" },
|
||||||
{ DIK_F9, "F9" },
|
{ DIK_F9, "F9" },
|
||||||
{ DIK_F10, "F10" },
|
{ DIK_F10, "F10" },
|
||||||
{ DIK_F11, "F11" },
|
{ DIK_F11, "F11" },
|
||||||
{ DIK_F12, "F12" },
|
{ DIK_F12, "F12" },
|
||||||
{ DIK_F13, "F13" },
|
{ DIK_F13, "F13" },
|
||||||
{ DIK_F14, "F14" },
|
{ DIK_F14, "F14" },
|
||||||
{ DIK_F15, "F15" },
|
{ DIK_F15, "F15" },
|
||||||
{ DIK_GRAVE, "GRAVE" },
|
{ DIK_GRAVE, "GRAVE" },
|
||||||
{ DIK_HOME, "HOME" },
|
{ DIK_HOME, "HOME" },
|
||||||
{ DIK_END, "END" },
|
{ DIK_END, "END" },
|
||||||
{ DIK_INSERT, "INSERT" },
|
{ DIK_INSERT, "INSERT" },
|
||||||
{ DIK_KANA, "KANA" },
|
{ DIK_KANA, "KANA" },
|
||||||
{ DIK_KANJI, "KANJI" },
|
{ DIK_KANJI, "KANJI" },
|
||||||
{ DIK_MAIL, "MAIL" },
|
{ DIK_MAIL, "MAIL" },
|
||||||
{ DIK_MEDIASELECT, "MEDIASELECT" },
|
{ DIK_MEDIASELECT, "MEDIASELECT" },
|
||||||
{ DIK_MEDIASTOP, "MEDIASTOP" },
|
{ DIK_MEDIASTOP, "MEDIASTOP" },
|
||||||
{ DIK_MINUS, "MINUS" },
|
{ DIK_MINUS, "MINUS" },
|
||||||
{ DIK_MULTIPLY, "MULTIPLY" },
|
{ DIK_MULTIPLY, "MULTIPLY" },
|
||||||
{ DIK_MUTE, "MUTE" },
|
{ DIK_MUTE, "MUTE" },
|
||||||
{ DIK_MYCOMPUTER, "MYCOMPUTER" },
|
{ DIK_MYCOMPUTER, "MYCOMPUTER" },
|
||||||
{ DIK_NEXTTRACK, "NEXTTRACK" },
|
{ DIK_NEXTTRACK, "NEXTTRACK" },
|
||||||
{ DIK_NOCONVERT, "NOCONVERT" },
|
{ DIK_NOCONVERT, "NOCONVERT" },
|
||||||
{ DIK_NUMLOCK, "NUMLOCK" },
|
{ DIK_NUMLOCK, "NUMLOCK" },
|
||||||
{ DIK_NUMPAD0, "NUMPAD0" },
|
{ DIK_NUMPAD0, "NUMPAD0" },
|
||||||
{ DIK_NUMPAD1, "NUMPAD1" },
|
{ DIK_NUMPAD1, "NUMPAD1" },
|
||||||
{ DIK_NUMPAD2, "NUMPAD2" },
|
{ DIK_NUMPAD2, "NUMPAD2" },
|
||||||
{ DIK_NUMPAD3, "NUMPAD3" },
|
{ DIK_NUMPAD3, "NUMPAD3" },
|
||||||
{ DIK_NUMPAD4, "NUMPAD4" },
|
{ DIK_NUMPAD4, "NUMPAD4" },
|
||||||
{ DIK_NUMPAD5, "NUMPAD5" },
|
{ DIK_NUMPAD5, "NUMPAD5" },
|
||||||
{ DIK_NUMPAD6, "NUMPAD6" },
|
{ DIK_NUMPAD6, "NUMPAD6" },
|
||||||
{ DIK_NUMPAD7, "NUMPAD7" },
|
{ DIK_NUMPAD7, "NUMPAD7" },
|
||||||
{ DIK_NUMPAD8, "NUMPAD8" },
|
{ DIK_NUMPAD8, "NUMPAD8" },
|
||||||
{ DIK_NUMPAD9, "NUMPAD9" },
|
{ DIK_NUMPAD9, "NUMPAD9" },
|
||||||
{ DIK_NUMPADCOMMA, "NUMPADCOMMA" },
|
{ DIK_NUMPADCOMMA, "NUMPADCOMMA" },
|
||||||
{ DIK_NUMPADENTER, "NUMPADENTER" },
|
{ DIK_NUMPADENTER, "NUMPADENTER" },
|
||||||
{ DIK_NUMPADEQUALS, "NUMPADEQUALS" },
|
{ DIK_NUMPADEQUALS, "NUMPADEQUALS" },
|
||||||
{ DIK_OEM_102, "OEM_102" },
|
{ DIK_OEM_102, "OEM_102" },
|
||||||
{ DIK_PAUSE, "PAUSE" },
|
{ DIK_PAUSE, "PAUSE" },
|
||||||
{ DIK_PERIOD, "PERIOD" },
|
{ DIK_PERIOD, "PERIOD" },
|
||||||
{ DIK_PLAYPAUSE, "PLAYPAUSE" },
|
{ DIK_PLAYPAUSE, "PLAYPAUSE" },
|
||||||
{ DIK_POWER, "POWER" },
|
{ DIK_POWER, "POWER" },
|
||||||
{ DIK_PREVTRACK, "PREVTRACK" },
|
{ DIK_PREVTRACK, "PREVTRACK" },
|
||||||
{ DIK_PRIOR, "PRIOR" },
|
{ DIK_PRIOR, "PRIOR" },
|
||||||
{ DIK_NEXT, "NEXT" },
|
{ DIK_NEXT, "NEXT" },
|
||||||
{ DIK_RETURN, "RETURN" },
|
{ DIK_RETURN, "RETURN" },
|
||||||
{ DIK_LBRACKET, "LBRACKET" },
|
{ DIK_LBRACKET, "LBRACKET" },
|
||||||
{ DIK_RBRACKET, "RBRACKET" },
|
{ DIK_RBRACKET, "RBRACKET" },
|
||||||
{ DIK_LCONTROL, "LCONTROL" },
|
{ DIK_LCONTROL, "LCONTROL" },
|
||||||
{ DIK_RCONTROL, "RCONTROL" },
|
{ DIK_RCONTROL, "RCONTROL" },
|
||||||
{ DIK_LMENU, "LMENU" },
|
{ DIK_LMENU, "LMENU" },
|
||||||
{ DIK_RMENU, "RMENU" },
|
{ DIK_RMENU, "RMENU" },
|
||||||
{ DIK_LSHIFT, "LSHIFT" },
|
{ DIK_LSHIFT, "LSHIFT" },
|
||||||
{ DIK_RSHIFT, "RSHIFT" },
|
{ DIK_RSHIFT, "RSHIFT" },
|
||||||
{ DIK_LWIN, "LWIN" },
|
{ DIK_LWIN, "LWIN" },
|
||||||
{ DIK_RWIN, "RWIN" },
|
{ DIK_RWIN, "RWIN" },
|
||||||
{ DIK_SCROLL, "SCROLL" },
|
{ DIK_SCROLL, "SCROLL" },
|
||||||
{ DIK_SEMICOLON, "SEMICOLON" },
|
{ DIK_SEMICOLON, "SEMICOLON" },
|
||||||
{ DIK_SLASH, "SLASH" },
|
{ DIK_SLASH, "SLASH" },
|
||||||
{ DIK_SLEEP, "SLEEP" },
|
{ DIK_SLEEP, "SLEEP" },
|
||||||
{ DIK_SPACE, "SPACE" },
|
{ DIK_SPACE, "SPACE" },
|
||||||
{ DIK_STOP, "STOP" },
|
{ DIK_STOP, "STOP" },
|
||||||
{ DIK_SUBTRACT, "SUBTRACT" },
|
{ DIK_SUBTRACT, "SUBTRACT" },
|
||||||
{ DIK_SYSRQ, "SYSRQ" },
|
{ DIK_SYSRQ, "SYSRQ" },
|
||||||
{ DIK_TAB, "TAB" },
|
{ DIK_TAB, "TAB" },
|
||||||
{ DIK_UNDERLINE, "UNDERLINE" },
|
{ DIK_UNDERLINE, "UNDERLINE" },
|
||||||
{ DIK_UNLABELED, "UNLABELED" },
|
{ DIK_UNLABELED, "UNLABELED" },
|
||||||
{ DIK_VOLUMEDOWN, "VOLUMEDOWN" },
|
{ DIK_VOLUMEDOWN, "VOLUMEDOWN" },
|
||||||
{ DIK_VOLUMEUP, "VOLUMEUP" },
|
{ DIK_VOLUMEUP, "VOLUMEUP" },
|
||||||
{ DIK_WAKE, "WAKE" },
|
{ DIK_WAKE, "WAKE" },
|
||||||
{ DIK_WEBBACK, "WEBBACK" },
|
{ DIK_WEBBACK, "WEBBACK" },
|
||||||
{ DIK_WEBFAVORITES, "WEBFAVORITES" },
|
{ DIK_WEBFAVORITES, "WEBFAVORITES" },
|
||||||
{ DIK_WEBFORWARD, "WEBFORWARD" },
|
{ DIK_WEBFORWARD, "WEBFORWARD" },
|
||||||
{ DIK_WEBHOME, "WEBHOME" },
|
{ DIK_WEBHOME, "WEBHOME" },
|
||||||
{ DIK_WEBREFRESH, "WEBREFRESH" },
|
{ DIK_WEBREFRESH, "WEBREFRESH" },
|
||||||
{ DIK_WEBSEARCH, "WEBSEARCH" },
|
{ DIK_WEBSEARCH, "WEBSEARCH" },
|
||||||
{ DIK_WEBSTOP, "WEBSTOP" },
|
{ DIK_WEBSTOP, "WEBSTOP" },
|
||||||
{ DIK_YEN, "YEN" },
|
{ DIK_YEN, "YEN" },
|
||||||
|
|
|
@ -1,266 +1,266 @@
|
||||||
#include "../ControllerInterface.h"
|
#include "../ControllerInterface.h"
|
||||||
|
|
||||||
#ifdef CIFACE_USE_SDL
|
#ifdef CIFACE_USE_SDL
|
||||||
|
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#if SDL_VERSION_ATLEAST(1, 3, 0)
|
#if SDL_VERSION_ATLEAST(1, 3, 0)
|
||||||
#pragma comment(lib, "SDL.1.3.lib")
|
#pragma comment(lib, "SDL.1.3.lib")
|
||||||
#else
|
#else
|
||||||
#pragma comment(lib, "SDL.lib")
|
#pragma comment(lib, "SDL.lib")
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace ciface
|
namespace ciface
|
||||||
{
|
{
|
||||||
namespace SDL
|
namespace SDL
|
||||||
{
|
{
|
||||||
|
|
||||||
void Init( std::vector<ControllerInterface::Device*>& devices )
|
void Init( std::vector<ControllerInterface::Device*>& devices )
|
||||||
{
|
{
|
||||||
if ( SDL_Init( SDL_INIT_FLAGS ) >= 0 )
|
if ( SDL_Init( SDL_INIT_FLAGS ) >= 0 )
|
||||||
{
|
{
|
||||||
// joysticks
|
// joysticks
|
||||||
for( int i = 0; i < SDL_NumJoysticks(); ++i )
|
for( int i = 0; i < SDL_NumJoysticks(); ++i )
|
||||||
{
|
{
|
||||||
SDL_Joystick* dev = SDL_JoystickOpen( i );
|
SDL_Joystick* dev = SDL_JoystickOpen( i );
|
||||||
if ( dev )
|
if ( dev )
|
||||||
{
|
{
|
||||||
Joystick* js = new Joystick( dev, i );
|
Joystick* js = new Joystick( dev, i );
|
||||||
// only add if it has some inputs/outputs
|
// only add if it has some inputs/outputs
|
||||||
if ( js->Inputs().size() || js->Outputs().size() )
|
if ( js->Inputs().size() || js->Outputs().size() )
|
||||||
devices.push_back( js );
|
devices.push_back( js );
|
||||||
else
|
else
|
||||||
delete js;
|
delete js;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Joystick::Joystick( SDL_Joystick* const joystick, const unsigned int index ) : m_joystick(joystick), m_index(index)
|
Joystick::Joystick( SDL_Joystick* const joystick, const unsigned int index ) : m_joystick(joystick), m_index(index)
|
||||||
{
|
{
|
||||||
// get buttons
|
// get buttons
|
||||||
for ( int i = 0; i < SDL_JoystickNumButtons( m_joystick ); ++i )
|
for ( int i = 0; i < SDL_JoystickNumButtons( m_joystick ); ++i )
|
||||||
{
|
{
|
||||||
inputs.push_back( new Button( i ) );
|
inputs.push_back( new Button( i ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// get hats
|
// get hats
|
||||||
for ( int i = 0; i < SDL_JoystickNumHats( m_joystick ); ++i )
|
for ( int i = 0; i < SDL_JoystickNumHats( m_joystick ); ++i )
|
||||||
{
|
{
|
||||||
// each hat gets 4 input instances associated with it, (up down left right)
|
// each hat gets 4 input instances associated with it, (up down left right)
|
||||||
for ( unsigned int d = 0; d < 4; ++d )
|
for ( unsigned int d = 0; d < 4; ++d )
|
||||||
inputs.push_back( new Hat( i, d ) );
|
inputs.push_back( new Hat( i, d ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// get axes
|
// get axes
|
||||||
for ( int i = 0; i < SDL_JoystickNumAxes( m_joystick ); ++i )
|
for ( int i = 0; i < SDL_JoystickNumAxes( m_joystick ); ++i )
|
||||||
{
|
{
|
||||||
// each axis gets a negative and a positive input instance associated with it
|
// each axis gets a negative and a positive input instance associated with it
|
||||||
inputs.push_back( new Axis( i, -32768 ) );
|
inputs.push_back( new Axis( i, -32768 ) );
|
||||||
inputs.push_back( new Axis( i, 32767 ) );
|
inputs.push_back( new Axis( i, 32767 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_SDL_HAPTIC
|
#ifdef USE_SDL_HAPTIC
|
||||||
// try to get supported ff effects
|
// try to get supported ff effects
|
||||||
m_haptic = SDL_HapticOpenFromJoystick( m_joystick );
|
m_haptic = SDL_HapticOpenFromJoystick( m_joystick );
|
||||||
if ( m_haptic )
|
if ( m_haptic )
|
||||||
{
|
{
|
||||||
//SDL_HapticSetGain( m_haptic, 1000 );
|
//SDL_HapticSetGain( m_haptic, 1000 );
|
||||||
//SDL_HapticSetAutocenter( m_haptic, 0 );
|
//SDL_HapticSetAutocenter( m_haptic, 0 );
|
||||||
|
|
||||||
const unsigned int supported_effects = SDL_HapticQuery( m_haptic );
|
const unsigned int supported_effects = SDL_HapticQuery( m_haptic );
|
||||||
|
|
||||||
// constant effect
|
// constant effect
|
||||||
if ( supported_effects & SDL_HAPTIC_CONSTANT )
|
if ( supported_effects & SDL_HAPTIC_CONSTANT )
|
||||||
{
|
{
|
||||||
outputs.push_back( new ConstantEffect( m_state_out.size() ) );
|
outputs.push_back( new ConstantEffect( m_state_out.size() ) );
|
||||||
m_state_out.push_back( EffectIDState() );
|
m_state_out.push_back( EffectIDState() );
|
||||||
}
|
}
|
||||||
|
|
||||||
// ramp effect
|
// ramp effect
|
||||||
if ( supported_effects & SDL_HAPTIC_RAMP )
|
if ( supported_effects & SDL_HAPTIC_RAMP )
|
||||||
{
|
{
|
||||||
outputs.push_back( new RampEffect( m_state_out.size() ) );
|
outputs.push_back( new RampEffect( m_state_out.size() ) );
|
||||||
m_state_out.push_back( EffectIDState() );
|
m_state_out.push_back( EffectIDState() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Joystick::~Joystick()
|
Joystick::~Joystick()
|
||||||
{
|
{
|
||||||
#ifdef USE_SDL_HAPTIC
|
#ifdef USE_SDL_HAPTIC
|
||||||
if ( m_haptic )
|
if ( m_haptic )
|
||||||
{
|
{
|
||||||
// stop/destroy all effects
|
// stop/destroy all effects
|
||||||
SDL_HapticStopAll( m_haptic );
|
SDL_HapticStopAll( m_haptic );
|
||||||
std::vector<EffectIDState>::iterator i = m_state_out.begin(),
|
std::vector<EffectIDState>::iterator i = m_state_out.begin(),
|
||||||
e = m_state_out.end();
|
e = m_state_out.end();
|
||||||
for ( ; i!=e; ++i )
|
for ( ; i!=e; ++i )
|
||||||
if ( i->id != -1 )
|
if ( i->id != -1 )
|
||||||
SDL_HapticDestroyEffect( m_haptic, i->id );
|
SDL_HapticDestroyEffect( m_haptic, i->id );
|
||||||
// close haptic first
|
// close haptic first
|
||||||
SDL_HapticClose( m_haptic );
|
SDL_HapticClose( m_haptic );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// close joystick
|
// close joystick
|
||||||
SDL_JoystickClose( m_joystick );
|
SDL_JoystickClose( m_joystick );
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_SDL_HAPTIC
|
#ifdef USE_SDL_HAPTIC
|
||||||
std::string Joystick::ConstantEffect::GetName() const
|
std::string Joystick::ConstantEffect::GetName() const
|
||||||
{
|
{
|
||||||
return "Constant";
|
return "Constant";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Joystick::RampEffect::GetName() const
|
std::string Joystick::RampEffect::GetName() const
|
||||||
{
|
{
|
||||||
return "Ramp";
|
return "Ramp";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Joystick::ConstantEffect::SetState( const ControlState state, Joystick::EffectIDState* const effect )
|
void Joystick::ConstantEffect::SetState( const ControlState state, Joystick::EffectIDState* const effect )
|
||||||
{
|
{
|
||||||
if ( state )
|
if ( state )
|
||||||
{
|
{
|
||||||
effect->effect.type = SDL_HAPTIC_CONSTANT;
|
effect->effect.type = SDL_HAPTIC_CONSTANT;
|
||||||
effect->effect.constant.length = SDL_HAPTIC_INFINITY;
|
effect->effect.constant.length = SDL_HAPTIC_INFINITY;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
effect->effect.type = 0;
|
effect->effect.type = 0;
|
||||||
|
|
||||||
Sint16 old = effect->effect.constant.level;
|
Sint16 old = effect->effect.constant.level;
|
||||||
effect->effect.constant.level = state * 0x7FFF;
|
effect->effect.constant.level = state * 0x7FFF;
|
||||||
if ( old != effect->effect.constant.level )
|
if ( old != effect->effect.constant.level )
|
||||||
effect->changed = true;
|
effect->changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Joystick::RampEffect::SetState( const ControlState state, Joystick::EffectIDState* const effect )
|
void Joystick::RampEffect::SetState( const ControlState state, Joystick::EffectIDState* const effect )
|
||||||
{
|
{
|
||||||
if ( state )
|
if ( state )
|
||||||
{
|
{
|
||||||
effect->effect.type = SDL_HAPTIC_RAMP;
|
effect->effect.type = SDL_HAPTIC_RAMP;
|
||||||
effect->effect.ramp.length = SDL_HAPTIC_INFINITY;
|
effect->effect.ramp.length = SDL_HAPTIC_INFINITY;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
effect->effect.type = 0;
|
effect->effect.type = 0;
|
||||||
|
|
||||||
Sint16 old = effect->effect.ramp.start;
|
Sint16 old = effect->effect.ramp.start;
|
||||||
effect->effect.ramp.start = state * 0x7FFF;
|
effect->effect.ramp.start = state * 0x7FFF;
|
||||||
if ( old != effect->effect.ramp.start )
|
if ( old != effect->effect.ramp.start )
|
||||||
effect->changed = true;
|
effect->changed = true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ControlState Joystick::GetInputState(const ControllerInterface::Device::Input* input)
|
ControlState Joystick::GetInputState(const ControllerInterface::Device::Input* input)
|
||||||
{
|
{
|
||||||
return ((Input*)input)->GetState( m_joystick );
|
return ((Input*)input)->GetState( m_joystick );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Joystick::SetOutputState(const ControllerInterface::Device::Output* output, const ControlState state)
|
void Joystick::SetOutputState(const ControllerInterface::Device::Output* output, const ControlState state)
|
||||||
{
|
{
|
||||||
#ifdef USE_SDL_HAPTIC
|
#ifdef USE_SDL_HAPTIC
|
||||||
((Output*)output)->SetState( state, &m_state_out[ ((Output*)output)->m_index ] );
|
((Output*)output)->SetState( state, &m_state_out[ ((Output*)output)->m_index ] );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Joystick::UpdateInput()
|
bool Joystick::UpdateInput()
|
||||||
{
|
{
|
||||||
// each joystick is doin this, o well
|
// each joystick is doin this, o well
|
||||||
SDL_JoystickUpdate();
|
SDL_JoystickUpdate();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Joystick::UpdateOutput()
|
bool Joystick::UpdateOutput()
|
||||||
{
|
{
|
||||||
#ifdef USE_SDL_HAPTIC
|
#ifdef USE_SDL_HAPTIC
|
||||||
std::vector<EffectIDState>::iterator i = m_state_out.begin(),
|
std::vector<EffectIDState>::iterator i = m_state_out.begin(),
|
||||||
e = m_state_out.end();
|
e = m_state_out.end();
|
||||||
for ( ; i!=e; ++i )
|
for ( ; i!=e; ++i )
|
||||||
if ( i->changed ) // if SetState was called on this output
|
if ( i->changed ) // if SetState was called on this output
|
||||||
{
|
{
|
||||||
if ( -1 == i->id ) // effect isn't currently uploaded
|
if ( -1 == i->id ) // effect isn't currently uploaded
|
||||||
{
|
{
|
||||||
if ( i->effect.type ) // if outputstate is >0 this would be true
|
if ( i->effect.type ) // if outputstate is >0 this would be true
|
||||||
if ( (i->id = SDL_HapticNewEffect( m_haptic, &i->effect )) > -1 ) // upload the effect
|
if ( (i->id = SDL_HapticNewEffect( m_haptic, &i->effect )) > -1 ) // upload the effect
|
||||||
SDL_HapticRunEffect( m_haptic, i->id, 1 ); // run the effect
|
SDL_HapticRunEffect( m_haptic, i->id, 1 ); // run the effect
|
||||||
}
|
}
|
||||||
else // effect is already uploaded
|
else // effect is already uploaded
|
||||||
{
|
{
|
||||||
if ( i->effect.type ) // if ouputstate >0
|
if ( i->effect.type ) // if ouputstate >0
|
||||||
SDL_HapticUpdateEffect( m_haptic, i->id, &i->effect ); // update the effect
|
SDL_HapticUpdateEffect( m_haptic, i->id, &i->effect ); // update the effect
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SDL_HapticStopEffect( m_haptic, i->id ); // else, stop and remove the effect
|
SDL_HapticStopEffect( m_haptic, i->id ); // else, stop and remove the effect
|
||||||
SDL_HapticDestroyEffect( m_haptic, i->id );
|
SDL_HapticDestroyEffect( m_haptic, i->id );
|
||||||
i->id = -1; // mark it as not uploaded
|
i->id = -1; // mark it as not uploaded
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
i->changed = false;
|
i->changed = false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Joystick::GetName() const
|
std::string Joystick::GetName() const
|
||||||
{
|
{
|
||||||
return SDL_JoystickName( m_index );
|
return SDL_JoystickName( m_index );
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Joystick::GetSource() const
|
std::string Joystick::GetSource() const
|
||||||
{
|
{
|
||||||
return "SDL";
|
return "SDL";
|
||||||
}
|
}
|
||||||
|
|
||||||
int Joystick::GetId() const
|
int Joystick::GetId() const
|
||||||
{
|
{
|
||||||
return m_index;
|
return m_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Joystick::Button::GetName() const
|
std::string Joystick::Button::GetName() const
|
||||||
{
|
{
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
ss << "Button " << m_index;
|
ss << "Button " << m_index;
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Joystick::Axis::GetName() const
|
std::string Joystick::Axis::GetName() const
|
||||||
{
|
{
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
ss << "Axis " << m_index << ( m_range>0 ? '+' : '-' );
|
ss << "Axis " << m_index << ( m_range>0 ? '+' : '-' );
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Joystick::Hat::GetName() const
|
std::string Joystick::Hat::GetName() const
|
||||||
{
|
{
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
ss << "Hat " << m_index << ' ' << "NESW"[m_direction];
|
ss << "Hat " << m_index << ' ' << "NESW"[m_direction];
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
ControlState Joystick::Button::GetState( SDL_Joystick* const js ) const
|
ControlState Joystick::Button::GetState( SDL_Joystick* const js ) const
|
||||||
{
|
{
|
||||||
return SDL_JoystickGetButton( js, m_index );
|
return SDL_JoystickGetButton( js, m_index );
|
||||||
}
|
}
|
||||||
|
|
||||||
ControlState Joystick::Axis::GetState( SDL_Joystick* const js ) const
|
ControlState Joystick::Axis::GetState( SDL_Joystick* const js ) const
|
||||||
{
|
{
|
||||||
return std::max( 0.0f, ControlState(SDL_JoystickGetAxis( js, m_index )) / m_range );
|
return std::max( 0.0f, ControlState(SDL_JoystickGetAxis( js, m_index )) / m_range );
|
||||||
}
|
}
|
||||||
|
|
||||||
ControlState Joystick::Hat::GetState( SDL_Joystick* const js ) const
|
ControlState Joystick::Hat::GetState( SDL_Joystick* const js ) const
|
||||||
{
|
{
|
||||||
return (SDL_JoystickGetHat( js, m_index ) & ( 1 << m_direction )) > 0;
|
return (SDL_JoystickGetHat( js, m_index ) & ( 1 << m_direction )) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,159 +1,159 @@
|
||||||
#ifndef _CIFACE_SDL_H_
|
#ifndef _CIFACE_SDL_H_
|
||||||
#define _CIFACE_SDL_H_
|
#define _CIFACE_SDL_H_
|
||||||
|
|
||||||
#include "../ControllerInterface.h"
|
#include "../ControllerInterface.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#else
|
#else
|
||||||
#include <SDL/SDL.h>
|
#include <SDL/SDL.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if SDL_VERSION_ATLEAST(1, 3, 0)
|
#if SDL_VERSION_ATLEAST(1, 3, 0)
|
||||||
#define USE_SDL_HAPTIC
|
#define USE_SDL_HAPTIC
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_SDL_HAPTIC
|
#ifdef USE_SDL_HAPTIC
|
||||||
#define SDL_INIT_FLAGS SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC
|
#define SDL_INIT_FLAGS SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <SDL_haptic.h>
|
#include <SDL_haptic.h>
|
||||||
#else
|
#else
|
||||||
#include <SDL/SDL_haptic.h>
|
#include <SDL/SDL_haptic.h>
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#define SDL_INIT_FLAGS SDL_INIT_JOYSTICK
|
#define SDL_INIT_FLAGS SDL_INIT_JOYSTICK
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace ciface
|
namespace ciface
|
||||||
{
|
{
|
||||||
namespace SDL
|
namespace SDL
|
||||||
{
|
{
|
||||||
|
|
||||||
void Init( std::vector<ControllerInterface::Device*>& devices );
|
void Init( std::vector<ControllerInterface::Device*>& devices );
|
||||||
|
|
||||||
class Joystick : public ControllerInterface::Device
|
class Joystick : public ControllerInterface::Device
|
||||||
{
|
{
|
||||||
friend class ControllerInterface;
|
friend class ControllerInterface;
|
||||||
friend class ControllerInterface::ControlReference;
|
friend class ControllerInterface::ControlReference;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
#ifdef USE_SDL_HAPTIC
|
#ifdef USE_SDL_HAPTIC
|
||||||
class EffectIDState
|
class EffectIDState
|
||||||
{
|
{
|
||||||
friend class Joystick;
|
friend class Joystick;
|
||||||
protected:
|
protected:
|
||||||
EffectIDState() : id(-1), changed(false) { memset( &effect, 0, sizeof(effect)); }
|
EffectIDState() : id(-1), changed(false) { memset( &effect, 0, sizeof(effect)); }
|
||||||
protected:
|
protected:
|
||||||
SDL_HapticEffect effect;
|
SDL_HapticEffect effect;
|
||||||
int id;
|
int id;
|
||||||
bool changed;
|
bool changed;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class Input : public ControllerInterface::Device::Input
|
class Input : public ControllerInterface::Device::Input
|
||||||
{
|
{
|
||||||
friend class Joystick;
|
friend class Joystick;
|
||||||
protected:
|
protected:
|
||||||
Input( const unsigned int index ) : m_index(index) {}
|
Input( const unsigned int index ) : m_index(index) {}
|
||||||
virtual ControlState GetState( SDL_Joystick* const js ) const = 0;
|
virtual ControlState GetState( SDL_Joystick* const js ) const = 0;
|
||||||
|
|
||||||
const unsigned int m_index;
|
const unsigned int m_index;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef USE_SDL_HAPTIC
|
#ifdef USE_SDL_HAPTIC
|
||||||
class Output : public ControllerInterface::Device::Output
|
class Output : public ControllerInterface::Device::Output
|
||||||
{
|
{
|
||||||
friend class Joystick;
|
friend class Joystick;
|
||||||
protected:
|
protected:
|
||||||
Output( const size_t index ) : m_index(index) {}
|
Output( const size_t index ) : m_index(index) {}
|
||||||
virtual void SetState( const ControlState state, EffectIDState* const effect ) = 0;
|
virtual void SetState( const ControlState state, EffectIDState* const effect ) = 0;
|
||||||
|
|
||||||
const size_t m_index;
|
const size_t m_index;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class Button : public Input
|
class Button : public Input
|
||||||
{
|
{
|
||||||
friend class Joystick;
|
friend class Joystick;
|
||||||
public:
|
public:
|
||||||
std::string GetName() const;
|
std::string GetName() const;
|
||||||
protected:
|
protected:
|
||||||
Button( const unsigned int index ) : Input(index) {}
|
Button( const unsigned int index ) : Input(index) {}
|
||||||
ControlState GetState( SDL_Joystick* const js ) const;
|
ControlState GetState( SDL_Joystick* const js ) const;
|
||||||
};
|
};
|
||||||
class Axis : public Input
|
class Axis : public Input
|
||||||
{
|
{
|
||||||
friend class Joystick;
|
friend class Joystick;
|
||||||
public:
|
public:
|
||||||
std::string GetName() const;
|
std::string GetName() const;
|
||||||
protected:
|
protected:
|
||||||
Axis( const unsigned int index, const Sint16 range ) : Input(index), m_range(range) {}
|
Axis( const unsigned int index, const Sint16 range ) : Input(index), m_range(range) {}
|
||||||
ControlState GetState( SDL_Joystick* const js ) const;
|
ControlState GetState( SDL_Joystick* const js ) const;
|
||||||
private:
|
private:
|
||||||
const Sint16 m_range;
|
const Sint16 m_range;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Hat : public Input
|
class Hat : public Input
|
||||||
{
|
{
|
||||||
friend class Joystick;
|
friend class Joystick;
|
||||||
public:
|
public:
|
||||||
std::string GetName() const;
|
std::string GetName() const;
|
||||||
protected:
|
protected:
|
||||||
Hat( const unsigned int index, const unsigned int direction ) : Input(index), m_direction(direction) {}
|
Hat( const unsigned int index, const unsigned int direction ) : Input(index), m_direction(direction) {}
|
||||||
ControlState GetState( SDL_Joystick* const js ) const;
|
ControlState GetState( SDL_Joystick* const js ) const;
|
||||||
private:
|
private:
|
||||||
const unsigned int m_direction;
|
const unsigned int m_direction;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef USE_SDL_HAPTIC
|
#ifdef USE_SDL_HAPTIC
|
||||||
class ConstantEffect : public Output
|
class ConstantEffect : public Output
|
||||||
{
|
{
|
||||||
friend class Joystick;
|
friend class Joystick;
|
||||||
public:
|
public:
|
||||||
std::string GetName() const;
|
std::string GetName() const;
|
||||||
protected:
|
protected:
|
||||||
ConstantEffect( const size_t index ) : Output(index) {}
|
ConstantEffect( const size_t index ) : Output(index) {}
|
||||||
void SetState( const ControlState state, EffectIDState* const effect );
|
void SetState( const ControlState state, EffectIDState* const effect );
|
||||||
};
|
};
|
||||||
|
|
||||||
class RampEffect : public Output
|
class RampEffect : public Output
|
||||||
{
|
{
|
||||||
friend class Joystick;
|
friend class Joystick;
|
||||||
public:
|
public:
|
||||||
std::string GetName() const;
|
std::string GetName() const;
|
||||||
protected:
|
protected:
|
||||||
RampEffect( const size_t index ) : Output(index) {}
|
RampEffect( const size_t index ) : Output(index) {}
|
||||||
void SetState( const ControlState state, EffectIDState* const effect );
|
void SetState( const ControlState state, EffectIDState* const effect );
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool UpdateInput();
|
bool UpdateInput();
|
||||||
bool UpdateOutput();
|
bool UpdateOutput();
|
||||||
|
|
||||||
ControlState GetInputState( const ControllerInterface::Device::Input* const input );
|
ControlState GetInputState( const ControllerInterface::Device::Input* const input );
|
||||||
void SetOutputState( const ControllerInterface::Device::Output* const output, const ControlState state );
|
void SetOutputState( const ControllerInterface::Device::Output* const output, const ControlState state );
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Joystick( SDL_Joystick* const joystick, const unsigned int index );
|
Joystick( SDL_Joystick* const joystick, const unsigned int index );
|
||||||
~Joystick();
|
~Joystick();
|
||||||
|
|
||||||
std::string GetName() const;
|
std::string GetName() const;
|
||||||
int GetId() const;
|
int GetId() const;
|
||||||
std::string GetSource() const;
|
std::string GetSource() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SDL_Joystick* const m_joystick;
|
SDL_Joystick* const m_joystick;
|
||||||
const unsigned int m_index;
|
const unsigned int m_index;
|
||||||
|
|
||||||
#ifdef USE_SDL_HAPTIC
|
#ifdef USE_SDL_HAPTIC
|
||||||
std::vector<EffectIDState> m_state_out;
|
std::vector<EffectIDState> m_state_out;
|
||||||
SDL_Haptic* m_haptic;
|
SDL_Haptic* m_haptic;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,214 +1,214 @@
|
||||||
#include "../ControllerInterface.h"
|
#include "../ControllerInterface.h"
|
||||||
|
|
||||||
#ifdef CIFACE_USE_XINPUT
|
#ifdef CIFACE_USE_XINPUT
|
||||||
|
|
||||||
#include "XInput.h"
|
#include "XInput.h"
|
||||||
|
|
||||||
namespace ciface
|
namespace ciface
|
||||||
{
|
{
|
||||||
namespace XInput
|
namespace XInput
|
||||||
{
|
{
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
const char* const name;
|
const char* const name;
|
||||||
const WORD bitmask;
|
const WORD bitmask;
|
||||||
} named_buttons[] =
|
} named_buttons[] =
|
||||||
{
|
{
|
||||||
{ "Button A", XINPUT_GAMEPAD_A },
|
{ "Button A", XINPUT_GAMEPAD_A },
|
||||||
{ "Button B", XINPUT_GAMEPAD_B },
|
{ "Button B", XINPUT_GAMEPAD_B },
|
||||||
{ "Button X", XINPUT_GAMEPAD_X },
|
{ "Button X", XINPUT_GAMEPAD_X },
|
||||||
{ "Button Y", XINPUT_GAMEPAD_Y },
|
{ "Button Y", XINPUT_GAMEPAD_Y },
|
||||||
{ "Pad N", XINPUT_GAMEPAD_DPAD_UP },
|
{ "Pad N", XINPUT_GAMEPAD_DPAD_UP },
|
||||||
{ "Pad S", XINPUT_GAMEPAD_DPAD_DOWN },
|
{ "Pad S", XINPUT_GAMEPAD_DPAD_DOWN },
|
||||||
{ "Pad W", XINPUT_GAMEPAD_DPAD_LEFT },
|
{ "Pad W", XINPUT_GAMEPAD_DPAD_LEFT },
|
||||||
{ "Pad E", XINPUT_GAMEPAD_DPAD_RIGHT },
|
{ "Pad E", XINPUT_GAMEPAD_DPAD_RIGHT },
|
||||||
{ "Start", XINPUT_GAMEPAD_START },
|
{ "Start", XINPUT_GAMEPAD_START },
|
||||||
{ "Back", XINPUT_GAMEPAD_BACK },
|
{ "Back", XINPUT_GAMEPAD_BACK },
|
||||||
{ "Shoulder L", XINPUT_GAMEPAD_LEFT_SHOULDER },
|
{ "Shoulder L", XINPUT_GAMEPAD_LEFT_SHOULDER },
|
||||||
{ "Shoulder R", XINPUT_GAMEPAD_RIGHT_SHOULDER },
|
{ "Shoulder R", XINPUT_GAMEPAD_RIGHT_SHOULDER },
|
||||||
{ "Thumb L", XINPUT_GAMEPAD_LEFT_THUMB },
|
{ "Thumb L", XINPUT_GAMEPAD_LEFT_THUMB },
|
||||||
{ "Thumb R", XINPUT_GAMEPAD_RIGHT_THUMB }
|
{ "Thumb R", XINPUT_GAMEPAD_RIGHT_THUMB }
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* named_triggers[] =
|
const char* named_triggers[] =
|
||||||
{
|
{
|
||||||
"Trigger L",
|
"Trigger L",
|
||||||
"Trigger R"
|
"Trigger R"
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* named_axes[] =
|
const char* named_axes[] =
|
||||||
{
|
{
|
||||||
"Left X",
|
"Left X",
|
||||||
"Left Y",
|
"Left Y",
|
||||||
"Right X",
|
"Right X",
|
||||||
"Right Y"
|
"Right Y"
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* named_motors[] =
|
const char* named_motors[] =
|
||||||
{
|
{
|
||||||
"Motor L",
|
"Motor L",
|
||||||
"Motor R"
|
"Motor R"
|
||||||
};
|
};
|
||||||
|
|
||||||
void Init( std::vector<ControllerInterface::Device*>& devices )
|
void Init( std::vector<ControllerInterface::Device*>& devices )
|
||||||
{
|
{
|
||||||
XINPUT_CAPABILITIES caps;
|
XINPUT_CAPABILITIES caps;
|
||||||
for ( int i = 0; i < 4; ++i )
|
for ( int i = 0; i < 4; ++i )
|
||||||
if ( ERROR_SUCCESS == XInputGetCapabilities( i, 0, &caps ) )
|
if ( ERROR_SUCCESS == XInputGetCapabilities( i, 0, &caps ) )
|
||||||
devices.push_back( new Device( &caps, i ) );
|
devices.push_back( new Device( &caps, i ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Device::Device( const XINPUT_CAPABILITIES* const caps, const unsigned int index )
|
Device::Device( const XINPUT_CAPABILITIES* const caps, const unsigned int index )
|
||||||
: m_index(index), m_subtype(caps->SubType)
|
: m_index(index), m_subtype(caps->SubType)
|
||||||
{
|
{
|
||||||
ZeroMemory( &m_state_out, sizeof(m_state_out) );
|
ZeroMemory( &m_state_out, sizeof(m_state_out) );
|
||||||
|
|
||||||
// XInputGetCaps seems to always claim all capabilities are supported
|
// XInputGetCaps seems to always claim all capabilities are supported
|
||||||
// but i will leave all this stuff in, incase m$ fixes xinput up a bit
|
// but i will leave all this stuff in, incase m$ fixes xinput up a bit
|
||||||
|
|
||||||
// get supported buttons
|
// get supported buttons
|
||||||
for ( int i = 0; i < sizeof(named_buttons)/sizeof(*named_buttons); ++i )
|
for ( int i = 0; i < sizeof(named_buttons)/sizeof(*named_buttons); ++i )
|
||||||
if ( named_buttons[i].bitmask & caps->Gamepad.wButtons )
|
if ( named_buttons[i].bitmask & caps->Gamepad.wButtons )
|
||||||
inputs.push_back( new Button( /*xinput_named_buttons[i].bitmask, */i ) );
|
inputs.push_back( new Button( /*xinput_named_buttons[i].bitmask, */i ) );
|
||||||
|
|
||||||
// get supported triggers
|
// get supported triggers
|
||||||
for ( int i = 0; i < sizeof(named_triggers)/sizeof(*named_triggers); ++i )
|
for ( int i = 0; i < sizeof(named_triggers)/sizeof(*named_triggers); ++i )
|
||||||
{
|
{
|
||||||
//BYTE val = (&caps->Gamepad.bLeftTrigger)[i]; // should be max value / msdn lies
|
//BYTE val = (&caps->Gamepad.bLeftTrigger)[i]; // should be max value / msdn lies
|
||||||
if ( (&caps->Gamepad.bLeftTrigger)[i] )
|
if ( (&caps->Gamepad.bLeftTrigger)[i] )
|
||||||
inputs.push_back( new Trigger( i, 255 ) );
|
inputs.push_back( new Trigger( i, 255 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// get supported axes
|
// get supported axes
|
||||||
for ( int i = 0; i < sizeof(named_axes)/sizeof(*named_axes); ++i )
|
for ( int i = 0; i < sizeof(named_axes)/sizeof(*named_axes); ++i )
|
||||||
{
|
{
|
||||||
//SHORT val = (&caps->Gamepad.sThumbLX)[i]; // xinput doesnt give the range / msdn is lier
|
//SHORT val = (&caps->Gamepad.sThumbLX)[i]; // xinput doesnt give the range / msdn is lier
|
||||||
if ( (&caps->Gamepad.sThumbLX)[i] )
|
if ( (&caps->Gamepad.sThumbLX)[i] )
|
||||||
{
|
{
|
||||||
// each axis gets a negative and a positive input instance associated with it
|
// each axis gets a negative and a positive input instance associated with it
|
||||||
inputs.push_back( new Axis( i, -32768 ) );
|
inputs.push_back( new Axis( i, -32768 ) );
|
||||||
inputs.push_back( new Axis( i, 32767 ) );
|
inputs.push_back( new Axis( i, 32767 ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get supported motors
|
// get supported motors
|
||||||
for ( int i = 0; i < sizeof(named_motors)/sizeof(*named_motors); ++i )
|
for ( int i = 0; i < sizeof(named_motors)/sizeof(*named_motors); ++i )
|
||||||
{
|
{
|
||||||
//WORD val = (&caps->Vibration.wLeftMotorSpeed)[i]; // should be max value / nope, more lies
|
//WORD val = (&caps->Vibration.wLeftMotorSpeed)[i]; // should be max value / nope, more lies
|
||||||
if ( (&caps->Vibration.wLeftMotorSpeed)[i] )
|
if ( (&caps->Vibration.wLeftMotorSpeed)[i] )
|
||||||
outputs.push_back( new Motor(i, 65535 ) );
|
outputs.push_back( new Motor(i, 65535 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
ClearInputState();
|
ClearInputState();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::ClearInputState()
|
void Device::ClearInputState()
|
||||||
{
|
{
|
||||||
ZeroMemory( &m_state_in, sizeof(m_state_in) );
|
ZeroMemory( &m_state_in, sizeof(m_state_in) );
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Device::GetName() const
|
std::string Device::GetName() const
|
||||||
{
|
{
|
||||||
// why aren't these defined
|
// why aren't these defined
|
||||||
// subtype doesn't seem to work, i tested with 2 diff arcade sticks, both were shown as gamepad
|
// subtype doesn't seem to work, i tested with 2 diff arcade sticks, both were shown as gamepad
|
||||||
// ill leave it in anyway, maybe m$ will fix it
|
// ill leave it in anyway, maybe m$ will fix it
|
||||||
|
|
||||||
switch ( m_subtype )
|
switch ( m_subtype )
|
||||||
{
|
{
|
||||||
case XINPUT_DEVSUBTYPE_GAMEPAD : return "Gamepad"; break;
|
case XINPUT_DEVSUBTYPE_GAMEPAD : return "Gamepad"; break;
|
||||||
case 0x02 /*XINPUT_DEVSUBTYPE_WHEEL*/ : return "Wheel"; break;
|
case 0x02 /*XINPUT_DEVSUBTYPE_WHEEL*/ : return "Wheel"; break;
|
||||||
case 0x03 /*XINPUT_DEVSUBTYPE_ARCADE_STICK*/ : return "Arcade Stick"; break;
|
case 0x03 /*XINPUT_DEVSUBTYPE_ARCADE_STICK*/ : return "Arcade Stick"; break;
|
||||||
case 0x04 /*XINPUT_DEVSUBTYPE_FLIGHT_STICK*/ : return "Flight Stick"; break;
|
case 0x04 /*XINPUT_DEVSUBTYPE_FLIGHT_STICK*/ : return "Flight Stick"; break;
|
||||||
case 0x05 /*XINPUT_DEVSUBTYPE_DANCE_PAD*/ : return "Dance Pad"; break;
|
case 0x05 /*XINPUT_DEVSUBTYPE_DANCE_PAD*/ : return "Dance Pad"; break;
|
||||||
case 0x06 /*XINPUT_DEVSUBTYPE_GUITAR*/ : return "Guitar"; break;
|
case 0x06 /*XINPUT_DEVSUBTYPE_GUITAR*/ : return "Guitar"; break;
|
||||||
case 0x08 /*XINPUT_DEVSUBTYPE_DRUM_KIT*/ : return "Drum Kit"; break;
|
case 0x08 /*XINPUT_DEVSUBTYPE_DRUM_KIT*/ : return "Drum Kit"; break;
|
||||||
default : return "Device"; break;
|
default : return "Device"; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Device::GetId() const
|
int Device::GetId() const
|
||||||
{
|
{
|
||||||
return m_index;
|
return m_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Device::GetSource() const
|
std::string Device::GetSource() const
|
||||||
{
|
{
|
||||||
return "XInput";
|
return "XInput";
|
||||||
}
|
}
|
||||||
|
|
||||||
// update i/o
|
// update i/o
|
||||||
|
|
||||||
bool Device::UpdateInput()
|
bool Device::UpdateInput()
|
||||||
{
|
{
|
||||||
return ( ERROR_SUCCESS == XInputGetState( m_index, &m_state_in ) );
|
return ( ERROR_SUCCESS == XInputGetState( m_index, &m_state_in ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Device::UpdateOutput()
|
bool Device::UpdateOutput()
|
||||||
{
|
{
|
||||||
return ( ERROR_SUCCESS == XInputSetState( m_index, &m_state_out ) );
|
return ( ERROR_SUCCESS == XInputSetState( m_index, &m_state_out ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET name/source/id
|
// GET name/source/id
|
||||||
|
|
||||||
|
|
||||||
std::string Device::Button::GetName() const
|
std::string Device::Button::GetName() const
|
||||||
{
|
{
|
||||||
return named_buttons[m_index].name;
|
return named_buttons[m_index].name;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Device::Axis::GetName() const
|
std::string Device::Axis::GetName() const
|
||||||
{
|
{
|
||||||
return std::string(named_axes[m_index]) + ( m_range>0 ? '+' : '-' );
|
return std::string(named_axes[m_index]) + ( m_range>0 ? '+' : '-' );
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Device::Trigger::GetName() const
|
std::string Device::Trigger::GetName() const
|
||||||
{
|
{
|
||||||
return named_triggers[m_index];
|
return named_triggers[m_index];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Device::Motor::GetName() const
|
std::string Device::Motor::GetName() const
|
||||||
{
|
{
|
||||||
return named_motors[m_index];
|
return named_motors[m_index];
|
||||||
}
|
}
|
||||||
|
|
||||||
// get/set control state
|
// get/set control state
|
||||||
|
|
||||||
ControlState Device::GetInputState( const ControllerInterface::Device::Input* const input )
|
ControlState Device::GetInputState( const ControllerInterface::Device::Input* const input )
|
||||||
{
|
{
|
||||||
return ((Input*)input)->GetState( &m_state_in.Gamepad );
|
return ((Input*)input)->GetState( &m_state_in.Gamepad );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::SetOutputState( const ControllerInterface::Device::Output* const output, const ControlState state )
|
void Device::SetOutputState( const ControllerInterface::Device::Output* const output, const ControlState state )
|
||||||
{
|
{
|
||||||
return ((Output*)output)->SetState( state, &m_state_out );
|
return ((Output*)output)->SetState( state, &m_state_out );
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET / SET STATES
|
// GET / SET STATES
|
||||||
|
|
||||||
ControlState Device::Button::GetState( const XINPUT_GAMEPAD* const gamepad )
|
ControlState Device::Button::GetState( const XINPUT_GAMEPAD* const gamepad )
|
||||||
{
|
{
|
||||||
return (gamepad->wButtons & named_buttons[m_index].bitmask) > 0;
|
return (gamepad->wButtons & named_buttons[m_index].bitmask) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ControlState Device::Trigger::GetState( const XINPUT_GAMEPAD* const gamepad )
|
ControlState Device::Trigger::GetState( const XINPUT_GAMEPAD* const gamepad )
|
||||||
{
|
{
|
||||||
return ControlState((&gamepad->bLeftTrigger)[m_index]) / m_range;
|
return ControlState((&gamepad->bLeftTrigger)[m_index]) / m_range;
|
||||||
}
|
}
|
||||||
|
|
||||||
ControlState Device::Axis::GetState( const XINPUT_GAMEPAD* const gamepad )
|
ControlState Device::Axis::GetState( const XINPUT_GAMEPAD* const gamepad )
|
||||||
{
|
{
|
||||||
return std::max( 0.0f, ControlState((&gamepad->sThumbLX)[m_index]) / m_range );
|
return std::max( 0.0f, ControlState((&gamepad->sThumbLX)[m_index]) / m_range );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::Motor::SetState( const ControlState state, XINPUT_VIBRATION* const vibration )
|
void Device::Motor::SetState( const ControlState state, XINPUT_VIBRATION* const vibration )
|
||||||
{
|
{
|
||||||
(&vibration->wLeftMotorSpeed)[m_index] = (WORD)(state * m_range);
|
(&vibration->wLeftMotorSpeed)[m_index] = (WORD)(state * m_range);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,116 +1,116 @@
|
||||||
#ifndef _CIFACE_XINPUT_H_
|
#ifndef _CIFACE_XINPUT_H_
|
||||||
#define _CIFACE_XINPUT_H_
|
#define _CIFACE_XINPUT_H_
|
||||||
|
|
||||||
#include "../ControllerInterface.h"
|
#include "../ControllerInterface.h"
|
||||||
|
|
||||||
#define NOMINMAX
|
#define NOMINMAX
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <XInput.h>
|
#include <XInput.h>
|
||||||
|
|
||||||
namespace ciface
|
namespace ciface
|
||||||
{
|
{
|
||||||
namespace XInput
|
namespace XInput
|
||||||
{
|
{
|
||||||
|
|
||||||
void Init( std::vector<ControllerInterface::Device*>& devices );
|
void Init( std::vector<ControllerInterface::Device*>& devices );
|
||||||
|
|
||||||
class Device : public ControllerInterface::Device
|
class Device : public ControllerInterface::Device
|
||||||
{
|
{
|
||||||
friend class ControllerInterface;
|
friend class ControllerInterface;
|
||||||
friend class ControllerInterface::ControlReference;
|
friend class ControllerInterface::ControlReference;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
class Input : public ControllerInterface::Device::Input
|
class Input : public ControllerInterface::Device::Input
|
||||||
{
|
{
|
||||||
friend class Device;
|
friend class Device;
|
||||||
protected:
|
protected:
|
||||||
virtual ControlState GetState( const XINPUT_GAMEPAD* const gamepad ) = 0;
|
virtual ControlState GetState( const XINPUT_GAMEPAD* const gamepad ) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Output : public ControllerInterface::Device::Output
|
class Output : public ControllerInterface::Device::Output
|
||||||
{
|
{
|
||||||
friend class Device;
|
friend class Device;
|
||||||
protected:
|
protected:
|
||||||
virtual void SetState( const ControlState state, XINPUT_VIBRATION* const vibration ) = 0;
|
virtual void SetState( const ControlState state, XINPUT_VIBRATION* const vibration ) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Button : public Input
|
class Button : public Input
|
||||||
{
|
{
|
||||||
friend class Device;
|
friend class Device;
|
||||||
public:
|
public:
|
||||||
std::string GetName() const;
|
std::string GetName() const;
|
||||||
protected:
|
protected:
|
||||||
Button( const unsigned int index ) : m_index(index) {}
|
Button( const unsigned int index ) : m_index(index) {}
|
||||||
ControlState GetState( const XINPUT_GAMEPAD* const gamepad );
|
ControlState GetState( const XINPUT_GAMEPAD* const gamepad );
|
||||||
private:
|
private:
|
||||||
const unsigned int m_index;
|
const unsigned int m_index;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Axis : public Input
|
class Axis : public Input
|
||||||
{
|
{
|
||||||
friend class Device;
|
friend class Device;
|
||||||
public:
|
public:
|
||||||
std::string GetName() const;
|
std::string GetName() const;
|
||||||
protected:
|
protected:
|
||||||
Axis( const unsigned int index, const SHORT range ) : m_index(index), m_range(range) {}
|
Axis( const unsigned int index, const SHORT range ) : m_index(index), m_range(range) {}
|
||||||
ControlState GetState( const XINPUT_GAMEPAD* const gamepad );
|
ControlState GetState( const XINPUT_GAMEPAD* const gamepad );
|
||||||
private:
|
private:
|
||||||
const unsigned int m_index;
|
const unsigned int m_index;
|
||||||
const SHORT m_range;
|
const SHORT m_range;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Trigger : public Input
|
class Trigger : public Input
|
||||||
{
|
{
|
||||||
friend class Device;
|
friend class Device;
|
||||||
public:
|
public:
|
||||||
std::string GetName() const;
|
std::string GetName() const;
|
||||||
protected:
|
protected:
|
||||||
Trigger( const unsigned int index, const BYTE range ) : m_index(index), m_range(range) {}
|
Trigger( const unsigned int index, const BYTE range ) : m_index(index), m_range(range) {}
|
||||||
ControlState GetState( const XINPUT_GAMEPAD* const gamepad );
|
ControlState GetState( const XINPUT_GAMEPAD* const gamepad );
|
||||||
private:
|
private:
|
||||||
const unsigned int m_index;
|
const unsigned int m_index;
|
||||||
const BYTE m_range;
|
const BYTE m_range;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Motor : public Output
|
class Motor : public Output
|
||||||
{
|
{
|
||||||
friend class Device;
|
friend class Device;
|
||||||
public:
|
public:
|
||||||
std::string GetName() const;
|
std::string GetName() const;
|
||||||
protected:
|
protected:
|
||||||
Motor( const unsigned int index, const WORD range ) : m_index(index), m_range(range) {}
|
Motor( const unsigned int index, const WORD range ) : m_index(index), m_range(range) {}
|
||||||
void SetState( const ControlState state, XINPUT_VIBRATION* const vibration );
|
void SetState( const ControlState state, XINPUT_VIBRATION* const vibration );
|
||||||
private:
|
private:
|
||||||
const unsigned int m_index;
|
const unsigned int m_index;
|
||||||
const WORD m_range;
|
const WORD m_range;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool UpdateInput();
|
bool UpdateInput();
|
||||||
bool UpdateOutput();
|
bool UpdateOutput();
|
||||||
|
|
||||||
ControlState GetInputState( const ControllerInterface::Device::Input* const input );
|
ControlState GetInputState( const ControllerInterface::Device::Input* const input );
|
||||||
void SetOutputState( const ControllerInterface::Device::Output* const input, const ControlState state );
|
void SetOutputState( const ControllerInterface::Device::Output* const input, const ControlState state );
|
||||||
|
|
||||||
void ClearInputState();
|
void ClearInputState();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Device( const XINPUT_CAPABILITIES* const capabilities, const unsigned int index );
|
Device( const XINPUT_CAPABILITIES* const capabilities, const unsigned int index );
|
||||||
|
|
||||||
std::string GetName() const;
|
std::string GetName() const;
|
||||||
int GetId() const;
|
int GetId() const;
|
||||||
std::string GetSource() const;
|
std::string GetSource() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const unsigned int m_index;
|
const unsigned int m_index;
|
||||||
XINPUT_STATE m_state_in;
|
XINPUT_STATE m_state_in;
|
||||||
XINPUT_VIBRATION m_state_out;
|
XINPUT_VIBRATION m_state_out;
|
||||||
const unsigned int m_subtype;
|
const unsigned int m_subtype;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,98 +1,98 @@
|
||||||
#include "../ControllerInterface.h"
|
#include "../ControllerInterface.h"
|
||||||
|
|
||||||
#ifdef CIFACE_USE_XLIB
|
#ifdef CIFACE_USE_XLIB
|
||||||
|
|
||||||
#include "Xlib.h"
|
#include "Xlib.h"
|
||||||
|
|
||||||
namespace ciface
|
namespace ciface
|
||||||
{
|
{
|
||||||
namespace Xlib
|
namespace Xlib
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
void Init( std::vector<ControllerInterface::Device*>& devices, void* const hwnd )
|
void Init( std::vector<ControllerInterface::Device*>& devices, void* const hwnd )
|
||||||
{
|
{
|
||||||
// mouse will be added to this, Keyboard class will be turned into KeyboardMouse
|
// mouse will be added to this, Keyboard class will be turned into KeyboardMouse
|
||||||
// single device for combined keyboard/mouse, this will allow combinations like shift+click more easily
|
// single device for combined keyboard/mouse, this will allow combinations like shift+click more easily
|
||||||
devices.push_back( new Keyboard( (Display*)display ) );
|
devices.push_back( new Keyboard( (Display*)display ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
Keyboard::Keyboard( Display* const display ) : m_display(display)
|
Keyboard::Keyboard( Display* const display ) : m_display(display)
|
||||||
{
|
{
|
||||||
|
|
||||||
memset( &m_state, 0, sizeof(m_state) );
|
memset( &m_state, 0, sizeof(m_state) );
|
||||||
|
|
||||||
// this is probably dumb
|
// this is probably dumb
|
||||||
for ( KeySym i = 0; i < 1024; ++i )
|
for ( KeySym i = 0; i < 1024; ++i )
|
||||||
{
|
{
|
||||||
if ( XKeysymToString( m_keysym ) ) // if it isnt NULL
|
if ( XKeysymToString( m_keysym ) ) // if it isnt NULL
|
||||||
inputs.push_back( new Key( i ) );
|
inputs.push_back( new Key( i ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Keyboard::~Keyboard()
|
Keyboard::~Keyboard()
|
||||||
{
|
{
|
||||||
// might not need this func
|
// might not need this func
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ControlState Keyboard::GetInputState( const ControllerInterface::Device::Input* const input )
|
ControlState Keyboard::GetInputState( const ControllerInterface::Device::Input* const input )
|
||||||
{
|
{
|
||||||
return ((Input*)input)->GetState( &m_state );
|
return ((Input*)input)->GetState( &m_state );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Keyboard::SetOutputState( const ControllerInterface::Device::Output* const output, const ControlState state )
|
void Keyboard::SetOutputState( const ControllerInterface::Device::Output* const output, const ControlState state )
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Keyboard::UpdateInput()
|
bool Keyboard::UpdateInput()
|
||||||
{
|
{
|
||||||
XQueryKeymap( m_display, m_state.keyboard );
|
XQueryKeymap( m_display, m_state.keyboard );
|
||||||
|
|
||||||
// mouse stuff in here too
|
// mouse stuff in here too
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Keyboard::UpdateOutput()
|
bool Keyboard::UpdateOutput()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string Keyboard::GetName() const
|
std::string Keyboard::GetName() const
|
||||||
{
|
{
|
||||||
return "Keyboard";
|
return "Keyboard";
|
||||||
//return "Keyboard Mouse"; // change to this later
|
//return "Keyboard Mouse"; // change to this later
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Keyboard::GetSource() const
|
std::string Keyboard::GetSource() const
|
||||||
{
|
{
|
||||||
return "Xlib";
|
return "Xlib";
|
||||||
}
|
}
|
||||||
|
|
||||||
int Keyboard::GetId() const
|
int Keyboard::GetId() const
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ControlState Keyboard::Key::GetState( const State* const state )
|
ControlState Keyboard::Key::GetState( const State* const state )
|
||||||
{
|
{
|
||||||
key_code = XKeysymToKeycode(m_display, m_keysym );
|
key_code = XKeysymToKeycode(m_display, m_keysym );
|
||||||
return (state->keyboard[key_code/8] & (1 << (key_code%8))); // need >0 ?
|
return (state->keyboard[key_code/8] & (1 << (key_code%8))); // need >0 ?
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Keyboard::Key::GetName() const
|
std::string Keyboard::Key::GetName() const
|
||||||
{
|
{
|
||||||
return XKeysymToString( m_keysym );
|
return XKeysymToString( m_keysym );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,70 +1,70 @@
|
||||||
#ifndef _CIFACE_XLIB_H_
|
#ifndef _CIFACE_XLIB_H_
|
||||||
#define _CIFACE_XLIB_H_
|
#define _CIFACE_XLIB_H_
|
||||||
|
|
||||||
#include "../ControllerInterface.h"
|
#include "../ControllerInterface.h"
|
||||||
|
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
|
||||||
namespace ciface
|
namespace ciface
|
||||||
{
|
{
|
||||||
namespace XInput
|
namespace XInput
|
||||||
{
|
{
|
||||||
|
|
||||||
void Init( std::vector<ControllerInterface::Device*>& devices, void* const hwnd );
|
void Init( std::vector<ControllerInterface::Device*>& devices, void* const hwnd );
|
||||||
|
|
||||||
class Keyboard : public ControllerInterface::Device
|
class Keyboard : public ControllerInterface::Device
|
||||||
{
|
{
|
||||||
friend class ControllerInterface;
|
friend class ControllerInterface;
|
||||||
friend class ControllerInterface::ControlReference;
|
friend class ControllerInterface::ControlReference;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
struct State
|
struct State
|
||||||
{
|
{
|
||||||
char keyboard[32];
|
char keyboard[32];
|
||||||
// mouse crap will go here
|
// mouse crap will go here
|
||||||
};
|
};
|
||||||
|
|
||||||
class Input : public ControllerInterface::Input
|
class Input : public ControllerInterface::Input
|
||||||
{
|
{
|
||||||
friend class Keyboard;
|
friend class Keyboard;
|
||||||
protected:
|
protected:
|
||||||
ControlState GetState( const State* const state ) = 0;
|
ControlState GetState( const State* const state ) = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Key : public Input
|
class Key : public Input
|
||||||
{
|
{
|
||||||
friend class Keyboard;
|
friend class Keyboard;
|
||||||
public:
|
public:
|
||||||
std::string GetName() const;
|
std::string GetName() const;
|
||||||
protected:
|
protected:
|
||||||
Key( KeySym keysym ) : m_keysym(keysym) {}
|
Key( KeySym keysym ) : m_keysym(keysym) {}
|
||||||
ControlState GetState( const State* const state );
|
ControlState GetState( const State* const state );
|
||||||
private:
|
private:
|
||||||
const KeySym m_keysym
|
const KeySym m_keysym
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
bool UpdateInput();
|
bool UpdateInput();
|
||||||
bool UpdateOutput();
|
bool UpdateOutput();
|
||||||
|
|
||||||
ControlState Keyboard::GetInputState( const ControllerInterface::Device::Input* const input );
|
ControlState Keyboard::GetInputState( const ControllerInterface::Device::Input* const input );
|
||||||
void Keyboard::SetOutputState( const ControllerInterface::Device::Output* const output, const ControlState state );
|
void Keyboard::SetOutputState( const ControllerInterface::Device::Output* const output, const ControlState state );
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Keyboard( Display* const display );
|
Keyboard( Display* const display );
|
||||||
~Keyboard();
|
~Keyboard();
|
||||||
|
|
||||||
std::string GetName() const;
|
std::string GetName() const;
|
||||||
std::string GetSource() const;
|
std::string GetSource() const;
|
||||||
int GetId() const;
|
int GetId() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Display* const m_display;
|
Display* const m_display;
|
||||||
State m_state;
|
State m_state;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,357 +1,362 @@
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "pluginspecs_pad.h"
|
#include "pluginspecs_pad.h"
|
||||||
#include "pluginspecs_wiimote.h"
|
#include "pluginspecs_wiimote.h"
|
||||||
|
|
||||||
#include "ControllerInterface/ControllerInterface.h"
|
#include "ControllerInterface/ControllerInterface.h"
|
||||||
#if defined(HAVE_WX) && HAVE_WX
|
#if defined(HAVE_WX) && HAVE_WX
|
||||||
#include "ConfigDiag.h"
|
#include "ConfigDiag.h"
|
||||||
#endif
|
#endif
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
|
||||||
#define CIFACE_PLUGIN_VERSION 0x0100
|
#if defined(HAVE_X11) && HAVE_X11
|
||||||
|
#include <X11/Xlib.h>
|
||||||
#define CIFACE_PLUGIN_BRANDING /*"Billiard's"//*/"Dolphin"
|
Display* GCdisplay;
|
||||||
#define CIFACE_PLUGIN_TYPE "GCPad"
|
#endif
|
||||||
#define CIFACE_PLUGIN_NAME "New"
|
|
||||||
//#define CIFACE_PLUGIN_VERSTR "v1.0"
|
#define CIFACE_PLUGIN_VERSION 0x0100
|
||||||
|
|
||||||
#define CIFACE_PLUGIN_FULL_NAME CIFACE_PLUGIN_BRANDING" "CIFACE_PLUGIN_TYPE" "CIFACE_PLUGIN_NAME//" "CIFACE_PLUGIN_VERSTR
|
#define CIFACE_PLUGIN_BRANDING /*"Billiard's"//*/"Dolphin"
|
||||||
|
#define CIFACE_PLUGIN_TYPE "GCPad"
|
||||||
#ifdef _WIN32
|
#define CIFACE_PLUGIN_NAME "New"
|
||||||
class wxDLLApp : public wxApp
|
//#define CIFACE_PLUGIN_VERSTR "v1.0"
|
||||||
{
|
|
||||||
bool OnInit()
|
#define CIFACE_PLUGIN_FULL_NAME CIFACE_PLUGIN_BRANDING" "CIFACE_PLUGIN_TYPE" "CIFACE_PLUGIN_NAME//" "CIFACE_PLUGIN_VERSTR
|
||||||
{
|
|
||||||
return true;
|
#ifdef _WIN32
|
||||||
};
|
class wxDLLApp : public wxApp
|
||||||
};
|
{
|
||||||
IMPLEMENT_APP_NO_MAIN(wxDLLApp)
|
bool OnInit()
|
||||||
WXDLLIMPEXP_BASE void wxSetInstance(HINSTANCE hInst);
|
{
|
||||||
#endif
|
return true;
|
||||||
// copied from GCPad
|
};
|
||||||
SPADInitialize *g_PADInitialize = NULL;
|
};
|
||||||
// Check if Dolphin is in focus
|
IMPLEMENT_APP_NO_MAIN(wxDLLApp)
|
||||||
// ----------------
|
WXDLLIMPEXP_BASE void wxSetInstance(HINSTANCE hInst);
|
||||||
bool IsFocus()
|
#endif
|
||||||
{
|
// copied from GCPad
|
||||||
#ifdef _WIN32
|
SPADInitialize *g_PADInitialize = NULL;
|
||||||
HWND RenderingWindow = (g_PADInitialize) ? g_PADInitialize->hWnd : NULL;
|
// Check if Dolphin is in focus
|
||||||
HWND Parent = GetParent(RenderingWindow);
|
// ----------------
|
||||||
HWND TopLevel = GetParent(Parent);
|
bool IsFocus()
|
||||||
|
{
|
||||||
if (GetForegroundWindow() == TopLevel || GetForegroundWindow() == RenderingWindow)
|
#ifdef _WIN32
|
||||||
return true;
|
HWND RenderingWindow = (g_PADInitialize) ? g_PADInitialize->hWnd : NULL;
|
||||||
else
|
HWND Parent = GetParent(RenderingWindow);
|
||||||
return false;
|
HWND TopLevel = GetParent(Parent);
|
||||||
#elif defined HAVE_X11 && HAVE_X11
|
|
||||||
Window GLWin = *(Window *)g_PADInitialize->pXWindow;
|
if (GetForegroundWindow() == TopLevel || GetForegroundWindow() == RenderingWindow)
|
||||||
Window FocusWin;
|
return true;
|
||||||
int Revert;
|
else
|
||||||
XGetInputFocus((Display*)g_PADInitialize->hWnd, &FocusWin, &Revert);
|
return false;
|
||||||
XWindowAttributes WinAttribs;
|
#elif defined HAVE_X11 && HAVE_X11
|
||||||
XGetWindowAttributes (GCdisplay, GLWin, &WinAttribs);
|
Window GLWin = *(Window *)g_PADInitialize->pXWindow;
|
||||||
return (GLWin != 0 && (GLWin == FocusWin || WinAttribs.override_redirect));
|
Window FocusWin;
|
||||||
#else
|
int Revert;
|
||||||
return true;
|
XGetInputFocus((Display*)g_PADInitialize->hWnd, &FocusWin, &Revert);
|
||||||
#endif
|
XWindowAttributes WinAttribs;
|
||||||
}
|
XGetWindowAttributes (GCdisplay, GLWin, &WinAttribs);
|
||||||
|
return (GLWin != 0 && (GLWin == FocusWin || WinAttribs.override_redirect));
|
||||||
// copied from GCPad
|
#else
|
||||||
HINSTANCE g_hInstance;
|
return true;
|
||||||
|
#endif
|
||||||
// copied from GCPad
|
}
|
||||||
#if defined(HAVE_WX) && HAVE_WX
|
|
||||||
wxWindow* GetParentedWxWindow(HWND Parent)
|
// copied from GCPad
|
||||||
{
|
HINSTANCE g_hInstance;
|
||||||
#ifdef _WIN32
|
|
||||||
wxSetInstance((HINSTANCE)g_hInstance);
|
// copied from GCPad
|
||||||
#endif
|
#if defined(HAVE_WX) && HAVE_WX
|
||||||
wxWindow *win = new wxWindow();
|
wxWindow* GetParentedWxWindow(HWND Parent)
|
||||||
#ifdef _WIN32
|
{
|
||||||
win->SetHWND((WXHWND)Parent);
|
#ifdef _WIN32
|
||||||
win->AdoptAttributesFromHWND();
|
wxSetInstance((HINSTANCE)g_hInstance);
|
||||||
#endif
|
#endif
|
||||||
return win;
|
wxWindow *win = new wxWindow();
|
||||||
}
|
#ifdef _WIN32
|
||||||
#endif
|
win->SetHWND((WXHWND)Parent);
|
||||||
// /
|
win->AdoptAttributesFromHWND();
|
||||||
|
#endif
|
||||||
// the plugin
|
return win;
|
||||||
Plugin g_plugin;
|
}
|
||||||
#ifdef _WIN32
|
#endif
|
||||||
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved )
|
// /
|
||||||
{
|
|
||||||
switch (fdwReason)
|
// the plugin
|
||||||
{
|
Plugin g_plugin;
|
||||||
case DLL_PROCESS_ATTACH:
|
#ifdef _WIN32
|
||||||
wxSetInstance(hinstDLL);
|
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved )
|
||||||
wxInitialize();
|
{
|
||||||
break;
|
switch (fdwReason)
|
||||||
case DLL_PROCESS_DETACH:
|
{
|
||||||
wxUninitialize();
|
case DLL_PROCESS_ATTACH:
|
||||||
break;
|
wxSetInstance(hinstDLL);
|
||||||
default:
|
wxInitialize();
|
||||||
break;
|
break;
|
||||||
}
|
case DLL_PROCESS_DETACH:
|
||||||
|
wxUninitialize();
|
||||||
g_hInstance = hinstDLL;
|
break;
|
||||||
return TRUE;
|
default:
|
||||||
}
|
break;
|
||||||
#endif
|
}
|
||||||
|
|
||||||
|
g_hInstance = hinstDLL;
|
||||||
// wut ??
|
return TRUE;
|
||||||
#define EXPORT
|
}
|
||||||
#define CALL
|
#endif
|
||||||
|
|
||||||
int _last_numPAD = 4;
|
|
||||||
|
// wut ??
|
||||||
|
#define EXPORT
|
||||||
// if plugin isn't initialized, init and load config
|
#define CALL
|
||||||
void InitPlugin( void* const hwnd )
|
|
||||||
{
|
int _last_numPAD = 4;
|
||||||
//g_plugin.controls_crit.Enter(); // enter
|
|
||||||
//g_plugin.interface_crit.Enter();
|
|
||||||
|
// if plugin isn't initialized, init and load config
|
||||||
if ( false == g_plugin.controller_interface.IsInit() )
|
void InitPlugin( void* const hwnd )
|
||||||
{
|
{
|
||||||
// load the saved controller config
|
//g_plugin.controls_crit.Enter(); // enter
|
||||||
g_plugin.LoadConfig();
|
//g_plugin.interface_crit.Enter();
|
||||||
|
|
||||||
// needed for Xlib and exclusive dinput
|
if ( false == g_plugin.controller_interface.IsInit() )
|
||||||
g_plugin.controller_interface.SetHwnd( hwnd );
|
{
|
||||||
g_plugin.controller_interface.Init();
|
// load the saved controller config
|
||||||
|
g_plugin.LoadConfig();
|
||||||
// update control refs
|
|
||||||
std::vector<ControllerEmu*>::const_iterator i = g_plugin.controllers.begin(),
|
// needed for Xlib and exclusive dinput
|
||||||
e = g_plugin.controllers.end();
|
g_plugin.controller_interface.SetHwnd( hwnd );
|
||||||
for ( ; i!=e; ++i )
|
g_plugin.controller_interface.Init();
|
||||||
(*i)->UpdateReferences( g_plugin.controller_interface );
|
|
||||||
|
// update control refs
|
||||||
}
|
std::vector<ControllerEmu*>::const_iterator i = g_plugin.controllers.begin(),
|
||||||
|
e = g_plugin.controllers.end();
|
||||||
//g_plugin.interface_crit.Leave();
|
for ( ; i!=e; ++i )
|
||||||
//g_plugin.controls_crit.Leave(); // leave
|
(*i)->UpdateReferences( g_plugin.controller_interface );
|
||||||
}
|
|
||||||
|
}
|
||||||
// I N T E R F A C E
|
|
||||||
|
//g_plugin.interface_crit.Leave();
|
||||||
// __________________________________________________________________________________________________
|
//g_plugin.controls_crit.Leave(); // leave
|
||||||
// Function:
|
}
|
||||||
// Purpose:
|
|
||||||
// input:
|
// I N T E R F A C E
|
||||||
// output:
|
|
||||||
//
|
// __________________________________________________________________________________________________
|
||||||
EXPORT void CALL PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
|
// Function:
|
||||||
{
|
// Purpose:
|
||||||
// why not, i guess
|
// input:
|
||||||
if ( NULL == _pPADStatus )
|
// output:
|
||||||
return;
|
//
|
||||||
|
EXPORT void CALL PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
|
||||||
memset( _pPADStatus, 0, sizeof(*_pPADStatus) );
|
{
|
||||||
_pPADStatus->err = PAD_ERR_NONE;
|
// why not, i guess
|
||||||
// wtf is this?
|
if ( NULL == _pPADStatus )
|
||||||
_pPADStatus->button |= PAD_USE_ORIGIN;
|
return;
|
||||||
|
|
||||||
// TODO: this will need changing
|
memset( _pPADStatus, 0, sizeof(*_pPADStatus) );
|
||||||
// need focus ?
|
_pPADStatus->err = PAD_ERR_NONE;
|
||||||
// i'm not inside CritSec when I access this bool
|
// wtf is this?
|
||||||
//if ( false == (g_plugin.pads[_numPAD].options.allow_background_input || IsFocus()) )
|
_pPADStatus->button |= PAD_USE_ORIGIN;
|
||||||
//{
|
|
||||||
// // center axes and return
|
// TODO: this will need changing
|
||||||
// memset( &_pPADStatus->stickX, 0x80, 4 );
|
// need focus ?
|
||||||
// return;
|
// i'm not inside CritSec when I access this bool
|
||||||
//}
|
//if ( false == (g_plugin.pads[_numPAD].options.allow_background_input || IsFocus()) )
|
||||||
|
//{
|
||||||
// try lock
|
// // center axes and return
|
||||||
if ( false == g_plugin.controls_crit.TryEnter() )
|
// memset( &_pPADStatus->stickX, 0x80, 4 );
|
||||||
{
|
// return;
|
||||||
// if gui has lock (messing with controls), skip this input cycle
|
//}
|
||||||
// center axes and return
|
|
||||||
memset( &_pPADStatus->stickX, 0x80, 4 );
|
// try lock
|
||||||
return;
|
if ( false == g_plugin.controls_crit.TryEnter() )
|
||||||
}
|
{
|
||||||
|
// if gui has lock (messing with controls), skip this input cycle
|
||||||
// if we are on the next input cycle, update output and input
|
// center axes and return
|
||||||
// if we can get a lock
|
memset( &_pPADStatus->stickX, 0x80, 4 );
|
||||||
if ( _numPAD <= _last_numPAD && g_plugin.interface_crit.TryEnter() )
|
return;
|
||||||
{
|
}
|
||||||
g_plugin.controller_interface.UpdateOutput();
|
|
||||||
g_plugin.controller_interface.UpdateInput();
|
// if we are on the next input cycle, update output and input
|
||||||
g_plugin.interface_crit.Leave();
|
// if we can get a lock
|
||||||
}
|
if ( _numPAD <= _last_numPAD && g_plugin.interface_crit.TryEnter() )
|
||||||
_last_numPAD = _numPAD;
|
{
|
||||||
|
g_plugin.controller_interface.UpdateOutput();
|
||||||
// get input
|
g_plugin.controller_interface.UpdateInput();
|
||||||
((GCPad*)g_plugin.controllers[ _numPAD ])->GetInput( _pPADStatus );
|
g_plugin.interface_crit.Leave();
|
||||||
|
}
|
||||||
// leave
|
_last_numPAD = _numPAD;
|
||||||
g_plugin.controls_crit.Leave();
|
|
||||||
|
// get input
|
||||||
}
|
((GCPad*)g_plugin.controllers[ _numPAD ])->GetInput( _pPADStatus );
|
||||||
|
|
||||||
// __________________________________________________________________________________________________
|
// leave
|
||||||
// Function: Send keyboard input to the plugin
|
g_plugin.controls_crit.Leave();
|
||||||
// Purpose:
|
|
||||||
// input: The key and if it's pressed or released
|
}
|
||||||
// output: None
|
|
||||||
//
|
// __________________________________________________________________________________________________
|
||||||
EXPORT void CALL PAD_Input(u16 _Key, u8 _UpDown)
|
// Function: Send keyboard input to the plugin
|
||||||
{
|
// Purpose:
|
||||||
// nofin
|
// input: The key and if it's pressed or released
|
||||||
}
|
// output: None
|
||||||
|
//
|
||||||
// __________________________________________________________________________________________________
|
EXPORT void CALL PAD_Input(u16 _Key, u8 _UpDown)
|
||||||
// Function: PAD_Rumble
|
{
|
||||||
// Purpose: Pad rumble!
|
// nofin
|
||||||
// input: PAD number, Command type (Stop=0, Rumble=1, Stop Hard=2) and strength of Rumble
|
}
|
||||||
// output: none
|
|
||||||
//
|
// __________________________________________________________________________________________________
|
||||||
EXPORT void CALL PAD_Rumble(u8 _numPAD, unsigned int _uType, unsigned int _uStrength)
|
// Function: PAD_Rumble
|
||||||
{
|
// Purpose: Pad rumble!
|
||||||
// enter
|
// input: PAD number, Command type (Stop=0, Rumble=1, Stop Hard=2) and strength of Rumble
|
||||||
if ( g_plugin.controls_crit.TryEnter() )
|
// output: none
|
||||||
{
|
//
|
||||||
// only on/off rumble
|
EXPORT void CALL PAD_Rumble(u8 _numPAD, unsigned int _uType, unsigned int _uStrength)
|
||||||
((GCPad*)g_plugin.controllers[ _numPAD ])->SetOutput( 1 == _uType && _uStrength > 2 );
|
{
|
||||||
|
// enter
|
||||||
// leave
|
if ( g_plugin.controls_crit.TryEnter() )
|
||||||
g_plugin.controls_crit.Leave();
|
{
|
||||||
}
|
// only on/off rumble
|
||||||
}
|
((GCPad*)g_plugin.controllers[ _numPAD ])->SetOutput( 1 == _uType && _uStrength > 2 );
|
||||||
|
|
||||||
|
// leave
|
||||||
// GLOBAL I N T E R F A C E
|
g_plugin.controls_crit.Leave();
|
||||||
// Function: GetDllInfo
|
}
|
||||||
// Purpose: This function allows the emulator to gather information
|
}
|
||||||
// about the DLL by filling in the PluginInfo structure.
|
|
||||||
// input: A pointer to a PLUGIN_INFO structure that needs to be
|
|
||||||
// filled by the function. (see def above)
|
// GLOBAL I N T E R F A C E
|
||||||
// output: none
|
// Function: GetDllInfo
|
||||||
//
|
// Purpose: This function allows the emulator to gather information
|
||||||
EXPORT void CALL GetDllInfo(PLUGIN_INFO* _pPluginInfo)
|
// about the DLL by filling in the PluginInfo structure.
|
||||||
{
|
// input: A pointer to a PLUGIN_INFO structure that needs to be
|
||||||
// don't feel like messing around with all those strcpy functions and warnings
|
// filled by the function. (see def above)
|
||||||
//char *s1 = CIFACE_PLUGIN_FULL_NAME, *s2 = _pPluginInfo->Name;
|
// output: none
|
||||||
//while ( *s2++ = *s1++ );
|
//
|
||||||
memcpy( _pPluginInfo->Name, CIFACE_PLUGIN_FULL_NAME, sizeof(CIFACE_PLUGIN_FULL_NAME) );
|
EXPORT void CALL GetDllInfo(PLUGIN_INFO* _pPluginInfo)
|
||||||
_pPluginInfo->Type = PLUGIN_TYPE_PAD;
|
{
|
||||||
_pPluginInfo->Version = CIFACE_PLUGIN_VERSION;
|
// don't feel like messing around with all those strcpy functions and warnings
|
||||||
}
|
//char *s1 = CIFACE_PLUGIN_FULL_NAME, *s2 = _pPluginInfo->Name;
|
||||||
|
//while ( *s2++ = *s1++ );
|
||||||
// ___________________________________________________________________________
|
memcpy( _pPluginInfo->Name, CIFACE_PLUGIN_FULL_NAME, sizeof(CIFACE_PLUGIN_FULL_NAME) );
|
||||||
// Function: DllConfig
|
_pPluginInfo->Type = PLUGIN_TYPE_PAD;
|
||||||
// Purpose: This function is optional function that is provided
|
_pPluginInfo->Version = CIFACE_PLUGIN_VERSION;
|
||||||
// to allow the user to configure the DLL
|
}
|
||||||
// input: A handle to the window that calls this function
|
|
||||||
// output: none
|
// ___________________________________________________________________________
|
||||||
//
|
// Function: DllConfig
|
||||||
EXPORT void CALL DllConfig(HWND _hParent)
|
// Purpose: This function is optional function that is provided
|
||||||
{
|
// to allow the user to configure the DLL
|
||||||
bool was_init = false;
|
// input: A handle to the window that calls this function
|
||||||
if ( g_plugin.controller_interface.IsInit() ) // hack for showing dialog when game isnt running
|
// output: none
|
||||||
was_init = true;
|
//
|
||||||
else
|
EXPORT void CALL DllConfig(HWND _hParent)
|
||||||
InitPlugin( _hParent );
|
{
|
||||||
|
bool was_init = false;
|
||||||
// copied from GCPad
|
if ( g_plugin.controller_interface.IsInit() ) // hack for showing dialog when game isnt running
|
||||||
#if defined(HAVE_WX) && HAVE_WX
|
was_init = true;
|
||||||
wxWindow *frame = GetParentedWxWindow(_hParent);
|
else
|
||||||
ConfigDialog* m_ConfigFrame = new ConfigDialog( frame, g_plugin, CIFACE_PLUGIN_FULL_NAME, was_init );
|
InitPlugin( _hParent );
|
||||||
|
|
||||||
#ifdef _WIN32
|
// copied from GCPad
|
||||||
frame->Disable();
|
#if defined(HAVE_WX) && HAVE_WX
|
||||||
m_ConfigFrame->ShowModal();
|
wxWindow *frame = GetParentedWxWindow(_hParent);
|
||||||
frame->Enable();
|
ConfigDialog* m_ConfigFrame = new ConfigDialog( frame, g_plugin, CIFACE_PLUGIN_FULL_NAME, was_init );
|
||||||
#else
|
|
||||||
m_ConfigFrame->ShowModal();
|
#ifdef _WIN32
|
||||||
#endif
|
frame->Disable();
|
||||||
|
m_ConfigFrame->ShowModal();
|
||||||
#ifdef _WIN32
|
frame->Enable();
|
||||||
wxMilliSleep( 50 ); // hooray for hacks
|
#else
|
||||||
frame->SetFocus();
|
m_ConfigFrame->ShowModal();
|
||||||
frame->SetHWND(NULL);
|
#endif
|
||||||
#endif
|
|
||||||
|
#ifdef _WIN32
|
||||||
m_ConfigFrame->Destroy();
|
wxMilliSleep( 50 ); // hooray for hacks
|
||||||
m_ConfigFrame = NULL;
|
frame->SetFocus();
|
||||||
frame->Destroy();
|
frame->SetHWND(NULL);
|
||||||
#endif
|
#endif
|
||||||
// /
|
|
||||||
|
m_ConfigFrame->Destroy();
|
||||||
if ( false == was_init ) // hack for showing dialog when game isnt running
|
m_ConfigFrame = NULL;
|
||||||
g_plugin.controller_interface.DeInit();
|
frame->Destroy();
|
||||||
}
|
#endif
|
||||||
|
// /
|
||||||
// ___________________________________________________________________________
|
|
||||||
// Function: DllDebugger
|
if ( false == was_init ) // hack for showing dialog when game isnt running
|
||||||
// Purpose: Open the debugger
|
g_plugin.controller_interface.DeInit();
|
||||||
// input: a handle to the window that calls this function
|
}
|
||||||
// output: none
|
|
||||||
//
|
// ___________________________________________________________________________
|
||||||
EXPORT void CALL DllDebugger(HWND _hParent, bool Show)
|
// Function: DllDebugger
|
||||||
{
|
// Purpose: Open the debugger
|
||||||
// wut?
|
// input: a handle to the window that calls this function
|
||||||
}
|
// output: none
|
||||||
|
//
|
||||||
// ___________________________________________________________________________
|
EXPORT void CALL DllDebugger(HWND _hParent, bool Show)
|
||||||
// Function: DllSetGlobals
|
{
|
||||||
// Purpose: Set the pointer for globals variables
|
// wut?
|
||||||
// input: a pointer to the global struct
|
}
|
||||||
// output: none
|
|
||||||
//
|
// ___________________________________________________________________________
|
||||||
EXPORT void CALL SetDllGlobals(PLUGIN_GLOBALS* _pPluginGlobals)
|
// Function: DllSetGlobals
|
||||||
{
|
// Purpose: Set the pointer for globals variables
|
||||||
// wut?
|
// input: a pointer to the global struct
|
||||||
}
|
// output: none
|
||||||
|
//
|
||||||
// ___________________________________________________________________________
|
EXPORT void CALL SetDllGlobals(PLUGIN_GLOBALS* _pPluginGlobals)
|
||||||
// Function: Initialize
|
{
|
||||||
// Purpose: Initialize the plugin
|
// wut?
|
||||||
// input: Init
|
}
|
||||||
// output: none
|
|
||||||
//
|
// ___________________________________________________________________________
|
||||||
EXPORT void CALL Initialize(void *init)
|
// Function: Initialize
|
||||||
{
|
// Purpose: Initialize the plugin
|
||||||
if ( false == g_plugin.controller_interface.IsInit() )
|
// input: Init
|
||||||
InitPlugin( ((SPADInitialize*)init)->hWnd );
|
// output: none
|
||||||
}
|
//
|
||||||
|
EXPORT void CALL Initialize(void *init)
|
||||||
// ___________________________________________________________________________
|
{
|
||||||
// Function: Shutdown
|
if ( false == g_plugin.controller_interface.IsInit() )
|
||||||
// Purpose: This function is called when the emulator is shutting down
|
InitPlugin( ((SPADInitialize*)init)->hWnd );
|
||||||
// a game allowing the dll to de-initialise.
|
}
|
||||||
// input: none
|
|
||||||
// output: none
|
// ___________________________________________________________________________
|
||||||
//
|
// Function: Shutdown
|
||||||
EXPORT void CALL Shutdown(void)
|
// Purpose: This function is called when the emulator is shutting down
|
||||||
{
|
// a game allowing the dll to de-initialise.
|
||||||
//plugin.controls_crit.Enter(); // enter
|
// input: none
|
||||||
if ( g_plugin.controller_interface.IsInit() )
|
// output: none
|
||||||
g_plugin.controller_interface.DeInit();
|
//
|
||||||
//plugin.controls_crit.Leave(); // leave
|
EXPORT void CALL Shutdown(void)
|
||||||
}
|
{
|
||||||
|
//plugin.controls_crit.Enter(); // enter
|
||||||
// ___________________________________________________________________________
|
if ( g_plugin.controller_interface.IsInit() )
|
||||||
// Function: DoState
|
g_plugin.controller_interface.DeInit();
|
||||||
// Purpose: Saves/load state
|
//plugin.controls_crit.Leave(); // leave
|
||||||
// input/output: ptr
|
}
|
||||||
// input: mode
|
|
||||||
//
|
// ___________________________________________________________________________
|
||||||
EXPORT void CALL DoState(unsigned char **ptr, int mode)
|
// Function: DoState
|
||||||
{
|
// Purpose: Saves/load state
|
||||||
// prolly won't need this
|
// input/output: ptr
|
||||||
}
|
// input: mode
|
||||||
|
//
|
||||||
// ___________________________________________________________________________
|
EXPORT void CALL DoState(unsigned char **ptr, int mode)
|
||||||
// Function: EmuStateChange
|
{
|
||||||
// Purpose: Notifies the plugin of a change in emulation state
|
// prolly won't need this
|
||||||
// input: newState
|
}
|
||||||
// output: none
|
|
||||||
//
|
// ___________________________________________________________________________
|
||||||
EXPORT void CALL EmuStateChange(PLUGIN_EMUSTATE newState)
|
// Function: EmuStateChange
|
||||||
{
|
// Purpose: Notifies the plugin of a change in emulation state
|
||||||
// maybe use this later
|
// input: newState
|
||||||
}
|
// output: none
|
||||||
|
//
|
||||||
|
EXPORT void CALL EmuStateChange(PLUGIN_EMUSTATE newState)
|
||||||
|
{
|
||||||
|
// maybe use this later
|
||||||
|
}
|
||||||
|
|
|
@ -1,142 +1,142 @@
|
||||||
|
|
||||||
#include "IniFile.h"
|
#include "IniFile.h"
|
||||||
|
|
||||||
//
|
//
|
||||||
// TrimChars
|
// TrimChars
|
||||||
//
|
//
|
||||||
// trim whitespace, or any, chars from both ends
|
// trim whitespace, or any, chars from both ends
|
||||||
//
|
//
|
||||||
template <typename S>
|
template <typename S>
|
||||||
std::string TrimChars( const std::string& str, const S space )
|
std::string TrimChars( const std::string& str, const S space )
|
||||||
{
|
{
|
||||||
const size_t start = str.find_first_not_of( space );
|
const size_t start = str.find_first_not_of( space );
|
||||||
|
|
||||||
if ( str.npos == start )
|
if ( str.npos == start )
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
return str.substr( start, str.find_last_not_of( space ) - start + 1 );
|
return str.substr( start, str.find_last_not_of( space ) - start + 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// IniSection :: Set
|
// IniSection :: Set
|
||||||
//
|
//
|
||||||
// set key's value if it doesn't match the default
|
// set key's value if it doesn't match the default
|
||||||
// otherwise remove the key from the section if it exists
|
// otherwise remove the key from the section if it exists
|
||||||
//
|
//
|
||||||
void IniSection::Set( const std::string& key, const std::string& val, const std::string& def )
|
void IniSection::Set( const std::string& key, const std::string& val, const std::string& def )
|
||||||
{
|
{
|
||||||
if ( val != def )
|
if ( val != def )
|
||||||
operator[](key) = val;
|
operator[](key) = val;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
iterator f = find(key);
|
iterator f = find(key);
|
||||||
if ( f != end() )
|
if ( f != end() )
|
||||||
erase( f );
|
erase( f );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// IniSection :: Get
|
// IniSection :: Get
|
||||||
//
|
//
|
||||||
// return a key's value if it exists
|
// return a key's value if it exists
|
||||||
// otherwise return the default
|
// otherwise return the default
|
||||||
//
|
//
|
||||||
std::string IniSection::Get( const std::string& key, const std::string& def )
|
std::string IniSection::Get( const std::string& key, const std::string& def )
|
||||||
{
|
{
|
||||||
const const_iterator f = find(key);
|
const const_iterator f = find(key);
|
||||||
if ( f != end() )
|
if ( f != end() )
|
||||||
if ( false == f->second.empty() )
|
if ( false == f->second.empty() )
|
||||||
return f->second;
|
return f->second;
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// IniFile :: Save
|
// IniFile :: Save
|
||||||
//
|
//
|
||||||
// save a file
|
// save a file
|
||||||
//
|
//
|
||||||
void IniFile::Save( std::ostream& file )
|
void IniFile::Save( std::ostream& file )
|
||||||
{
|
{
|
||||||
const_iterator i = begin(),
|
const_iterator i = begin(),
|
||||||
e = end();
|
e = end();
|
||||||
for ( ; i != e; ++i )
|
for ( ; i != e; ++i )
|
||||||
{
|
{
|
||||||
// skip a line at new sections
|
// skip a line at new sections
|
||||||
file << "\n[" << i->first << "]\n";
|
file << "\n[" << i->first << "]\n";
|
||||||
Section::const_iterator si = i->second.begin(),
|
Section::const_iterator si = i->second.begin(),
|
||||||
se = i->second.end();
|
se = i->second.end();
|
||||||
for ( ; si != se; ++si )
|
for ( ; si != se; ++si )
|
||||||
file << si->first << " = " << si->second << '\n';
|
file << si->first << " = " << si->second << '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// IniFile :: Load
|
// IniFile :: Load
|
||||||
//
|
//
|
||||||
// load a file
|
// load a file
|
||||||
//
|
//
|
||||||
void IniFile::Load( std::istream& file )
|
void IniFile::Load( std::istream& file )
|
||||||
{
|
{
|
||||||
const char* const space = "\t\r ";
|
const char* const space = "\t\r ";
|
||||||
std::string line;
|
std::string line;
|
||||||
// start off with an empty section
|
// start off with an empty section
|
||||||
Section* section = &(*this)[""];
|
Section* section = &(*this)[""];
|
||||||
while ( std::getline( file, line ).good() ) // read a line
|
while ( std::getline( file, line ).good() ) // read a line
|
||||||
{
|
{
|
||||||
line = TrimChars(line,space);
|
line = TrimChars(line,space);
|
||||||
if ( line.size() )
|
if ( line.size() )
|
||||||
{
|
{
|
||||||
switch ( line[0] )
|
switch ( line[0] )
|
||||||
{
|
{
|
||||||
// comment
|
// comment
|
||||||
case '#' :
|
case '#' :
|
||||||
case ';' :
|
case ';' :
|
||||||
break;
|
break;
|
||||||
// section
|
// section
|
||||||
case '[' :
|
case '[' :
|
||||||
// kinda odd trimming
|
// kinda odd trimming
|
||||||
section = &(*this)[ TrimChars(line,"][\t\r ") ];
|
section = &(*this)[ TrimChars(line,"][\t\r ") ];
|
||||||
break;
|
break;
|
||||||
// key/value
|
// key/value
|
||||||
default :
|
default :
|
||||||
{
|
{
|
||||||
std::istringstream ss(line);
|
std::istringstream ss(line);
|
||||||
std::string key; std::getline( ss, key, '=' );
|
std::string key; std::getline( ss, key, '=' );
|
||||||
std::string val; std::getline( ss, val );
|
std::string val; std::getline( ss, val );
|
||||||
(*section)[ TrimChars(key,space) ] = TrimChars(val,space);
|
(*section)[ TrimChars(key,space) ] = TrimChars(val,space);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Clean();
|
Clean();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// IniFile :: Clean
|
// IniFile :: Clean
|
||||||
//
|
//
|
||||||
// remove empty key/values and sections
|
// remove empty key/values and sections
|
||||||
// after trying to access ini sections/values, they are automatically allocated
|
// after trying to access ini sections/values, they are automatically allocated
|
||||||
// this deletes the empty stuff
|
// this deletes the empty stuff
|
||||||
//
|
//
|
||||||
void IniFile::Clean()
|
void IniFile::Clean()
|
||||||
{
|
{
|
||||||
iterator i = begin(),
|
iterator i = begin(),
|
||||||
e = end();
|
e = end();
|
||||||
for ( ; i != e; )
|
for ( ; i != e; )
|
||||||
{
|
{
|
||||||
Section::iterator si = i->second.begin(),
|
Section::iterator si = i->second.begin(),
|
||||||
se = i->second.end();
|
se = i->second.end();
|
||||||
for ( ; si != se; )
|
for ( ; si != se; )
|
||||||
{
|
{
|
||||||
if ( si->second.empty() )
|
if ( si->second.empty() )
|
||||||
i->second.erase( si++ );
|
i->second.erase( si++ );
|
||||||
else
|
else
|
||||||
++si;
|
++si;
|
||||||
}
|
}
|
||||||
if ( i->second.empty() )
|
if ( i->second.empty() )
|
||||||
erase( i++ );
|
erase( i++ );
|
||||||
else
|
else
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,61 +1,61 @@
|
||||||
#ifndef _INIFILE_H_
|
#ifndef _INIFILE_H_
|
||||||
#define _INIFILE_H_
|
#define _INIFILE_H_
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
//
|
//
|
||||||
// IniFile
|
// IniFile
|
||||||
//
|
//
|
||||||
class IniSection : public std::map< std::string, std::string >
|
class IniSection : public std::map< std::string, std::string >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void Set( const std::string& key, const std::string& val, const std::string& def = "" );
|
void Set( const std::string& key, const std::string& val, const std::string& def = "" );
|
||||||
std::string Get( const std::string& key, const std::string& def = "" );
|
std::string Get( const std::string& key, const std::string& def = "" );
|
||||||
|
|
||||||
template <typename V, typename D>
|
template <typename V, typename D>
|
||||||
void Set( const std::string& key, const V& val, const D& def = 0 )
|
void Set( const std::string& key, const V& val, const D& def = 0 )
|
||||||
{
|
{
|
||||||
if ( val != def )
|
if ( val != def )
|
||||||
{
|
{
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
ss << long(val);
|
ss << long(val);
|
||||||
operator[](key) = ss.str();
|
operator[](key) = ss.str();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
iterator f = find(key);
|
iterator f = find(key);
|
||||||
if ( f != end() )
|
if ( f != end() )
|
||||||
erase( f );
|
erase( f );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
template <typename V>
|
template <typename V>
|
||||||
V Get( const std::string& key, const V& def = 0 )
|
V Get( const std::string& key, const V& def = 0 )
|
||||||
{
|
{
|
||||||
const const_iterator f = find(key);
|
const const_iterator f = find(key);
|
||||||
if ( f != end() )
|
if ( f != end() )
|
||||||
if ( false == f->second.empty() )
|
if ( false == f->second.empty() )
|
||||||
{
|
{
|
||||||
std::istringstream ss(f->second);
|
std::istringstream ss(f->second);
|
||||||
int val;
|
int val;
|
||||||
ss >> val;
|
ss >> val;
|
||||||
return V(val);
|
return V(val);
|
||||||
}
|
}
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class IniFile : public std::map< std::string, IniSection >
|
class IniFile : public std::map< std::string, IniSection >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef IniSection Section;
|
typedef IniSection Section;
|
||||||
|
|
||||||
void Clean();
|
void Clean();
|
||||||
void Save( std::ostream& file );
|
void Save( std::ostream& file );
|
||||||
void Load( std::istream& file );
|
void Load( std::istream& file );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue