filename | src/maple/lightgun.c |
changeset | 1072:d82e04e6d497 |
prev | 1034:7044e01148f0 |
next | 1298:d0eb2307b847 |
author | nkeynes |
date | Fri Sep 10 08:48:34 2010 +1000 (13 years ago) |
permissions | -rw-r--r-- |
last change | Run the eventq at the end of the time-slice rather than the beginning, so that it runs for the correct period of time when the time-slice finishes early |
file | annotate | diff | log | raw |
1.1 --- a/src/maple/lightgun.c Wed Jun 24 02:41:12 2009 +00001.2 +++ b/src/maple/lightgun.c Fri Sep 10 08:48:34 2010 +10001.3 @@ -57,19 +57,22 @@1.4 static void lightgun_destroy( maple_device_t dev );1.5 static maple_device_t lightgun_clone( maple_device_t dev );1.6 static maple_device_t lightgun_new();1.7 -static lxdream_config_entry_t lightgun_get_config( maple_device_t dev );1.8 -static void lightgun_set_config_value( maple_device_t dev, unsigned int key, const gchar *value );1.9 +static void lightgun_key_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown );1.10 +static lxdream_config_group_t lightgun_get_config( maple_device_t dev );1.11 static int lightgun_get_cond( maple_device_t dev, int function, unsigned char *outbuf,1.12 unsigned int *outlen );1.13 static void lightgun_start_gun( maple_device_t dev );1.14 static void lightgun_stop_gun( maple_device_t dev );1.16 +static gboolean lightgun_set_config_value( lxdream_config_group_t group, unsigned int key,1.17 + const gchar *oldvalue, const gchar *value );1.18 +1.19 typedef struct lightgun_device {1.20 struct maple_device dev;1.21 uint32_t condition[2];1.22 int gun_active;1.23 int mouse_x, mouse_y;1.24 - struct lxdream_config_entry config[LIGHTGUN_CONFIG_ENTRIES+1];1.25 + struct lxdream_config_group config;1.26 } *lightgun_device_t;1.28 struct maple_device_class lightgun_class = { "Sega Lightgun",1.29 @@ -78,30 +81,29 @@1.30 static struct lightgun_device base_lightgun = {1.31 { MAPLE_DEVICE_TAG, &lightgun_class,1.32 LIGHTGUN_IDENT, LIGHTGUN_VERSION,1.33 - lightgun_get_config, lightgun_set_config_value,1.34 + lightgun_get_config,1.35 lightgun_attach, lightgun_detach, lightgun_destroy,1.36 lightgun_clone, NULL, NULL, lightgun_get_cond, NULL, NULL, NULL, NULL,1.37 lightgun_start_gun, lightgun_stop_gun},1.38 - {0x0000FFFF, 0x80808080}, 0, -1, -1,1.39 - {{ "dpad left", N_("Dpad left"), CONFIG_TYPE_KEY },1.40 - { "dpad right", N_("Dpad right"), CONFIG_TYPE_KEY },1.41 - { "dpad up", N_("Dpad up"), CONFIG_TYPE_KEY },1.42 - { "dpad down", N_("Dpad down"), CONFIG_TYPE_KEY },1.43 - { "button A", N_("Button A"), CONFIG_TYPE_KEY },1.44 - { "button B", N_("Button B"), CONFIG_TYPE_KEY },1.45 - { "start", N_("Start button"), CONFIG_TYPE_KEY },1.46 - { NULL, CONFIG_TYPE_NONE }} };1.47 + {0x0000FFFF, 0x80808080}, 0, -1, -1,1.48 + {"Sega Lightgun", NULL, lightgun_key_callback, NULL,1.49 + {{ "dpad left", N_("Dpad left"), CONFIG_TYPE_KEY, NULL, BUTTON_DPAD_LEFT },1.50 + { "dpad right", N_("Dpad right"), CONFIG_TYPE_KEY, NULL, BUTTON_DPAD_RIGHT },1.51 + { "dpad up", N_("Dpad up"), CONFIG_TYPE_KEY, NULL, BUTTON_DPAD_UP },1.52 + { "dpad down", N_("Dpad down"), CONFIG_TYPE_KEY, NULL, BUTTON_DPAD_DOWN },1.53 + { "button A", N_("Button A"), CONFIG_TYPE_KEY, NULL, BUTTON_A },1.54 + { "button B", N_("Button B"), CONFIG_TYPE_KEY, NULL, BUTTON_B },1.55 + { "start", N_("Start button"), CONFIG_TYPE_KEY, NULL, BUTTON_START },1.56 + { NULL, CONFIG_TYPE_NONE }}} };1.58 -static int config_button_map[] = {1.59 - BUTTON_DPAD_LEFT, BUTTON_DPAD_RIGHT, BUTTON_DPAD_UP, BUTTON_DPAD_DOWN,1.60 - BUTTON_A, BUTTON_B, BUTTON_START };1.61 -1.62 +1.63 #define lightgun(x) ((lightgun_device_t)(x))1.65 static maple_device_t lightgun_new( )1.66 {1.67 lightgun_device_t dev = malloc( sizeof(struct lightgun_device) );1.68 memcpy( dev, &base_lightgun, sizeof(base_lightgun) );1.69 + dev->config.data = dev;1.70 return MAPLE_DEVICE(dev);1.71 }1.73 @@ -109,11 +111,22 @@1.74 {1.75 lightgun_device_t src = (lightgun_device_t)srcdevice;1.76 lightgun_device_t dev = (lightgun_device_t)lightgun_new();1.77 - lxdream_copy_config_list( dev->config, src->config );1.78 + lxdream_copy_config_group( &dev->config, &src->config );1.79 memcpy( dev->condition, src->condition, sizeof(src->condition) );1.80 return MAPLE_DEVICE(dev);1.81 }1.83 +static lxdream_config_group_t lightgun_get_config( maple_device_t mdev )1.84 +{1.85 + lightgun_device_t dev = (lightgun_device_t)mdev;1.86 + return &dev->config;1.87 +}1.88 +1.89 +static void lightgun_destroy( maple_device_t mdev )1.90 +{1.91 + free( mdev );1.92 +}1.93 +1.94 /**1.95 * Input callback1.96 */1.97 @@ -127,28 +140,6 @@1.98 }1.99 }1.101 -static lxdream_config_entry_t lightgun_get_config( maple_device_t mdev )1.102 -{1.103 - lightgun_device_t dev = (lightgun_device_t)mdev;1.104 - return dev->config;1.105 -}1.106 -1.107 -static void lightgun_set_config_value( maple_device_t mdev, unsigned int key, const gchar *value )1.108 -{1.109 - lightgun_device_t dev = (lightgun_device_t)mdev;1.110 - assert( key < LIGHTGUN_CONFIG_ENTRIES );1.111 -1.112 - input_unregister_key( dev->config[key].value, lightgun_key_callback, dev, config_button_map[key] );1.113 - lxdream_set_config_value( &dev->config[key], value );1.114 - input_register_key( dev->config[key].value, lightgun_key_callback, dev, config_button_map[key] );1.115 -}1.116 -1.117 -static void lightgun_destroy( maple_device_t mdev )1.118 -{1.119 - free( mdev );1.120 -}1.121 -1.122 -1.123 static void lightgun_mouse_callback( void *mdev, uint32_t buttons, int32_t x, int32_t y, gboolean absolute )1.124 {1.125 lightgun_device_t dev = (lightgun_device_t)mdev;1.126 @@ -169,21 +160,16 @@1.127 static void lightgun_attach( maple_device_t mdev )1.128 {1.129 lightgun_device_t dev = (lightgun_device_t)mdev;1.130 - int i;1.131 - for( i=0; i<LIGHTGUN_CONFIG_ENTRIES; i++ ) {1.132 - input_register_key( dev->config[i].value, lightgun_key_callback, dev, config_button_map[i] );1.133 - }1.134 + dev->config.on_change = input_keygroup_changed;1.135 + input_register_keygroup( &dev->config );1.136 input_register_mouse_hook( TRUE, lightgun_mouse_callback, dev );1.137 -1.138 }1.140 static void lightgun_detach( maple_device_t mdev )1.141 {1.142 lightgun_device_t dev = (lightgun_device_t)mdev;1.143 - int i;1.144 - for( i=0; i<LIGHTGUN_CONFIG_ENTRIES; i++ ) {1.145 - input_unregister_key( dev->config[i].value, lightgun_key_callback, dev, config_button_map[i] );1.146 - }1.147 + input_unregister_keygroup( &dev->config );1.148 + dev->config.on_change = NULL;1.149 input_unregister_mouse_hook( lightgun_mouse_callback, dev );1.151 }
.