@@ -97,9 +97,9 @@ def get_file_list(api_filepath, output_dir, headers=False, sources=False):
97
97
files .append (str (source_filename .as_posix ()))
98
98
99
99
for engine_class in api ["classes" ]:
100
- # TODO: Properly setup this singleton since it conflicts with ClassDB in the bindings .
100
+ # Generate code for the ClassDB singleton under a different name .
101
101
if engine_class ["name" ] == "ClassDB" :
102
- continue
102
+ engine_class [ "name" ] = "ClassDBSingleton"
103
103
header_filename = include_gen_folder / "classes" / (camel_to_snake (engine_class ["name" ]) + ".hpp" )
104
104
source_filename = source_gen_folder / "classes" / (camel_to_snake (engine_class ["name" ]) + ".cpp" )
105
105
if headers :
@@ -1036,21 +1036,21 @@ def generate_engine_classes_bindings(api, output_dir, use_template_get_node):
1036
1036
1037
1037
# First create map of classes and singletons.
1038
1038
for class_api in api ["classes" ]:
1039
- # TODO: Properly setup this singleton since it conflicts with ClassDB in the bindings .
1039
+ # Generate code for the ClassDB singleton under a different name .
1040
1040
if class_api ["name" ] == "ClassDB" :
1041
- continue
1041
+ class_api [ "name" ] = "ClassDBSingleton"
1042
1042
engine_classes [class_api ["name" ]] = class_api ["is_refcounted" ]
1043
1043
for native_struct in api ["native_structures" ]:
1044
1044
engine_classes [native_struct ["name" ]] = False
1045
1045
native_structures .append (native_struct ["name" ])
1046
1046
1047
1047
for singleton in api ["singletons" ]:
1048
+ # Generate code for the ClassDB singleton under a different name.
1049
+ if singleton ["name" ] == "ClassDB" :
1050
+ singleton ["name" ] = "ClassDBSingleton"
1048
1051
singletons .append (singleton ["name" ])
1049
1052
1050
1053
for class_api in api ["classes" ]:
1051
- # TODO: Properly setup this singleton since it conflicts with ClassDB in the bindings.
1052
- if class_api ["name" ] == "ClassDB" :
1053
- continue
1054
1054
# Check used classes for header include.
1055
1055
used_classes = set ()
1056
1056
fully_used_classes = set ()
@@ -1242,7 +1242,7 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us
1242
1242
if len (fully_used_classes ) > 0 :
1243
1243
result .append ("" )
1244
1244
1245
- if class_name != "Object" :
1245
+ if class_name != "Object" and class_name != "ClassDBSingleton" :
1246
1246
result .append ("#include <godot_cpp/core/class_db.hpp>" )
1247
1247
result .append ("" )
1248
1248
result .append ("#include <type_traits>" )
@@ -1421,6 +1421,51 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us
1421
1421
result .append (f'VARIANT_ENUM_CAST({ class_name } ::{ enum_api ["name" ]} );' )
1422
1422
result .append ("" )
1423
1423
1424
+ if class_name == "ClassDBSingleton" :
1425
+ result .append ("#define CLASSDB_SINGLETON_FORWARD_METHODS \\ " )
1426
+ for method in class_api ["methods" ]:
1427
+ # ClassDBSingleton shouldn't have any static or vararg methods, but if some appear later, lets skip them.
1428
+ if vararg :
1429
+ continue
1430
+ if "is_static" in method and method ["is_static" ]:
1431
+ continue
1432
+
1433
+ method_signature = "\t static "
1434
+ if "return_type" in method :
1435
+ method_signature += f'{ correct_type (method ["return_type" ])} '
1436
+ elif "return_value" in method :
1437
+ method_signature += (
1438
+ correct_type (method ["return_value" ]["type" ], method ["return_value" ].get ("meta" , None )) + " "
1439
+ )
1440
+ else :
1441
+ method_signature += "void "
1442
+
1443
+ method_signature += f'{ method ["name" ]} ('
1444
+
1445
+ method_arguments = []
1446
+ if "arguments" in method :
1447
+ method_arguments = method ["arguments" ]
1448
+
1449
+ method_signature += make_function_parameters (
1450
+ method_arguments , include_default = True , for_builtin = True , is_vararg = False
1451
+ )
1452
+
1453
+ method_signature += ") { \\ "
1454
+
1455
+ result .append (method_signature )
1456
+
1457
+ method_body = "\t \t "
1458
+ if "return_type" in method or "return_value" in method :
1459
+ method_body += "return "
1460
+ method_body += f'ClassDBSingleton::get_singleton()->{ method ["name" ]} ('
1461
+ method_body += ", " .join (map (lambda x : escape_identifier (x ["name" ]), method_arguments ))
1462
+ method_body += "); \\ "
1463
+
1464
+ result .append (method_body )
1465
+ result .append ("\t } \\ " )
1466
+ result .append ("\t ;" )
1467
+ result .append ("" )
1468
+
1424
1469
result .append (f"#endif // ! { header_guard } " )
1425
1470
1426
1471
return "\n " .join (result )
@@ -2285,6 +2330,7 @@ def escape_identifier(id):
2285
2330
"operator" : "_operator" ,
2286
2331
"typeof" : "type_of" ,
2287
2332
"typename" : "type_name" ,
2333
+ "enum" : "_enum" ,
2288
2334
}
2289
2335
if id in cpp_keywords_map :
2290
2336
return cpp_keywords_map [id ]
0 commit comments