David Wilkinson wrote:
Eric Lilja wrote:
Ah, well, every tile on the game board share the same view so I have
only one. The problem is that one of the data members of document
class needs the view when it's constructed.
Why?
Well, the document holds a matrix of tiles that make up the game board.
Each tile knows where it's located (it has a CRect that describes its
position on the view's client area, it also knows its position in the
matrix). When a tile changes state (a cell dies or comes alive), it
invalidates itself. This is when I need a pointer to the view to call
InvalidateRect(). Since UpdateAllViews() was suggested in this thread,
I'm now thinking about calling that instead of the invalidate function
of the tile, and using the parameters to tell the view that a tile was
invalidated and supply its rect. Then a tile won't have to know about
the view and the document doesn't have to get a pointer to the view in
OnNewDocument(). How does that sound? If I go down this road, I will be
calling UpdateAllViews() alot when the simulation is running.... If "The
Game of Life" doesn't mean anything to you, you can read about it on
wikipedia. :) Just a little project of mine for learning purposes.
UpdateAllViews() is the way to go. This calls the virtual OnUpdate()
specific about the view(s).