Skip to content

Commit e29230b

Browse files
committed
Add double precision build support.
1 parent c6109fb commit e29230b

File tree

4 files changed

+29
-18
lines changed

4 files changed

+29
-18
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ jobs:
1515
artifact-name: godot-cpp-linux-glibc2.27-x86_64-release
1616
artifact-path: bin/libgodot-cpp.linux.release.64.a
1717

18+
- name: 🐧 Linux (GCC, Double Precision)
19+
os: ubuntu-18.04
20+
platform: linux
21+
artifact-name: godot-cpp-linux-glibc2.27-x86_64-double-release
22+
artifact-path: bin/libgodot-cpp.linux.release.64.a
23+
flags: float=64
24+
1825
- name: 🏁 Windows (x86_64, MSVC)
1926
os: windows-2019
2027
platform: windows

SConstruct

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ opts.Add(
144144
opts.Add(BoolVariable("generate_template_get_node", "Generate a template version of the Node class's get_node.", True))
145145

146146
opts.Add(BoolVariable("build_library", "Build the godot-cpp library.", True))
147+
opts.Add(EnumVariable("float", "Floating-point precision", "32", ("32", "64")))
147148

148149
opts.Update(env)
149150
Help(opts.GenerateHelpText(env))
@@ -176,6 +177,9 @@ else:
176177
if env["target"] == "debug":
177178
env.Append(CPPDEFINES=["DEBUG_ENABLED", "DEBUG_METHODS_ENABLED"])
178179

180+
if env["float"] == "64":
181+
env.Append(CPPDEFINES=["REAL_T_IS_DOUBLE"])
182+
179183
if env["platform"] == "linux" or env["platform"] == "freebsd":
180184
if env["use_llvm"]:
181185
env["CXX"] = "clang++"
@@ -469,7 +473,7 @@ if should_generate_bindings:
469473
# Actually create the bindings here
470474
import binding_generator
471475

472-
binding_generator.generate_bindings(json_api_file, env["generate_template_get_node"])
476+
binding_generator.generate_bindings(json_api_file, env["generate_template_get_node"], env["bits"], "double" if (env["float"] == "64") else "float")
473477

474478
# Sources to compile
475479
sources = []

binding_generator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def print_file_list(api_filepath, output_dir, headers=False, sources=False):
5050
print(str(utility_functions_source_path.as_posix()), end=end)
5151

5252

53-
def generate_bindings(api_filepath, use_template_get_node, output_dir="."):
53+
def generate_bindings(api_filepath, use_template_get_node, bits="64", double="float", output_dir="."):
5454
api = None
5555

5656
target_dir = Path(output_dir) / "gen"
@@ -63,7 +63,7 @@ def generate_bindings(api_filepath, use_template_get_node, output_dir="."):
6363

6464
generate_global_constants(api, target_dir)
6565
generate_global_constant_binds(api, target_dir)
66-
generate_builtin_bindings(api, target_dir, "float_64")
66+
generate_builtin_bindings(api, target_dir, double + "_" + bits)
6767
generate_engine_classes_bindings(api, target_dir, use_template_get_node)
6868
generate_utility_functions(api, target_dir)
6969

include/godot_cpp/variant/color.hpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class Color {
159159

160160
inline Color blend(const Color &p_over) const {
161161
Color res;
162-
float sa = (real_t)1.0 - p_over.a;
162+
float sa = 1.0 - p_over.a;
163163
res.a = a * sa + p_over.a;
164164
if (res.a == 0) {
165165
return Color(0, 0, 0, 0);
@@ -173,16 +173,16 @@ class Color {
173173

174174
inline Color to_linear() const {
175175
return Color(
176-
r < (real_t)0.04045 ? r * (real_t)(1.0 / 12.92) : Math::pow((r + (real_t)0.055) * (real_t)(1.0 / (1.0 + 0.055)), (real_t)2.4),
177-
g < (real_t)0.04045 ? g * (real_t)(1.0 / 12.92) : Math::pow((g + (real_t)0.055) * (real_t)(1.0 / (1.0 + 0.055)), (real_t)2.4),
178-
b < (real_t)0.04045 ? b * (real_t)(1.0 / 12.92) : Math::pow((b + (real_t)0.055) * (real_t)(1.0 / (1.0 + 0.055)), (real_t)2.4),
176+
r < 0.04045 ? r * (1.0 / 12.92) : Math::pow((r + 0.055f) * (1.0 / (1.0 + 0.055)), 2.4),
177+
g < 0.04045 ? g * (1.0 / 12.92) : Math::pow((g + 0.055f) * (1.0 / (1.0 + 0.055)), 2.4),
178+
b < 0.04045 ? b * (1.0 / 12.92) : Math::pow((b + 0.055f) * (1.0 / (1.0 + 0.055)), 2.4),
179179
a);
180180
}
181181
inline Color to_srgb() const {
182182
return Color(
183-
r < (real_t)0.0031308 ? (real_t)12.92 * r : (real_t)(1.0 + 0.055) * Math::pow(r, (real_t)(1.0 / 2.4)) - (real_t)0.055,
184-
g < (real_t)0.0031308 ? (real_t)12.92 * g : (real_t)(1.0 + 0.055) * Math::pow(g, (real_t)(1.0 / 2.4)) - (real_t)0.055,
185-
b < (real_t)0.0031308 ? (real_t)12.92 * b : (real_t)(1.0 + 0.055) * Math::pow(b, (real_t)(1.0 / 2.4)) - (real_t)0.055, a);
183+
r < 0.0031308f ? 12.92f * r : (1.0f + 0.055f) * Math::pow(r, 1.0f / 2.4f) - 0.055f,
184+
g < 0.0031308f ? 12.92f * g : (1.0f + 0.055f) * Math::pow(g, 1.0f / 2.4f) - 0.055f,
185+
b < 0.0031308f ? 12.92f * b : (1.0f + 0.055f) * Math::pow(b, 1.0f / 2.4f) - 0.055f, a);
186186
}
187187

188188
static Color hex(uint32_t p_hex);
@@ -204,14 +204,14 @@ class Color {
204204
operator String() const;
205205

206206
// For the binder.
207-
inline void set_r8(int32_t r8) { r = (Math::clamp(r8, 0, 255) / (real_t)255.0); }
208-
inline int32_t get_r8() const { return int32_t(Math::clamp(r * (real_t)255.0, (real_t)0.0, (real_t)255.0)); }
209-
inline void set_g8(int32_t g8) { g = (Math::clamp(g8, 0, 255) / (real_t)255.0); }
210-
inline int32_t get_g8() const { return int32_t(Math::clamp(g * (real_t)255.0, (real_t)0.0, (real_t)255.0)); }
211-
inline void set_b8(int32_t b8) { b = (Math::clamp(b8, 0, 255) / (real_t)255.0); }
212-
inline int32_t get_b8() const { return int32_t(Math::clamp(b * (real_t)255.0, (real_t)0.0, (real_t)255.0)); }
213-
inline void set_a8(int32_t a8) { a = (Math::clamp(a8, 0, 255) / (real_t)255.0); }
214-
inline int32_t get_a8() const { return int32_t(Math::clamp(a * (real_t)255.0, (real_t)0.0, (real_t)255.0)); }
207+
inline void set_r8(int32_t r8) { r = (Math::clamp(r8, 0, 255) / 255.0); }
208+
inline int32_t get_r8() const { return int32_t(Math::clamp(r * 255.0, 0.0, 255.0)); }
209+
inline void set_g8(int32_t g8) { g = (Math::clamp(g8, 0, 255) / 255.0); }
210+
inline int32_t get_g8() const { return int32_t(Math::clamp(g * 255.0, 0.0, 255.0)); }
211+
inline void set_b8(int32_t b8) { b = (Math::clamp(b8, 0, 255) / 255.0); }
212+
inline int32_t get_b8() const { return int32_t(Math::clamp(b * 255.0, 0.0, 255.0)); }
213+
inline void set_a8(int32_t a8) { a = (Math::clamp(a8, 0, 255) / 255.0); }
214+
inline int32_t get_a8() const { return int32_t(Math::clamp(a * 255.0, 0.0, 255.0)); }
215215

216216
inline void set_h(float p_h) { set_hsv(p_h, get_s(), get_v()); }
217217
inline void set_s(float p_s) { set_hsv(get_h(), p_s, get_v()); }

0 commit comments

Comments
 (0)