ddnet/datasrc/crosscompile.py

53 lines
1.2 KiB
Python
Raw Normal View History

2020-12-02 14:22:26 +00:00
import network
import seven.network
2020-04-16 08:46:43 +00:00
2020-12-02 14:22:26 +00:00
def get_msgs():
return ["NETMSG_INVALID"] + [m.enum_name for m in network.Messages]
2020-04-16 08:46:43 +00:00
def get_msgs_7():
2020-12-02 14:22:26 +00:00
return ["NETMSG_INVALID"] + [m.enum_name for m in seven.network.Messages]
2020-04-16 08:46:43 +00:00
2020-06-12 19:22:54 +00:00
def get_objs():
2020-12-02 14:22:26 +00:00
return ["NETOBJ_INVALID"] + [m.enum_name for m in network.Objects if m.ex is None]
2020-06-12 19:22:54 +00:00
def get_objs_7():
2020-12-02 14:22:26 +00:00
return ["NETOBJ_INVALID"] + [m.enum_name for m in seven.network.Objects]
2020-06-12 19:22:54 +00:00
2020-04-16 08:46:43 +00:00
def generate_map(a, b):
2020-12-02 14:22:26 +00:00
result = []
for m in a:
try:
result += [b.index(m)]
except ValueError:
result += [-1]
2020-04-16 08:46:43 +00:00
2020-12-02 14:22:26 +00:00
return result
2020-04-16 08:46:43 +00:00
2020-12-02 14:22:26 +00:00
def output_map(name, m):
print("static const int gs_{}[{}] = {{".format(name, len(m)))
print(*m, sep=',')
print("};")
print("inline int {0}(int a) {{ if(a < 0 || a >= {1}) return -1; return gs_{0}[a]; }}".format(name, len(m)))
2020-04-16 08:46:43 +00:00
def main():
2020-12-02 14:22:26 +00:00
guard = "GAME_GENERATED_PROTOCOLGLUE"
print("#ifndef " + guard)
print("#define " + guard)
2020-12-02 14:22:26 +00:00
msgs = get_msgs()
msgs7 = get_msgs_7()
2020-04-16 08:46:43 +00:00
2020-12-02 14:22:26 +00:00
output_map("Msg_SixToSeven", generate_map(msgs, msgs7))
output_map("Msg_SevenToSix", generate_map(msgs7, msgs))
2020-06-12 19:22:54 +00:00
2020-12-02 14:22:26 +00:00
objs = get_objs()
objs7 = get_objs_7()
output_map("Obj_SixToSeven", generate_map(objs, objs7))
output_map("Obj_SevenToSix", generate_map(objs7, objs))
2020-04-16 08:46:43 +00:00
2020-12-02 14:22:26 +00:00
print("#endif //" + guard)
2020-04-16 08:46:43 +00:00
if __name__ == "__main__":
2020-12-02 14:22:26 +00:00
main()