This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
bjornir90's profile picture

How does term. clear() actually work?

Started by bjornir90, 23 April 2014 - 03:35 PM
bjornir90 #1
Posted 23 April 2014 - 05:35 PM
I mean, does it redraw all the screen with something like
paintutils or is it a special thing done at another level? (java) I know the function is in Java, but I need to know how it actually work, or even better, where can I have a look into it. Thanks for reading :)/>
Lyqyd #2
Posted 23 April 2014 - 05:41 PM
I'd have to look into it further to be sure, but I suspect it sends a packet from the server to any clients viewing the computer that instructs them to clear the screen, or sends a packet containing the new (cleared) contents of the screen. The native method is executed Java-side, so it would be hard to tell exactly without packet analysis, looking at the source, or an answer from dan himself.

If you need to write a similar version for a redirect buffer or similar, write one full line of spaces for every row of the screen.
bjornir90 #3
Posted 23 April 2014 - 09:31 PM
Thanks you Lyqyd :)/> I want to know so I know if my buffer is useful even when using term. clear(), because repainting all the screen is very flickery ^^ so I guess it do it another way
Bomb Bloke #4
Posted 23 April 2014 - 11:27 PM
I'm of the impression that it manually fills the screen with blank lines. I say this because the end result is a screen covered in whatever the current text background colour is set to. It's my guess.

Generally, if you're getting a flickering effect with your screen clearing, then that either means you shouldn't be clearing the whole screen at once (maybe try clearing individual lines at a time?), or you're taking too long with the refresh process (make sure any lengthy calculations that are involved are performed before the wipe and redraw, not in-between).
theoriginalbit #5
Posted 24 April 2014 - 02:01 AM
I'm of the impression that it manually fills the screen with blank lines. I say this because the end result is a screen covered in whatever the current text background colour is set to. It's my guess.
You're indeed correct…

public void clear() {
  for (int y = 0; y < this.m_height; y++) {
	if (!this.m_lines[y].equals(this.m_emptyLine)) {
	  this.m_lines[y] = this.m_emptyLine;
	  this.m_changed = true;
	}

	if (!this.m_colourLines[y].equals(this.m_emptyColourLine)) {
	  this.m_colourLines[y] = this.m_emptyColourLine;
	  this.m_changed = true;
	}
  }
}
Edited on 24 April 2014 - 12:02 AM
bjornir90 #6
Posted 24 April 2014 - 09:18 AM
Ok, that is all I wanted to know, thanks you all!