Skip to content

Commit 463da99

Browse files
committed
Update and improve background load demo
1 parent 04d8677 commit 463da99

30 files changed

+128
-130
lines changed
Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,64 @@
11
extends Control
22

3-
var thread = null
3+
const SIMULATED_DELAY_SEC = 0.1
44

5-
onready var progress = $progress
5+
var thread = null
66

7-
var SIMULATED_DELAY_SEC = 1.0
7+
onready var progress = $Progress
88

99
func _thread_load(path):
1010
var ril = ResourceLoader.load_interactive(path)
1111
assert(ril)
1212
var total = ril.get_stage_count()
13-
# Call deferred to configure max load steps
13+
# Call deferred to configure max load steps.
1414
progress.call_deferred("set_max", total)
15-
15+
1616
var res = null
17-
17+
1818
while true: #iterate until we have a resource
19-
# Update progress bar, use call deferred, which routes to main thread
19+
# Update progress bar, use call deferred, which routes to main thread.
2020
progress.call_deferred("set_value", ril.get_stage())
21-
# Simulate a delay
22-
OS.delay_msec(SIMULATED_DELAY_SEC * 1000.0)
23-
# Poll (does a load step)
21+
# Simulate a delay.
22+
OS.delay_msec(int(SIMULATED_DELAY_SEC * 1000.0))
23+
# Poll (does a load step).
2424
var err = ril.poll()
25-
# if OK, then load another one. If EOF, it' s done. Otherwise there was an error.
25+
# If OK, then load another one. If EOF, it' s done. Otherwise there was an error.
2626
if err == ERR_FILE_EOF:
27-
# Loading done, fetch resource
27+
# Loading done, fetch resource.
2828
res = ril.get_resource()
2929
break
3030
elif err != OK:
31-
# Not OK, there was an error
31+
# Not OK, there was an error.
3232
print("There was an error loading")
3333
break
34-
35-
# Send whathever we did (or not) get
34+
35+
# Send whathever we did (or did not) get.
3636
call_deferred("_thread_done", res)
3737

38+
3839
func _thread_done(resource):
3940
assert(resource)
40-
41-
# Always wait for threads to finish, this is required on Windows
41+
42+
# Always wait for threads to finish, this is required on Windows.
4243
thread.wait_to_finish()
43-
44-
#Hide the progress bar
44+
45+
# Hide the progress bar.
4546
progress.hide()
46-
47-
# Instantiate new scene
47+
48+
# Instantiate new scene.
4849
var new_scene = resource.instance()
49-
# Free current scene
50+
# Free current scene.
5051
get_tree().current_scene.free()
5152
get_tree().current_scene = null
52-
# Add new one to root
53+
# Add new one to root.
5354
get_tree().root.add_child(new_scene)
54-
# Set as current scene
55+
# Set as current scene.
5556
get_tree().current_scene = new_scene
56-
57+
5758
progress.visible = false
5859

5960
func load_scene(path):
60-
6161
thread = Thread.new()
6262
thread.start( self, "_thread_load", path)
63-
raise() # show on top
63+
raise() # Show on top.
6464
progress.visible = true
65-
66-

loading/background_load/background_load.tscn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
[ext_resource path="res://background_load.gd" type="Script" id=1]
44

5-
[node name="bgload" type="Control"]
5+
[node name="BackgroundLoad" type="Control"]
66
script = ExtResource( 1 )
77

8-
[node name="progress" type="ProgressBar" parent="."]
8+
[node name="Progress" type="ProgressBar" parent="."]
99
visible = false
1010
margin_left = 7.0
1111
margin_top = 8.0
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
extends Node2D
22

33
func _on_switch_pressed():
4-
$CanvasLayer/switch.hide()
4+
$CanvasLayer/Switch.hide()
55
background_load.load_scene("res://sculptures.tscn")

loading/background_load/paintings.tscn

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
[gd_scene load_steps=9 format=2]
22

