Jump to content




Quick Buffer - A fast terminal buffering solution


9 replies to this topic

#1 Grim Reaper

  • Members
  • 503 posts
  • LocationSeattle, WA

Posted 14 September 2014 - 07:22 AM

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:
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!
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:
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.


#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 14 September 2014 - 05:49 PM

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. :)

#3 Grim Reaper

  • Members
  • 503 posts
  • LocationSeattle, WA

Posted 14 September 2014 - 06:09 PM

View PostLyqyd, 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. :)
It does indeed work similarly. In fact, I tested mine against yours in a couple of tests, but I doubt the tests were well designed enough and the results conclusive enough to decide on a victor ;)

#4 Symmetryc

  • Members
  • 434 posts

Posted 14 September 2014 - 07:59 PM

Really nice Grim! Definitely +1 ;).

#5 Grim Reaper

  • Members
  • 503 posts
  • LocationSeattle, WA

Posted 14 September 2014 - 08:00 PM

View PostSymmetryc, on 14 September 2014 - 07:59 PM, said:

Really nice Grim! Definitely +1 ;).

Ah thanks :)

#6 Tthecreator

  • New Members
  • 1 posts

Posted 05 September 2015 - 06:08 PM

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.

#7 Grim Reaper

  • Members
  • 503 posts
  • LocationSeattle, WA

Posted 08 September 2015 - 07:13 AM

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:
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!

#8 Dahknee

  • Members
  • 1,808 posts
  • Location/home/da

Posted 08 September 2015 - 09:26 AM

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?

#9 Grim Reaper

  • Members
  • 503 posts
  • LocationSeattle, WA

Posted 15 September 2015 - 07:08 PM

Redraw? As in draw the contents of the buffer? Yes, it does.

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()


#10 Dahknee

  • Members
  • 1,808 posts
  • Location/home/da

Posted 16 September 2015 - 10:14 AM

View PostGrim 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:
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 :P





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users