StPendl
Feb 24, 2011
- "removed excess formating"
=Flushing strategies= //Rod Bird// [[toc]] ---- ==Intro== Flush is a command that perplexes quite a few folks. I hope to clarify its use and help you choose the most appropriate drawing and flushing strategy for your project. The Help File is very clearly worded, as you read this document refresh your mind on each of the noted graphics commands. The main purpose of flush is to preserve the drawn graphics so that they may be redrawn instantly, should the program window be minimized or covered by another window. If the graphics have not been flushed you will be looking at a blank white window when it is restored or uncovered. For the more adventurous, flush allows multiple graphic scenes to be flicked on and off screen. ==The drawing history past and present== Liberty drawing commands do more than paint pixels on the screen, the drawing commands you issue are recorded in memory. The commands are recorded sequentially and grouped together in SEGMENTS. You form a segment by issuing a FLUSH command. Realize that this recording is always on. From the moment the program starts and immediately after a flush command, a new CURRENT SEGMENT is in play. Flushed segments are the past, only they will be restored if the screen is minimized or covered by another window. The current segment is the present, drawing will be lost unless flushed into the past or preserved in another way. ==Naming and numbering== Segments are identified by an ever increasing number. The first segment created will be numbered 1, the next 2 and so on. If we delete segments it makes no difference, the next segment will be numbered one higher than the last. Liberty allows us to establish the number of a segment and store that in an appropriate variable name by issuing a SEGMENT name, command. ==Managing segments== Segments can be deleted with DELSEGMENT (name), redrawn individually with REDRAW (name) or all undeleted segments redrawn with the command, REDRAW. REDRAW (name) will paint the named segment to the front of the screen, this appears to change the Z order of the drawing. REDRAW will appear to restore the Z order and paint undeleted segments in their original Z order. You can erase all segments by issuing a CLS command. This deletes all segments, and clears the current segment. You can clear the current segment and leave the segment history untouched by issuing a DISCARD command. ==Decouple the screen and drawing history== Only the redraw and cls command have any impact on what you see on the screen, other commands act only on the segments held in memory. Delsegment (name) will have no impact on the screen, discard will have no impact on the screen but the segment (name) will be deleted and the current segment will be wiped clean. Decouple the screen and the drawing history in your mind. ==Manage memory== It is important to mange segments as they consume memory. Even if you don’t use flush it is important to manage the current segment memory with discard. ==Start with a clean sheet== When you start, start with a clean sheet, use DISCARD. Think what is in your current segment, think what you have flushed already . You might use CLS if you wanted to start completely fresh. [[image:scr1.png]][[image:mu1.png]]Memory use is zero and there are no forgotten drawing commands. ==Static graphics== If you are painting graphics that will not be changed, say a Company logo then simply draw and flush once. [[image:scr2.png]][[image:mu1.png]]Memory use is managed to one segment. ==Refreshed graphics== If you are painting fresh graphics from time to time that completely replace the previous graphics then you must DELSEGMENT the previous segment prior to drawing and flushing the next. That way there is only ever one segment in memory. This is the task that gets most folks tied in knots. If you find that your program runs out of memory it is probably because you are not deleting the correct segment. [[image:scr8.png]][[image:mu1.png]]Memory use is managed to one segment. ==Animated graphics== If you are painting animated graphics by overdrawing and redrawing repetitively you must manage memory and repetitively DISCARD the current segment. The screen will behave as you expect but unless you DISCARD the current segment history memory use will build. [[image:scr3.png]][[image:mu1.png]]Memory use is minimal. ==Background and foreground graphics== If you are going to have a mostly static background and some constantly changing foreground graphics, say sliders or dials then draw the background, FLUSH that as the first segment. You will retain that segment. Now draw and FLUSH the foreground segment. Next time through DELSEGMENT the foreground segment REDRAW the background and then draw and FLUSH the new foreground. [[image:scr4.png]][[image:mu1.png]]Memory use will not exceed two segments. ==Multiple segment graphics== If you want to get fancy you can maintain several segments in memory and change the order they appear on screen. Now most often this strategy will use partial or transparent graphics. By that I mean they will fill only parts of the screen. If you use Fills they will cover graphics behind. The segments are maintained in memory in the Z order they were created. They can be pulled to the front of the screen with REDRAW (name). And appear to change the Z order on screen. If the segment has a full screen fill in it, all graphics will be hidden when that segment is redrawn. You might choose to do this and have a background segment, in this way you can hide and show any segments you wish. [[image:scr5.png]][[image:scr6.png]][[image:scr7.png]][[image:mu2.png]]Memory use builds depending on segments used.