diff --git a/process_groups/multi_threaded/Main.gd b/process_groups/multi_threaded/Main.gd new file mode 100644 index 0000000..20944a2 --- /dev/null +++ b/process_groups/multi_threaded/Main.gd @@ -0,0 +1,30 @@ +extends Node + + +# Declare member variables here. Examples: +# var a: int = 2 +# var b: String = "text" + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + print("") + print("") + print("When running this demo what you need to see is that ") + print("between every frame steps you see 3 _process() calls, and 3 _process_group_process() start,") + print("and 3 _process_group_process() end calls printed to the console.") + print("This means that the ProcessGroups works properly.") + print("_process() methods will run in the main thread, and ProcessGroup calls it's ") + print("children's _process_group_process() in it's own thread, and ProcessGroup2 also calls it's ") + print("children's _process_group_process() in it's own thread,") + print("and SceneTree waits for them to finish before going to the next step.") + print("This allows multi threaded processing similar to Godot 4s,") + print("howewer this implementation tries t make it as explicit as possible when you are working in a thread or not.") + print("") + print("") + + get_tree().connect("idle_frame", self, "idle_frame") + + +func idle_frame(): + print("============== NEW FRAME START ==============") diff --git a/process_groups/multi_threaded/Main.tscn b/process_groups/multi_threaded/Main.tscn new file mode 100644 index 0000000..4f86e75 --- /dev/null +++ b/process_groups/multi_threaded/Main.tscn @@ -0,0 +1,20 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://Main.gd" type="Script" id=1] +[ext_resource path="res://ProcessorNode.gd" type="Script" id=2] + +[node name="Main" type="Node"] +script = ExtResource( 1 ) + +[node name="ProcessGroup" type="ProcessGroup" parent="."] + +[node name="ProcessorNode" type="Node" parent="ProcessGroup"] +script = ExtResource( 2 ) + +[node name="ProcessorNode2" type="Node" parent="ProcessGroup"] +script = ExtResource( 2 ) + +[node name="ProcessGroup2" type="ProcessGroup" parent="."] + +[node name="ProcessorNode4" type="Node" parent="ProcessGroup2"] +script = ExtResource( 2 ) diff --git a/process_groups/multi_threaded/ProcessorNode.gd b/process_groups/multi_threaded/ProcessorNode.gd new file mode 100644 index 0000000..2ae4675 --- /dev/null +++ b/process_groups/multi_threaded/ProcessorNode.gd @@ -0,0 +1,26 @@ +extends Node + + +# Declare member variables here. Examples: +# var a: int = 2 +# var b: String = "text" + + +# Called when the node enters the scene tree for the first time. +#func _ready() -> void: +# set_process_group_process(false) +# set_process_group_process(true) + +func _process_group_process(delta: float) -> void: + print(str(get_path()) + " _process_group_process() start") + OS.delay_msec(1000) + print(str(get_path()) + " _process_group_process() fin") + + +func _process(delta: float) -> void: + print(str(get_path()) + " _process()") + +#func _notification(what: int) -> void: +# #print(what) +# if what >= 60 && what <= 70: +# print(what) diff --git a/process_groups/multi_threaded/default_env.tres b/process_groups/multi_threaded/default_env.tres new file mode 100644 index 0000000..4f08e8f --- /dev/null +++ b/process_groups/multi_threaded/default_env.tres @@ -0,0 +1,7 @@ +[gd_resource type="Environment3D" load_steps=2 format=2] + +[sub_resource type="ProceduralSky" id=1] + +[resource] +background_mode = 2 +background_sky = SubResource( 1 ) diff --git a/process_groups/multi_threaded/icon.png b/process_groups/multi_threaded/icon.png new file mode 100644 index 0000000..87f1f75 Binary files /dev/null and b/process_groups/multi_threaded/icon.png differ diff --git a/process_groups/multi_threaded/icon.png.import b/process_groups/multi_threaded/icon.png.import new file mode 100644 index 0000000..a4c02e6 --- /dev/null +++ b/process_groups/multi_threaded/icon.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://icon.png" +dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/process_groups/multi_threaded/project.pandemonium b/process_groups/multi_threaded/project.pandemonium new file mode 100644 index 0000000..4161331 --- /dev/null +++ b/process_groups/multi_threaded/project.pandemonium @@ -0,0 +1,25 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=4 + +[application] + +config/name="Multi Threaded" +run/main_scene="res://Main.tscn" +config/icon="res://icon.png" + +[physics] + +common/enable_pause_aware_picking=true + +[rendering] + +vram_compression/import_etc=true +vram_compression/import_etc2=false +environment/default_environment="res://default_env.tres"