godot ai 更新
This commit is contained in:
@@ -156,8 +156,13 @@ func _process(_delta: float) -> void:
|
||||
## through the debugger packet path in a single tick. Surplus stays in
|
||||
## `_pending_outbound` and bleeds out across subsequent frames.
|
||||
if not _logger_attached or _logger == null:
|
||||
_pending_outbound.clear()
|
||||
return
|
||||
if not EngineDebugger.is_active():
|
||||
## No remote can consume these lines. Drop current and already-drained
|
||||
## batches so a detached/headless run cannot retain logs indefinitely (#1123).
|
||||
_logger.clear()
|
||||
_pending_outbound.clear()
|
||||
return
|
||||
if _pending_outbound.is_empty():
|
||||
if not _logger.has_pending():
|
||||
@@ -1024,13 +1029,7 @@ func _handle_eval(data: Array) -> void:
|
||||
_eval_token_counter += 1
|
||||
var token := str(_eval_token_counter)
|
||||
var run_fn := "_mcp_run_%s" % token
|
||||
var script_source := (
|
||||
"extends Node\n"
|
||||
+ "func execute():\n"
|
||||
+ "\treturn await %s()\n\n" % run_fn
|
||||
+ "func %s():\n" % run_fn
|
||||
+ _indent_eval_code(code)
|
||||
)
|
||||
var script_source := _build_eval_script_source(run_fn, code)
|
||||
|
||||
## Snapshot the logger's script-error seq BEFORE running so we only attribute
|
||||
## errors raised by this eval. In a debug build a parse error aborts reload()
|
||||
@@ -1227,7 +1226,23 @@ func _handle_eval_check(data: Array) -> void:
|
||||
_try_report_eval_runtime_error(request_id)
|
||||
|
||||
|
||||
func _indent_eval_code(code: String) -> String:
|
||||
## `execute()` always returns, so it carries a return type. The inner function
|
||||
## holds caller code that need not return on every path; a declared return type
|
||||
## there makes Godot reject it with "Not all code paths return a value". It
|
||||
## stays untyped and suppresses `untyped_declaration` on its own declaration
|
||||
## instead (#1119). The annotation shares the `func` line so the line numbers
|
||||
## reported for caller code do not move.
|
||||
static func _build_eval_script_source(run_fn: String, code: String) -> String:
|
||||
return (
|
||||
"extends Node\n"
|
||||
+ "func execute() -> Variant:\n"
|
||||
+ "\treturn await %s()\n\n" % run_fn
|
||||
+ "@warning_ignore(\"untyped_declaration\") func %s():\n" % run_fn
|
||||
+ _indent_eval_code(code)
|
||||
)
|
||||
|
||||
|
||||
static func _indent_eval_code(code: String) -> String:
|
||||
var lines: PackedStringArray = code.split("\n")
|
||||
var out := ""
|
||||
for line in lines:
|
||||
|
||||
@@ -37,6 +37,11 @@ var _mutex := Mutex.new()
|
||||
## (types 0/1) never count. Mutex-guarded: _log_error can fire from any thread.
|
||||
const _ERROR_TYPE_SCRIPT := 2
|
||||
const _MAX_RECENT_SCRIPT_ERRORS := 64
|
||||
const _MAX_PENDING := 4096
|
||||
const _PENDING_TRIM_THRESHOLD := _MAX_PENDING * 2
|
||||
## Lines trimmed from `_pending` since the last drain. The next drain reports
|
||||
## the count as a leading warn entry, so a gap in the log is never silent.
|
||||
var _dropped: int = 0
|
||||
var _script_error_seq: int = 0
|
||||
var _recent_script_errors: Array = []
|
||||
|
||||
@@ -93,6 +98,19 @@ func _append(level: String, text: String, details: Dictionary = {}) -> void:
|
||||
_pending.append([level, text])
|
||||
else:
|
||||
_pending.append([level, text, details.duplicate(true)])
|
||||
## Drop an old batch when a script floods the logger before the next frame.
|
||||
## Trimming at 2x the cap amortizes the slice instead of doing it per line.
|
||||
if _pending.size() >= _PENDING_TRIM_THRESHOLD:
|
||||
_dropped += _pending.size() - _MAX_PENDING
|
||||
_pending = _pending.slice(_pending.size() - _MAX_PENDING)
|
||||
_mutex.unlock()
|
||||
|
||||
|
||||
## Drop queued lines that no active debugger can consume.
|
||||
func clear() -> void:
|
||||
_mutex.lock()
|
||||
_pending.clear()
|
||||
_dropped = 0
|
||||
_mutex.unlock()
|
||||
|
||||
|
||||
@@ -102,7 +120,15 @@ func drain() -> Array:
|
||||
_mutex.lock()
|
||||
var out := _pending
|
||||
_pending = []
|
||||
var dropped := _dropped
|
||||
_dropped = 0
|
||||
_mutex.unlock()
|
||||
if dropped > 0:
|
||||
out.push_front([
|
||||
"warn",
|
||||
"[godot_ai] dropped %d older game log lines: the game logged faster than they could be forwarded"
|
||||
% dropped,
|
||||
])
|
||||
return out
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user