home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / gchsrc31 / include / doublebu.h next >
Encoding:
C/C++ Source or Header  |  1992-04-27  |  2.0 KB  |  66 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  This file is part of the Atari Machine Specific Library,
  4. //  and is Copyright 1992 by Warwick W. Allison.
  5. //
  6. //  You are free to copy and modify these sources, provided you acknoledge
  7. //  the origin by retaining this notice, and adhere to the conditions
  8. //  described in the file COPYING.
  9. //
  10. //////////////////////////////////////////////////////////////////////////////
  11.  
  12. #ifndef _DoubleBuffer_h
  13. #define _DoubleBuffer_h
  14. //
  15. //  Encapsulated Double Buffering support.
  16. //
  17. //  Various other modules in this library write to the current double
  18. //  buffer page.  Double buffering provides smoothe output, even at
  19. //  slow update rates.
  20. //
  21. //  To use, simply create two Screens you want to use as the two pages,
  22. //  and create Pages with them.  eg. Pages=new DoubleBuffer(This,That);
  23. //
  24. //  Once created, use Pages->Flip() to swap pages.  This call includes
  25. //  a wait for vertical retrace.
  26. //
  27. //  Too write on the double buffer (as Sprites do), write to the screen
  28. //  specified by Pages->Current(), or just access Pages->Location().
  29. //
  30. //  Use Flop() if, for some reason, you don't want the retrace to be
  31. //  waited for.
  32. //
  33. //  NowShowing() gives the page PHYSICALLY showing, whereas Location() is
  34. //  the page not showing.  For double buffering to work correctly, you
  35. //  should never write on the currently shown page.
  36. //
  37.  
  38. #include "screen.h"
  39.  
  40. class DoubleBuffer
  41. {
  42. public:
  43.     DoubleBuffer();
  44.     DoubleBuffer(Screen&,Screen&);
  45.  
  46.     void    Flip();    // Swap pages smoothly (synced to retrace)
  47.     void    Flop();    // Swap pages immediately (unsynced)
  48.     char     *Location();
  49.     char     *NowShowing();
  50.     Screen&    Current();
  51.  
  52.     short Pulse;
  53.  
  54. private:
  55.     Screen* Canvas[2];
  56. };
  57.  
  58. extern    DoubleBuffer *Pages;
  59.  
  60.  
  61. inline char *DoubleBuffer::Location() { return Canvas[Pulse]->Location(); }
  62. inline char *DoubleBuffer::NowShowing() { return Canvas[1-Pulse]->Location(); }
  63. inline Screen&    DoubleBuffer::Current() { return *Canvas[Pulse]; }
  64.  
  65. #endif
  66.