Extern references in library/controller-data.hpp are no-no
This commit is contained in:
parent
9a8c9377b2
commit
5795288660
3 changed files with 90 additions and 64 deletions
|
@ -214,4 +214,63 @@ private:
|
||||||
std::vector<controller_frame> _autofire;
|
std::vector<controller_frame> _autofire;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern const char* button_symbols;
|
||||||
|
extern const char* controller_names[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic port display function.
|
||||||
|
*/
|
||||||
|
template<unsigned controllers, unsigned analog_axis, unsigned buttons, unsigned sidx>
|
||||||
|
inline void generic_port_display(const unsigned char* buffer, unsigned idx, char* buf) throw()
|
||||||
|
{
|
||||||
|
if(idx > controllers) {
|
||||||
|
buf[0] = '\0';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
size_t ptr = 0;
|
||||||
|
for(unsigned i = 0; i < analog_axis; i++) {
|
||||||
|
uint16_t a = buffer[2 * idx * analog_axis + 2 * i];
|
||||||
|
uint16_t b = buffer[2 * idx * analog_axis + 2 * i + 1];
|
||||||
|
ptr += sprintf(buf + ptr, "%i ", static_cast<short>(256 * a + b));
|
||||||
|
}
|
||||||
|
for(unsigned i = 0; i < buttons; i++) {
|
||||||
|
size_t bit = 16 * controllers * analog_axis + idx * buttons + i;
|
||||||
|
buf[ptr++] = ((buffer[bit / 8] & (1 << (bit % 8))) != 0) ? button_symbols[i + sidx] : '-';
|
||||||
|
}
|
||||||
|
buf[ptr] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic port controller name function.
|
||||||
|
*/
|
||||||
|
template<unsigned controllers, unsigned nameindex>
|
||||||
|
inline const char* generic_controller_name(unsigned controller)
|
||||||
|
{
|
||||||
|
if(controller >= controllers)
|
||||||
|
return NULL;
|
||||||
|
return controller_names[nameindex];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic port serialization function.
|
||||||
|
*/
|
||||||
|
template<unsigned controllers, unsigned analog_axis, unsigned buttons, unsigned sidx>
|
||||||
|
inline size_t generic_port_serialize(const unsigned char* buffer, char* textbuf) throw()
|
||||||
|
{
|
||||||
|
size_t ptr = 0;
|
||||||
|
for(unsigned j = 0; j < controllers; j++) {
|
||||||
|
textbuf[ptr++] = '|';
|
||||||
|
for(unsigned i = 0; i < buttons; i++) {
|
||||||
|
size_t bit = 16 * controllers * analog_axis + j * buttons + i;
|
||||||
|
textbuf[ptr++] = ((buffer[bit / 8] & (1 << (bit % 8))) != 0) ? button_symbols[i + sidx] : '.';
|
||||||
|
}
|
||||||
|
for(unsigned i = 0; i < analog_axis; i++) {
|
||||||
|
uint16_t a = buffer[2 * j * analog_axis + 2 * i];
|
||||||
|
uint16_t b = buffer[2 * j * analog_axis + 2 * i + 1];
|
||||||
|
ptr += sprintf(textbuf + ptr, " %i", static_cast<short>(256 * a + b));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1325,32 +1325,6 @@ inline short generic_port_read(const unsigned char* buffer, unsigned idx, unsign
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern const char* button_symbols;
|
|
||||||
extern const char* controller_names[];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generic port display function.
|
|
||||||
*/
|
|
||||||
template<unsigned controllers, unsigned analog_axis, unsigned buttons, unsigned sidx>
|
|
||||||
inline void generic_port_display(const unsigned char* buffer, unsigned idx, char* buf) throw()
|
|
||||||
{
|
|
||||||
if(idx > controllers) {
|
|
||||||
buf[0] = '\0';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
size_t ptr = 0;
|
|
||||||
for(unsigned i = 0; i < analog_axis; i++) {
|
|
||||||
uint16_t a = buffer[2 * idx * analog_axis + 2 * i];
|
|
||||||
uint16_t b = buffer[2 * idx * analog_axis + 2 * i + 1];
|
|
||||||
ptr += sprintf(buf + ptr, "%i ", static_cast<short>(256 * a + b));
|
|
||||||
}
|
|
||||||
for(unsigned i = 0; i < buttons; i++) {
|
|
||||||
size_t bit = 16 * controllers * analog_axis + idx * buttons + i;
|
|
||||||
buf[ptr++] = ((buffer[bit / 8] & (1 << (bit % 8))) != 0) ? button_symbols[i + sidx] : '-';
|
|
||||||
}
|
|
||||||
buf[ptr] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generic port control index function.
|
* Generic port control index function.
|
||||||
*/
|
*/
|
||||||
|
@ -1362,38 +1336,6 @@ inline unsigned generic_used_indices(unsigned controller)
|
||||||
return indices;
|
return indices;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Generic port controller name function.
|
|
||||||
*/
|
|
||||||
template<unsigned controllers, unsigned nameindex>
|
|
||||||
inline const char* generic_controller_name(unsigned controller)
|
|
||||||
{
|
|
||||||
if(controller >= controllers)
|
|
||||||
return NULL;
|
|
||||||
return controller_names[nameindex];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generic port serialization function.
|
|
||||||
*/
|
|
||||||
template<unsigned controllers, unsigned analog_axis, unsigned buttons, unsigned sidx>
|
|
||||||
inline size_t generic_port_serialize(const unsigned char* buffer, char* textbuf) throw()
|
|
||||||
{
|
|
||||||
size_t ptr = 0;
|
|
||||||
for(unsigned j = 0; j < controllers; j++) {
|
|
||||||
textbuf[ptr++] = '|';
|
|
||||||
for(unsigned i = 0; i < buttons; i++) {
|
|
||||||
size_t bit = 16 * controllers * analog_axis + j * buttons + i;
|
|
||||||
textbuf[ptr++] = ((buffer[bit / 8] & (1 << (bit % 8))) != 0) ? button_symbols[i + sidx] : '.';
|
|
||||||
}
|
|
||||||
for(unsigned i = 0; i < analog_axis; i++) {
|
|
||||||
uint16_t a = buffer[2 * j * analog_axis + 2 * i];
|
|
||||||
uint16_t b = buffer[2 * j * analog_axis + 2 * i + 1];
|
|
||||||
ptr += sprintf(textbuf + ptr, " %i", static_cast<short>(256 * a + b));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generic port size function.
|
* Generic port size function.
|
||||||
|
|
|
@ -28,7 +28,32 @@ namespace
|
||||||
i.indices[0].control = 0;
|
i.indices[0].control = 0;
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline size_t invalid_serialize(const unsigned char* buffer, char* textbuf) throw()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void invalid_display(const unsigned char* buffer, unsigned idx, char* buf)
|
||||||
|
{
|
||||||
|
*buf = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void basecontrol_display(const unsigned char* buffer, unsigned idx, char* buf)
|
||||||
|
{
|
||||||
|
if(idx)
|
||||||
|
*buf = 0;
|
||||||
|
else {
|
||||||
|
buf[0] = (buffer[0] & 1) ? 'F' : '-';
|
||||||
|
buf[1] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const char* invalid_controller_name(unsigned c)
|
||||||
|
{
|
||||||
|
return c ? NULL : "(system)";
|
||||||
|
}
|
||||||
|
|
||||||
struct port_type_group invalid_group;
|
struct port_type_group invalid_group;
|
||||||
struct porttype_invalid : public port_type
|
struct porttype_invalid : public port_type
|
||||||
{
|
{
|
||||||
|
@ -36,13 +61,13 @@ namespace
|
||||||
{
|
{
|
||||||
write = generic_port_write<0, 0, 0>;
|
write = generic_port_write<0, 0, 0>;
|
||||||
read = generic_port_read<0, 0, 0>;
|
read = generic_port_read<0, 0, 0>;
|
||||||
display = generic_port_display<0, 0, 0, 0>;
|
display = invalid_display;
|
||||||
serialize = generic_port_serialize<0, 0, 0, 0>;
|
serialize = invalid_serialize;
|
||||||
deserialize = generic_port_deserialize<0, 0, 0>;
|
deserialize = generic_port_deserialize<0, 0, 0>;
|
||||||
legal = generic_port_legal<0xFFFFFFFFU>;
|
legal = generic_port_legal<0xFFFFFFFFU>;
|
||||||
deviceflags = generic_port_deviceflags<0, 0>;
|
deviceflags = generic_port_deviceflags<0, 0>;
|
||||||
used_indices = generic_used_indices<0, 0>;
|
used_indices = generic_used_indices<0, 0>;
|
||||||
controller_name = generic_controller_name<0, 0>;
|
controller_name = invalid_controller_name;
|
||||||
button_id = button_id_illegal;
|
button_id = button_id_illegal;
|
||||||
construct_map = invalid_construct_map;
|
construct_map = invalid_construct_map;
|
||||||
controllers = 0;
|
controllers = 0;
|
||||||
|
@ -62,7 +87,7 @@ namespace
|
||||||
{
|
{
|
||||||
write = generic_port_write<1, 0, 1>;
|
write = generic_port_write<1, 0, 1>;
|
||||||
read = generic_port_read<1, 0, 1>;
|
read = generic_port_read<1, 0, 1>;
|
||||||
display = generic_port_display<0, 0, 0, 0>;
|
display = basecontrol_display;
|
||||||
serialize = basecontrol_serialize;
|
serialize = basecontrol_serialize;
|
||||||
deserialize = generic_port_deserialize<1, 0, 1>;
|
deserialize = generic_port_deserialize<1, 0, 1>;
|
||||||
legal = generic_port_legal<0>;
|
legal = generic_port_legal<0>;
|
||||||
|
@ -70,7 +95,7 @@ namespace
|
||||||
button_id = button_id_illegal;
|
button_id = button_id_illegal;
|
||||||
construct_map = invalid_construct_map;
|
construct_map = invalid_construct_map;
|
||||||
used_indices = generic_used_indices<1, 1>;
|
used_indices = generic_used_indices<1, 1>;
|
||||||
controller_name = generic_controller_name<1, 0>;
|
controller_name = invalid_controller_name;
|
||||||
controllers = 1;
|
controllers = 1;
|
||||||
set_core_controller = set_core_controller_illegal;
|
set_core_controller = set_core_controller_illegal;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue