Implemented direct image data transfer
via websockets to the job-server. The images are then served by the job-server itself.
This commit is contained in:
30
JobServer.gd
30
JobServer.gd
@@ -4,7 +4,8 @@ var socket = WebSocketPeer.new()
|
||||
|
||||
func InitWebsocket():
|
||||
print("Connecting websocket ")
|
||||
|
||||
socket.max_queued_packets = 32768
|
||||
socket.outbound_buffer_size = 5000000
|
||||
socket.connect_to_url($"/root/Main".websocket_url, TLSOptions.client_unsafe())
|
||||
while socket.get_ready_state() != WebSocketPeer.STATE_OPEN:
|
||||
socket.poll()
|
||||
@@ -38,20 +39,37 @@ func PollWebsocket():
|
||||
var job = json["job"]
|
||||
print("Recevied Job ", job["jobId"])
|
||||
main.rendering = true
|
||||
var result = await $"../Renderer".RenderJob(job)
|
||||
|
||||
var result_path = await $"../Renderer".RenderJob(job)
|
||||
var result_value = ""
|
||||
var result_type = "URL" if $"/root/Main".serve_mode == "local" else "B64:PNG"
|
||||
if $"/root/Main".serve_mode == "local":
|
||||
result_value = result_path
|
||||
if $"/root/Main".serve_mode == "remote":
|
||||
print("trying to open " + result_path)
|
||||
var resut_file = FileAccess.open(result_path,FileAccess.READ)
|
||||
result_value = "{path}:{data}".format({
|
||||
"path":result_path,
|
||||
"data": Marshalls.raw_to_base64(resut_file.get_buffer(resut_file.get_length()))
|
||||
})
|
||||
var debugFile = FileAccess.open("user://debug.log", FileAccess.WRITE)
|
||||
debugFile.store_string(result_value)
|
||||
debugFile.flush()
|
||||
debugFile.close()
|
||||
var response = {
|
||||
"result": {
|
||||
"type": result_type,
|
||||
"jobId": job["jobId"],
|
||||
"path": $"/root/Main".public_path + result
|
||||
"value": result_value
|
||||
}
|
||||
}
|
||||
socket.send_text(str(response))
|
||||
print("Sent result ", result)
|
||||
print("Sent result ", result_path)
|
||||
main.rendering = false
|
||||
elif state == WebSocketPeer.STATE_CLOSING:
|
||||
# Keep polling to achieve proper close.
|
||||
pass
|
||||
socket.poll()
|
||||
elif state == WebSocketPeer.STATE_CLOSED:
|
||||
print(socket.get_packet())
|
||||
var code = socket.get_close_code()
|
||||
var reason = socket.get_close_reason()
|
||||
print("WebSocket closed with code: %d, reason %s. Clean: %s" % [code, reason, code != -1])
|
||||
|
||||
2
Main.gd
2
Main.gd
@@ -5,6 +5,7 @@ var config = ConfigFile.new()
|
||||
var websocket_url
|
||||
var public_path
|
||||
var output_dir
|
||||
var serve_mode
|
||||
var cache_dir
|
||||
var auth_key
|
||||
var rendering = false
|
||||
@@ -16,6 +17,7 @@ func _ready():
|
||||
websocket_url = config.get_value("core", "websocket_url")
|
||||
public_path = config.get_value("core", "public_path")
|
||||
output_dir = config.get_value("core", "output_dir")
|
||||
serve_mode = config.get_value("core", "serve_mode")
|
||||
cache_dir = config.get_value("core", "cache_dir")
|
||||
auth_key = config.get_value("core", "auth_key")
|
||||
|
||||
|
||||
@@ -45,8 +45,12 @@ func RenderJob(job):
|
||||
|
||||
# Get rendered image
|
||||
var img = get_viewport().get_texture().get_image()
|
||||
var outFile = "%s_%s.png" % [job["type"],str(job["elements"]).hash()]
|
||||
img.save_png("%s/%s" % [$"/root/Main".output_dir, outFile])
|
||||
var outFile = "{path}/{type}_{hash}.png".format({
|
||||
"path":$"/root/Main".output_dir,
|
||||
"type":job["type"],
|
||||
"hash": str(job["elements"]).hash()
|
||||
})
|
||||
img.save_png(outFile)
|
||||
|
||||
return outFile
|
||||
|
||||
|
||||
@@ -4,3 +4,4 @@ websocket_url="ws://localhost:6980"
|
||||
public_path="http://localhost:8899/"
|
||||
output_dir="./output"
|
||||
cache_dir="./cache"
|
||||
serve_mode="local"
|
||||
|
||||
@@ -20,3 +20,4 @@ config/icon="res://icon.svg"
|
||||
|
||||
renderer/rendering_method="gl_compatibility"
|
||||
renderer/rendering_method.mobile="gl_compatibility"
|
||||
textures/vram_compression/import_etc2_astc=true
|
||||
|
||||
Reference in New Issue
Block a user