Make port_type::legal based on data instead of generated
This commit is contained in:
parent
ccd4c2d5b8
commit
a38ce6b99e
4 changed files with 13 additions and 17 deletions
|
@ -226,6 +226,7 @@ struct port_controller
|
|||
struct port_controller_set
|
||||
{
|
||||
std::vector<port_controller*> controllers; //Controllers.
|
||||
std::set<unsigned> legal_for; //Ports this is legal for
|
||||
/**
|
||||
* Get specified controller, or NULL if it doesn't exist.
|
||||
*/
|
||||
|
@ -305,7 +306,10 @@ public:
|
|||
* Parameter port: Port to query.
|
||||
* Returns: Nonzero if legal, zero if illegal.
|
||||
*/
|
||||
int (*legal)(unsigned port);
|
||||
int legal(unsigned port)
|
||||
{
|
||||
return controller_info->legal_for.count(port) ? 1 : 0;
|
||||
}
|
||||
/**
|
||||
* Controller info.
|
||||
*/
|
||||
|
|
|
@ -112,7 +112,12 @@ for i = 1,#ports do
|
|||
s = s .."&"..csyms[j];
|
||||
end
|
||||
s = s .. "}"
|
||||
print("\tport_controller_set "..psym2.." = {"..s.."};");
|
||||
local legal_for = "{";
|
||||
for j = 1,#(port.legal) do
|
||||
legal_for = legal_for .. port.legal[j] .. ",";
|
||||
end
|
||||
legal_for = legal_for .. "}"
|
||||
print("\tport_controller_set "..psym2.." = {"..s..","..legal_for.."};");
|
||||
print("}");
|
||||
print("struct _"..port.symbol.." : public port_type");
|
||||
print("{");
|
||||
|
@ -256,12 +261,6 @@ for i = 1,#ports do
|
|||
print("\t\t\treturn ptr;");
|
||||
end
|
||||
print("\t\t};");
|
||||
print("\t\tlegal = [](unsigned c) -> int {");
|
||||
for j = 1,#(port.legal) do
|
||||
print("\t\t\tif(c == "..port.legal[j]..") return true;");
|
||||
end
|
||||
print("\t\t\treturn false;");
|
||||
print("\t\t};");
|
||||
print("\t\tcontroller_info = &portdefs::"..psym2..";");
|
||||
print("\t}");
|
||||
print("} "..port.symbol..";");
|
||||
|
|
|
@ -83,7 +83,7 @@ namespace sky
|
|||
{port_controller_button::TYPE_NULL, '\0', "", false},
|
||||
}};
|
||||
|
||||
port_controller_set X2 = {{&X4, &X8}};
|
||||
port_controller_set X2 = {{&X4, &X8},{0}};
|
||||
|
||||
void port_write(unsigned char* buffer, unsigned idx, unsigned ctrl, short x)
|
||||
{
|
||||
|
@ -192,11 +192,6 @@ namespace sky
|
|||
if(read_button_value(textbuf, ptr)) buffer[0] |= 128;
|
||||
skip_rest_of_field(textbuf, ptr, false);
|
||||
};
|
||||
int port_legal(unsigned c)
|
||||
{
|
||||
if(c == 0) return true;
|
||||
return false;
|
||||
};
|
||||
|
||||
struct _psystem : public port_type
|
||||
{
|
||||
|
@ -206,7 +201,6 @@ namespace sky
|
|||
read = port_read;
|
||||
serialize = port_serialize;
|
||||
deserialize = port_deserialize;
|
||||
legal = port_legal;
|
||||
controller_info = &X2;
|
||||
}
|
||||
} psystem;
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
namespace
|
||||
{
|
||||
port_controller simple_controller = {"(system)", "system", {}};
|
||||
port_controller_set simple_port = {{&simple_controller}};
|
||||
port_controller_set simple_port = {{&simple_controller},{0}};
|
||||
|
||||
struct porttype_basecontrol : public port_type
|
||||
{
|
||||
|
@ -40,7 +40,6 @@ namespace
|
|||
skip_rest_of_field(textbuf, ptr, false);
|
||||
return ptr;
|
||||
};
|
||||
legal = [](unsigned port) -> int { return (port == 0); };
|
||||
controller_info = &simple_port;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue