Skip to content

Commit 2b7094f

Browse files
authored
Merge pull request godotengine#988 from rburing/precision=double
Rename `float=64` build option to `precision=double`
2 parents 8ee9cab + 47140cd commit 2b7094f

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
platform: linux
3030
artifact-name: godot-cpp-linux-glibc2.27-x86_64-double-release
3131
artifact-path: bin/libgodot-cpp.linux.template_release.double.x86_64.a
32-
flags: float=64
32+
flags: precision=double
3333
cache-name: linux-x86_64-f64
3434

3535
- name: 🏁 Windows (x86_64, MSVC)

CMakeLists.txt

+6-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# godot-cpp cmake arguments
55
# GODOT_GDEXTENSION_DIR: Path to the directory containing GDExtension interface header and API JSON file
66
# GODOT_CUSTOM_API_FILE: Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`)
7-
# FLOAT_TYPE Floating-point precision (32, 64)
7+
# FLOAT_PRECISION: Floating-point precision level ("single", "double")
88
#
99
# Android cmake arguments
1010
# 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 "")
4545
set(CMAKE_BUILD_TYPE Debug)
4646
endif()
4747

48-
set(FLOAT_TYPE_FLAG "float" CACHE STRING "")
49-
if(FLOAT_TYPE EQUAL 64)
50-
set(FLOAT_TYPE_FLAG "double" CACHE STRING "")
51-
endif(FLOAT_TYPE EQUAL 64)
52-
5348
if(NOT DEFINED BITS)
5449
set(BITS 32)
5550
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
@@ -60,6 +55,10 @@ endif()
6055
# Input from user for GDExtension interface header and the API JSON file
6156
set(GODOT_GDEXTENSION_DIR "gdextension" CACHE STRING "")
6257
set(GODOT_CUSTOM_API_FILE "" CACHE STRING "")
58+
set(FLOAT_PRECISION "single" CACHE STRING "")
59+
if ("${FLOAT_PRECISION}" STREQUAL "double")
60+
add_definitions(-DREAL_T_IS_DOUBLE)
61+
endif()
6362

6463
set(GODOT_GDEXTENSION_API_FILE "${GODOT_GDEXTENSION_DIR}/extension_api.json")
6564
if (NOT "${GODOT_CUSTOM_API_FILE}" STREQUAL "") # User-defined override.
@@ -136,7 +135,7 @@ execute_process(COMMAND "${Python3_EXECUTABLE}" "-c" "import binding_generator;
136135
)
137136

138137
add_custom_command(OUTPUT ${GENERATED_FILES_LIST}
139-
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}\")"
138+
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}\")"
140139
VERBATIM
141140
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
142141
MAIN_DEPENDENCY ${GODOT_GDEXTENSION_API_FILE}

SConstruct

+3-3
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ opts.Add(
122122
opts.Add(BoolVariable("generate_template_get_node", "Generate a template version of the Node class's get_node.", True))
123123

124124
opts.Add(BoolVariable("build_library", "Build the godot-cpp library.", True))
125-
opts.Add(EnumVariable("float", "Floating-point precision", "32", ("32", "64")))
125+
opts.Add(EnumVariable("precision", "Set the floating-point precision level", "single", ("single", "double")))
126126

127127
# Add platform options
128128
tools = {}
@@ -204,7 +204,7 @@ if env.get("is_msvc", False):
204204
else:
205205
env.Append(CXXFLAGS=["-std=c++17"])
206206

207-
if env["float"] == "64":
207+
if env["precision"] == "double":
208208
env.Append(CPPDEFINES=["REAL_T_IS_DOUBLE"])
209209

210210
# Generate bindings
@@ -239,7 +239,7 @@ sources.extend([f for f in bindings if str(f).endswith(".cpp")])
239239
suffix = ".{}.{}".format(env["platform"], env["target"])
240240
if env.dev_build:
241241
suffix += ".dev"
242-
if env["float"] == "64":
242+
if env["precision"] == "double":
243243
suffix += ".double"
244244
suffix += "." + env["arch"]
245245
if env["ios_simulator"]:

binding_generator.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,13 @@ def scons_generate_bindings(target, source, env):
151151
str(source[0]),
152152
env["generate_template_get_node"],
153153
"32" if "32" in env["arch"] else "64",
154-
"double" if (env["float"] == "64") else "float",
154+
env["precision"],
155155
env["godot_cpp_gen_dir"],
156156
)
157157
return None
158158

159159

160-
def generate_bindings(api_filepath, use_template_get_node, bits="64", double="float", output_dir="."):
160+
def generate_bindings(api_filepath, use_template_get_node, bits="64", precision="single", output_dir="."):
161161
api = None
162162

163163
target_dir = Path(output_dir) / "gen"
@@ -168,11 +168,12 @@ def generate_bindings(api_filepath, use_template_get_node, bits="64", double="fl
168168
shutil.rmtree(target_dir, ignore_errors=True)
169169
target_dir.mkdir(parents=True)
170170

171-
print("Built-in type config: " + double + "_" + bits)
171+
real_t = "double" if precision == "double" else "float"
172+
print("Built-in type config: " + real_t + "_" + bits)
172173

173174
generate_global_constants(api, target_dir)
174175
generate_global_constant_binds(api, target_dir)
175-
generate_builtin_bindings(api, target_dir, double + "_" + bits)
176+
generate_builtin_bindings(api, target_dir, real_t + "_" + bits)
176177
generate_engine_classes_bindings(api, target_dir, use_template_get_node)
177178
generate_utility_functions(api, target_dir)
178179

misc/scripts/check_get_file_list.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
api_filepath = "gdextension/extension_api.json"
1212
bits = "64"
13-
double = "float"
13+
precision = "single"
1414
output_dir = "self_test"
1515

16-
generate_bindings(api_filepath, use_template_get_node=False, bits=bits, double=double, output_dir=output_dir)
16+
generate_bindings(api_filepath, use_template_get_node=False, bits=bits, precision=precision, output_dir=output_dir)
1717
flist = get_file_list(api_filepath, output_dir, headers=True, sources=True)
1818

1919
p = Path(output_dir) / "gen"

0 commit comments

Comments
 (0)