Skip to content

Commit

Permalink
fixed data graph issues
Browse files Browse the repository at this point in the history
restored groupedText renderer
added Ref<T> patch.
Need godotengine/godot#69902 to work
  • Loading branch information
DmitriySalnikov committed Dec 12, 2022
1 parent 17f22bd commit 7133097
Show file tree
Hide file tree
Showing 15 changed files with 292 additions and 205 deletions.
1 change: 1 addition & 0 deletions .github/actions/compile_gdextension/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ runs:
git apply --ignore-space-change --ignore-whitespace ../patches/godot_cpp_exclude_unused_classes.patch
git apply --ignore-space-change --ignore-whitespace ../patches/typed_ptr.patch
git apply --ignore-space-change --ignore-whitespace ../patches/enum_names.patch
git apply --ignore-space-change --ignore-whitespace ../patches/ref_patch.patch
cd ..
scons platform=${{inputs.platform}} arch=${{inputs.arch}} target=${{inputs.target}} addon_output_dir=${{inputs.output_libs_path}} ${{inputs.additional}}
echo "::endgroup::"
Expand Down
2 changes: 1 addition & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

import lib_utils
env = SConscript("godot-cpp/SConstruct")
Default(lib_utils.gdnative_get_library_object(env, ARGUMENTS, lambda e, o: Help(o.GenerateHelpText(e))))
Default(lib_utils.gdnative_get_library_object(env.Clone(), ARGUMENTS, lambda e, o: Help(o.GenerateHelpText(e))))
1 change: 1 addition & 0 deletions dev_build_godot_cpp.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set api=
git apply --ignore-space-change --ignore-whitespace ../patches/godot_cpp_exclude_unused_classes.patch
git apply --ignore-space-change --ignore-whitespace ../patches/typed_ptr.patch
git apply --ignore-space-change --ignore-whitespace ../patches/enum_names.patch
git apply --ignore-space-change --ignore-whitespace ../patches/ref_patch.patch

title win x64 debug dev
scons platform=windows target=template_debug arch=x86_64 dev_build=yes %api% generate_bindings=yes
Expand Down
2 changes: 1 addition & 1 deletion dev_debug_draw_3d_Library.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
<WholeProgramOptimization>
</WholeProgramOptimization>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard>stdcpp20</LanguageStandard>
<EnableEnhancedInstructionSet>NotSet</EnableEnhancedInstructionSet>
<SuppressStartupBanner>true</SuppressStartupBanner>
<CreateHotpatchableImage>
Expand Down
26 changes: 12 additions & 14 deletions examples/DebugDrawDemoScene.gd
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ func _process(delta: float) -> void:
DebugDraw.visible_instance_bounds = Input.is_key_pressed(KEY_RIGHT)

# Enable FPSGraph if not exists
var g = _create_graph("FPS", true, false, DebugDraw.POSITION_LEFT_TOP if Engine.is_editor_hint() else DebugDraw.POSITION_RIGHT_TOP, GraphParameters.TEXT_CURRENT | GraphParameters.TEXT_AVG | GraphParameters.TEXT_MAX | GraphParameters.TEXT_MIN, Vector2(200, 80), custom_font)
if g:
g.buffer_size = 300
_create_graph("FPS", true, false, DebugDraw.POSITION_LEFT_TOP if Engine.is_editor_hint() else DebugDraw.POSITION_RIGHT_TOP, GraphParameters.TEXT_CURRENT | GraphParameters.TEXT_AVG | GraphParameters.TEXT_MAX | GraphParameters.TEXT_MIN, Vector2(200, 80), custom_font)

# Adding more graphs
if test_graphs:
Expand Down Expand Up @@ -224,34 +222,34 @@ func _draw_array_of_boxes():

func _graph_test():
# warning-ignore:return_value_discarded
_create_graph("fps", true, true, DebugDraw.BlockPosition_RightTop, DebugDraw.GraphTextFlags_Current)
_create_graph("fps", true, true, DebugDraw.POSITION_RIGHT_TOP, GraphParameters.TEXT_CURRENT)
# warning-ignore:return_value_discarded
_create_graph("fps2", true, false, DebugDraw.BlockPosition_RightTop, DebugDraw.GraphTextFlags_Current)
_create_graph("fps2", true, false, DebugDraw.POSITION_RIGHT_TOP, GraphParameters.TEXT_CURRENT)
# warning-ignore:return_value_discarded
_create_graph("fps3", true, true, DebugDraw.BlockPosition_RightTop, DebugDraw.GraphTextFlags_Current)
_create_graph("fps3", true, true, DebugDraw.POSITION_RIGHT_TOP, GraphParameters.TEXT_CURRENT)