33
[ext_resource path="res://paintings.gd" type="Script" id=1]
4-
[ext_resource path="res://painting_parasol.jpg" type="Texture" id=2]
5-
[ext_resource path="res://painting_babel.jpg" type="Texture" id=3]
6-
[ext_resource path="res://painting_mona_lisa.jpg" type="Texture" id=4]
7-
[ext_resource path="res://painting_las_meninas.png" type="Texture" id=5]
8-
[ext_resource path="res://painting_old_guitarist.jpg" type="Texture" id=6]
9-
[ext_resource path="res://painting_the_swing.jpg" type="Texture" id=7]
4+
[ext_resource path="res://paintings/painting_babel.jpg" type="Texture" id=2]
5+
[ext_resource path="res://paintings/painting_las_meninas.png" type="Texture" id=3]
6+
[ext_resource path="res://paintings/painting_mona_lisa.jpg" type="Texture" id=4]
7+
[ext_resource path="res://paintings/painting_old_guitarist.jpg" type="Texture" id=5]
8+
[ext_resource path="res://paintings/painting_parasol.jpg" type="Texture" id=6]
9+
[ext_resource path="res://paintings/painting_the_swing.jpg" type="Texture" id=7]
1010

1111
[sub_resource type="Animation" id=1]
1212
resource_name = "move_around"
1313
length = 4.0
1414
loop = true
1515
tracks/0/type = "value"
16-
tracks/0/path = NodePath("painting_mona_lisa:position")
16+
tracks/0/path = NodePath("MonaLisa:position")
1717
tracks/0/interp = 2
1818
tracks/0/loop_wrap = true
1919
tracks/0/imported = false
@@ -25,7 +25,7 @@ tracks/0/keys = {
2525
"values": [ Vector2( 117.659, 173.793 ), Vector2( 164.387, 206.955 ) ]
2626
}
2727
tracks/1/type = "value"
28-
tracks/1/path = NodePath("painting_mona_lisa:rotation_degrees")
28+
tracks/1/path = NodePath("MonaLisa:rotation_degrees")
2929
tracks/1/interp = 2
3030
tracks/1/loop_wrap = true
3131
tracks/1/imported = false
@@ -37,7 +37,7 @@ tracks/1/keys = {
3737
"values": [ 0.0, 0.0 ]
3838
}
3939
tracks/2/type = "value"
40-
tracks/2/path = NodePath("painting_parasol:position")
40+
tracks/2/path = NodePath("Parasol:position")
4141
tracks/2/interp = 2
4242
tracks/2/loop_wrap = true
4343
tracks/2/imported = false
@@ -49,7 +49,7 @@ tracks/2/keys = {
4949
"values": [ Vector2( 451.448, 256.916 ), Vector2( 483.102, 317.21 ) ]
5050
}
5151
tracks/3/type = "value"
52-
tracks/3/path = NodePath("painting_parasol:rotation_degrees")
52+
tracks/3/path = NodePath("Parasol:rotation_degrees")
5353
tracks/3/interp = 2
5454
tracks/3/loop_wrap = true
5555
tracks/3/imported = false
@@ -61,7 +61,7 @@ tracks/3/keys = {
6161
"values": [ 0.0, 0.0 ]
6262
}
6363
tracks/4/type = "value"
64-
tracks/4/path = NodePath("painting_the_swing:position")
64+
tracks/4/path = NodePath("TheSwing:position")
6565
tracks/4/interp = 2
6666
tracks/4/loop_wrap = true
6767
tracks/4/imported = false
@@ -73,7 +73,7 @@ tracks/4/keys = {
7373
"values": [ Vector2( 715.927, 181.745 ), Vector2( 661.663, 205.863 ) ]
7474
}
7575
tracks/5/type = "value"
76-
tracks/5/path = NodePath("painting_the_swing:rotation_degrees")
76+
tracks/5/path = NodePath("TheSwing:rotation_degrees")
7777
tracks/5/interp = 2
7878
tracks/5/loop_wrap = true
7979
tracks/5/imported = false
@@ -85,7 +85,7 @@ tracks/5/keys = {
8585
"values": [ 0.0, 0.0 ]
8686
}
8787
tracks/6/type = "value"
88-
tracks/6/path = NodePath("painting_old_guitarist:position")
88+
tracks/6/path = NodePath("OldGuitarist:position")
8989
tracks/6/interp = 2
9090
tracks/6/loop_wrap = true
9191
tracks/6/imported = false
@@ -97,7 +97,7 @@ tracks/6/keys = {
9797
"values": [ Vector2( 886.982, 185.641 ), Vector2( 901.179, 210.693 ) ]
9898
}
9999
tracks/7/type = "value"
100-
tracks/7/path = NodePath("painting_old_guitarist:rotation_degrees")
100+
tracks/7/path = NodePath("OldGuitarist:rotation_degrees")
101101
tracks/7/interp = 2
102102
tracks/7/loop_wrap = true
103103
tracks/7/imported = false
@@ -109,7 +109,7 @@ tracks/7/keys = {
109109
"values": [ 0.0, 15.0 ]
110110
}
111111
tracks/8/type = "value"
112-
tracks/8/path = NodePath("painting_babel:position")
112+
tracks/8/path = NodePath("Babel:position")
113113
tracks/8/interp = 2
114114
tracks/8/loop_wrap = true
115115
tracks/8/imported = false
@@ -121,7 +121,7 @@ tracks/8/keys = {
121121
"values": [ Vector2( 155.796, 468.287 ), Vector2( 194.21, 444.904 ) ]
122122
}
123123
tracks/9/type = "value"
124-
tracks/9/path = NodePath("painting_babel:rotation_degrees")
124+
tracks/9/path = NodePath("Babel:rotation_degrees")
125125
tracks/9/interp = 2
126126
tracks/9/loop_wrap = true
127127
tracks/9/imported = false
@@ -133,7 +133,7 @@ tracks/9/keys = {
133133
"values": [ 0.0, 0.0 ]
134134
}
135135
tracks/10/type = "value"
136-
tracks/10/path = NodePath("painting_las_meninas:position")
136+
tracks/10/path = NodePath("LasMeninas:position")
137137
tracks/10/interp = 2
138138
tracks/10/loop_wrap = true
139139
tracks/10/imported = false
@@ -145,7 +145,7 @@ tracks/10/keys = {
145145
"values": [ Vector2( 861.734, 494.059 ), Vector2( 840.022, 470.677 ) ]
146146
}
147147
tracks/11/type = "value"
148-
tracks/11/path = NodePath("painting_las_meninas:rotation_degrees")
148+
tracks/11/path = NodePath("LasMeninas:rotation_degrees")
149149
tracks/11/interp = 2
150150
tracks/11/loop_wrap = true
151151
tracks/11/imported = false
@@ -157,35 +157,35 @@ tracks/11/keys = {
157157
"values": [ 0.0, 0.0 ]
158158
}
159159

