Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some work on double-precision support #21922

Merged
merged 1 commit into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ opts.Add(BoolVariable("tools", "Build the tools (a.k.a. the Godot editor)", True
opts.Add(EnumVariable("target", "Compilation target", "debug", ("debug", "release_debug", "release")))
opts.Add("arch", "Platform-dependent architecture (arm/arm64/x86/x64/mips/...)", "")
opts.Add(EnumVariable("bits", "Target platform bits", "default", ("default", "32", "64")))
opts.Add(EnumVariable("float", "Floating-point precision", "default", ("default", "32", "64")))
opts.Add(EnumVariable("optimize", "Optimization type", "speed", ("speed", "size", "none")))
opts.Add(BoolVariable("production", "Set defaults to build Godot for use in production", False))
opts.Add(BoolVariable("use_lto", "Use link-time optimization", False))
Expand Down Expand Up @@ -327,6 +328,9 @@ if env_base["no_editor_splash"]:
if not env_base["deprecated"]:
env_base.Append(CPPDEFINES=["DISABLE_DEPRECATED"])

if env_base["float"] == "64":
env_base.Append(CPPDEFINES=["REAL_T_IS_DOUBLE"])

if selected_platform in platform_list:
tmppath = "./platform/" + selected_platform
sys.path.insert(0, tmppath)
Expand Down Expand Up @@ -564,6 +568,9 @@ if selected_platform in platform_list:
else:
suffix = "." + selected_platform

if env_base["float"] == "64":
suffix += ".double"

if env["target"] == "release":
if env["tools"]:
print("Error: The editor can only be built with `target=debug` or `target=release_debug`.")
Expand Down
4 changes: 2 additions & 2 deletions editor/import/editor_import_collada.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,7 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones
//animation->set_loop(true);
//create animation tracks

Vector<float> base_snapshots;
Vector<real_t> base_snapshots;

float f = 0;
float snapshot_interval = 1.0 / bake_fps; //should be customizable somewhere...
Expand Down Expand Up @@ -1466,7 +1466,7 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones
animation->track_set_path(track, path);
animation->track_set_imported(track, true); //helps merging later

Vector<float> snapshots = base_snapshots;
Vector<real_t> snapshots = base_snapshots;

if (nm.anim_tracks.size() == 1) {
//use snapshot keys from anim track instead, because this was most likely exported baked
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/animation_blend_space_1d_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class AnimationNodeBlendSpace1DEditor : public AnimationTreeNodeEditorPlugin {
PopupMenu *animations_menu;
Vector<String> animations_to_add;
float add_point_pos;
Vector<float> points;
Vector<real_t> points;

bool dragging_selected_attempt;
bool dragging_selected;
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/canvas_item_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class CanvasItemEditorSelectedItem : public Object {
Transform2D pre_drag_xform;
Rect2 pre_drag_rect;

List<float> pre_drag_bones_length;
List<real_t> pre_drag_bones_length;
List<Dictionary> pre_drag_bones_undo_state;

Dictionary undo_state;
Expand Down
8 changes: 4 additions & 4 deletions editor/plugins/editor_preview_plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ EditorMaterialPreviewPlugin::EditorMaterialPreviewPlugin() {
Vector<Vector3> vertices;
Vector<Vector3> normals;
Vector<Vector2> uvs;
Vector<float> tangents;
Vector<real_t> tangents;
Basis tt = Basis(Vector3(0, 1, 0), Math_PI * 0.5);

for (int i = 1; i <= lats; i++) {
Expand Down Expand Up @@ -635,7 +635,7 @@ Ref<Texture2D> EditorAudioStreamPreviewPlugin::generate(const RES &p_from, const
Ref<AudioStreamPlayback> playback = stream->instance_playback();
ERR_FAIL_COND_V(playback.is_null(), Ref<Texture2D>());

float len_s = stream->get_length();
real_t len_s = stream->get_length();
if (len_s == 0) {
len_s = 60; //one minute audio if no length specified
}
Expand All @@ -649,8 +649,8 @@ Ref<Texture2D> EditorAudioStreamPreviewPlugin::generate(const RES &p_from, const
playback->stop();

for (int i = 0; i < w; i++) {
float max = -1000;
float min = 1000;
real_t max = -1000;
real_t min = 1000;
int from = uint64_t(i) * frame_length / w;
int to = (uint64_t(i) + 1) * frame_length / w;
to = MIN(to, frame_length);
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/node_3d_editor_gizmos.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class EditorNode3DGizmo : public Node3DGizmo {
Vector<Vector3> secondary_handles;
Vector<int> secondary_handle_ids;

float selectable_icon_size;
real_t selectable_icon_size;
bool billboard_handle;

bool valid;
Expand Down
2 changes: 2 additions & 0 deletions modules/bullet/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ thirdparty_obj = []
if env["builtin_bullet"]:
# Build only version 2 for now (as of 2.89)
# Sync file list with relevant upstream CMakeLists.txt for each folder.
if env["float"] == "64":
env.Append(CPPDEFINES=["BT_USE_DOUBLE_PRECISION=1"])
thirdparty_dir = "#thirdparty/bullet/"

bullet2_src = [
Expand Down
4 changes: 2 additions & 2 deletions modules/csg/csg_shape.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ class CSGShape3D : public GeometryInstance3D {
Vector<Vector3> vertices;
Vector<Vector3> normals;
Vector<Vector2> uvs;
Vector<float> tans;
Vector<real_t> tans;
Ref<Material> material;
int last_added = 0;

Vector3 *verticesw = nullptr;
Vector3 *normalsw = nullptr;
Vector2 *uvsw = nullptr;
float *tansw = nullptr;
real_t *tansw = nullptr;
};

//mikktspace callbacks
Expand Down
4 changes: 2 additions & 2 deletions modules/fbx/data/fbx_mesh_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ void FBXMeshData::sanitize_vertex_weights(const ImportState &state) {

{
// Sort
real_t *weights_ptr = vm->weights.ptrw();
float *weights_ptr = vm->weights.ptrw();
int *bones_ptr = vm->bones.ptrw();
for (int i = 0; i < vm->weights.size(); i += 1) {
for (int x = i + 1; x < vm->weights.size(); x += 1) {
Expand All @@ -449,7 +449,7 @@ void FBXMeshData::sanitize_vertex_weights(const ImportState &state) {
// Resize
vm->weights.resize(max_vertex_influence_count);
vm->bones.resize(max_vertex_influence_count);
real_t *weights_ptr = vm->weights.ptrw();
float *weights_ptr = vm->weights.ptrw();
int *bones_ptr = vm->bones.ptrw();
for (int i = initial_size; i < max_vertex_influence_count; i += 1) {
weights_ptr[i] = 0.0;
Expand Down
2 changes: 1 addition & 1 deletion modules/fbx/data/fbx_mesh_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct SurfaceData {
};

struct VertexWeightMapping {
Vector<real_t> weights;
Vector<float> weights;
Vector<int> bones;
// This extra vector is used because the bone id is computed in a second step.
// TODO Get rid of this extra step is a good idea.
Expand Down
2 changes: 1 addition & 1 deletion modules/vhacd/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "thirdparty/vhacd/public/VHACD.h"

static Vector<Vector<Face3>> convex_decompose(const Vector<Face3> &p_faces, int p_max_convex_hulls = -1) {
Vector<float> vertices;
Vector<real_t> vertices;
vertices.resize(p_faces.size() * 9);
Vector<uint32_t> indices;
indices.resize(p_faces.size() * 3);
Expand Down
2 changes: 1 addition & 1 deletion scene/2d/cpu_particles_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ void CPUParticles2D::_particles_process(double p_delta) {
tex_hue_variation = curve_parameters[PARAM_HUE_VARIATION]->interpolate(tv);
}

real_t hue_rot_angle = (parameters[PARAM_HUE_VARIATION] + tex_hue_variation) * Math_TAU * Math::lerp(1.0f, p.hue_rot_rand * 2.0f - 1.0f, randomness[PARAM_HUE_VARIATION]);
real_t hue_rot_angle = (parameters[PARAM_HUE_VARIATION] + tex_hue_variation) * Math_TAU * Math::lerp(1, p.hue_rot_rand * 2.0f - 1.0f, randomness[PARAM_HUE_VARIATION]);
real_t hue_rot_c = Math::cos(hue_rot_angle);
real_t hue_rot_s = Math::sin(hue_rot_angle);

Expand Down
2 changes: 1 addition & 1 deletion scene/2d/cpu_particles_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class CPUParticles2D : public Node2D {
struct Particle {
Transform2D transform;
Color color;
float custom[4] = {};
real_t custom[4] = {};
real_t rotation = 0.0;
Vector2 velocity;
bool active = false;
Expand Down
4 changes: 2 additions & 2 deletions scene/2d/gpu_particles_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,11 @@ double GPUParticles2D::get_pre_process_time() const {
return pre_process_time;
}

float GPUParticles2D::get_explosiveness_ratio() const {
real_t GPUParticles2D::get_explosiveness_ratio() const {
return explosiveness_ratio;
}

float GPUParticles2D::get_randomness_ratio() const {
real_t GPUParticles2D::get_randomness_ratio() const {
return randomness_ratio;
}

Expand Down
8 changes: 4 additions & 4 deletions scene/2d/gpu_particles_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,16 @@ class GPUParticles2D : public Node2D {
double get_lifetime() const;
bool get_one_shot() const;
double get_pre_process_time() const;
float get_explosiveness_ratio() const;
float get_randomness_ratio() const;
real_t get_explosiveness_ratio() const;
real_t get_randomness_ratio() const;
Rect2 get_visibility_rect() const;
bool get_use_local_coordinates() const;
Ref<Material> get_process_material() const;
double get_speed_scale() const;

float get_collision_base_size() const;
real_t get_collision_base_size() const;
bool is_trail_enabled() const;
float get_trail_length() const;
real_t get_trail_length() const;
int get_trail_sections() const;
int get_trail_section_subdivisions() const;

Expand Down
4 changes: 2 additions & 2 deletions scene/2d/navigation_region_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ void NavigationRegion2D::_notification(int p_what) {
// Draw the region
Transform2D xform = get_global_transform();
const NavigationServer2D *ns = NavigationServer2D::get_singleton();
float radius = ns->map_get_edge_connection_margin(get_world_2d()->get_navigation_map()) / 2.0;
real_t radius = ns->map_get_edge_connection_margin(get_world_2d()->get_navigation_map()) / 2.0;
for (int i = 0; i < ns->region_get_connections_count(region); i++) {
// Two main points
Vector2 a = ns->region_get_connection_pathway_start(region, i);
Expand All @@ -465,7 +465,7 @@ void NavigationRegion2D::_notification(int p_what) {
draw_line(a, b, doors_color);

// Draw a circle to illustrate the margins.
float angle = (b - a).angle();
real_t angle = (b - a).angle();
draw_arc(a, radius, angle + Math_PI / 2.0, angle - Math_PI / 2.0 + Math_TAU, 10, doors_color);
draw_arc(b, radius, angle - Math_PI / 2.0, angle + Math_PI / 2.0, 10, doors_color);
}
Expand Down
8 changes: 4 additions & 4 deletions scene/2d/ray_cast_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,17 +212,17 @@ void RayCast2D::_update_raycast_state() {
void RayCast2D::_draw_debug_shape() {
Color draw_col = collided ? Color(1.0, 0.01, 0) : get_tree()->get_debug_collisions_color();
if (!enabled) {
float g = draw_col.get_v();
const float g = draw_col.get_v();
draw_col.r = g;
draw_col.g = g;
draw_col.b = g;
}

// Draw an arrow indicating where the RayCast is pointing to
const float max_arrow_size = 6;
const float line_width = 1.4;
const real_t max_arrow_size = 6;
const real_t line_width = 1.4;
bool no_line = target_position.length() < line_width;
float arrow_size = CLAMP(target_position.length() * 2 / 3, line_width, max_arrow_size);
real_t arrow_size = CLAMP(target_position.length() * 2 / 3, line_width, max_arrow_size);

if (no_line) {
arrow_size = target_position.length();
Expand Down
20 changes: 10 additions & 10 deletions scene/2d/skeleton_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ bool Bone2D::_set(const StringName &p_path, const Variant &p_value) {
} else if (path.begins_with("length")) {
set_length(p_value);
} else if (path.begins_with("bone_angle")) {
set_bone_angle(Math::deg2rad(float(p_value)));
set_bone_angle(Math::deg2rad(real_t(p_value)));
} else if (path.begins_with("default_length")) {
set_length(p_value);
}
Expand Down Expand Up @@ -330,7 +330,7 @@ bool Bone2D::_editor_get_bone_shape(Vector<Vector2> *p_shape, Vector<Vector2> *p
rel = (p_other_bone->get_global_transform().get_origin() - get_global_transform().get_origin());
rel = rel.rotated(-get_global_rotation()); // Undo Bone2D node's rotation so its drawn correctly regardless of the node's rotation
} else {
float angle_to_use = get_rotation() + bone_angle;
real_t angle_to_use = get_rotation() + bone_angle;
rel = Vector2(cos(angle_to_use), sin(angle_to_use)) * (length * MIN(get_global_scale().x, get_global_scale().y));
rel = rel.rotated(-get_rotation()); // Undo Bone2D node's rotation so its drawn correctly regardless of the node's rotation
}
Expand Down Expand Up @@ -414,12 +414,12 @@ void Bone2D::apply_rest() {
set_transform(rest);
}

void Bone2D::set_default_length(float p_length) {
void Bone2D::set_default_length(real_t p_length) {
WARN_DEPRECATED_MSG("set_default_length is deprecated. Please use set_length instead!");
set_length(p_length);
}

float Bone2D::get_default_length() const {
real_t Bone2D::get_default_length() const {
WARN_DEPRECATED_MSG("get_default_length is deprecated. Please use get_length instead!");
return get_length();
}
Expand Down Expand Up @@ -485,27 +485,27 @@ bool Bone2D::get_autocalculate_length_and_angle() const {
return autocalculate_length_and_angle;
}

void Bone2D::set_length(float p_length) {
void Bone2D::set_length(real_t p_length) {
length = p_length;

#ifdef TOOLS_ENABLED
update();
#endif // TOOLS_ENABLED
}

float Bone2D::get_length() const {
real_t Bone2D::get_length() const {
return length;
}

void Bone2D::set_bone_angle(float p_angle) {
void Bone2D::set_bone_angle(real_t p_angle) {
bone_angle = p_angle;

#ifdef TOOLS_ENABLED
update();
#endif // TOOLS_ENABLED
}

float Bone2D::get_bone_angle() const {
real_t Bone2D::get_bone_angle() const {
return bone_angle;
}

Expand Down Expand Up @@ -690,7 +690,7 @@ RID Skeleton2D::get_skeleton() const {
return skeleton;
}

void Skeleton2D::set_bone_local_pose_override(int p_bone_idx, Transform2D p_override, float p_amount, bool p_persistent) {
void Skeleton2D::set_bone_local_pose_override(int p_bone_idx, Transform2D p_override, real_t p_amount, bool p_persistent) {
ERR_FAIL_INDEX_MSG(p_bone_idx, bones.size(), "Bone index is out of range!");
bones.write[p_bone_idx].local_pose_override = p_override;
bones.write[p_bone_idx].local_pose_override_amount = p_amount;
Expand Down Expand Up @@ -728,7 +728,7 @@ Ref<SkeletonModificationStack2D> Skeleton2D::get_modification_stack() const {
return modification_stack;
}

void Skeleton2D::execute_modifications(float p_delta, int p_execution_mode) {
void Skeleton2D::execute_modifications(real_t p_delta, int p_execution_mode) {
if (!modification_stack.is_valid()) {
return;
}
Expand Down
18 changes: 9 additions & 9 deletions scene/2d/skeleton_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class Bone2D : public Node2D {
Transform2D rest;

bool autocalculate_length_and_angle = true;
float length = 16;
float bone_angle = 0;
real_t length = 16;
real_t bone_angle = 0;

int skeleton_index = -1;

Expand Down Expand Up @@ -85,10 +85,10 @@ class Bone2D : public Node2D {

void set_autocalculate_length_and_angle(bool p_autocalculate);
bool get_autocalculate_length_and_angle() const;
void set_length(float p_length);
float get_length() const;
void set_bone_angle(float p_angle);
float get_bone_angle() const;
void set_length(real_t p_length);
real_t get_length() const;
void set_bone_angle(real_t p_angle);
real_t get_bone_angle() const;

int get_index_in_skeleton() const;

Expand Down Expand Up @@ -122,7 +122,7 @@ class Skeleton2D : public Node2D {

//Transform2D local_pose_cache;
Transform2D local_pose_override;
float local_pose_override_amount = 0;
real_t local_pose_override_amount = 0;
bool local_pose_override_persistent = false;
};

Expand Down Expand Up @@ -153,12 +153,12 @@ class Skeleton2D : public Node2D {

RID get_skeleton() const;

void set_bone_local_pose_override(int p_bone_idx, Transform2D p_override, float p_amount, bool p_persistent = true);
void set_bone_local_pose_override(int p_bone_idx, Transform2D p_override, real_t p_amount, bool p_persistent = true);
Transform2D get_bone_local_pose_override(int p_bone_idx);

Ref<SkeletonModificationStack2D> get_modification_stack() const;
void set_modification_stack(Ref<SkeletonModificationStack2D> p_stack);
void execute_modifications(float p_delta, int p_execution_mode);
void execute_modifications(real_t p_delta, int p_execution_mode);

Skeleton2D();
~Skeleton2D();
Expand Down
Loading