Skip to content

Commit

Permalink
precision=double fixes
Browse files Browse the repository at this point in the history
Added the ability to disable world coordinates for shaders.
Added the ability to fix the position of instances.
`ScopedPairIdConfig` is now a structure.
Added a class `ViewportToDebugContainerItem` for storing containers of the world and viewports.
Replaced `typedef` with `using`.
Fixed warnings about converting `double` to `float`.
  • Loading branch information
DmitriySalnikov committed Nov 4, 2024
1 parent 65b4e62 commit a93e677
Show file tree
Hide file tree
Showing 26 changed files with 402 additions and 143 deletions.
11 changes: 11 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def setup_options(env: SConsEnvironment, arguments):
opts.Add(BoolVariable("telemetry_enabled", "Enable the telemetry module", False))
opts.Add(BoolVariable("tracy_enabled", "Enable tracy profiler", False))
opts.Add(BoolVariable("force_enabled_dd3d", "Keep the rendering code in the release build", False))
opts.Add(BoolVariable("fix_precision_enabled", "Fix precision errors at greater distances, utilizing more CPU resources.", True))
opts.Add(BoolVariable("shader_world_coords_enabled", "Use world coordinates in shaders, if applicable.\nDisable it for stability at a great distance from the center of the world.", True))
opts.Add(BoolVariable("lto", "Link-time optimization", False))

opts.Update(env)
Expand Down Expand Up @@ -84,6 +86,12 @@ def setup_defines_and_flags(env: SConsEnvironment, src_out):
env.Append(CPPDEFINES=["TRACY_ENABLE", "TRACY_ON_DEMAND", "TRACY_DELAYED_INIT", "TRACY_MANUAL_LIFETIME"])
src_out.append("thirdparty/tracy/public/TracyClient.cpp")

if env["fix_precision_enabled"]:
env.Append(CPPDEFINES=["FIX_PRECISION_ENABLED"])

if not env["shader_world_coords_enabled"]:
env.Append(CPPDEFINES=["DISABLE_SHADER_WORLD_COORDS"])

if env.get("is_msvc", False):
env.Append(LINKFLAGS=["/WX:NO"])

Expand Down Expand Up @@ -162,6 +170,9 @@ extra_tags = ""
if "release" in env["target"] and env["force_enabled_dd3d"]:
extra_tags += ".enabled"

if env.get("precision", "single") == "double":
extra_tags += ".double"

lib_utils.get_library_object(
env, project_name, lib_name, extra_tags, env["addon_output_dir"], src_folder, additional_src
)
Expand Down
50 changes: 50 additions & 0 deletions addons/debug_draw_3d/debug_draw_3d.gdextension
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,53 @@ web.template_release.wasm32.nothreads.forced_dd3d = "libs/libdd3d.web.template_r
web.template_release.wasm32.forced_dd3d = "libs/libdd3d.web.template_release.wasm32.threads.enabled.wasm"

ios.template_release.forced_dd3d = "libs/libdd3d.ios.template_release.universal.enabled.dylib"

; -------------------------------------
; DOUBLE PRECISION
; -------------------------------------

; -------------------------------------
; debug

macos.double = "libs/libdd3d.macos.editor.universal.double.framework"
windows.x86_64.double = "libs/libdd3d.windows.editor.x86_64.double.dll"
linux.x86_64.double = "libs/libdd3d.linux.editor.x86_64.double.so"

web.wasm32.nothreads.double = "libs/libdd3d.web.template_debug.wasm32.double.wasm"
web.wasm32.double = "libs/libdd3d.web.template_debug.wasm32.threads.double.wasm"

android.arm32.double = "libs/libdd3d.android.template_debug.arm32.double.so"
android.arm64.double = "libs/libdd3d.android.template_debug.arm64.double.so"
android.x86_32.double = "libs/libdd3d.android.template_debug.x86_32.double.so"
android.x86_64.double = "libs/libdd3d.android.template_debug.x86_64.double.so"

ios.double = "libs/libdd3d.ios.template_debug.universal.dylib"

; -------------------------------------
; release no debug draw

macos.template_release.double = "libs/libdd3d.macos.template_release.universal.double.framework"
windows.template_release.x86_64.double = "libs/libdd3d.windows.template_release.x86_64.double.dll"
linux.template_release.x86_64.double = "libs/libdd3d.linux.template_release.x86_64.double.so"

web.template_release.wasm32.nothreads.double = "libs/libdd3d.web.template_release.wasm32.double.wasm"
web.template_release.wasm32.double = "libs/libdd3d.web.template_release.wasm32.threads.double.wasm"

android.template_release.arm32.double = "libs/libdd3d.android.template_release.arm32.double.so"
android.template_release.arm64.double = "libs/libdd3d.android.template_release.arm64.double.so"
android.template_release.x86_32.double = "libs/libdd3d.android.template_release.x86_32.double.so"
android.template_release.x86_64.double = "libs/libdd3d.android.template_release.x86_64.double.so"

ios.template_release.double = "libs/libdd3d.ios.template_release.universal.double.dylib"

; -------------------------------------
; release forced debug draw

macos.template_release.forced_dd3d.double = "libs/libdd3d.macos.template_release.universal.enabled.double.framework"
windows.template_release.x86_64.forced_dd3d.double = "libs/libdd3d.windows.template_release.x86_64.enabled.double.dll"
linux.template_release.x86_64.forced_dd3d.double = "libs/libdd3d.linux.template_release.x86_64.enabled.double.so"

web.template_release.wasm32.nothreads.forced_dd3d.double = "libs/libdd3d.web.template_release.wasm32.enabled.double.wasm"
web.template_release.wasm32.forced_dd3d.double = "libs/libdd3d.web.template_release.wasm32.threads.enabled.double.wasm"

