Main Page   Class Hierarchy   Compound List   File List   Compound Members  

dirtyrectangle.h

00001 /*--License:
00002         Kyra Sprite Engine
00003         Copyright Lee Thomason (Grinning Lizard Software) 2001-2002
00004         www.grinninglizard.com/kyra
00005         www.sourceforge.net/projects/kyra
00006 
00007         Kyra is provided under 2 licenses:
00008 
00009         - The GPL, with no additional restrictions.
00010         - The LGPL, provided you display the Kyra splash screen, described below.
00011 
00012 
00013 --- GPL License --
00014         This program is free software; you can redistribute it and/or
00015         modify it under the terms of the GNU General Public License
00016         as published by the Free Software Foundation; either version 2
00017         of the License, or (at your option) any later version.
00018 
00019         This program is distributed in the hope that it will be useful,
00020         but WITHOUT ANY WARRANTY; without even the implied warranty of
00021         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022         GNU General Public License for more details.
00023 
00024         You should have received a copy of the GNU General Public License
00025         along with this program; if not, write to the Free Software
00026         Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00027 
00028         The full text of the license can be found in license.txt
00029 
00030 
00031 --- LGPL License --
00032   **Provided you kindly display the Kyra splash screen (details below), 
00033         you     may use the LGPL license:**
00034 
00035     This library is free software; you can redistribute it and/or
00036     modify it under the terms of the GNU Lesser General Public
00037     License as published by the Free Software Foundation; either
00038     version 2.1 of the License, or (at your option) any later version.
00039 
00040     This library is distributed in the hope that it will be useful,
00041     but WITHOUT ANY WARRANTY; without even the implied warranty of
00042     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00043     Lesser General Public License for more details.
00044 
00045     You should have received a copy of the GNU Lesser General Public
00046     License along with this library; if not, write to the Free Software
00047     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00048 
00049         The full text of the license can be found in lgpl.txt
00050 
00051 
00052 --- Kyra Splash Screen.
00053 
00054         It would be appreciate if you display the Kyra splash screen when using
00055         either license, however it is only required for the LGPL. All the
00056         resources for the splash are compiled into the library, and it can be
00057         accessed through the following API:
00058 
00059                 KrEngine::StartSplash
00060                 KrEngine::UpdateSplash
00061                 KrEngine::EndSplash
00062 
00063         Full documentation is provided with the KrEngine class. The splash screen
00064         should be displayed for 2 seconds.
00065 
00066         Thank you.
00067 */
00068 
00069 
00070 #ifndef DIRTY_RECTANGLE_INCLUDED
00071 #define DIRTY_RECTANGLE_INCLUDED
00072 
00073 
00074 #include "../engine/krmath.h"
00075 #include "../util/gllist.h"
00076 
00077 
00078 #ifdef DEBUG
00079         #include "SDL.h"
00080         #include "../util/gldynarray.h"
00081 #endif
00082 
00083 
00084 class KrDirtyRectangle;
00085 struct SDL_Surface;
00086 
00087 
00088 struct KrMappedRectInfo
00089 {
00090         int xmin;
00091         int ymin;
00092         int hPixelsPerBit;
00093         int vPixelsPerRow;
00094 
00095         void Set( const KrRect& bounds );
00096 };
00097 
00098 
00099 /*      Specialized rectangles.
00100         This adds a 4x8 pixel map (32 bits) that can be used to "quick compare" 
00101         the rectangles.
00102 
00103         Per byte, the min bit is at x=0, the max bit the right x.
00104         Each byte is a row, starting with y=0.
00105 */
00106 class KrMappedRect : public KrRect
00107 {
00108   public:
00109         KrMappedRect() { xmin = -1; ymin = -1; xmax = -2; ymax = -2; }
00110         KrMappedRect( const KrRect& from, const KrMappedRectInfo& info ) 
00111                 { xmin = from.xmin; ymin = from.ymin; xmax = from.xmax; ymax = from.ymax; CalcMap( info ); }
00112         KrMappedRect( const KrMappedRect& from ) 
00113                 { xmin = from.xmin; ymin = from.ymin; xmax = from.xmax; ymax = from.ymax; map = from.map; }
00114 
00115         void Set( const KrRect& from, const KrMappedRectInfo& info )
00116         {
00117                 xmin = from.xmin;
00118                 ymin = from.ymin;
00119                 xmax = from.xmax;
00120                 ymax = from.ymax;
00121                 CalcMap( info ); 
00122         }
00123 
00124         void operator=( const KrMappedRect& from )
00125         {
00126                 xmin = from.xmin;
00127                 ymin = from.ymin;
00128                 xmax = from.xmax;
00129                 ymax = from.ymax;
00130                 map  = from.map; 
00131         }
00132 
00133         void CalcMap( const KrMappedRectInfo& );
00134 
00135         bool Intersect( const KrMappedRect& rect ) const
00136         {
00137                 GLASSERT( rect.map );
00138 
00139                 if (    ( ( rect.map & map ) == 0 )
00140                              || rect.xmax < xmin
00141                                  || rect.xmin > xmax
00142                                  || rect.ymax < ymin
00143                                  || rect.ymin > ymax )
00144                 {
00145                         return false;
00146                 }
00147                 return true;
00148         }       
00149 
00150         U32 Map() const         { return map; }
00151   private:
00152         U32 map;
00153 };
00154 
00169 class KrDirtyRectangle
00170 {
00171   public:
00172         KrDirtyRectangle();
00173         ~KrDirtyRectangle();
00174 
00176         void SetClipping( const KrRect& rect )          { clippingRect = rect; clipping = true; mappedInfo.Set( clippingRect ); }
00178         bool IsClipping()                                                       { return clipping; }
00179 
00181         void AddRectangle( const KrRect& rect );
00183         void Clear()                                                            {       //GLOUTPUT( "Rects cleared.\n" );
00184                                                                                                         nRect = 0; }
00185         int                       NumRect()                                             { return nRect;         }
00186         const KrMappedRect& Rect( int i )                       {       GLASSERT( i>=0 && i<nRect );
00187                                                                                                         return rectArray[i];    }
00188 
00189         // The DR maintains both a blit list and a dirty rectangle list.
00190         // The blit rects are >= the dirty rectangle list.
00191         // This blits the blit rects to the screen.
00192         //void UpdateScreen( SDL_Surface* screen );
00193 
00194         #ifdef DEBUG
00195                 void DrawAllRects( SDL_Surface* surface );
00196 //              void DrawBlitRects( SDL_Surface* surface );
00197                 void DrawRects( SDL_Surface* surface );
00198                 void DrawWindow( int y0, int y1 );
00199 
00200                 void PrintRects( const char* message );
00201         #endif
00202 
00203         enum
00204         {
00205                 // Should be greater than 32. 35+ for some
00206                 // working room. The test I have seem to settle
00207                 // at the best performance at this point, but
00208                 // other apps might be happier with a different
00209                 // number.
00210                 MAX_DIRTY_RECTANGLES = 128,
00211         };
00212 
00213   private:
00214         void Remove( int index );
00215         void HandleOutOfRect( const KrMappedRect& rect );
00216         
00217         KrMappedRect rectArray[ MAX_DIRTY_RECTANGLES ];
00218         
00219         KrRect  clippingRect;
00220         bool    clipping;
00221 
00222         int nRect;
00223         KrMappedRectInfo mappedInfo;
00224 };
00225 
00226 
00227 
00228 #endif

Generated on Mon Sep 15 12:01:10 2003 for Kyra by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001