# warning-ignore:return_value_discarded
_create_graph("randf", false, true, DebugDraw.BlockPosition_RightBottom, DebugDraw.GraphTextFlags_Avarage, Vector2(256, 60), custom_font)
_create_graph("randf", false, true, DebugDraw.POSITION_RIGHT_BOTTOM, GraphParameters.TEXT_AVG, Vector2(256, 60), custom_font)
# warning-ignore:return_value_discarded
_create_graph("fps5", true, false, DebugDraw.BlockPosition_RightBottom, DebugDraw.GraphTextFlags_All)
_create_graph("fps5", true, false, DebugDraw.POSITION_RIGHT_BOTTOM, GraphParameters.TEXT_ALL)
# warning-ignore:return_value_discarded
_create_graph("fps6", true, true, DebugDraw.BlockPosition_RightBottom, DebugDraw.GraphTextFlags_All)
_create_graph("fps6", true, true, DebugDraw.POSITION_RIGHT_BOTTOM, GraphParameters.TEXT_ALL)

# warning-ignore:return_value_discarded
_create_graph("fps7", true, false, DebugDraw.BlockPosition_LeftTop, DebugDraw.GraphTextFlags_All)
_create_graph("fps7", true, false, DebugDraw.POSITION_LEFT_TOP, GraphParameters.TEXT_ALL)
# warning-ignore:return_value_discarded
_create_graph("fps8", true, true, DebugDraw.BlockPosition_LeftBottom, DebugDraw.GraphTextFlags_All)
_create_graph("fps8", true, true, DebugDraw.POSITION_LEFT_BOTTOM, GraphParameters.TEXT_ALL)
# warning-ignore:return_value_discarded
_create_graph("fps9", true, true, DebugDraw.BlockPosition_LeftBottom, DebugDraw.GraphTextFlags_All)
_create_graph("fps9", true, true, DebugDraw.POSITION_LEFT_BOTTOM, GraphParameters.TEXT_ALL)
# warning-ignore:return_value_discarded
_create_graph("fps10", true, false, DebugDraw.BlockPosition_LeftBottom, DebugDraw.GraphTextFlags_All)
_create_graph("fps10", true, false, DebugDraw.POSITION_LEFT_BOTTOM, GraphParameters.TEXT_ALL)

# If graphs exists, then more tests are done
if DebugDraw.get_graph_config("randf"):
DebugDraw.get_graph_config("randf").text_suffix = "utf8 ноль zéro"
DebugDraw.get_graph_config("fps9").centered_graph_line = false

if Engine.editor_hint:
if Engine.is_editor_hint():
DebugDraw.get_graph_config("fps5").offset = Vector2(0, -30)
DebugDraw.get_graph_config("fps8").offset = Vector2(280, -60)
DebugDraw.get_graph_config("fps9").offset = Vector2(0, -75)
Expand Down
42 changes: 14 additions & 28 deletions examples/DebugDrawDemoScene.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -115,42 +115,27 @@ tracks/1/keys = PackedFloat32Array(0, 1, -1.03574, 2.47907, -0.819963, 0.5, 1, 0

[sub_resource type="Animation" id="7"]
length = 0.001
tracks/0/type = "value"
tracks/0/type = "position_3d"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("RayEmitter:translation")
tracks/0/path = NodePath("RayEmitter")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector3(0, 2.44568, 0)]
}
tracks/1/type = "value"
tracks/0/keys = PackedFloat32Array(0, 1, -1.03574, 2.47907, -0.819963)
tracks/1/type = "rotation_3d"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("RayEmitter:rotation_degrees")
tracks/1/path = NodePath("RayEmitter")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector3(0, 0, 0)]
}
tracks/2/type = "value"
tracks/1/keys = PackedFloat32Array(0, 1, 0, 0, 0, 1)
tracks/2/type = "scale_3d"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath("RayEmitter:scale")
tracks/2/path = NodePath("RayEmitter")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector3(1, 1, 1)]
}
tracks/2/keys = PackedFloat32Array(0, 1, 1, 1, 1)

