home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / advanced / fire / firewnd.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  3.0 KB  |  131 lines

  1. // firewnd.h : header file
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CFireWnd window
  15.  
  16. class CFireWnd : public CStatic
  17. {
  18. // Construction
  19. public:
  20.     CFireWnd();
  21.  
  22. // Attributes
  23. public:
  24.  
  25.     // Fire Attributes
  26.     int m_nDecay;
  27.     int m_nFlammability;
  28.     int m_nMaxHeat;
  29.     int m_nSpreadRate;
  30.     int m_nSize;
  31.     int m_nSmoothness;
  32.     int m_nDistribution;
  33.     int m_nChaos;
  34.  
  35. protected:
  36.  
  37.     int m_MaxBurn;
  38.     BYTE* m_Fire;
  39.     static unsigned long m_RandSeed;
  40.         // Seed used by faster Rand().
  41.  
  42.     // Device Context Attributes
  43.     CDC* m_pMemDC;
  44.     CWindowDC* m_pWinDC;
  45.  
  46.     // Palette Attributes
  47.     RGBQUAD m_rgbPalette[256];
  48.     CPalette m_Palette;
  49.     CPalette* m_pOldPalette;
  50.  
  51.     // Bitmap Attributes
  52.     CBitmap m_Bitmap;
  53.     CBitmap* m_pOldBitmap;
  54.     BYTE* m_pBits;
  55.  
  56. // Operations
  57. public:
  58.     enum { red = 1, green = 2, blue = 3 };
  59.     void InitFire(int nColor);
  60.     CPalette* GetPalette();
  61.     void RenderFlame();
  62.     void PaintFlame(CDC* pDC = NULL);
  63.     void SetMaxBurn(int nMax);
  64.     int GetMaxBurn();
  65.     CSize GetBitmapSize();
  66.  
  67. protected:
  68.     void CreatePalette(int nColor);
  69.     void CreateBitmap();
  70.     void BurnPoint(BYTE* pRow, BYTE* pNextRow);
  71.  
  72.     // This function replaces the crt lib rand() function.
  73.     // The CRT lib function is very slow.  Since rand() is
  74.     // one of the most frequently called functions it was
  75.     // necessary to optimize it.  This function may be
  76.     // inlined and is computationally simple.
  77.     unsigned long Rand();
  78.  
  79. // Overrides
  80.     // ClassWizard generated virtual function overrides
  81.     //{{AFX_VIRTUAL(CFireWnd)
  82.     //}}AFX_VIRTUAL
  83.  
  84. // Implementation
  85. public:
  86.     virtual ~CFireWnd();
  87.  
  88.     // Generated message map functions
  89. protected:
  90.     //{{AFX_MSG(CFireWnd)
  91.     afx_msg void OnPaint();
  92.     afx_msg void OnDestroy();
  93.     afx_msg void OnPaletteChanged(CWnd* pFocusWnd);
  94.     afx_msg BOOL OnQueryNewPalette();
  95.     //}}AFX_MSG
  96.  
  97.     DECLARE_MESSAGE_MAP()
  98. };
  99.  
  100. inline unsigned long CFireWnd::Rand()
  101. {
  102.     // Using the current seed, generate a new random value
  103.     // and seed and return it.  The random value is shifted
  104.     // to reduce some of the noise and produce a more
  105.     // realistic flame.
  106.     return (m_RandSeed = 1664525L * m_RandSeed + 1013904223L) >> 5;
  107. }
  108.  
  109. inline void CFireWnd::BurnPoint(BYTE* pRow, BYTE* pNextRow)
  110. {
  111.     BYTE* pTarget;
  112.  
  113.     int off = Rand() % (m_nDistribution + 1);
  114.  
  115.     int val = m_nDecay + 1;
  116.     val = Rand() % val;
  117.     val = *pNextRow - val;
  118.  
  119.     if (Rand() & 1)
  120.         pTarget = pRow + off;
  121.     else
  122.         pTarget = pRow - off;
  123.  
  124.     if (val > 16)
  125.         *pTarget = (BYTE)val;
  126.     else
  127.         *pTarget = 16;
  128. }
  129.  
  130. /////////////////////////////////////////////////////////////////////////////
  131.