ios.template_release.forced_dd3d.double = "libs/libdd3d.ios.template_release.universal.enabled.double.dylib"
3 changes: 3 additions & 0 deletions dev_debug_draw_3d_Library.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "debug_draw_3d_Library", "sr
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
editor_dev_double|x64 = editor_dev_double|x64
editor_dev|x64 = editor_dev|x64
editor|x64 = editor|x64
release_forced|x64 = release_forced|x64
template_release|x64 = template_release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A265372D-FCD7-4FBD-9F8C-0D31F6D0F557}.editor_dev_double|x64.ActiveCfg = editor_dev_double|x64
{A265372D-FCD7-4FBD-9F8C-0D31F6D0F557}.editor_dev_double|x64.Build.0 = editor_dev_double|x64
{A265372D-FCD7-4FBD-9F8C-0D31F6D0F557}.editor_dev|x64.ActiveCfg = editor_dev|x64
{A265372D-FCD7-4FBD-9F8C-0D31F6D0F557}.editor_dev|x64.Build.0 = editor_dev|x64
{A265372D-FCD7-4FBD-9F8C-0D31F6D0F557}.editor|x64.ActiveCfg = editor|x64
Expand Down
2 changes: 1 addition & 1 deletion examples_dd3d/DebugDrawDemoScene.gd
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ func _draw_array_of_boxes():
var size = Vector3.ONE
cfg.set_thickness(randf_range(0, 0.1))
#var size = Vector3(randf_range(0.1, 100),randf_range(0.1, 100),randf_range(0.1, 100))
DebugDraw3D.draw_box(Vector3(x * mul, (-4-z) * mul, y * mul), Quaternion.IDENTITY, size, DebugDraw3D.empty_color, false, cubes_max_time)
DebugDraw3D.draw_box(Vector3(x * mul, (-4-z) * mul, y * mul) + global_position, Quaternion.IDENTITY, size, DebugDraw3D.empty_color, false, cubes_max_time)
#print("Draw Cubes: %fms" % ((Time.get_ticks_usec() - _start_time) / 1000.0))
timer_cubes = cubes_max_time

Expand Down
2 changes: 1 addition & 1 deletion examples_dd3d/DebugDrawDemoSceneCS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ void _draw_array_of_boxes()
var size = Vector3.One;
cfg.SetThickness(Random.Shared.NextSingle() * 0.1f);
//size = new Vector3(Random.Shared.NextSingle() * 100 + 0.1f, Random.Shared.NextSingle() * 100 + 0.1f, Random.Shared.NextSingle() * 100 + 0.1f);
DebugDraw3D.DrawBox(new Vector3(x * mul, (-4 - z) * mul, y * mul), Quaternion.Identity, size, null, false, cubes_max_time);
DebugDraw3D.DrawBox(new Vector3(x * mul, (-4 - z) * mul, y * mul) + GlobalPosition, Quaternion.Identity, size, null, false, cubes_max_time);
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/2d/debug_draw_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ DebugDraw2D::~DebugDraw2D() {
static bool DebugDraw2D_frame_mark_2d_started = false;
#endif

void DebugDraw2D::process(double delta) {
void DebugDraw2D::process_start(double delta) {
}

void DebugDraw2D::process_end(double delta) {
ZoneScoped;

#ifdef TRACY_ENABLE
Expand Down
3 changes: 2 additions & 1 deletion src/2d/debug_draw_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class DebugDraw2D : public Object {
void _on_canvas_item_draw(Control *ci);
inline bool _is_enabled_override() const;

void process(double delta);
void process_start(double delta);
void process_end(double delta);
void physics_process_start(double delta);
void physics_process_end(double delta);

Expand Down
2 changes: 1 addition & 1 deletion src/2d/grouped_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ void GroupedText::draw(CanvasItem *p_ci, const Ref<Font> &p_font, const Vector2
const Vector2 text_padding = owner->get_config()->get_text_padding();
const Vector2 font_offset = Vector2(0, (real_t)draw_font->get_ascent(font_size)) + text_padding;

float size_right_revert = (size.x + text_padding.x * 2) * right_side_multiplier;
real_t size_right_revert = (size.x + text_padding.x * 2) * right_side_multiplier;
backgrounds.push_back(DrawRectInstance(
Rect2(Vector2(pos.x + size_right_revert, pos.y).floor(), Vector2(size.x + text_padding.x * 2, size.y + text_padding.y * 2).floor()),
owner->get_config()->get_text_background_color()));
Expand Down
4 changes: 2 additions & 2 deletions src/2d/grouped_text.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class TextGroupItem {
bool is_expired();
};

typedef std::shared_ptr<TextGroupItem> TextGroupItem_ptr;
using TextGroupItem_ptr = std::shared_ptr<TextGroupItem>;

class TextGroup {
private:
Expand Down Expand Up @@ -74,7 +74,7 @@ class TextGroup {
void cleanup_texts(const std::function<void()> &p_update, const double &p_delta);
};

typedef std::shared_ptr<TextGroup> TextGroup_ptr;
using TextGroup_ptr = std::shared_ptr<TextGroup>;

class GroupedText {
struct DrawRectInstance {
Expand Down
2 changes: 1 addition & 1 deletion src/3d/config_scope_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class DebugDraw3DScopeConfig : public RefCounted {
uint64_t thread_id;
uint64_t guard_id;

typedef std::function<void(const uint64_t &, const uint64_t &)> unregister_func;
using unregister_func = std::function<void(const uint64_t &, const uint64_t &)>;
unregister_func unregister_action;

public:
Expand Down
Loading

0 comments on commit a93e677

Please sign in to comment.