From 16938eb80ce30c341ba5b68274f533837d57c01b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Mikrut?= <41945903+qarmin@users.noreply.github.com> Date: Tue, 12 Jan 2021 09:06:16 +0100 Subject: [PATCH] Add reparenting test (#18) --- .gitignore | 2 +- ...487276ed1e3a0c39cad0279d744ee560.etc2.stex | Bin 0 -> 716 bytes ...n.png-487276ed1e3a0c39cad0279d744ee560.md5 | 3 + ...487276ed1e3a0c39cad0279d744ee560.s3tc.stex | Bin 0 -> 716 bytes Autoload/Autoload.gd | 12 +- Reparenting/Reparenting.gd | 203 ++++++++++++++++++ Reparenting/Reparenting.tscn | 6 + 7 files changed, 219 insertions(+), 7 deletions(-) create mode 100644 .import/icon.png-487276ed1e3a0c39cad0279d744ee560.etc2.stex create mode 100644 .import/icon.png-487276ed1e3a0c39cad0279d744ee560.md5 create mode 100644 .import/icon.png-487276ed1e3a0c39cad0279d744ee560.s3tc.stex create mode 100644 Reparenting/Reparenting.gd create mode 100644 Reparenting/Reparenting.tscn diff --git a/.gitignore b/.gitignore index d631211..1379628 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ .DS_Store *~ -.import/ +#.import/ logs/ .~lock.*# .mono/ diff --git a/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.etc2.stex b/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.etc2.stex new file mode 100644 index 0000000000000000000000000000000000000000..0a0d3c87c62680e9abf01c93eb4e65238bb87be4 GIT binary patch literal 716 zcmYL`T}V@L7{=fK*?*pMY&)H^jpjt+m|ln|ZVOV#aIWPhN}RPKByeBBEMsg_r?_Zq zsrfNKW@zL^8zG_=b3~RGt3GQxBT)AQBnj%xBy@#x|UB!vxF&gdpU@M zR%X0R148oh{zXG8)H8JdqSBz`rAU~KZ$^^YcE{4*3Ck3HI8NHdP_6cFkP>(jB)ME} zUrR+qoh$jUgZKa&?aUtyAu%>l z5P2{-!p9&5Mq}&dfE#CMYZwq9i==05+A7mvaE6pQg_Tk38z48A$=3KLj}t6Nkw4^p z{leit8;Bk&2_*7`Qm|{P5qWa^=?q4WnL{1s?^nkz=o(pTRy|;+#K0=EZ}MdUI-AHj zMTz4c9C#k~6>5JZ7^<=%4?f~QmvCzcRv}BdyeZfcIsC(WRdxET+SrnUl-4HcSeIqq zrd8xZ5Wkn@RTkgarNq3*<(SRKZ*bM!o^rq z3E>(8vJco64X8KeA7JT;d+*v$#LQ)@|X~J>b&^J2eA{ZvngyD zMZ->}b(vYSO>(p%@F7Sl+H~E#8*WGts1G##Gi(+j8YhXPQ5oTQvy)DFSaD#e*;FoL?mDMWmGc5qy_N z_*&e+$mo8l#rqy#3REJLT>^I6lGD>qkc8%A06fo+0O$zJ@WfIYAdeR)vXg#9Ar$?T zHS;&e$3FUVHa_5+`r^-7`K`ts&cJ^dA>wPBooN5UV1iF7Tl9uq&pKASS7C;chD9*BbXaT^T zcN-d69X*JUTnq1INZgrIwM2EcSd3vmSsWakRRJ93Dw|1~_=$I$&5blbU=5%*t7l45 z5$Dn$cA%B03+IAij`QPOK(g+ZpC~J`hFDyb5t=a<_VvAL-rJ!CJp(oyb5*5<39f%= zUDbg2U#<SXf+zWjddyGH2YxQoER92UCK!25Et*M zH!v@-4bV}+IH91+byFxfJU+IbCOu_EL1mTVh3&ta9~6VVj1+Wh%A6PRhxW2eJz z&)OmyfVVe1F8ps4>t?&+T7o!6fK|l);Cxm~YKh5q%IJ#eXz8`b(}n$ void: diff --git a/Reparenting/Reparenting.gd b/Reparenting/Reparenting.gd new file mode 100644 index 0000000..d656899 --- /dev/null +++ b/Reparenting/Reparenting.gd @@ -0,0 +1,203 @@ +extends Node + +var number_of_nodes : int = -1 + +func _ready() -> void: + seed(45) + + for _i in range(3): + add_child(Control.new()) + add_child(Popup.new()) + add_child(WindowDialog.new()) + add_child(AcceptDialog.new()) + add_child(ConfirmationDialog.new()) + add_child(FileDialog.new()) + add_child(PopupDialog.new()) + add_child(PopupMenu.new()) + add_child(PopupPanel.new()) + add_child(Button.new()) + add_child(CheckBox.new()) + add_child(CheckButton.new()) + add_child(ColorPickerButton.new()) + add_child(MenuButton.new()) + add_child(OptionButton.new()) + add_child(ToolButton.new()) + add_child(LinkButton.new()) + add_child(TextureButton.new()) + add_child(Container.new()) + add_child(ColorPicker.new()) + add_child(VBoxContainer.new()) + add_child(HBoxContainer.new()) + add_child(CenterContainer.new()) + add_child(ScrollContainer.new()) + add_child(GraphNode.new()) + add_child(GridContainer.new()) + add_child(HSplitContainer.new()) + add_child(VSplitContainer.new()) + add_child(MarginContainer.new()) + add_child(PanelContainer.new()) + add_child(TabContainer.new()) + add_child(ViewportContainer.new()) + add_child(ColorRect.new()) + add_child(HScrollBar.new()) + add_child(VScrollBar.new()) + add_child(HSlider.new()) + add_child(VSlider.new()) + add_child(ProgressBar.new()) + add_child(SpinBox.new()) + add_child(TextureProgress.new()) + add_child(GraphEdit.new()) + add_child(HSeparator.new()) + add_child(VSeparator.new()) + add_child(ItemList.new()) + add_child(Label.new()) + add_child(LineEdit.new()) + add_child(NinePatchRect.new()) + add_child(Panel.new()) + add_child(ReferenceRect.new()) + add_child(RichTextLabel.new()) + add_child(Tabs.new()) + add_child(TextEdit.new()) + add_child(TextureRect.new()) + add_child(Tree.new()) + add_child(VideoPlayer.new()) + + add_child(Node2D.new()) + add_child(AnimatedSprite.new()) + add_child(Area2D.new()) + add_child(KinematicBody2D.new()) + add_child(RigidBody2D.new()) + add_child(StaticBody2D.new()) + add_child(AudioStreamPlayer2D.new()) + add_child(BackBufferCopy.new()) + add_child(Bone2D.new()) + add_child(CPUParticles2D.new()) + add_child(Camera2D.new()) + add_child(CanvasModulate.new()) + add_child(CollisionPolygon2D.new()) # Errors + add_child(CollisionShape2D.new()) + add_child(DampedSpringJoint2D.new()) + add_child(GrooveJoint2D.new()) + add_child(PinJoint2D.new()) + add_child(Light2D.new()) + add_child(LightOccluder2D.new()) + add_child(Line2D.new()) + add_child(MeshInstance2D.new()) + add_child(MultiMeshInstance2D.new()) + add_child(Navigation2D.new()) + add_child(NavigationPolygonInstance.new()) + add_child(ParallaxLayer.new()) + add_child(Particles2D.new()) + add_child(Path2D.new()) + add_child(PathFollow2D.new()) + add_child(Polygon2D.new()) + add_child(Position2D.new()) + add_child(RayCast2D.new()) + add_child(RemoteTransform2D.new()) + add_child(Skeleton2D.new()) + add_child(Sprite.new()) + add_child(TileMap.new()) + add_child(TouchScreenButton.new()) + add_child(VisibilityNotifier2D.new()) + add_child(VisibilityEnabler2D.new()) + add_child(YSort.new()) + + add_child(AnimationPlayer.new()) + add_child(AnimationTree.new()) + add_child(AnimationTreePlayer.new()) + add_child(AudioStreamPlayer.new()) + add_child(CanvasLayer.new()) + add_child(ParallaxBackground.new()) + add_child(HTTPRequest.new()) + add_child(ResourcePreloader.new()) + add_child(Skeleton2D.new()) + add_child(Timer.new()) + add_child(Tween.new()) + add_child(Viewport.new()) + add_child(WorldEnvironment.new()) + + add_child(Spatial.new()) + add_child(ARVRAnchor.new()) + add_child(Camera.new()) + add_child(ARVRCamera.new()) + add_child(ClippedCamera.new()) + add_child(InterpolatedCamera.new()) + add_child(ARVRController.new()) + add_child(ARVROrigin.new()) + add_child(AnimatedSprite3D.new()) + add_child(Sprite3D.new()) + add_child(CPUParticles.new()) + add_child(CSGBox.new()) + add_child(CSGCylinder.new()) + add_child(CSGMesh.new()) + add_child(CSGPolygon.new()) + add_child(CSGSphere.new()) + add_child(CSGTorus.new()) + add_child(CSGCombiner.new()) + add_child(ImmediateGeometry.new()) + add_child(MeshInstance.new()) + add_child(SoftBody.new()) + add_child(MultiMeshInstance.new()) + add_child(Particles.new()) + add_child(BakedLightmap.new()) + add_child(DirectionalLight.new()) + add_child(OmniLight.new()) + add_child(SpotLight.new()) + add_child(GIProbe.new()) + add_child(ReflectionProbe.new()) + add_child(Area.new()) + add_child(KinematicBody.new()) + add_child(PhysicalBone.new()) + add_child(RigidBody.new()) + add_child(VehicleBody.new()) + add_child(StaticBody.new()) + add_child(AudioStreamPlayer3D.new()) + add_child(BoneAttachment.new()) + add_child(CollisionPolygon.new()) + add_child(CollisionShape.new()) + add_child(ConeTwistJoint.new()) + add_child(Generic6DOFJoint.new()) + add_child(HingeJoint.new()) + add_child(PinJoint.new()) + add_child(SliderJoint.new()) + add_child(GridMap.new()) + add_child(Listener.new()) + add_child(Navigation.new()) + add_child(NavigationMeshInstance.new()) + add_child(Path.new()) + add_child(PathFollow.new()) + add_child(Position3D.new()) + add_child(ProximityGroup.new()) + add_child(RayCast.new()) + add_child(RemoteTransform.new()) + add_child(Skeleton.new()) + add_child(SpringArm.new()) + add_child(VehicleWheel.new()) + add_child(VisibilityNotifier.new()) + add_child(VisibilityEnabler.new()) + + + for i in range(get_child_count()): + get_child(i).set_name("Node " + str(i)) + + number_of_nodes = get_child_count() + +func _process(delta: float) -> void: + assert(Performance.get_monitor(Performance.OBJECT_ORPHAN_NODE_COUNT) == 0) + + var choosen_node : Node + var parent_of_node : Node + for i in range(20): + var number = "Node " + str(randi() % number_of_nodes) + choosen_node = find_node(number,true,false) + parent_of_node = choosen_node.get_parent() + + var random_node = find_node("Node " + str(randi() % number_of_nodes),true,false) + if choosen_node.find_node(random_node.get_name(),true,false) != null: # Cannot set as node parent one of its child + continue + if choosen_node == random_node: # Do not reparent node to self + continue + parent_of_node.remove_child(choosen_node) + random_node.add_child(choosen_node) + if !choosen_node.is_inside_tree() || choosen_node.get_parent() == null: # Failed to add node, due e.g. requsrive problem or similar + add_child(choosen_node) diff --git a/Reparenting/Reparenting.tscn b/Reparenting/Reparenting.tscn new file mode 100644 index 0000000..ac33eed --- /dev/null +++ b/Reparenting/Reparenting.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://Reparenting/Reparenting.gd" type="Script" id=1] + +[node name="Reparenting" type="Node"] +script = ExtResource( 1 )