Jump to content

Gpu: Difference between revisions

From Advanced Computers Wiki
 
(One intermediate revision by the same user not shown)
Line 16: Line 16:
|<code>:newBuffer(integer:width, integer:height)</code>
|<code>:newBuffer(integer:width, integer:height)</code>
|<code>TextBufferUD</code>
|<code>TextBufferUD</code>
|Attempts to allocate and return a new [[TextBuffer]] of the given size.
|Attempts to allocate and return a new [[Gpu#TextBufferUD|TextBuffer]] of the given size.
|-
|-
|<code>:assignBuffer(textBufferUD, screenBlockUD:screenComponent)</code>
|<code>:assignBuffer(textBufferUD, screenBlockUD:screenComponent)</code>
Line 28: Line 28:


=== TextBufferUD ===
=== TextBufferUD ===
You can interact with textBuffers using the following api:
You can interact with textBuffers using the following API:
{| class="wikitable"
{| class="wikitable"
|+ TextBufferUD properties
|+ TextBufferUD properties

Latest revision as of 15:05, 18 August 2026

The GpuUD component is what allows for rendering to screens. It offers the following functionality:

GpuUD component properties
Name Type Read/Write Description
remainingVideoRam integer READ The amount of video ram remaining. Every alive buffer requires a certain amount of video memory.
GpuUD component methods
Name Returns Description
:newBuffer(integer:width, integer:height) TextBufferUD Attempts to allocate and return a new TextBuffer of the given size.
:assignBuffer(textBufferUD, screenBlockUD:screenComponent) void Assigns the given textBuffer to the given Screen, displaying the contents on the screen.
:freeAllBuffers() int Frees all buffers allocated by this GPU and returns the number of freed buffers.

TextBufferUD

You can interact with textBuffers using the following API:

TextBufferUD properties
Name Type Read/Write Description
width int READ The width/height of this buffer, as specified in GpuUD:newBuffer(...).
height int READ
isAlive bool READ Whether this buffer is still alive, i.e. has not been deleted yet via :free().

In the following, x refers to the horizontal axis (like width) and y refers to the vertical axis (like height).

TextBufferUD methods
Name Returns Description
:getTextAsString() string Returns the entire content of this buffer as a single string.
:free() void Deletes this buffer, releasing the held video memory.
:getFg(x:int, y:int) byte Returns the foreground color of this position. Currently does not have any visible effect.
:getBg(x:int, y:int) byte Returns the background color of this position. Currently does not have any visible effect.
:getText(x:int, y:int) char Returns a single-letter string representing the letter stored at this position.
:set(x:int, y:int, chr:char, fgColor:byte, bgColor: byte) void Sets the given position's character data, foreground and background color. Any arguments except for the position may be nil and will then have no effect. Color rendering is currently not implemented.
:rotRows(cnt:int) void Rotates the lines of the buffer, allowing for efficient implementation of scrolling.
:clearRow(line:int) void Clears the given line, resetting colors and text content of all positions of the given line.
:newline() void Shorthand for: clearRow(0); rotRows(1);
:pasteText(x:int, y:int, mode:PasteMode, uText:string) x:int, y:int Pastes the given text uText at the given position with the given pasteMode mode. Returns the position directly after the pasted text. So when performing multiple paste-operations you likely want to supply the previously returned position as the next position argument.
:pasteText(uText:string) x:int, y:int Shorthand for: :pasteText(0, 0, uText)
:pasteText(x:int, y:int, uText:string) x:int, y:int Shorthand for: :pasteText(x, y, PasteMode.STOP, uText)

PasteMode

PasteMode is an enum that can take one of the values below. When trying to supply a value of this type, simply use the string representation.

PasteModes
String representation LineMode clearRestOnNewLine spillOnBufferLineEnd
STOP SINGLE false false
STOP_CLEAR SINGLE true false
FILL_CLIP MULTI false false
FILL_CLIP_CLEAR MULTI true false
FILL_SPILL MULTI false true
FILL_SPILL_CLEAR MULTI true true
SCROLL_CLIP SCROLL false false
SCROLL_CLIP_CLEAR SCROLL true false
SCROLL_SPILL SCROLL false true
SCROLL_SPILL_CLEAR SCROLL true true

if clearRestOnNewLine is true, the remainder of the line is cleared when a newline character (\n) character is encountered.

if spillOnBufferLineEnd is true and the horizontal end of the buffer is reached, printing simply continues in the next line as if there was a newline character.

LineModes
Type Behavior
SINGLE Abort printing as soon as we would need to transition into the next line to continue.
MULTI Print multiple lines, but stop printing if we reach the vertical end of the buffer.
SCROLL Like MULTI, but when reaching the end of the buffer scroll instead of aborting.