2 Revīzijas 4bf28baf4b ... 569f34f5be

Autors SHA1 Ziņojums Datums
  Malf 569f34f5be more downloader fixes 2 gadi atpakaļ
  Malf 1c13012886 add speed indication to downloader 2 gadi atpakaļ
6 mainītis faili ar 36 papildinājumiem un 8 dzēšanām
  1. 10 1
      Downloader_UI.gd
  2. 1 1
      Main.gd
  3. 8 1
      Main.tscn
  4. 3 0
      TopoLoader.gd
  5. 6 2
      chunk.gd
  6. 8 3
      downloader.gd

+ 10 - 1
Downloader_UI.gd

@@ -5,6 +5,8 @@ extends Panel
 # var a = 2
 # var b = "text"
 
+var last_downloaded=0
+var last_update=OS.get_ticks_msec()
 
 # Called when the node enters the scene tree for the first time.
 func _ready():
@@ -16,8 +18,15 @@ func _ready():
 #	pass
 
 func _on_status_updated(download):
+	var now = OS.get_ticks_msec()
+	var timeElapsed=1#(now-last_update)/1000
+	last_update = now
+	var diff = (download._downloaded_size - last_downloaded) / 1024
+	var speed = diff / timeElapsed
+	last_downloaded = download._downloaded_size
 	rect_size = $VBoxContainer.rect_size
-	$VBoxContainer/name.text = download._file_name
+	$VBoxContainer/name.text = download._current_url
 	$VBoxContainer/size.text = "size: %s"%download._file_size
 	$VBoxContainer/downloaded.text = "downloaded: %s"%download._downloaded_size
+	$VBoxContainer/speed.text = "%skb/s"%speed
 	$VBoxContainer/ProgressBar.value = download._downloaded_percent

+ 1 - 1
Main.gd

@@ -16,7 +16,7 @@ extends Spatial
 
 #var resolution = 512
 var radius = 1737.4*1000
-var startPos = Vector3(0,90,radius)
+var startPos = Vector3(0,354,radius)
 
 #var curlat = 0
 #var curlon = 0

+ 8 - 1
Main.tscn

@@ -140,10 +140,17 @@ margin_bottom = 76.0
 text = "downloaded:"
 align = 1
 
-[node name="ProgressBar" type="ProgressBar" parent="UI/Downloader/VBoxContainer"]
+[node name="speed" type="Label" parent="UI/Downloader/VBoxContainer"]
 margin_top = 80.0
 margin_right = 264.0
 margin_bottom = 94.0
+text = "speed:"
+align = 1
+
+[node name="ProgressBar" type="ProgressBar" parent="UI/Downloader/VBoxContainer"]
+margin_top = 98.0
+margin_right = 264.0
+margin_bottom = 112.0
 
 [node name="reference" type="MeshInstance" parent="."]
 visible = false

+ 3 - 0
TopoLoader.gd

@@ -71,6 +71,9 @@ func cacheArea(latMinIN, latMaxIN, lonMinIN, lonMaxIN):
 	if not _validate(latMinIN,lonMinIN) and not _validate(latMaxIN,lonMaxIN) :
 		print("out of scope!")
 		return
+	
+	if not file.is_open():
+		file.open(getFilepath(), File.READ)
 		
 	var lat = latMinIN
 	while lat <= latMaxIN:

+ 6 - 2
chunk.gd

@@ -15,6 +15,8 @@ var scaleFact:int = 1
 var origin:Vector3
 var center:Vector3
 
+var initialized = false
+
 func setParams(latMinIN, latMaxIN, lonMinIN, lonMaxIN, resolutionIN, radiusIN:float, scaleFactIN):
 	latMin = latMinIN
 	latMax = latMaxIN
@@ -26,6 +28,10 @@ func setParams(latMinIN, latMaxIN, lonMinIN, lonMaxIN, resolutionIN, radiusIN:fl
 
 # Called when the node enters the scene tree for the first time.
 func _ready():
+	initialize()
+	#.translate(.get_node("Mesh").origin)
+
+func initialize():
 	print("chunk %s,%s initializing" %[latMin, lonMin])
 	var initialized = .get_node("Mesh").initialize(latMin, latMax, lonMin, lonMax, resolution, radius, scaleFact)
 	if not initialized:
@@ -33,12 +39,10 @@ func _ready():
 		while not download._file_name == .get_node("Mesh").tl.getFilepath():
 			print("awaiting file download for %s" %.get_node("Mesh").tl.getFilepath())
 			download = yield(Messenger, "fileDownloaded")
-			print(download)
 	.get_node("Mesh").genMesh()
 	.get_node("Origin").transform.origin = .get_node("Mesh").origin
 	.get_node("Center").transform.origin = .get_node("Mesh").center
 	print("chunk %s,%s ready" %[latMin, lonMin])
-	#.translate(.get_node("Mesh").origin)
 
 # Called every frame. 'delta' is the elapsed time since the previous frame.
 #func _process(delta):

+ 8 - 3
downloader.gd

@@ -36,6 +36,9 @@ class Download:
 func _init() -> void:
 	set_process(false)
 	connect("request_completed", self, "_on_request_completed")
+	
+func _ready():
+	connect("stats_updated", Messenger, "_on_statusUpdate")
 
 func get_stats() -> Download:
 	return currentDownload
@@ -74,9 +77,8 @@ func _process(delta):
 func _download():
 	ensureFolder(currentDownload._kind)
 	download_file = currentDownload._file_name
-	.connect("stats_updated", Messenger, "_on_statusUpdate")
 	_send_head_request()
-	print("downloading %s" %currentDownload._file_name)
+	print("downloading %s" %currentDownload._current_url)
 	downloading = true
 
 func ensureFolder(kind):
@@ -99,7 +101,7 @@ func download(file, kind):
 	download._file_name = "user://%s/%s"%[kind, file]
 	download._current_url = make_filename(kind, file)
 	download._kind = kind
-	downloads[kind][file] = download
+	downloads[kind][download._file_name] = download
 	
 func make_filename(kind, file):
 	return kinds[kind]%file
@@ -139,8 +141,11 @@ func _on_request_completed(p_result,
 			_send_get_request()
 			
 		elif _last_method == HTTPClient.METHOD_GET:
+			print("file download complete %s"%currentDownload._current_url)
+			_file.close()
 			emit_signal("file_downloaded", currentDownload)
 			Messenger._on_file_downloaded(currentDownload)
+			downloading = false
 			downloads[currentDownload._kind].erase(currentDownload._file_name)
 			if len(downloads[currentDownload._kind]) == 0:
 				downloads.erase(currentDownload._kind)