Skip to content

Commit d3626a3

Browse files
Xwditcoppolaemilio
andauthored
Change timers process callback to physics (#1228)
* Change timers process callback to physics * Add a setting to change timer process callback * Updating with Jowan's feedback Co-authored-by: Emi <[email protected]>
1 parent 12d9451 commit d3626a3

File tree

10 files changed

+126
-32
lines changed

10 files changed

+126
-32
lines changed

addons/dialogic/Editor/Settings/Settings_General.gd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func refresh():
2424
%CustomEventsFolderButton.icon = get_theme_icon("Folder", "EditorIcons")
2525
%TestingSceneButton.icon = get_theme_icon("Folder", "EditorIcons")
2626
%TestingSceneLabel.text = DialogicUtil.get_project_setting('dialogic/editor/test_dialog_scene', 'res://addons/dialogic/Other/DefaultDialogNode.tscn')
27+
%PhysicsTimerButton.button_pressed = DialogicUtil.is_physics_timer()
2728

2829
# Color Palett
2930
color_palette = DialogicUtil.get_color_palette()
@@ -65,3 +66,7 @@ func custom_testing_scene_selected(path:String):
6566
%TestingSceneLabel.text = path
6667
ProjectSettings.set_setting('dialogic/editor/test_dialog_scene', path)
6768
ProjectSettings.save()
69+
70+
func _on_physics_timer_button_toggled(button_pressed:bool) -> void:
71+
ProjectSettings.set_setting('dialogic/timer/process_in_physics', button_pressed)
72+
ProjectSettings.save()
Lines changed: 106 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
[gd_scene load_steps=6 format=3 uid="uid://dm4kxvcn7d7ug"]
1+
[gd_scene load_steps=8 format=3 uid="uid://dm4kxvcn7d7ug"]
22

33
[ext_resource type="Script" path="res://addons/dialogic/Editor/Settings/Settings_General.gd" id="2"]
4-
[ext_resource type="LabelSettings" uid="uid://nkh7ypguw3il" path="res://addons/dialogic/Editor/Common/HintLabelSettings.tres" id="2_hs15a"]
4+
[ext_resource type="LabelSettings" uid="uid://bqlmi2bwcj0s6" path="res://addons/dialogic/Editor/Common/HintLabelSettings.tres" id="2_hs15a"]
55
[ext_resource type="StyleBox" uid="uid://dmsjhgv22dns8" path="res://addons/dialogic/Editor/Common/TitleBgStylebox.tres" id="2_u584y"]
66

7-
[sub_resource type="Image" id="Image_3nstt"]
7+
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_6mpk2"]
8+
content_margin_left = 5.0
9+
content_margin_top = 5.0
10+
content_margin_right = 5.0
11+
content_margin_bottom = 5.0
12+
bg_color = Color(0.545098, 0.545098, 0.545098, 0.211765)
13+
14+
[sub_resource type="Image" id="Image_iyfpw"]
815
data = {
916
"data": PackedByteArray(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
1017
"format": "LumAlpha8",
@@ -14,39 +21,54 @@ data = {
1421
}
1522

1623
[sub_resource type="ImageTexture" id="7"]
17-
image = SubResource("Image_3nstt")
24+
image = SubResource("Image_iyfpw")
25+
26+
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_3mwvq"]
27+
content_margin_left = 5.0
28+
content_margin_top = 5.0
29+
content_margin_right = 5.0
30+
content_margin_bottom = 5.0
31+
bg_color = Color(0.545098, 0.545098, 0.545098, 0.211765)
1832

1933
[node name="General" type="HBoxContainer"]
34+
anchors_preset = 15
2035
anchor_right = 1.0
2136
anchor_bottom = 1.0
37+
grow_horizontal = 2
38+
grow_vertical = 2
2239
script = ExtResource("2")
2340

2441
[node name="General" type="VBoxContainer" parent="."]
25-
offset_right = 830.0
26-
offset_bottom = 600.0
42+
layout_mode = 2
43+
offset_right = 958.0
44+
offset_bottom = 648.0
2745
size_flags_horizontal = 3
2846

2947
[node name="TitleLabel" type="Label" parent="General"]
30-
offset_right = 830.0
48+
layout_mode = 2
49+
offset_right = 958.0
3150
offset_bottom = 36.0
32-
theme_override_styles/normal = ExtResource("2_u584y")
51+
theme_override_styles/normal = SubResource("StyleBoxFlat_6mpk2")
3352
text = "Extensions"
3453

3554
[node name="HBoxContainer" type="HBoxContainer" parent="General"]
55+
layout_mode = 2
3656
offset_top = 40.0
37-
offset_right = 830.0
57+
offset_right = 958.0
3858
offset_bottom = 66.0
3959

4060
[node name="Label" type="Label" parent="General/HBoxContainer"]
41-
offset_right = 498.0
61+
layout_mode = 2
62+
offset_right = 626.0
4263
offset_bottom = 26.0
4364
size_flags_horizontal = 3
4465
text = "Custom events folder"
4566

4667
[node name="CustomEventsFolderLabel" type="Label" parent="General/HBoxContainer"]
4768
unique_name_in_owner = true
48-
offset_left = 502.0
49-
offset_right = 802.0
69+
layout_mode = 2
70+
offset_left = 630.0
71+
offset_right = 930.0
5072
offset_bottom = 26.0
5173
size_flags_horizontal = 8
5274
text = "res://addons/dialogic_additions/Events"
@@ -55,45 +77,52 @@ visible_characters_behavior = 4
5577

5678
[node name="CustomEventsFolderButton" type="Button" parent="General/HBoxContainer"]
5779
unique_name_in_owner = true
58-
offset_left = 806.0
59-
offset_right = 830.0
80+
layout_mode = 2
81+
offset_left = 934.0
82+
offset_right = 958.0
6083
offset_bottom = 26.0
6184
icon = SubResource("7")
6285

6386
[node name="Label" type="Label" parent="General"]
87+
layout_mode = 2
6488
offset_top = 70.0
65-
offset_right = 830.0
89+
offset_right = 958.0
6690
offset_bottom = 96.0
6791
text = "You should restart godot after changing this path!"
6892
label_settings = ExtResource("2_hs15a")
6993

7094
[node name="HSeparator" type="HSeparator" parent="General"]
95+
layout_mode = 2
7196
offset_top = 100.0
72-
offset_right = 830.0
97+
offset_right = 958.0
7398
offset_bottom = 104.0
7499

75100
[node name="TitleLabel2" type="Label" parent="General"]
101+
layout_mode = 2
76102
offset_top = 108.0
77-
offset_right = 830.0
103+
offset_right = 958.0
78104
offset_bottom = 144.0
79-
theme_override_styles/normal = ExtResource("2_u584y")
105+
theme_override_styles/normal = SubResource("StyleBoxFlat_6mpk2")
80106
text = "Testing"
81107

82108
[node name="HBoxContainer2" type="HBoxContainer" parent="General"]
109+
layout_mode = 2
83110
offset_top = 148.0
84-
offset_right = 830.0
111+
offset_right = 958.0
85112
offset_bottom = 174.0
86113

87114
[node name="Label" type="Label" parent="General/HBoxContainer2"]
88-
offset_right = 494.0
115+
layout_mode = 2
116+
offset_right = 622.0
89117
offset_bottom = 26.0
90118
size_flags_horizontal = 3
91119
text = "Testing scene"
92120

93121
[node name="TestingSceneLabel" type="Label" parent="General/HBoxContainer2"]
94122
unique_name_in_owner = true
95-
offset_left = 498.0
96-
offset_right = 802.0
123+
layout_mode = 2
124+
offset_left = 626.0
125+
offset_right = 930.0
97126
offset_bottom = 26.0
98127
size_flags_horizontal = 8
99128
text = "res://addons/dialogic_additions/Events "
@@ -102,70 +131,116 @@ visible_characters_behavior = 4
102131

103132
[node name="TestingSceneButton" type="Button" parent="General/HBoxContainer2"]
104133
unique_name_in_owner = true
105-
offset_left = 806.0
106-
offset_right = 830.0
134+
layout_mode = 2
135+
offset_left = 934.0
136+
offset_right = 958.0
107137
offset_bottom = 26.0
108138
icon = SubResource("7")
109139

140+
[node name="HSeparator2" type="HSeparator" parent="General"]
141+
layout_mode = 2
142+
offset_top = 178.0
143+
offset_right = 958.0
144+
offset_bottom = 182.0
145+
146+
[node name="TitleLabel3" type="Label" parent="General"]
147+
layout_mode = 2
148+
offset_top = 186.0
149+
offset_right = 958.0
150+
offset_bottom = 222.0
151+
theme_override_styles/normal = SubResource("StyleBoxFlat_3mwvq")
152+
text = "Timer"
153+
154+
[node name="HBoxContainer3" type="HBoxContainer" parent="General"]
155+
layout_mode = 2
156+
offset_top = 226.0
157+
offset_right = 958.0
158+
offset_bottom = 252.0
159+
160+
[node name="Label" type="Label" parent="General/HBoxContainer3"]
161+
layout_mode = 2
162+
offset_right = 930.0
163+
offset_bottom = 26.0
164+
size_flags_horizontal = 3
165+
text = "Process in physics"
166+
167+
[node name="PhysicsTimerButton" type="CheckBox" parent="General/HBoxContainer3"]
168+
unique_name_in_owner = true
169+
layout_mode = 2
170+
offset_left = 934.0
171+
offset_right = 958.0
172+
offset_bottom = 26.0
173+
110174
[node name="VSeparator" type="VSeparator" parent="."]
111-
offset_left = 834.0
112-
offset_right = 838.0
113-
offset_bottom = 600.0
175+
layout_mode = 2
176+
offset_left = 962.0
177+
offset_right = 966.0
178+
offset_bottom = 648.0
114179

115180
[node name="Theming" type="VBoxContainer" parent="."]
116-
offset_left = 842.0
117-
offset_right = 1024.0
118-
offset_bottom = 600.0
181+
layout_mode = 2
182+
offset_left = 970.0
183+
offset_right = 1152.0
184+
offset_bottom = 648.0
119185

120186
[node name="Label" type="Label" parent="Theming"]
187+
layout_mode = 2
121188
offset_right = 182.0
122189
offset_bottom = 36.0
123190
theme_override_styles/normal = ExtResource("2_u584y")
124191
text = "Color palette"
125192

126193
[node name="Colors" type="HBoxContainer" parent="Theming"]
127194
unique_name_in_owner = true
195+
layout_mode = 2
128196
offset_top = 40.0
129197
offset_right = 182.0
130198
offset_bottom = 48.0
131199

132200
[node name="Color1" type="ColorPickerButton" parent="Theming/Colors"]
201+
layout_mode = 2
133202
offset_right = 8.0
134203
offset_bottom = 8.0
135204
color = Color(0.231373, 0.545098, 0.94902, 1)
136205

137206
[node name="Color2" type="ColorPickerButton" parent="Theming/Colors"]
207+
layout_mode = 2
138208
offset_left = 12.0
139209
offset_right = 20.0
140210
offset_bottom = 8.0
141211
color = Color(0, 0.694118, 0.372549, 1)
142212

143213
[node name="Color3" type="ColorPickerButton" parent="Theming/Colors"]
214+
layout_mode = 2
144215
offset_left = 24.0
145216
offset_right = 32.0
146217
offset_bottom = 8.0
147218
color = Color(0.580392, 0.407843, 0.909804, 1)
148219

149220
[node name="Color4" type="ColorPickerButton" parent="Theming/Colors"]
221+
layout_mode = 2
150222
offset_left = 36.0
151223
offset_right = 44.0
152224
offset_bottom = 8.0
153225
color = Color(0.870588, 0.360784, 0.360784, 1)
154226

155227
[node name="Color5" type="ColorPickerButton" parent="Theming/Colors"]
228+
layout_mode = 2
156229
offset_left = 48.0
157230
offset_right = 56.0
158231
offset_bottom = 8.0
159232
color = Color(0.980392, 0.584314, 0.164706, 1)
160233

161234
[node name="Color6" type="ColorPickerButton" parent="Theming/Colors"]
235+
layout_mode = 2
162236
offset_left = 60.0
163237
offset_right = 68.0
164238
offset_bottom = 8.0
165239
color = Color(0.486275, 0.486275, 0.486275, 1)
166240

167241
[node name="ResetColorsButton" type="Button" parent="Theming"]
168242
unique_name_in_owner = true
243+
layout_mode = 2
169244
offset_top = 52.0
170245
offset_right = 182.0
171246
offset_bottom = 83.0
@@ -174,3 +249,4 @@ text = "Reset colors to default"
174249

175250
[connection signal="pressed" from="General/HBoxContainer/CustomEventsFolderButton" to="." method="_on_CustomEventsFolderButton_pressed"]
176251
[connection signal="pressed" from="General/HBoxContainer2/TestingSceneButton" to="." method="_on_TestingSceneButton_pressed"]
252+
[connection signal="toggled" from="General/HBoxContainer3/PhysicsTimerButton" to="." method="_on_physics_timer_button_toggled"]

addons/dialogic/Events/Choice/Subsystem_Choices.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var choice_blocker = Timer.new()
44

55
func _ready():
66
choice_blocker.one_shot = true
7+
DialogicUtil.update_timer_process_callback(choice_blocker)
78
add_child(choice_blocker)
89

910
####################################################################################################

addons/dialogic/Events/Save/Subsystem_Save.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ var autosave_timer = Timer.new()
190190

191191
func _ready():
192192
autosave_timer.one_shot = true
193+
DialogicUtil.update_timer_process_callback(autosave_timer)
193194
autosave_timer.name = "AutosaveTimer"
194195
autosave_timer.timeout.connect(_on_autosave_timer_timeout)
195196
add_child(autosave_timer)

addons/dialogic/Events/Text/CharacterEdit_TypingSounds_MoodItem.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func preview():
7272
if %SoundFolder.hint_tooltip.is_empty(): return
7373
$DialogicNode_TypeSounds.load_overwrite(get_data())
7474
var preview_timer = Timer.new()
75+
DialogicUtil.update_timer_process_callback(preview_timer)
7576
add_child(preview_timer)
7677
preview_timer.start(DialogicUtil.get_project_setting('text/speed', 0.01))
7778
for i in range(20):

addons/dialogic/Events/Text/Display_DialogText.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func _ready() -> void:
3232
add_child(timer)
3333
timer.wait_time = 0.01
3434
timer.one_shot = true
35+
DialogicUtil.update_timer_process_callback(timer)
3536
timer.timeout.connect(continue_reveal)
3637

3738
# compile effects regex

addons/dialogic/Events/Text/event.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func _execute() -> void:
7777
if dialogic.has_subsystem('Voice') and dialogic.Voice.is_voiced(dialogic.current_event_idx):
7878
#autocontinue settings is set as minimal. change or keep this? - Kvagram
7979
wait = max(wait, dialogic.Voice.get_remaining_time())
80-
await dialogic.get_tree().create_timer(wait).timeout
80+
await dialogic.get_tree().create_timer(wait, true, DialogicUtil.is_physics_timer()).timeout
8181
dialogic.handle_next_event()
8282
else:
8383
dialogic.Text.show_next_indicators()

addons/dialogic/Events/Voice/Subsystem_Voice.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func stop_audio():
7272
func set_timer(time:float):
7373
if !voicetimer:
7474
voicetimer = Timer.new()
75+
DialogicUtil.update_timer_process_callback(voicetimer)
7576
voicetimer.one_shot = true
7677
add_child(voicetimer)
7778
voicetimer.timeout.connect(stop_audio)

addons/dialogic/Events/Wait/event.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func _execute() -> void:
1010
if (HideText):
1111
dialogic.Text.hide_text_boxes()
1212
dialogic.current_state = dialogic.states.WAITING
13-
await dialogic.get_tree().create_timer(SecondsTime).timeout
13+
await dialogic.get_tree().create_timer(SecondsTime, true, DialogicUtil.is_physics_timer()).timeout
1414
dialogic.current_state = dialogic.states.IDLE
1515
if (HideText):
1616
dialogic.Text.show_text_boxes()

addons/dialogic/Other/DialogicUtil.gd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,11 @@ static func get_color_palette(default:bool = false) -> Dictionary:
164164
static func get_color(value:String) -> Color:
165165
var colors = get_color_palette()
166166
return colors[value]
167+
168+
169+
static func is_physics_timer()->bool:
170+
return get_project_setting('dialogic/timer/process_in_physics', false)
171+
172+
173+
static func update_timer_process_callback(timer:Timer) -> void:
174+
timer.process_callback = Timer.TIMER_PROCESS_PHYSICS if is_physics_timer() else Timer.TIMER_PROCESS_IDLE

0 commit comments

Comments
 (0)