Quick Buffer - A fast terminal buffering s...
Grim Reaper 14 Sep 2014
Writing a buffer that uses minimal color setting function calls in order to create a very quick rendering experience has been a sort of obsession of mine for quite some time now. I've written several versions which have each been a bit quicker than the last, but this version seems to have topped all of those prior.
Quick Buffer:
This buffer makes use of a method that I've had written on paper and imprinted in my mind for quite some time but was never able to translate it into code. This being the following stolen description from the file itself:
In essence, I think that this buffering method allows for some of the quickest rendering of common program visual output by making use of the aforementioned method. However, there is also a hangup to specializing for common output:
Basically, if you have a program whose visual output is very, very colorful and unique all over the place, then rendering will probably be slower than the other rendering methods.
Uses:
- Windowing
- Multiple programs running at the same time
- Taking screen shots of the screen
- Making animations from a frame or series of frames
- Accessing information that has been written to the screen
- Stuff that I haven't even thought of
Examples of Usage:
Buffer Pastebin
Animation Pastebin
As always, you're welcome to use this code and modify it as long as credit is given where credit is due.
Thanks for reading!
Edited by Grim Reaper, 14 September 2014 - 07:23 AM.
Quick Buffer:
This buffer makes use of a method that I've had written on paper and imprinted in my mind for quite some time but was never able to translate it into code. This being the following stolen description from the file itself:
Spoiler
In essence, I think that this buffering method allows for some of the quickest rendering of common program visual output by making use of the aforementioned method. However, there is also a hangup to specializing for common output:
Quote
However, it is important to note that this maximizes
efficiency for common use, for most programs make use
of large portions of similarly colored text both in
the text color and background color.
- HOWEVER, situations in which the text and background
color pair is changing very often, this buffer may
actually be SLOWER than the classic change-every-iteration
approach!
efficiency for common use, for most programs make use
of large portions of similarly colored text both in
the text color and background color.
- HOWEVER, situations in which the text and background
color pair is changing very often, this buffer may
actually be SLOWER than the classic change-every-iteration
approach!
Uses:
- Windowing
- Multiple programs running at the same time
- Taking screen shots of the screen
- Making animations from a frame or series of frames
- Accessing information that has been written to the screen
- Stuff that I haven't even thought of
Examples of Usage:
Spoiler
Buffer Pastebin
Animation Pastebin
As always, you're welcome to use this code and modify it as long as credit is given where credit is due.
Thanks for reading!
Edited by Grim Reaper, 14 September 2014 - 07:23 AM.
Lyqyd 14 Sep 2014
Ah, so it works on similar principles to the way my framebuffer API draws to the screen! It is an efficient method indeed. Good to see more people taking advantage of it. There are still speed gains to be had, though.
Grim Reaper 14 Sep 2014
Lyqyd, on 14 September 2014 - 05:49 PM, said:
Ah, so it works on similar principles to the way my framebuffer API draws to the screen! It is an efficient method indeed. Good to see more people taking advantage of it. There are still speed gains to be had, though.
Grim Reaper 14 Sep 2014
Tthecreator 05 Sep 2015
Hi there!,
For my own project i do need something like a buffer api to prevent flickering.
The problem is I dont understand how i'm supposed to implement QuickBuffer.
I also do not understand your example nor do i know how to start your example. Where does tBuffer come from? and is getShrunkBuffer a local function?
Could anyone explain please.
For my own project i do need something like a buffer api to prevent flickering.
The problem is I dont understand how i'm supposed to implement QuickBuffer.
I also do not understand your example nor do i know how to start your example. Where does tBuffer come from? and is getShrunkBuffer a local function?
Could anyone explain please.
Grim Reaper 08 Sep 2015
Before I answer your question, I'd like to point out that, given the updates to ComputerCraft, my QuickBuffer here on the forums is actually slower than what is currently possible.
Here's a link to an updated version: http://pastebin.com/BMQ9wQbx
To answer your question, you implement the QuickBuffer by doing the following:
1. Download the file to your CC computer.
2. Load the file using CC's os.loadAPI.
3. Create a new QuickBuffer object by doing this:
From there, you can redirect to it by doing
Sorry for the rushed reply!
Here's a link to an updated version: http://pastebin.com/BMQ9wQbx
To answer your question, you implement the QuickBuffer by doing the following:
1. Download the file to your CC computer.
2. Load the file using CC's os.loadAPI.
3. Create a new QuickBuffer object by doing this:
local buffer = QuickBuffer.new(51, 19 1, 1, term.current())This example is for a buffer that takes up the whole screen.
From there, you can redirect to it by doing
local currentTerm = term.redirect(buffer:redirect())Then, you can use the terminal API how you wish, redirecting back to the previous terminal object by doing
term.redirect(currentTerm)
Sorry for the rushed reply!
Dahknee 08 Sep 2015
I am looking into better buffer API's other than the Window API, for my 4.1 update on my AppStore, if possible, does it have a redraw function?
Grim Reaper 15 Sep 2015
Redraw? As in draw the contents of the buffer? Yes, it does.
The function is called 'render,' though.
It's used like this:
The function is called 'render,' though.
It's used like this:
local buffer = Buffer.new(25, 10, 1, 1, term.current()) term.redirect(buffer:redirect()) print("Hello!") term.redirect(buffer.tTerm) buffer:render()
Dahknee 16 Sep 2015
Grim Reaper, on 15 September 2015 - 07:08 PM, said:
Redraw? As in draw the contents of the buffer? Yes, it does.
The function is called 'render,' though.
It's used like this:
The function is called 'render,' though.
It's used like this:
local buffer = Buffer.new(25, 10, 1, 1, term.current()) term.redirect(buffer:redirect()) print("Hello!") term.redirect(buffer.tTerm) buffer:render()
I see awesome! Thank you! May look into this