summaryrefslogtreecommitdiff
path: root/main/SCsub
diff options
context:
space:
mode:
authorCarter Anderson <mcanders1@gmail.com>2018-03-05 19:10:17 -0800
committerCarter Anderson <mcanders1@gmail.com>2018-03-05 22:23:49 -0800
commit40b0c5583493ca34e5a1f3623cb122b98d74cc52 (patch)
tree953f1615586ae2cfad63c4376ab01c9349f4aad9 /main/SCsub
parent91ed6787088f888e196331915d59154ef2a6ce58 (diff)
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 5748bc38d2..8b4f878c85 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):
@@ -63,10 +63,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")