extends Node var Downloader = preload("res://downloader.gd") var datafile = "height/SLDEM2015_512_00N_30N_000_045_FLOAT.IMG" var samplesPerLine = 23040 var lines = 15360 var offset = 1737.4#*1000 var scaleFact = 1 var resolution = 512 var latMin = 0 var latMax = 30 var lonMin = 0 var lonMax = 45 var cache = {} var file: File # Called when the node enters the scene tree for the first time. func open(): file = File.new() if not file.file_exists("user://"+datafile): var downloader = Downloader.new() add_child(downloader) downloader.load(datafile, "height") yield(downloader, "request_completed") file.open("user://"+datafile, File.READ) func close(): file.close() queue_free() func cacheArea(latMinIN, latMaxIN, lonMinIN, lonMaxIN): if not _validate(latMinIN,lonMinIN) and not _validate(latMaxIN,lonMaxIN) : print("out of scope!") return var lat = latMinIN while lat <= latMaxIN: cache[lat]={} file.seek((latMax*resolution*samplesPerLine*4 - lat*resolution*samplesPerLine*4) + lonMinIN*resolution*4) var lon = lonMinIN while lon <= lonMaxIN: cache[lat][lon] = file.get_float() lon += 1.0/float(resolution) lat += 1.0/float(resolution) return func read(lat,lon): if _validate(lat,lon): return cache[lat][lon] else: print("out of scope!") func _validate(lat,lon): if lat <= latMax and lat >= latMin and lon <= lonMax and lon >= lonMin: return true return false # Called every frame. 'delta' is the elapsed time since the previous frame. #func _process(delta): # pass