MCPcopy Create free account
hub / github.com/Noumena-Network/code / resetScreen

Function resetScreen

src/ink/screen.ts:538–585  ·  view source on GitHub ↗
(
  screen: Screen,
  width: number,
  height: number,
)

Source from the content-addressed store, hash-verified

536 * without allocating new Screen objects each frame.
537 */
538export function resetScreen(
539 screen: Screen,
540 width: number,
541 height: number,
542): void {
543 // Warn if dimensions are not valid integers
544 warn.ifNotInteger(width, 'resetScreen width')
545 warn.ifNotInteger(height, 'resetScreen height')
546
547 // Ensure width and height are valid integers to prevent crashes
548 if (!Number.isInteger(width) || width < 0) {
549 width = Math.max(0, Math.floor(width) || 0)
550 }
551 if (!Number.isInteger(height) || height < 0) {
552 height = Math.max(0, Math.floor(height) || 0)
553 }
554
555 const size = width * height
556
557 // Resize if needed (only grow, to avoid reallocations)
558 if (screen.cells64.length < size) {
559 const buf = new ArrayBuffer(size << 3)
560 screen.cells = new Int32Array(buf)
561 screen.cells64 = new BigInt64Array(buf)
562 screen.noSelect = new Uint8Array(size)
563 }
564 if (screen.softWrap.length < height) {
565 screen.softWrap = new Int32Array(height)
566 }
567 if (screen.contentEnd.length < height) {
568 screen.contentEnd = new Int32Array(height)
569 }
570
571 // Reset all cells — single fill call, no loop
572 screen.cells64.fill(EMPTY_CELL_VALUE, 0, size)
573 screen.noSelect.fill(0, 0, size)
574 screen.softWrap.fill(0, 0, height)
575 screen.contentEnd.fill(0, 0, height)
576
577 // Update dimensions
578 screen.width = width
579 screen.height = height
580
581 // Shared pools accumulate — no clearing needed. Unique char/hyperlink sets are bounded.
582
583 // Clear damage tracking
584 screen.damage = undefined
585}
586
587/**
588 * Re-intern a screen's char and hyperlink IDs into new pools.

Callers 2

constructorMethod · 0.85
resetMethod · 0.85

Calls 1

maxMethod · 0.80

Tested by

no test coverage detected