Sign in to follow this  
flashinpan

what is this doing: frontBuffer / backBuffer

Recommended Posts

public void DrawPicture()
{
Graphics g = Graphics.FromImage(_frontBuffer);
g.DrawImage(_backBuffer,0,0);

GamePiece gp;

if (_gw != null)
{
if ((_isDragging) && (_draggingBitmapSet))
{
g.DrawImage(_dragBuffer,0,0);
}
else
{
//Draw pieces
for (int col = MIN_COL; col < _boardCellWidth; col++)
{
for (int row = MIN_ROW; row < _boardCellWidth; row++)
{
if ((_isDragging) &&
(_movingPiecePosition.X == col) &&
(_movingPiecePosition.Y == row))
{

continue;
}
//**********************************
// Start drag highlighting
//**********************************

if ((_isDragging)&&(_MoveCostPositions != null))
{
for (int i = 0; i < _MoveCostPositions.Length; i++)
{
if ((_MoveCostPositions[i] != _gw.NoMove)&&
(_MoveCostPositions[i].X == col)&&
(_MoveCostPositions[i].Y == row))
{
if (_gw.CanMoveTo(_movingPiecePosition.X,_movingPiecePosition.Y,col,row))
{
ShadeCell(g,col,row);
break;
}
}
}
}

//**********************************
// End drag highlighting
//**********************************
gp = _gw.ReturnGamePieceAtCell(col,row);
if (gp != null)
{
DrawPieceAtCell(g,gp.ImageIndex,col,row);
}
}
}
}
if (_isDragging)
{
if (!_draggingBitmapSet)
{
Graphics gTmp = Graphics.FromImage(_dragBuffer);
gTmp.DrawImage(_frontBuffer,0,0);
gTmp.Dispose();
_draggingBitmapSet = true;
}
gp = _gw.ReturnGamePieceAtCell(_movingPiecePosition.X,_movingPiecePosition.Y);
if(gp != null)
{
g.DrawImage(_iList.Images[gp.ImageIndex],_lastMousePosition.X - _lastOffset.X,_lastMousePosition.Y - _lastOffset.Y);
}
}
}
g.Dispose();
_pBox.Image = _frontBuffer;
}

Share this post


Link to post
Share on other sites
Quote:
Original post by mrbastard
you realise that names with a preceding underscore (like _isDragging) are reserved for the compiler under the c++ standard, right?


I didn't. So I googled for it and found this:

Quote:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndeepc/html/deep04202000.asp
The rules differ slightly between the two languages. In C90 and C99, the implementation reserves

* any global-scope name beginning with _.
* any name beginning with _ followed by an upper-case letter.
* any name beginning with __.

In C++, the implementation reserves

* any global-scope name beginning with _.
* any name beginning with _ followed by an upper-case letter.
* any name containing __.

(The C++ rules are more restrictive, reserving any name that features double underscores anywhere, not just at the beginning.)


So the TS (and I :)) should be save.

Share this post


Link to post
Share on other sites
I don't think this forum has any syntax highliting for C#, I'm not sure. Simply use the tag as C++ source code (since they're almost similar):
{source lang="cpp"}...{/source}
NOTE: Replace the "{}"s with "[]"s.

   As for your question about double buffering, what it does is it attempts to prevent "tearing", or that flashing effect when you draw something incomplete on the specified surface. Imagine that you're taking requests for drawing from some people (I don't know how to put this in a real-world situation), you have to constantly show the audience one sheet of paper, and you only draw on one sheet of paper. Each time the people request a new drawing from you, you have to draw a new, well, drawing, and the bad thing is, the people actually see your picture in the process of it being drawn, which'll probably look... odd.
   So, to fix this problem, you would need more than one sheet of paper to draw on, so you get two sheets of paper. One sheet of paper is the "viewing paper", or the paper that the people are currently seeing (similar to the "frontBuffer"), and the other sheet of paper is the "drawing paper", the paper that you are currently drawing on ("backBuffer").
   Whenever someone requests a new drawing, you wait until you're done with your current drawing (if you choose to do so), take the "drawing paper" up there, and swap it with the "viewing paper". So now, the papers have traded places, so the previous "viewing paper" is now the "drawing paper" and vice versa. Now, you can draw on the "drawing paper" without the people seeing it, but they still have something to look at.

Meh, it was the best example I could think of.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this