Change button_id to be a function pointer field, not a virtual method

This commit is contained in:
Ilari Liusvaara 2012-10-10 22:56:22 +03:00
parent 286240eff4
commit 81795bbaec
4 changed files with 37 additions and 60 deletions

View file

@ -254,7 +254,7 @@ struct porttype_info
* Parameter lbid: Logigal button ID.
* Returns: The physical button ID, or -1 if no such button exists.
*/
virtual int button_id(unsigned controller, unsigned lbid) const throw() = 0;
int (*button_id)(unsigned controller, unsigned lbid);
/**
* Set this controller as core controller.
*

View file

@ -569,15 +569,11 @@ namespace
deserialize = generic_port_deserialize<1, 0, 12>;
legal = generic_port_legal<3>;
deviceflags = generic_port_deviceflags<1, 1>;
button_id = get_button_id_gamepad;
ctrlname = "gamepad";
controllers = 1;
set_core_controller = set_core_controller_gamepad;
}
int button_id(unsigned controller, unsigned lbid) const throw()
{
return get_button_id_gamepad(controller, lbid);
}
} gamepad;
struct porttype_justifier : public porttype_info
@ -591,15 +587,11 @@ namespace
deserialize = generic_port_deserialize<1, 2, 2>;
legal = generic_port_legal<2>;
deviceflags = generic_port_deviceflags<1, 3>;
button_id = get_button_id_justifier;
ctrlname = "justifier";
controllers = 1;
set_core_controller = set_core_controller_justifier;
}
int button_id(unsigned controller, unsigned lbid) const throw()
{
return get_button_id_justifier(controller, lbid);
}
} justifier;
struct porttype_justifiers : public porttype_info
@ -613,15 +605,11 @@ namespace
deserialize = generic_port_deserialize<2, 2, 2>;
legal = generic_port_legal<2>;
deviceflags = generic_port_deviceflags<2, 3>;
button_id = get_button_id_justifiers;
ctrlname = "justifier";
controllers = 2;
set_core_controller = set_core_controller_justifiers;
}
int button_id(unsigned controller, unsigned lbid) const throw()
{
return get_button_id_justifiers(controller, lbid);
}
} justifiers;
struct porttype_mouse : public porttype_info
@ -635,15 +623,11 @@ namespace
deserialize = generic_port_deserialize<1, 2, 2>;
legal = generic_port_legal<3>;
deviceflags = generic_port_deviceflags<1, 5>;
button_id = get_button_id_mouse;
ctrlname = "mouse";
controllers = 1;
set_core_controller = set_core_controller_mouse;
}
int button_id(unsigned controller, unsigned lbid) const throw()
{
return get_button_id_mouse(controller, lbid);
}
} mouse;
struct porttype_multitap : public porttype_info
@ -657,15 +641,11 @@ namespace
deserialize = generic_port_deserialize<4, 0, 12>;
legal = generic_port_legal<3>;
deviceflags = generic_port_deviceflags<4, 1>;
button_id = get_button_id_multitap;
ctrlname = "multitap";
controllers = 4;
set_core_controller = set_core_controller_multitap;
}
int button_id(unsigned controller, unsigned lbid) const throw()
{
return get_button_id_multitap(controller, lbid);
}
} multitap;
struct porttype_none : public porttype_info
@ -679,15 +659,11 @@ namespace
deserialize = generic_port_deserialize<0, 0, 0>;
legal = generic_port_legal<3>;
deviceflags = generic_port_deviceflags<0, 0>;
button_id = get_button_id_none;
ctrlname = "";
controllers = 0;
set_core_controller = set_core_controller_none;
}
int button_id(unsigned controller, unsigned lbid) const throw()
{
return get_button_id_none(controller, lbid);
}
} none;
struct porttype_superscope : public porttype_info
@ -701,15 +677,11 @@ namespace
deserialize = generic_port_deserialize<1, 2, 4>;
deviceflags = generic_port_deviceflags<1, 3>;
legal = generic_port_legal<2>;
button_id = get_button_id_superscope;
ctrlname = "superscope";
controllers = 1;
set_core_controller = set_core_controller_superscope;
}
int button_id(unsigned controller, unsigned lbid) const throw()
{
return get_button_id_superscope(controller, lbid);
}
} superscope;
my_interface my_interface_obj;

View file

@ -23,6 +23,11 @@ namespace
exit(1);
}
int button_id_illegal(unsigned controller, unsigned lbid)
{
return -1;
}
struct porttype_invalid : public porttype_info
{
porttype_invalid() : porttype_info("invalid-port-type", "invalid-port-type", 99999, 0)
@ -34,15 +39,11 @@ namespace
deserialize = NULL;
legal = NULL;
deviceflags = generic_port_deviceflags<0, 0>;
button_id = button_id_illegal;
ctrlname = "";
controllers = 0;
set_core_controller = set_core_controller_illegal;
}
int button_id(unsigned controller, unsigned lbid) const throw()
{
return -1;
}
};

View file

@ -166,6 +166,27 @@ namespace
const char* buttonnames[] = {"left", "right", "up", "down", "A", "B", "select", "start"};
void _set_core_controller(unsigned port) throw() {}
int get_button_id_gamepad(unsigned controller, unsigned lbid) throw()
{
if(controller)
return -1;
if(lbid == LOGICAL_BUTTON_A) return 0;
if(lbid == LOGICAL_BUTTON_B) return 1;
if(lbid == LOGICAL_BUTTON_SELECT) return 2;
if(lbid == LOGICAL_BUTTON_START) return 3;
if(lbid == LOGICAL_BUTTON_RIGHT) return 4;
if(lbid == LOGICAL_BUTTON_LEFT) return 5;
if(lbid == LOGICAL_BUTTON_UP) return 6;
if(lbid == LOGICAL_BUTTON_DOWN) return 7;
return -1;
}
int get_button_id_none(unsigned controller, unsigned lbid) throw()
{
return -1;
}
struct porttype_gamepad : public porttype_info
{
@ -178,25 +199,12 @@ namespace
deserialize = generic_port_deserialize<1, 0, 8>;
legal = generic_port_legal<1>;
deviceflags = generic_port_deviceflags<1, 1>;
button_id = get_button_id_gamepad;
ctrlname = "gamepad";
controllers = 1;
set_core_controller = _set_core_controller;
}
int button_id(unsigned controller, unsigned lbid) const throw()
{
if(controller)
return -1;
if(lbid == LOGICAL_BUTTON_A) return 0;
if(lbid == LOGICAL_BUTTON_B) return 1;
if(lbid == LOGICAL_BUTTON_SELECT) return 2;
if(lbid == LOGICAL_BUTTON_START) return 3;
if(lbid == LOGICAL_BUTTON_RIGHT) return 4;
if(lbid == LOGICAL_BUTTON_LEFT) return 5;
if(lbid == LOGICAL_BUTTON_UP) return 6;
if(lbid == LOGICAL_BUTTON_DOWN) return 7;
return -1;
}
} gamepad;
struct porttype_none : public porttype_info
@ -210,15 +218,11 @@ namespace
deserialize = generic_port_deserialize<0, 0, 0>;
legal = generic_port_legal<2>;
deviceflags = generic_port_deviceflags<0, 0>;
button_id = get_button_id_none;
ctrlname = "";
controllers = 0;
set_core_controller = _set_core_controller;
}
int button_id(unsigned controller, unsigned lbid) const throw()
{
return -1;
}
} none;
}