[comp.sys.amiga] Bobs and Double Buffering

obie@eleazar.Dartmouth.EDU (Timothy D. Notestein) (02/26/88)

[ is there really a line eater?  only in isolated galaxies.... ]
 
On page 149 of the RKM Libraries and Device Manual, we are informed
that it is indeed possible to have double-buffered blitter objects.
 
I have not, as of yet, seen any source code that is using this precise
feature.  Now, I have seen nifty display hacks that use double 
buffering as an aspect of the viewport.
 
However, this is not good for me, as intuition in general doesn't take
well to double buffering, and I really do need the intuition environment
existing peacefully as well.  Basically, I'm writing an application that
requires that the user be able to drag icons around on the screen.  Currently,
the icons are so large (1/8th of screen apiece) that the irritating flicker
is ever-present whenever dragging the icons.

Without attempting double-buffering on the part of the bobs, everything
is functioning properly, w/ exception of the flicker.  If I allocate
DBufPacket for my bob, preset BufY, BufX coordinates (this shoudn't (?)
make any difference; set BufPath to NULL; set BufBuffer to an allocated
array the same size as my previous SAVEBACK array.
 
  struct DBufPacket my_icon_dbuf[number_of_icons] = 
  {
    0,0,    /* BufY, BufX */
    0,      /* BufPath    */
    &drawingDB[0]   /* BufBuffer */
 },
 ....
 
When declaring my actual bob...icon/images
 
struct MyIcon {struct Bob, Gadget} my_icon[number_of_icons]
  { 
   {
    0,
    &faceSave[0],
    &faceMask[0],
    NULL,NULL,
    &faceVS,  /* virtual sprite */
    NULL,
    &my_icon_dbuf[0],
    0
   },
  ...

This is all that the RKM says is necessary for bob double-buffering.
 
Is there something that I'm missing?  Do i HAVE to have the Rastport set up
for double-buffering, or anything like that?  Do I have to add the bob twice?
(I notice that it's documented that if double-buffering, you may have to
 remove it twice, but it doesn't mention AddBob())
 
Is there some maintainence that has to be done by my program everytime I
move a bob or something?
 
Symptoms:  The display comes up okay, but when I drag an icon around,
it's leaving bits and pieces of itself behind.  As well, if part of one
icon passes under another  (sorry, when I say icon, I DO mean bob), then
I get a kind of double-flickering affect, kind of.. (NOW YOU SEE IT, NOW
YOU DON'T).  But, I also don't notice any movements being at ALL smoother.
 
Anyone have any ideas/suggestions?  Also, if anyone has public domain source 
code that accomplishes something along these same lines, I WOULD GREAT
appreciate it if you could forward it, so I can get a grasp on what I'm
doing wrong.

Thanks in advance,
Tim

cs178abu@sdcc8.ucsd.EDU (John Schultz) (02/27/88)

In article <8259@eleazar.Dartmouth.EDU> obie@eleazar.Dartmouth.EDU (Timothy D. Notestein) writes:
>
> 
>Is there something that I'm missing?  Do i HAVE to have the Rastport set up
>for double-buffering, or anything like that?  Do I have to add the bob twice?

>Tim

  Yes, you need to set up a double buffered display as outlined in
the RKM under Advanced Topics.  There are other ways to do double
buffering as well (set up two separate views and use LoadView to
flip between, that way you don't have to diddle with copper lists at
run time [as in the RKM example]).
  The Benchmark M2 package has an example of double buffered bobs,
but you are using C, so...  (Someone out there must have a C version
:-) ). 

  John
 

jan@oscvax.UUCP (Jan Sven Trabandt) (03/02/88)

In article <8259@eleazar.Dartmouth.EDU> obie@eleazar.Dartmouth.EDU (Timothy D. Notestein) writes:
>[...]
>This is all that the RKM says is necessary for bob double-buffering.
> 
>Is there something that I'm missing?  Do i HAVE to have the Rastport set up
>for double-buffering, or anything like that?  Do I have to add the bob twice?
>(I notice that it's documented that if double-buffering, you may have to
> remove it twice, but it doesn't mention AddBob())
> 
>Is there some maintainence that has to be done by my program everytime I
>move a bob or something?
> 

Yes, you HAVE to double-buffer the rastport if you are double-buffering
the bobs (*all* of them) and you want the double-buffering to work
properly.
I just spent some time playing around with this last week.
What you have to do, after setting up all the double-buffering:
- do AddBob *once* for your double-buffered bob
 repeat the following until motion complete:
- do your SortGList and DrawGList into the offscreen rastport (#2)
- swap displayed and offscreen rastports (#1 <==> #2)
- alter the coordinates of your moving bobs, etc.
- do a SortGList and DrawGlist on the now-offscreen rastport (#1)
- swap displayed and offscreen rastports (#2 <==> #1)
Now your bobs have moved smoothly (by one incremental amount)

When you do a DrawGList with double-buffered bobs, the background
of the rastport being drawn into is saved into the SaveBuffer,
the DBufPacket.BufBuffer, alternating between the two buffers with
each DrawGList.
Thus, if you double-buffer the rastport, a DrawGList into alternating
rastport bitmaps will keep the backgrounds in *each* rastport bitmap
saved and restored separately.

>Symptoms:  The display comes up okay, but when I drag an icon around,
>it's leaving bits and pieces of itself behind.  As well, if part of one
>icon passes under another  (sorry, when I say icon, I DO mean bob), then
>I get a kind of double-flickering affect, kind of.. (NOW YOU SEE IT, NOW
>YOU DON'T).  But, I also don't notice any movements being at ALL smoother.
> 
If you don't double-buffer the rastport but do double-buffer the bos,
you effectively:  save the background into SaveBuffer, draw the bob, 
save the "background" which contains part of the bob you just drew
(assuming you moved your bob by a small amount) into DBufPacket.BufBuffer,
draw the bob in the new location while restoring/saving SaveBuffer
(this save will again contain part of the bob you just drew), 
then restore the DBufPacket.BufBuffer
which has part of the bob you drew back in the beginning, etc.
This is why it leaves bits and pieces of itself behind.

Also, to completely remove the double-buffered bob from both rastport
bitmaps, you will have to do 2 DrawGList's (one on each rastport)
After that, the BOBNIX flag in the vsprite flags field should be set,
which tells you that it's ok to free or reuse the bob (only one call
to RemBob necessary, since you only did one AddBob).

Hope this clears things up a bit,
Jan Sven.
--------------------------------------------------------
-"Are you, besides Neysa, perchance a virgin?"
-"No."
-"Well, that's over-rated anyways."
	( paraphrased from 'Split Infinity', by Piers Anthony)

Mind like parachute  -  function only when open!

Jan  (Jan, from Amsterdam) no-hyphen Sven  Trabandt
...!{allegro,ihnp4,decvax,pyramid}!utzoo!oscvax!jan

merchie@eleazar.Dartmouth.EDU (Anthony Wiggins) (03/14/88)

Jan (or anyone else that is familiar with double-buffering)

I can not get your suggestion to work.  My problem mainly seems to
be that I have ONE rastport.
 
1.  I open a rastport with DBUFFER set as flag
2.  Do my AddBob once.
3.  Because of the fact that at the moment, I have only one rastport,
    I create another one (this is where the problem is occurring).
4.  I then try to do SortGList, DrawGList on this second Rastport, then
    swap them, etc.
 
I get gurus (code berzerk guru).  I have a feeling that I'm barking up the wrong
tree and it's most frustrating.
 
If you have done this, I plead (for reasons of sanity) to please give more
detailed information on this.  Can anyone PLEASE post a sample source code
that just double-buffers a tiny bob moving.  The code CAN'T be large, and I
would be most greatful, 'cause it appears that Usenet is the only resource
that I can fall back on.
 
Also, it is important that I attach this special RastPort to an Intuition
Screen structure, if possible.
 
Is this a dead end?  I mean, is it impossible to double-buffer bobs,
while using an Intuition-created Screen?  Does this mean that I can't have
windows, gadgets, and other intuition-related phenomena if I have double-
buffering?


All replies are welcome.  Others have informed me that they'd like to know the
answer to this dilemna as well, so public postings would probably be 
appreciated by the populace-at-large, but private replies are welcome.


[opinions?  what opinions?  I'm too confused to have opinions   - Anthony]