////////////////////////////////////////////////////////////////////////////// // // This file is part of the Atari Machine Specific Library, // and is Copyright 1992 by Warwick W. Allison. // // You are free to copy and modify these sources, provided you acknoledge // the origin by retaining this notice, and adhere to the conditions // described in the file COPYING. // ////////////////////////////////////////////////////////////////////////////// #ifndef _DoubleBuffer_h #define _DoubleBuffer_h // // Encapsulated Double Buffering support. // // Various other modules in this library write to the current double // buffer page. Double buffering provides smoothe output, even at // slow update rates. // // To use, simply create two Screens you want to use as the two pages, // and create Pages with them. eg. Pages=new DoubleBuffer(This,That); // // Once created, use Pages->Flip() to swap pages. This call includes // a wait for vertical retrace. // // Too write on the double buffer (as Sprites do), write to the screen // specified by Pages->Current(), or just access Pages->Location(). // // Use Flop() if, for some reason, you don't want the retrace to be // waited for. // // NowShowing() gives the page PHYSICALLY showing, whereas Location() is // the page not showing. For double buffering to work correctly, you // should never write on the currently shown page. // #include "screen.h" class DoubleBuffer { public: DoubleBuffer(); DoubleBuffer(Screen&,Screen&); void Flip(); // Swap pages smoothly (synced to retrace) void Flop(); // Swap pages immediately (unsynced) char *Location(); char *NowShowing(); Screen& Current(); short Pulse; private: Screen* Canvas[2]; }; extern DoubleBuffer *Pages; inline char *DoubleBuffer::Location() { return Canvas[Pulse]->Location(); } inline char *DoubleBuffer::NowShowing() { return Canvas[1-Pulse]->Location(); } inline Screen& DoubleBuffer::Current() { return *Canvas[Pulse]; } #endif