home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool_main.zip / ool / samples / sample13 / sample13.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-09  |  5.9 KB  |  183 lines

  1. /*
  2.  * Fire - a sample program for the XGame library
  3.  * Copyright (C) 1997 by Thomas Bonk (thomas@ghecko.saar.de).
  4.  * All rights reserved.
  5.  * Fire.cpp - main module (class definitions)
  6.  */
  7.  
  8. #include "sample13.h"
  9.  
  10. void FlameThread::PrepPal( void )
  11. {
  12.         ULONG    data[256];
  13.         int i;
  14.  
  15.  
  16.         pPal = new XPalette();
  17.  
  18.         // initialize palette for the fire
  19.         memset( data, 0, sizeof( data ) );      // everything black
  20.         for( i = 0; i <= 7; i++ )
  21.         {
  22.                 data[11 + i] = i * 9;           // col 10-17: ascending blue
  23.                 data[19 + i] = 63 - i * 9;      // col 18-25: descending blue
  24.         } // for
  25.         for( i = 8; i <= 31; i++ )
  26.                 data[11 + i] |= (((i - 8) * 255 / 23) << 16);   // col 8-31: ascending red
  27.         for( i = 32; i <= 55; i++ )             // col 32-55: ascending green, red constant
  28.         {
  29.                 data[11 + i] |= 255 << 16;
  30.                 data[11 + i] |= (((i - 32) * 255 / 23) << 8);
  31.         } // for
  32.         for( i = 56; i <= 79; i++ )             // col 56-79: ascending blue, red and green constant
  33.         {
  34.                 data[11 + i] |= ((255 << 16) | (255 << 8));
  35.                 data[11 + i] |= ((i - 56) * 255 / 23);
  36.         } // for
  37.         for( i = 80; i <= 245; i++ )
  38.                 data[11 + i] = (255 << 16) | (255 << 8) | 255;
  39.  
  40.         pPal->SetColors( data, 10, 236 );
  41.         pBlitter->SetPalette( pPal );
  42. } // FlameThread::PrepPal
  43.  
  44. void FlameThread::ScrollUp( void )
  45. {
  46.         int   x, y;
  47.         PBYTE pbuf = &pBuffer[31360];
  48.  
  49.         memmove( &pBuffer[31360], &pBuffer[31680], 32000 );
  50.         for( y = 98; y < 199; y++ )
  51.                 for( x = 0; x < 320; x++, pbuf++ )
  52.                 {
  53.                         if( 0 == x )
  54.                                 *pbuf = (*pbuf         + *(pbuf - 320) + *(pbuf - 319) +
  55.                                          *(pbuf + 1)   + *(pbuf + 321) + *(pbuf + 320)  ) / 6;
  56.                         else if( 319 == x )
  57.                                 *pbuf = (*pbuf         + *(pbuf - 320) + *(pbuf + 320) +
  58.                                          *(pbuf - 1)   + *(pbuf - 321) + *(pbuf - 319)  ) / 6;
  59.                         else
  60.                                 *pbuf = (*pbuf         + *(pbuf - 320) + *(pbuf - 319) +
  61.                                          *(pbuf + 1)   + *(pbuf + 321) + *(pbuf + 320) +
  62.                                          *(pbuf - 1)   + *(pbuf - 321) + *(pbuf - 319)  ) / 9;
  63.                         if( *pbuf > 10 )
  64.                                 (*pbuf)--;
  65.                         else
  66.                                 *pbuf = 10;
  67.                 } // for
  68. } // FlameThread::ScrollUp
  69.  
  70. void FlameThread::NewLine( void )
  71. {
  72.         int   x, y;
  73.         PBYTE pbuf = &pBuffer[63040];
  74.  
  75.         for( y = 197; y < 200; y++ )
  76.                 for( x = 0; x < 320; x++, pbuf++ )
  77.                 {
  78.                         BYTE c;
  79.  
  80.                         do
  81.                         {
  82.                                 c = rand();
  83.                         } while( (c < 75) || (c > 90) );
  84.                         *pbuf = c;
  85.                 } // for
  86.  
  87.         for( y = 0; y < rand() % 45; y++ )
  88.         {
  89.                 x = rand() % 320;
  90.                 pbuf = &pBuffer[x + 63040];
  91.  
  92.                 *pbuf           = 255;
  93.                 *(pbuf + 320)   = 255;
  94.                 *(pbuf + 640)   = 255;
  95.                 *(pbuf + 1)     = 255;
  96.                 *(pbuf + 321)   = 255;
  97.                 *(pbuf + 641)   = 255;
  98.                 *(pbuf - 1)     = 255;
  99.                 *(pbuf - 321)   = 255;
  100.                 *(pbuf - 641)   = 255;
  101.         } // for
  102. } // FlameThread::NewLine
  103.  
  104. void FlameThread::Init( void )
  105. {
  106.         PrepPal();
  107.         pBuffer = pBlitter->GetVirtualScreen()->GetBuffer();
  108.         srand( 42 );
  109.  
  110.         while( TRUE )
  111.         {
  112.                 ScrollUp();
  113.                 NewLine();
  114.                 pBlitter->Blit();
  115.                 DosSleep( 0 );
  116.         } // while
  117. } // FlameThread::Init
  118.  
  119. /***
  120. FlameApp::FlameApp( void ) : XApplication()
  121. {
  122.         // initialize virt. screen and blitter
  123.         pScreen  = new XVirtualScreen( 320, 200 );
  124.         pBlitter = new XBlitter();
  125.         pBlitter->AssociateVirtualScreen( pScreen );
  126.  
  127.         // initialize window
  128.         XResource        xres( 100, GetResourceLibrary() );
  129.         XRect            xrect( 100, 100, 320, 230 );
  130.         pWindow = new FlameWindow( &xres,
  131.                                    "Flame demo",
  132.                                    pBlitter,
  133.                                    BLT_NODIRTYRECT,
  134.                                    XFrameWindow::defaultStyle,
  135.                                    &xrect                      );
  136.  
  137.         pThread = new FlameThread( pBlitter );
  138.         pThread->Run();
  139. } // FlameApp::FlameApp
  140.  
  141.  
  142. FlameApp::~FlameApp() //virtual raus, svb
  143. {
  144.         pThread->Terminate();
  145.         delete pThread;
  146.         pBlitter->DisassociateVirtualScreen();
  147.         delete pBlitter;
  148.         delete pScreen;
  149.         delete pWindow;
  150. } // FlameApp::~FlameApp
  151. ***********/
  152.  
  153. void main( void )
  154. {
  155.    XVirtualScreen * pScreen  = new XVirtualScreen( 320, 200 );
  156.    XBlitter * pBlitter = new XBlitter();
  157.    pBlitter->AssociateVirtualScreen( pScreen );
  158.  
  159.    XRect xrect( 100, 100, 320, 230 );
  160.    // initialize window
  161.    FlameWindow * pWindow = new FlameWindow( 100,
  162.                                    "Flame demo",
  163.                                    pBlitter,     0,
  164.                                    XFrameWindow::defaultStyle,
  165.                                    xrect                      );
  166.  
  167.    FlameThread * pThread = new FlameThread( pBlitter );
  168.    pThread->Run();
  169.  
  170.    XApplication::GetApplication()->Start();
  171. /****
  172.    pThread->Terminate();
  173.  
  174.    delete pThread;
  175.    pBlitter->DisassociateVirtualScreen();
  176.    delete pBlitter;
  177.    delete pScreen;
  178. ****/
  179. //   delete pWindow; wird automatisch gelöscht
  180.  
  181. }
  182.  
  183.