( screen: Screen, width: number, height: number, )
| 499 | * without allocating new Screen objects each frame. |
| 500 | */ |
| 501 | export function resetScreen( |
| 502 | screen: Screen, |
| 503 | width: number, |
| 504 | height: number, |
| 505 | ): void { |
| 506 | // Warn if dimensions are not valid integers |
| 507 | warn.ifNotInteger(width, 'resetScreen width') |
| 508 | warn.ifNotInteger(height, 'resetScreen height') |
| 509 | |
| 510 | // Ensure width and height are valid integers to prevent crashes |
| 511 | if (!Number.isInteger(width) || width < 0) { |
| 512 | width = Math.max(0, Math.floor(width) || 0) |
| 513 | } |
| 514 | if (!Number.isInteger(height) || height < 0) { |
| 515 | height = Math.max(0, Math.floor(height) || 0) |
| 516 | } |
| 517 | |
| 518 | const size = width * height |
| 519 | |
| 520 | // Resize if needed (only grow, to avoid reallocations) |
| 521 | if (screen.cells64.length < size) { |
| 522 | const buf = new ArrayBuffer(size << 3) |
| 523 | screen.cells = new Int32Array(buf) |
| 524 | screen.cells64 = new BigInt64Array(buf) |
| 525 | screen.noSelect = new Uint8Array(size) |
| 526 | } |
| 527 | if (screen.softWrap.length < height) { |
| 528 | screen.softWrap = new Int32Array(height) |
| 529 | } |
| 530 | |
| 531 | // Reset all cells — single fill call, no loop |
| 532 | screen.cells64.fill(EMPTY_CELL_VALUE, 0, size) |
| 533 | screen.noSelect.fill(0, 0, size) |
| 534 | screen.softWrap.fill(0, 0, height) |
| 535 | |
| 536 | // Update dimensions |
| 537 | screen.width = width |
| 538 | screen.height = height |
| 539 | |
| 540 | // Shared pools accumulate — no clearing needed. Unique char/hyperlink sets are bounded. |
| 541 | |
| 542 | // Clear damage tracking |
| 543 | screen.damage = undefined |
| 544 | } |
| 545 | |
| 546 | /** |
| 547 | * Re-intern a screen's char and hyperlink IDs into new pools. |
no test coverage detected