summaryrefslogtreecommitdiff
path: root/main/SCsub
diff options
context:
space:
mode:
authorHein-Pieter van Braam <hp@tmm.cx>2018-03-15 22:42:06 +0100
committerGitHub <noreply@github.com>2018-03-15 22:42:06 +0100
commite4e0ba908affceb3bcd64d9b376685eafb595f62 (patch)
treed8c6c864470830628043ead7055fed84396ca5a8 /main/SCsub
parent9bc0503c9174309dcdaf116ae16ccd9e4d9bce20 (diff)
parent40b0c5583493ca34e5a1f3623cb122b98d74cc52 (diff)
Merge pull request #17296 from cart/controller-mapping-autogen
Generate controller mapping class from one or more SDL2 database files
Diffstat (limited to 'main/SCsub')
-rw-r--r--main/SCsub71
1 files changed, 70 insertions, 1 deletions
diff --git a/main/SCsub b/main/SCsub
index aa9092ca51..ab4016190d 100644
--- a/main/SCsub
+++ b/main/SCsub
@@ -2,7 +2,7 @@
Import('env')
from compat import byte_to_str
-
+from collections import OrderedDict
def make_splash(target, source, env):
@@ -62,10 +62,79 @@ def make_app_icon(target, source, env):
g.write("};\n")
g.write("#endif")
+def make_default_controller_mappings(target, source, env):
+ dst = target[0].srcnode().abspath
+ g = open(dst, "w")
+
+ g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
+ g.write("#include \"default_controller_mappings.h\"\n")
+ g.write("#include \"typedefs.h\"\n")
+
+ # ensure mappings have a consistent order
+ platform_mappings = OrderedDict()
+ for src in source:
+ src_path = src.srcnode().abspath
+ f = open(src_path, "rb")
+
+ # read mapping file and skip header
+ mapping_file_lines = f.readlines()[2:]
+
+ current_platform = None
+ for line in mapping_file_lines:
+ if not line:
+ continue
+ line = line.strip()
+ if len(line) == 0:
+ continue
+ if line[0] == "#":
+ current_platform = line[1:].strip()
+ if current_platform not in platform_mappings:
+ platform_mappings[current_platform] = {}
+ elif current_platform:
+ line_parts = line.split(",")
+ guid = line_parts[0]
+ if guid in platform_mappings[current_platform]:
+ g.write("// WARNING - DATABASE {} OVERWROTE PRIOR MAPPING: {} {}\n".format(src_path, current_platform, platform_mappings[current_platform][guid]))
+ valid_mapping = True
+ for input_map in line_parts[2:]:
+ if "+" in input_map or "-" in input_map or "~" in input_map:
+ g.write("// WARNING - DISCARDED UNSUPPORTED MAPPING TYPE FROM DATABASE {}: {} {}\n".format(src_path, current_platform, line))
+ valid_mapping = False
+ break
+ if valid_mapping:
+ platform_mappings[current_platform][guid] = line
+
+ platform_variables = {
+ "Linux": "#if X11_ENABLED",
+ "Windows": "#ifdef WINDOWS_ENABLED",
+ "Mac OS X": "#ifdef OSX_ENABLED",
+ "Android": "#if defined(__ANDROID__)",
+ "iOS": "#ifdef IPHONE_ENABLED",
+ "Javascript": "#ifdef JAVASCRIPT_ENABLED",
+ "UWP": "#ifdef UWP_ENABLED",
+ }
+
+ g.write("const char* DefaultControllerMappings::mappings[] = {\n")
+ for platform, mappings in platform_mappings.items():
+ variable = platform_variables[platform]
+ g.write("{}\n".format(variable))
+ for mapping in mappings.values():
+ g.write("\t\"{}\",\n".format(mapping))
+ g.write("#endif\n")
+
+ g.write("};\n")
env.main_sources = []
env.add_source_files(env.main_sources, "*.cpp")
+# order matters here. higher index controller database files write on top of lower index database files
+controller_databases = ["#main/gamecontrollerdb.txt", "#main/gamecontrollerdb_205.txt", "#main/gamecontrollerdb_204.txt", "#main/godotcontrollerdb.txt"]
+
+env.Depends("#main/default_controller_mappings.gen.cpp", controller_databases)
+env.Command("#main/default_controller_mappings.gen.cpp", controller_databases, make_default_controller_mappings)
+
+env.main_sources.append("#main/default_controller_mappings.gen.cpp")
+
Export('env')
env.Depends("#main/splash.gen.h", "#main/splash.png")