Merge pull request #988 from rburing/precision=double

Rename `float=64` build option to `precision=double`
pull/990/head
Rémi Verschelde 2023-01-10 16:09:02 +01:00 committed by GitHub
commit 2b7094f342
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 17 deletions

View File

@ -29,7 +29,7 @@ jobs:
platform: linux platform: linux
artifact-name: godot-cpp-linux-glibc2.27-x86_64-double-release artifact-name: godot-cpp-linux-glibc2.27-x86_64-double-release
artifact-path: bin/libgodot-cpp.linux.template_release.double.x86_64.a artifact-path: bin/libgodot-cpp.linux.template_release.double.x86_64.a
flags: float=64 flags: precision=double
cache-name: linux-x86_64-f64 cache-name: linux-x86_64-f64
- name: 🏁 Windows (x86_64, MSVC) - name: 🏁 Windows (x86_64, MSVC)

View File

@ -4,7 +4,7 @@
# godot-cpp cmake arguments # godot-cpp cmake arguments
# GODOT_GDEXTENSION_DIR: Path to the directory containing GDExtension interface header and API JSON file # GODOT_GDEXTENSION_DIR: Path to the directory containing GDExtension interface header and API JSON file
# GODOT_CUSTOM_API_FILE: Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`) # GODOT_CUSTOM_API_FILE: Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`)
# FLOAT_TYPE Floating-point precision (32, 64) # FLOAT_PRECISION: Floating-point precision level ("single", "double")
# #
# Android cmake arguments # Android cmake arguments
# CMAKE_TOOLCHAIN_FILE: The path to the android cmake toolchain ($ANDROID_NDK/build/cmake/android.toolchain.cmake) # CMAKE_TOOLCHAIN_FILE: The path to the android cmake toolchain ($ANDROID_NDK/build/cmake/android.toolchain.cmake)
@ -45,11 +45,6 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "")
set(CMAKE_BUILD_TYPE Debug) set(CMAKE_BUILD_TYPE Debug)
endif() endif()
set(FLOAT_TYPE_FLAG "float" CACHE STRING "")
if(FLOAT_TYPE EQUAL 64)
set(FLOAT_TYPE_FLAG "double" CACHE STRING "")
endif(FLOAT_TYPE EQUAL 64)
if(NOT DEFINED BITS) if(NOT DEFINED BITS)
set(BITS 32) set(BITS 32)
if(CMAKE_SIZEOF_VOID_P EQUAL 8) if(CMAKE_SIZEOF_VOID_P EQUAL 8)
@ -60,6 +55,10 @@ endif()
# Input from user for GDExtension interface header and the API JSON file # Input from user for GDExtension interface header and the API JSON file
set(GODOT_GDEXTENSION_DIR "gdextension" CACHE STRING "") set(GODOT_GDEXTENSION_DIR "gdextension" CACHE STRING "")
set(GODOT_CUSTOM_API_FILE "" CACHE STRING "") set(GODOT_CUSTOM_API_FILE "" CACHE STRING "")
set(FLOAT_PRECISION "single" CACHE STRING "")
if ("${FLOAT_PRECISION}" STREQUAL "double")
add_definitions(-DREAL_T_IS_DOUBLE)
endif()
set(GODOT_GDEXTENSION_API_FILE "${GODOT_GDEXTENSION_DIR}/extension_api.json") set(GODOT_GDEXTENSION_API_FILE "${GODOT_GDEXTENSION_DIR}/extension_api.json")
if (NOT "${GODOT_CUSTOM_API_FILE}" STREQUAL "") # User-defined override. if (NOT "${GODOT_CUSTOM_API_FILE}" STREQUAL "") # User-defined override.
@ -136,7 +135,7 @@ execute_process(COMMAND "${Python3_EXECUTABLE}" "-c" "import binding_generator;
) )
add_custom_command(OUTPUT ${GENERATED_FILES_LIST} add_custom_command(OUTPUT ${GENERATED_FILES_LIST}
COMMAND "${Python3_EXECUTABLE}" "-c" "import binding_generator; binding_generator.generate_bindings(\"${GODOT_GDEXTENSION_API_FILE}\", \"${GENERATE_BINDING_PARAMETERS}\", \"${BITS}\", \"${FLOAT_TYPE_FLAG}\", \"${CMAKE_CURRENT_BINARY_DIR}\")" COMMAND "${Python3_EXECUTABLE}" "-c" "import binding_generator; binding_generator.generate_bindings(\"${GODOT_GDEXTENSION_API_FILE}\", \"${GENERATE_BINDING_PARAMETERS}\", \"${BITS}\", \"${FLOAT_PRECISION}\", \"${CMAKE_CURRENT_BINARY_DIR}\")"
VERBATIM VERBATIM
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
MAIN_DEPENDENCY ${GODOT_GDEXTENSION_API_FILE} MAIN_DEPENDENCY ${GODOT_GDEXTENSION_API_FILE}

View File

@ -122,7 +122,7 @@ opts.Add(
opts.Add(BoolVariable("generate_template_get_node", "Generate a template version of the Node class's get_node.", True)) opts.Add(BoolVariable("generate_template_get_node", "Generate a template version of the Node class's get_node.", True))
opts.Add(BoolVariable("build_library", "Build the godot-cpp library.", True)) opts.Add(BoolVariable("build_library", "Build the godot-cpp library.", True))
opts.Add(EnumVariable("float", "Floating-point precision", "32", ("32", "64"))) opts.Add(EnumVariable("precision", "Set the floating-point precision level", "single", ("single", "double")))
# Add platform options # Add platform options
tools = {} tools = {}
@ -204,7 +204,7 @@ if env.get("is_msvc", False):
else: else:
env.Append(CXXFLAGS=["-std=c++17"]) env.Append(CXXFLAGS=["-std=c++17"])
if env["float"] == "64": if env["precision"] == "double":
env.Append(CPPDEFINES=["REAL_T_IS_DOUBLE"]) env.Append(CPPDEFINES=["REAL_T_IS_DOUBLE"])
# Generate bindings # Generate bindings
@ -239,7 +239,7 @@ sources.extend([f for f in bindings if str(f).endswith(".cpp")])
suffix = ".{}.{}".format(env["platform"], env["target"]) suffix = ".{}.{}".format(env["platform"], env["target"])
if env.dev_build: if env.dev_build:
suffix += ".dev" suffix += ".dev"
if env["float"] == "64": if env["precision"] == "double":
suffix += ".double" suffix += ".double"
suffix += "." + env["arch"] suffix += "." + env["arch"]
if env["ios_simulator"]: if env["ios_simulator"]:

View File

@ -151,13 +151,13 @@ def scons_generate_bindings(target, source, env):
str(source[0]), str(source[0]),
env["generate_template_get_node"], env["generate_template_get_node"],
"32" if "32" in env["arch"] else "64", "32" if "32" in env["arch"] else "64",
"double" if (env["float"] == "64") else "float", env["precision"],
env["godot_cpp_gen_dir"], env["godot_cpp_gen_dir"],
) )
return None return None
def generate_bindings(api_filepath, use_template_get_node, bits="64", double="float", output_dir="."): def generate_bindings(api_filepath, use_template_get_node, bits="64", precision="single", output_dir="."):
api = None api = None
target_dir = Path(output_dir) / "gen" target_dir = Path(output_dir) / "gen"
@ -168,11 +168,12 @@ def generate_bindings(api_filepath, use_template_get_node, bits="64", double="fl
shutil.rmtree(target_dir, ignore_errors=True) shutil.rmtree(target_dir, ignore_errors=True)
target_dir.mkdir(parents=True) target_dir.mkdir(parents=True)
print("Built-in type config: " + double + "_" + bits) real_t = "double" if precision == "double" else "float"
print("Built-in type config: " + real_t + "_" + bits)
generate_global_constants(api, target_dir) generate_global_constants(api, target_dir)
generate_global_constant_binds(api, target_dir) generate_global_constant_binds(api, target_dir)
generate_builtin_bindings(api, target_dir, double + "_" + bits) generate_builtin_bindings(api, target_dir, real_t + "_" + bits)
generate_engine_classes_bindings(api, target_dir, use_template_get_node) generate_engine_classes_bindings(api, target_dir, use_template_get_node)
generate_utility_functions(api, target_dir) generate_utility_functions(api, target_dir)

View File

@ -10,10 +10,10 @@ from binding_generator import get_file_list, generate_bindings
api_filepath = "gdextension/extension_api.json" api_filepath = "gdextension/extension_api.json"
bits = "64" bits = "64"
double = "float" precision = "single"
output_dir = "self_test" output_dir = "self_test"
generate_bindings(api_filepath, use_template_get_node=False, bits=bits, double=double, output_dir=output_dir) generate_bindings(api_filepath, use_template_get_node=False, bits=bits, precision=precision, output_dir=output_dir)
flist = get_file_list(api_filepath, output_dir, headers=True, sources=True) flist = get_file_list(api_filepath, output_dir, headers=True, sources=True)
p = Path(output_dir) / "gen" p = Path(output_dir) / "gen"