home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 11 Learning / 01 Manslow / GPExample / GPExampleView.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-07  |  2.2 KB  |  104 lines

  1. //GPExample
  2. //Copyright John Manslow
  3. //29/09/2001
  4.  
  5. // GPExampleView.cpp : implementation of the CGPExampleView class
  6. //
  7.  
  8. #include "stdafx.h"
  9. #include "GPExample.h"
  10.  
  11. #include "GPExampleDoc.h"
  12. #include "GPExampleView.h"
  13.  
  14. #include "CWorld.h"
  15.  
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CGPExampleView
  24.  
  25. IMPLEMENT_DYNCREATE(CGPExampleView, CView)
  26.  
  27. BEGIN_MESSAGE_MAP(CGPExampleView, CView)
  28.     //{{AFX_MSG_MAP(CGPExampleView)
  29.     ON_WM_TIMER()
  30.     //}}AFX_MSG_MAP
  31. END_MESSAGE_MAP()
  32.  
  33. extern CWorld *pWorld;
  34. extern void Evaluate(void);
  35. CGPExampleView *pView;
  36.  
  37. /////////////////////////////////////////////////////////////////////////////
  38. // CGPExampleView construction/destruction
  39.  
  40. CGPExampleView::CGPExampleView()
  41. {
  42.     //This is used in the document to draw to the window
  43.     pView=this;
  44. }
  45.  
  46. CGPExampleView::~CGPExampleView()
  47. {
  48. }
  49.  
  50. BOOL CGPExampleView::PreCreateWindow(CREATESTRUCT& cs)
  51. {
  52.     // TODO: Modify the Window class or styles here by modifying
  53.     //  the CREATESTRUCT cs
  54.  
  55.     return CView::PreCreateWindow(cs);
  56. }
  57.  
  58. /////////////////////////////////////////////////////////////////////////////
  59. // CGPExampleView drawing
  60.  
  61. void CGPExampleView::OnDraw(CDC* pDC)
  62. {
  63.     CGPExampleDoc* pDoc = GetDocument();
  64.     ASSERT_VALID(pDoc);
  65.  
  66.     //Redraw the world
  67.     pWorld->Draw(pDC);
  68.  
  69.     //Set the timer that calls the main loop
  70.     SetTimer(0,0,NULL);
  71. }
  72.  
  73. /////////////////////////////////////////////////////////////////////////////
  74. // CGPExampleView diagnostics
  75.  
  76. #ifdef _DEBUG
  77. void CGPExampleView::AssertValid() const
  78. {
  79.     CView::AssertValid();
  80. }
  81.  
  82. void CGPExampleView::Dump(CDumpContext& dc) const
  83. {
  84.     CView::Dump(dc);
  85. }
  86.  
  87. CGPExampleDoc* CGPExampleView::GetDocument() // non-debug version is inline
  88. {
  89.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGPExampleDoc)));
  90.     return (CGPExampleDoc*)m_pDocument;
  91. }
  92. #endif //_DEBUG
  93.  
  94. /////////////////////////////////////////////////////////////////////////////
  95. // CGPExampleView message handlers
  96.  
  97. void CGPExampleView::OnTimer(UINT nIDEvent) 
  98. {
  99.     KillTimer(0);    
  100.     CView::OnTimer(nIDEvent);
  101.     Evaluate();
  102.     SetTimer(0,0,NULL);
  103. }
  104.