optimize canvas redraw and batch Lua canvas operations
This commit is contained in:
@@ -3,8 +3,35 @@ extends RefCounted
|
||||
|
||||
# This file mainly creates operations that are handled by canvas.gd
|
||||
|
||||
static var pending_operations: Dictionary = {}
|
||||
static var batch_timer: SceneTreeTimer = null
|
||||
|
||||
static func emit_canvas_operation(lua_api: LuaAPI, operation: Dictionary) -> void:
|
||||
lua_api.threaded_vm.call_deferred("_emit_dom_operation_request", operation)
|
||||
var element_id = operation.get("element_id", "")
|
||||
|
||||
if not pending_operations.has(element_id):
|
||||
pending_operations[element_id] = []
|
||||
|
||||
pending_operations[element_id].append(operation)
|
||||
|
||||
if not batch_timer or batch_timer.time_left <= 0:
|
||||
var scene_tree = lua_api.get_tree() if lua_api else Engine.get_main_loop()
|
||||
if scene_tree:
|
||||
batch_timer = scene_tree.create_timer(0.001) # 1ms batch window
|
||||
batch_timer.timeout.connect(_flush_pending_operations.bind(lua_api))
|
||||
|
||||
static func _flush_pending_operations(lua_api: LuaAPI) -> void:
|
||||
if not lua_api or not lua_api.is_inside_tree():
|
||||
pending_operations.clear()
|
||||
return
|
||||
|
||||
for element_id in pending_operations:
|
||||
var operations = pending_operations[element_id]
|
||||
for operation in operations:
|
||||
lua_api.threaded_vm.call_deferred("_emit_dom_operation_request", operation)
|
||||
|
||||
pending_operations.clear()
|
||||
batch_timer = null
|
||||
|
||||
static func _element_withContext_wrapper(vm: LuauVM) -> int:
|
||||
var lua_api = vm.get_meta("lua_api") as LuaAPI
|
||||
|
||||
Reference in New Issue
Block a user