mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Made compiling process Python 3 compatible
This commit is contained in:
parent
b90a015daf
commit
4ff61fcdaa
|
@ -23,23 +23,22 @@ def create_flags_table(names):
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
def EmitEnum(names, num):
|
def EmitEnum(names, num):
|
||||||
print "enum"
|
print("enum")
|
||||||
print "{"
|
print("{")
|
||||||
print "\t%s=0,"%names[0]
|
print("\t%s=0," % names[0])
|
||||||
for name in names[1:]:
|
for name in names[1:]:
|
||||||
print "\t%s,"%name
|
print("\t%s," % name)
|
||||||
print "\t%s" % num
|
print("\t%s" % num)
|
||||||
print "};"
|
print("};")
|
||||||
|
|
||||||
def EmitFlags(names, num):
|
def EmitFlags(names, num):
|
||||||
print "enum"
|
print("enum")
|
||||||
print "{"
|
print("{")
|
||||||
i = 0
|
i = 0
|
||||||
for name in names:
|
for name in names:
|
||||||
print "\t%s = 1<<%d," % (name,i)
|
print("\t%s = 1<<%d," % (name,i))
|
||||||
i += 1
|
i += 1
|
||||||
print "};"
|
print("};")
|
||||||
|
|
||||||
|
|
||||||
gen_network_header = False
|
gen_network_header = False
|
||||||
gen_network_source = False
|
gen_network_source = False
|
||||||
|
@ -56,28 +55,28 @@ if "server_content_header" in sys.argv: gen_server_content_header = True
|
||||||
if "server_content_source" in sys.argv: gen_server_content_source = True
|
if "server_content_source" in sys.argv: gen_server_content_source = True
|
||||||
|
|
||||||
if gen_client_content_header:
|
if gen_client_content_header:
|
||||||
print "#ifndef CLIENT_CONTENT_HEADER"
|
print("#ifndef CLIENT_CONTENT_HEADER")
|
||||||
print "#define CLIENT_CONTENT_HEADER"
|
print("#define CLIENT_CONTENT_HEADER")
|
||||||
|
|
||||||
if gen_server_content_header:
|
if gen_server_content_header:
|
||||||
print "#ifndef SERVER_CONTENT_HEADER"
|
print("#ifndef SERVER_CONTENT_HEADER")
|
||||||
print "#define SERVER_CONTENT_HEADER"
|
print("#define SERVER_CONTENT_HEADER")
|
||||||
|
|
||||||
|
|
||||||
if gen_client_content_header or gen_server_content_header:
|
if gen_client_content_header or gen_server_content_header:
|
||||||
# emit the type declarations
|
# emit the type declarations
|
||||||
contentlines = file("datasrc/content.py").readlines()
|
contentlines = open("datasrc/content.py", "rb").readlines()
|
||||||
order = []
|
order = []
|
||||||
for line in contentlines:
|
for line in contentlines:
|
||||||
line = line.strip()
|
line = line.decode("iso8859-1").strip()
|
||||||
if line[:6] == "class " and '(Struct)' in line:
|
if line[:6] == "class " and '(Struct)' in line:
|
||||||
order += [line.split()[1].split("(")[0]]
|
order += [line.split()[1].split("(")[0]]
|
||||||
for name in order:
|
for name in order:
|
||||||
EmitTypeDeclaration(content.__dict__[name])
|
EmitTypeDeclaration(content.__dict__[name])
|
||||||
|
|
||||||
# the container pointer
|
# the container pointer
|
||||||
print 'extern DATACONTAINER *g_pData;';
|
print('extern DATACONTAINER *g_pData;')
|
||||||
|
|
||||||
# enums
|
# enums
|
||||||
EmitEnum(["IMAGE_%s"%i.name.value.upper() for i in content.container.images.items], "NUM_IMAGES")
|
EmitEnum(["IMAGE_%s"%i.name.value.upper() for i in content.container.images.items], "NUM_IMAGES")
|
||||||
EmitEnum(["ANIM_%s"%i.name.value.upper() for i in content.container.animations.items], "NUM_ANIMS")
|
EmitEnum(["ANIM_%s"%i.name.value.upper() for i in content.container.animations.items], "NUM_ANIMS")
|
||||||
|
@ -85,41 +84,41 @@ if gen_client_content_header or gen_server_content_header:
|
||||||
|
|
||||||
if gen_client_content_source or gen_server_content_source:
|
if gen_client_content_source or gen_server_content_source:
|
||||||
if gen_client_content_source:
|
if gen_client_content_source:
|
||||||
print '#include "client_data.h"'
|
print('#include "client_data.h"')
|
||||||
if gen_server_content_source:
|
if gen_server_content_source:
|
||||||
print '#include "server_data.h"'
|
print('#include "server_data.h"')
|
||||||
EmitDefinition(content.container, "datacontainer")
|
EmitDefinition(content.container, "datacontainer")
|
||||||
print 'DATACONTAINER *g_pData = &datacontainer;';
|
print('DATACONTAINER *g_pData = &datacontainer;')
|
||||||
|
|
||||||
# NETWORK
|
# NETWORK
|
||||||
if gen_network_header:
|
if gen_network_header:
|
||||||
|
|
||||||
print "#ifndef GAME_GENERATED_PROTOCOL_H"
|
print("#ifndef GAME_GENERATED_PROTOCOL_H")
|
||||||
print "#define GAME_GENERATED_PROTOCOL_H"
|
print("#define GAME_GENERATED_PROTOCOL_H")
|
||||||
print network.RawHeader
|
print(network.RawHeader)
|
||||||
|
|
||||||
for e in network.Enums:
|
for e in network.Enums:
|
||||||
for l in create_enum_table(["%s_%s"%(e.name, v) for v in e.values], 'NUM_%sS'%e.name): print l
|
for l in create_enum_table(["%s_%s"%(e.name, v) for v in e.values], 'NUM_%sS'%e.name): print(l)
|
||||||
print ""
|
print("")
|
||||||
|
|
||||||
for e in network.Flags:
|
for e in network.Flags:
|
||||||
for l in create_flags_table(["%s_%s" % (e.name, v) for v in e.values]): print l
|
for l in create_flags_table(["%s_%s" % (e.name, v) for v in e.values]): print(l)
|
||||||
print ""
|
print("")
|
||||||
|
|
||||||
for l in create_enum_table(["NETOBJ_INVALID"]+[o.enum_name for o in network.Objects], "NUM_NETOBJTYPES"): print l
|
for l in create_enum_table(["NETOBJ_INVALID"]+[o.enum_name for o in network.Objects], "NUM_NETOBJTYPES"): print(l)
|
||||||
print ""
|
print("")
|
||||||
for l in create_enum_table(["NETMSG_INVALID"]+[o.enum_name for o in network.Messages], "NUM_NETMSGTYPES"): print l
|
for l in create_enum_table(["NETMSG_INVALID"]+[o.enum_name for o in network.Messages], "NUM_NETMSGTYPES"): print(l)
|
||||||
print ""
|
print("")
|
||||||
|
|
||||||
for item in network.Objects + network.Messages:
|
for item in network.Objects + network.Messages:
|
||||||
for line in item.emit_declaration():
|
for line in item.emit_declaration():
|
||||||
print line
|
print(line)
|
||||||
print ""
|
print("")
|
||||||
|
|
||||||
EmitEnum(["SOUND_%s"%i.name.value.upper() for i in content.container.sounds.items], "NUM_SOUNDS")
|
EmitEnum(["SOUND_%s"%i.name.value.upper() for i in content.container.sounds.items], "NUM_SOUNDS")
|
||||||
EmitEnum(["WEAPON_%s"%i.name.value.upper() for i in content.container.weapons.id.items], "NUM_WEAPONS")
|
EmitEnum(["WEAPON_%s"%i.name.value.upper() for i in content.container.weapons.id.items], "NUM_WEAPONS")
|
||||||
|
|
||||||
print """
|
print("""
|
||||||
|
|
||||||
class CNetObjHandler
|
class CNetObjHandler
|
||||||
{
|
{
|
||||||
|
@ -147,9 +146,9 @@ public:
|
||||||
const char *FailedMsgOn();
|
const char *FailedMsgOn();
|
||||||
};
|
};
|
||||||
|
|
||||||
"""
|
""")
|
||||||
|
|
||||||
print "#endif // GAME_GENERATED_PROTOCOL_H"
|
print("#endif // GAME_GENERATED_PROTOCOL_H")
|
||||||
|
|
||||||
|
|
||||||
if gen_network_source:
|
if gen_network_source:
|
||||||
|
@ -228,13 +227,13 @@ if gen_network_source:
|
||||||
|
|
||||||
|
|
||||||
for l in lines:
|
for l in lines:
|
||||||
print l
|
print(l)
|
||||||
|
|
||||||
if 0:
|
if 0:
|
||||||
for item in network.Objects:
|
for item in network.Objects:
|
||||||
for line in item.emit_validate():
|
for line in item.emit_validate():
|
||||||
print line
|
print(line)
|
||||||
print ""
|
print("")
|
||||||
|
|
||||||
# create validate tables
|
# create validate tables
|
||||||
lines = []
|
lines = []
|
||||||
|
@ -271,8 +270,8 @@ if gen_network_source:
|
||||||
if 0:
|
if 0:
|
||||||
for item in network.Messages:
|
for item in network.Messages:
|
||||||
for line in item.emit_unpack():
|
for line in item.emit_unpack():
|
||||||
print line
|
print(line)
|
||||||
print ""
|
print("")
|
||||||
|
|
||||||
lines += ['static void *secure_unpack_invalid(CUnpacker *pUnpacker) { return 0; }']
|
lines += ['static void *secure_unpack_invalid(CUnpacker *pUnpacker) { return 0; }']
|
||||||
lines += ['typedef void *(*SECUREUNPACKFUNC)(CUnpacker *pUnpacker);']
|
lines += ['typedef void *(*SECUREUNPACKFUNC)(CUnpacker *pUnpacker);']
|
||||||
|
@ -313,7 +312,7 @@ if gen_network_source:
|
||||||
|
|
||||||
|
|
||||||
for l in lines:
|
for l in lines:
|
||||||
print l
|
print(l)
|
||||||
|
|
||||||
if gen_client_content_header or gen_server_content_header:
|
if gen_client_content_header or gen_server_content_header:
|
||||||
print "#endif"
|
print("#endif")
|
||||||
|
|
|
@ -169,7 +169,7 @@ class DataContainer(Struct):
|
||||||
self.weapons = Weapons()
|
self.weapons = Weapons()
|
||||||
|
|
||||||
def FileList(format, num):
|
def FileList(format, num):
|
||||||
return [format%(x+1) for x in xrange(0,num)]
|
return [format%(x+1) for x in range(0,num)]
|
||||||
|
|
||||||
container = DataContainer()
|
container = DataContainer()
|
||||||
container.sounds.Add(SoundSet("gun_fire", FileList("audio/wp_gun_fire-%02d.wv", 3)))
|
container.sounds.Add(SoundSet("gun_fire", FileList("audio/wp_gun_fire-%02d.wv", 3)))
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
GlobalIdCounter = 0
|
GlobalIdCounter = 0
|
||||||
def GetID():
|
def GetID():
|
||||||
global GlobalIdCounter
|
global GlobalIdCounter
|
||||||
|
@ -33,7 +33,7 @@ class BaseType:
|
||||||
def __init__(self, type_name):
|
def __init__(self, type_name):
|
||||||
self._type_name = type_name
|
self._type_name = type_name
|
||||||
self._target_name = "INVALID"
|
self._target_name = "INVALID"
|
||||||
self._id = GetID() # this is used to remeber what order the members have in structures etc
|
self._id = GetID() # this is used to remember what order the members have in structures etc
|
||||||
|
|
||||||
def Identifyer(self): return "x"+str(self._id)
|
def Identifyer(self): return "x"+str(self._id)
|
||||||
def TargetName(self): return self._target_name
|
def TargetName(self): return self._target_name
|
||||||
|
@ -57,18 +57,18 @@ class Struct(BaseType):
|
||||||
def __init__(self, type_name):
|
def __init__(self, type_name):
|
||||||
BaseType.__init__(self, type_name)
|
BaseType.__init__(self, type_name)
|
||||||
def Members(self):
|
def Members(self):
|
||||||
def sorter(a,b):
|
def sorter(a):
|
||||||
return a.var.ID()-b.var.ID()
|
return a.var.ID()
|
||||||
m = []
|
m = []
|
||||||
for name in self.__dict__:
|
for name in self.__dict__:
|
||||||
if name[0] == "_":
|
if name[0] == "_":
|
||||||
continue
|
continue
|
||||||
m += [MemberType(name, self.__dict__[name])]
|
m += [MemberType(name, self.__dict__[name])]
|
||||||
try:
|
try:
|
||||||
m.sort(sorter)
|
m.sort(key = sorter)
|
||||||
except:
|
except:
|
||||||
for v in m:
|
for v in m:
|
||||||
print v.name, v.var
|
print(v.name, v.var)
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
return m
|
return m
|
||||||
|
|
||||||
|
@ -172,15 +172,15 @@ class Pointer(BaseType):
|
||||||
|
|
||||||
def EmitTypeDeclaration(root):
|
def EmitTypeDeclaration(root):
|
||||||
for l in root().EmitTypeDeclaration(""):
|
for l in root().EmitTypeDeclaration(""):
|
||||||
print l
|
print(l)
|
||||||
|
|
||||||
def EmitDefinition(root, name):
|
def EmitDefinition(root, name):
|
||||||
for l in root.EmitPreDefinition(name):
|
for l in root.EmitPreDefinition(name):
|
||||||
print l
|
print(l)
|
||||||
print "%s %s = " % (root.TypeName(), name)
|
print("%s %s = " % (root.TypeName(), name))
|
||||||
for l in root.EmitDefinition(name):
|
for l in root.EmitDefinition(name):
|
||||||
print l
|
print(l)
|
||||||
print ";"
|
print(";")
|
||||||
|
|
||||||
# Network stuff after this
|
# Network stuff after this
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ Emotes = ["NORMAL", "PAIN", "HAPPY", "SURPRISE", "ANGRY", "BLINK"]
|
||||||
PlayerStates = ["UNKNOWN", "PLAYING", "IN_MENU", "CHATTING"]
|
PlayerStates = ["UNKNOWN", "PLAYING", "IN_MENU", "CHATTING"]
|
||||||
GameFlags = ["TEAMS", "FLAGS"]
|
GameFlags = ["TEAMS", "FLAGS"]
|
||||||
|
|
||||||
Emoticons = [str(x) for x in xrange(1,16)]
|
Emoticons = [str(x) for x in range(1,16)]
|
||||||
|
|
||||||
Powerups = ["HEALTH", "ARMOR", "WEAPON", "NINJA"]
|
Powerups = ["HEALTH", "ARMOR", "WEAPON", "NINJA"]
|
||||||
|
|
||||||
|
|
|
@ -26,12 +26,11 @@ def cstrip(lines):
|
||||||
|
|
||||||
f = ""
|
f = ""
|
||||||
for filename in sys.argv[1:]:
|
for filename in sys.argv[1:]:
|
||||||
f += cstrip([l.strip() for l in file(filename)])
|
f += cstrip([l.decode("iso8859-1").strip() for l in open(filename, "rb")])
|
||||||
|
|
||||||
|
hash = hashlib.md5(f.encode()).hexdigest().lower()[16:]
|
||||||
hash = hashlib.md5(f).hexdigest().lower()[16:]
|
|
||||||
# TODO: refactor hash that is equal to the 0.5 hash, remove when we
|
# TODO: refactor hash that is equal to the 0.5 hash, remove when we
|
||||||
# TODO: remove when we don't need it any more
|
# TODO: remove when we don't need it any more
|
||||||
if hash == "026b8eceb4cdd369":
|
if hash == "026b8eceb4cdd369":
|
||||||
hash = "b67d1f1a1eea234e"
|
hash = "b67d1f1a1eea234e"
|
||||||
print '#define GAME_NETVERSION_HASH "%s"' % hash
|
print('#define GAME_NETVERSION_HASH "%s"' % hash)
|
||||||
|
|
Loading…
Reference in a new issue