[sub_resource type="AnimationLibrary" id="AnimationLibrary_vh8ml"]
_data = {
Expand Down Expand Up @@ -195,10 +180,10 @@ func _ready() -> void:
await get_tree().process_frame
await get_tree().process_frame

var test = DebugDraw.get_graph_config(\"FPS\")
var test := DebugDraw.get_graph_config(\"FPS\")
if test:
$VB/H/FPSEnabled.pressed = test.enabled
$VB/FPSMS.pressed = test.frame_time_mode
$VB/H/FPSEnabled.button_pressed = test.enabled
$VB/FPSMS.button_pressed = test.frame_time_mode
$VB/HSlider.value = test.size.x
$VB/HSlider2.value = test.buffer_size
await get_tree().create_timer(0.2).timeout
Expand All @@ -223,7 +208,7 @@ func _on_HSlider_value_changed(value: float) -> void:
func _on_HSlider2_value_changed(value: float) -> void:
var cfg = DebugDraw.get_graph_config(\"FPS\")
if cfg:
cfg.buffer_size = value
cfg.buffer_size = int(value)


func _on_Button_pressed() -> void:
Expand All @@ -234,6 +219,7 @@ func _on_Button_pressed() -> void:
[node name="DebugDrawDemoScene" type="Node3D"]
process_priority = 1
script = ExtResource("1")
test_graphs = true
[node name="Panel" type="PanelContainer" parent="."]
visible = false
Expand Down
9 changes: 9 additions & 0 deletions lib_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,22 @@ def gdnative_get_sources(src):
return [src_folder + "/" + file for file in src]


def gdnative_replace_flag(arr, flag, new_flag):
if flag in arr:
arr.remove(flag)
arr.append(new_flag)


def gdnative_get_library_object(env, arguments=None, gen_help=None):
if arguments != None and gen_help:
setup_options(env, arguments, gen_help)
gdnative_setup_default_cpp_defines(env)

env.Append(CPPPATH=[src_folder])

gdnative_replace_flag(env["CXXFLAGS"], "/std:c++17" if env.get("is_msvc", False) else "-std=c++17",
"/std:c++20" if env.get("is_msvc", False) else "-std=c++20")

src = []
with open(src_folder + "/default_sources.json") as f:
src = json.load(f)
Expand Down
58 changes: 58 additions & 0 deletions patches/ref_patch.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
diff --git a/godot-headers/godot/gdnative_interface.h b/godot-headers/godot/gdnative_interface.h
index 486f5be..e4fcc9c 100644
--- a/godot-headers/godot/gdnative_interface.h
+++ b/godot-headers/godot/gdnative_interface.h
@@ -154,6 +154,8 @@ typedef const void *GDNativeMethodBindPtr;
typedef int64_t GDNativeInt;
typedef uint8_t GDNativeBool;
typedef uint64_t GDObjectInstanceID;
+typedef void *GDExtensionRefPtr;
+typedef const void *GDExtensionConstRefPtr;

/* VARIANT DATA I/O */

@@ -551,6 +553,10 @@ typedef struct {
GDNativeObjectPtr (*object_get_instance_from_id)(GDObjectInstanceID p_instance_id);
GDObjectInstanceID (*object_get_instance_id)(GDNativeConstObjectPtr p_object);

+ /* REFERENCE */
+ GDNativeObjectPtr (*ref_get_object)(GDExtensionConstRefPtr p_ref);
+ void (*ref_set_object)(GDExtensionRefPtr p_ref, GDNativeObjectPtr p_object);
+
/* SCRIPT INSTANCE */

GDNativeScriptInstancePtr (*script_instance_create)(const GDNativeExtensionScriptInstanceInfo *p_info, GDNativeExtensionScriptInstanceDataPtr p_instance_data);
diff --git a/include/godot_cpp/classes/ref.hpp b/include/godot_cpp/classes/ref.hpp
index cc7f2d6..470aa83 100644
--- a/include/godot_cpp/classes/ref.hpp
+++ b/include/godot_cpp/classes/ref.hpp
@@ -240,13 +240,24 @@ public:
template <class T>
struct PtrToArg<Ref<T>> {
_FORCE_INLINE_ static Ref<T> convert(const void *p_ptr) {
- return Ref<T>(reinterpret_cast<T *>(godot::internal::gdn_interface->object_get_instance_binding(*reinterpret_cast<GDNativeObjectPtr *>(const_cast<void *>(p_ptr)), godot::internal::token, &T::___binding_callbacks)));
+ GDExtensionRefPtr ref = (GDExtensionRefPtr)p_ptr;
+ ERR_FAIL_NULL_V(ref, Ref<T>());
+
+ T *obj = reinterpret_cast<T *>(godot::internal::gdn_interface->object_get_instance_binding(godot::internal::gdn_interface->ref_get_object(ref), godot::internal::token, &T::___binding_callbacks));
+ return Ref<T>(obj);
}

typedef Ref<T> EncodeT;

_FORCE_INLINE_ static void encode(Ref<T> p_val, void *p_ptr) {
- *reinterpret_cast<const GodotObject **>(p_ptr) = p_val->_owner;
+ GDExtensionRefPtr ref = (GDExtensionRefPtr)p_ptr;
+ ERR_FAIL_NULL(ref);
+
+ // This code assumes that p_ptr points to an unset Ref<T> variable on the Godot side
+ // so we only set it if we have an object to set.
+ if (p_val.is_valid()) {
+ godot::internal::gdn_interface->ref_set_object(ref, p_val->_owner);
+ }
}
};

--
2.33.0.windows.2

Loading

0 comments on commit 7133097

Please sign in to comment.