Skip to content

Commit c85535e

Browse files
committed
Improve progress indicator
1 parent 8561e33 commit c85535e

File tree

3 files changed

+42
-14
lines changed

3 files changed

+42
-14
lines changed

addons/wfc/examples/demo_wfc_2d_tilemap.tscn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ room_half_size_base = Vector2i(2, 2)
3838
room_half_size_variation = Vector2i(2, 2)
3939
room_probability = 0.5
4040
road_len_base = 15
41-
road_len_variation = 5
41+
road_len_variation = 10
4242
fork_probability = 0.5
4343
full_fork_probability = 0.5
4444
passable_area_ratio = 0.1

addons/wfc/examples/helpers/progress_indicator.tscn

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[gd_scene load_steps=3 format=3 uid="uid://dt2nffs32s7o1"]
1+
[gd_scene load_steps=4 format=3 uid="uid://dt2nffs32s7o1"]
22

33
[sub_resource type="GDScript" id="GDScript_3tvrq"]
44
script/source = "extends CanvasLayer
@@ -11,25 +11,50 @@ func _ready():
1111
%ProgressBar.max_value = 1.0
1212
%ProgressBar.step = 0.001
1313

14+
generator.started.connect(on_start)
15+
generator.done.connect(on_done)
16+
1417
func _process(delta):
1518
%ProgressBar.value = generator.get_progress()
19+
20+
var start_time: int = 0
21+
22+
func on_start():
23+
%StatusLabel.text = \"Started\"
24+
start_time = Time.get_ticks_msec()
25+
26+
func on_done():
27+
var delta = Time.get_ticks_msec() - start_time
28+
29+
%StatusLabel.text = \"Done in %.2f second(s)\" % (0.001 * delta)
1630
"
1731

1832
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_6msag"]
1933
bg_color = Color(0.6, 0.6, 0.6, 0.807843)
2034

21-
[node name="progressIndicator" type="CanvasLayer" node_paths=PackedStringArray("generator")]
35+
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_xru5r"]
36+
bg_color = Color(0.6, 0.6, 0.6, 0.858824)
37+
38+
[node name="progressIndicator" type="CanvasLayer"]
2239
script = SubResource("GDScript_3tvrq")
23-
generator = NodePath("")
2440

2541
[node name="CenterContainer" type="CenterContainer" parent="."]
2642
custom_minimum_size = Vector2(0, 100)
2743
anchors_preset = 10
2844
anchor_right = 1.0
2945
grow_horizontal = 2
3046

31-
[node name="ProgressBar" type="ProgressBar" parent="CenterContainer"]
47+
[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer"]
48+
layout_mode = 2
49+
50+
[node name="ProgressBar" type="ProgressBar" parent="CenterContainer/VBoxContainer"]
3251
unique_name_in_owner = true
3352
custom_minimum_size = Vector2(500, 0)
3453
layout_mode = 2
3554
theme_override_styles/fill = SubResource("StyleBoxFlat_6msag")
55+
56+
[node name="StatusLabel" type="Label" parent="CenterContainer/VBoxContainer"]
57+
unique_name_in_owner = true
58+
layout_mode = 2
59+
theme_override_styles/normal = SubResource("StyleBoxFlat_xru5r")
60+
text = "Not started"

addons/wfc/nodes/generator_2d.gd

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ var render_intermediate_results: bool = false
4646
@export_category("Debug mode")
4747
var print_rules: bool = false
4848

49+
signal started
4950
signal done
5051

5152

@@ -118,48 +119,50 @@ func start():
118119

119120
if not rules.is_ready():
120121
assert(positive_sample != null)
121-
122+
122123
var positive_sample_node: Node = get_node(positive_sample)
123124
assert(positive_sample_node != null)
124-
125+
125126
if rules == null:
126127
rules = WFCRules2D.new()
127128
else:
128129
rules = rules.duplicate(false) as WFCRules2D
129130

130131
assert(rules != null)
131-
132+
132133
if rules.mapper == null:
133134
rules.mapper = _create_mapper(target_node)
134135
if not rules.mapper.is_ready():
135136
rules.mapper.learn_from(positive_sample_node)
136137
rules.learn_from(positive_sample_node)
137-
138+
138139
if rules.complete_matrices and negative_sample != null and not negative_sample.is_empty():
139140
var negative_sample_node: Node = get_node(negative_sample)
140-
141+
141142
if negative_sample_node != null:
142143
rules.learn_negative_from(negative_sample_node)
143144

144145
if print_rules and OS.is_debug_build():
145146
print_debug('Rules learned:\n', rules.format())
146-
147+
147148
print_debug('Influence range: ', rules.get_influence_range())
148149

149150
var problem_settings: WFC2DProblem.WFC2DProblemSettings = WFC2DProblem.WFC2DProblemSettings.new()
150-
151+
151152
problem_settings.rules = rules
152153
problem_settings.rect = rect
153154

154155
var precondition: WFC2DPrecondition = _create_precondition(problem_settings, target_node)
155156

157+
started.emit()
158+
156159
# TODO: Call this in separate thread if long-running generators will be used to generate preconditions
157160
precondition.prepare()
158161

159162
var problem: WFC2DProblem = _create_problem(problem_settings, target_node, precondition)
160163

161164
_runner = _create_runner()
162-
165+
163166
_runner.start(problem)
164167

165168
_runner.all_solved.connect(func(): done.emit())
@@ -173,7 +176,7 @@ func _on_solved(problem: WFC2DProblem, state: WFCSolverState):
173176
func _on_partial_solution(problem: WFC2DProblem, state: WFCSolverState):
174177
if not render_intermediate_results:
175178
return
176-
179+
177180
_on_solved(problem, state)
178181

179182
func _ready():

0 commit comments

Comments
 (0)