160-
[node name="Node2D" type="Node2D"]
160+
[node name="Paintings" type="Node2D"]
161161
script = ExtResource( 1 )
162162

163-
[node name="painting_parasol" type="Sprite" parent="."]
164-
position = Vector2( 451.448, 256.916 )
165-
scale = Vector2( 0.557998, 0.557998 )
166-
texture = ExtResource( 2 )
167-
168-
[node name="painting_babel" type="Sprite" parent="."]
163+
[node name="Babel" type="Sprite" parent="."]
169164
position = Vector2( 155.796, 468.287 )
170165
scale = Vector2( 0.29005, 0.29005 )
166+
texture = ExtResource( 2 )
167+
168+
[node name="LasMeninas" type="Sprite" parent="."]
169+
position = Vector2( 861.734, 494.059 )
170+
scale = Vector2( 0.348146, 0.348146 )
171171
texture = ExtResource( 3 )
172172

173-
[node name="painting_mona_lisa" type="Sprite" parent="."]
173+
[node name="MonaLisa" type="Sprite" parent="."]
174174
position = Vector2( 117.659, 173.793 )
175175
scale = Vector2( 0.696799, 0.696799 )
176176
texture = ExtResource( 4 )
177177

178-
[node name="painting_las_meninas" type="Sprite" parent="."]
179-
position = Vector2( 861.734, 494.059 )
180-
scale = Vector2( 0.348146, 0.348146 )
181-
texture = ExtResource( 5 )
182-
183-
[node name="painting_old_guitarist" type="Sprite" parent="."]
178+
[node name="OldGuitarist" type="Sprite" parent="."]
184179
position = Vector2( 886.982, 185.641 )
185180
scale = Vector2( 0.344706, 0.328421 )
181+
texture = ExtResource( 5 )
182+
183+
[node name="Parasol" type="Sprite" parent="."]
184+
position = Vector2( 451.448, 256.916 )
185+
scale = Vector2( 0.557998, 0.557998 )
186186
texture = ExtResource( 6 )
187187

188-
[node name="painting_the_swing" type="Sprite" parent="."]
188+
[node name="TheSwing" type="Sprite" parent="."]
189189
position = Vector2( 715.927, 181.745 )
190190
scale = Vector2( 0.286677, 0.286677 )
191191
texture = ExtResource( 7 )
@@ -200,7 +200,7 @@ current = true
200200

201201
[node name="CanvasLayer" type="CanvasLayer" parent="."]
202202

203-
[node name="switch" type="Button" parent="CanvasLayer"]
203+
[node name="Switch" type="Button" parent="CanvasLayer"]
204204
margin_left = 10.0
205205
margin_top = 10.0
206206
margin_right = 156.0
@@ -209,4 +209,4 @@ text = "Switch to Sculptures"
209209
__meta__ = {
210210
"_edit_use_anchors_": false
211211
}
212-
[connection signal="pressed" from="CanvasLayer/switch" to="." method="_on_switch_pressed"]
212+
[connection signal="pressed" from="CanvasLayer/Switch" to="." method="_on_switch_pressed"]

loading/background_load/painting_babel.jpg.import renamed to loading/background_load/paintings/painting_babel.jpg.import

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
importer="texture"
44
type="StreamTexture"
5-
path="res://.import/painting_babel.jpg-bb6b7c64c260f78ce43012bcac8a1c4e.stex"
5+
path="res://.import/painting_babel.jpg-7d4afda4b0268025e231a7f9e793a18d.stex"
66
metadata={
77
"vram_texture": false
88
}
99

1010
[deps]
1111

12-
source_file="res://painting_babel.jpg"
13-
dest_files=[ "res://.import/painting_babel.jpg-bb6b7c64c260f78ce43012bcac8a1c4e.stex" ]
12+
source_file="res://paintings/painting_babel.jpg"
13+
dest_files=[ "res://.import/painting_babel.jpg-7d4afda4b0268025e231a7f9e793a18d.stex" ]
1414

1515
[params]
1616

loading/background_load/painting_las_meninas.png.import renamed to loading/background_load/paintings/painting_las_meninas.png.import

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
importer="texture"
44
type="StreamTexture"
5-
path="res://.import/painting_las_meninas.png-158bef53fe63c53626df2020827ea75b.stex"
5+
path="res://.import/painting_las_meninas.png-980a9e4669b648b01417bfb871e282ee.stex"
66
metadata={
77
"vram_texture": false
88
}
99

1010
[deps]
1111

12-
source_file="res://painting_las_meninas.png"
13-
dest_files=[ "res://.import/painting_las_meninas.png-158bef53fe63c53626df2020827ea75b.stex" ]
12+
source_file="res://paintings/painting_las_meninas.png"
13+
dest_files=[ "res://.import/painting_las_meninas.png-980a9e4669b648b01417bfb871e282ee.stex" ]
1414

1515
[params]
1616

loading/background_load/painting_mona_lisa.jpg.import renamed to loading/background_load/paintings/painting_mona_lisa.jpg.import

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
importer="texture"
44
type="StreamTexture"
5-
path="res://.import/painting_mona_lisa.jpg-cefdc64dfa49e9ee9566b078597cd552.stex"
5+
path="res://.import/painting_mona_lisa.jpg-0d1e89a489f14142e264e1f238465e1c.stex"
66
metadata={
77
"vram_texture": false
88
}
99

1010
[deps]
1111

12-
source_file="res://painting_mona_lisa.jpg"
13-
dest_files=[ "res://.import/painting_mona_lisa.jpg-cefdc64dfa49e9ee9566b078597cd552.stex" ]
12+
source_file="res://paintings/painting_mona_lisa.jpg"
13+
dest_files=[ "res://.import/painting_mona_lisa.jpg-0d1e89a489f14142e264e1f238465e1c.stex" ]
1414

1515
[params]
1616

0 commit comments

Comments
 (0)