engine.h

00001 /*--License:
00002         Kyra Sprite Engine
00003         Copyright Lee Thomason (Grinning Lizard Software) 2001-2005
00004         www.grinninglizard.com/kyra
00005         www.sourceforge.net/projects/kyra
00006 
00007         Kyra is provided under the LGPL. 
00008         
00009         I kindly request you display a splash screen (provided in the HTML documentation)
00010         to promote Kyra and acknowledge the software and everyone who has contributed to it, 
00011         but it is not required by the license.
00012 
00013 --- LGPL License --
00014 
00015     This library is free software; you can redistribute it and/or
00016     modify it under the terms of the GNU Lesser General Public
00017     License as published by the Free Software Foundation; either
00018     version 2.1 of the License, or (at your option) any later version.
00019 
00020     This library is distributed in the hope that it will be useful,
00021     but WITHOUT ANY WARRANTY; without even the implied warranty of
00022     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00023     Lesser General Public License for more details.
00024 
00025     You should have received a copy of the GNU Lesser General Public
00026     License along with this library; if not, write to the Free Software
00027     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00028 
00029         The full text of the license can be found in lgpl.txt
00030 */
00031 
00032 
00033 #ifndef KYRA_ENGINE_INCLUDED
00034 #define KYRA_ENGINE_INCLUDED
00035 
00036 #include "SDL.h"
00037 #include "vault.h"
00038 #include "imagetree.h"
00039 #include "dirtyrectangle.h"
00040 #include "kyrabuild.h"
00041 
00042 const int KyraVersionMajor = 2;
00043 const int KyraVersionMinor = 1;
00044 const int KyraVersionBuild = 3;
00045 
00146 enum
00147 {
00148         KrQualityNone,          // Use the parent quality, if available.
00149         KrQualityFast,          // Nearest neighbor algorithm.
00150         KrQualityLinear,        // Bi-linear interpolation
00151         KrQualityAdaptive,      // Bi-linear or oversample
00152 };
00153 
00157 class KrEngine
00158 {
00159   public:
00165         KrEngine( SDL_Surface* screen );
00166         
00175         KrEngine( SDL_Surface* screen, const grinliz::Rectangle2I& bounds, const KrRGBA* extraFill );
00176 
00189         KrEngine( SDL_Surface* screen, int nWindows, const grinliz::Rectangle2I* bounds, const KrRGBA* extraFill );
00190         
00191         ~KrEngine();
00192 
00199         KrImageTree*            Tree()                  { return tree; }
00200 
00209         KrResourceVault*        Vault()                 { return vault; }
00210 
00212         int NumWindows()                                        {       GLASSERT( nWindows <= KR_MAX_WINDOWS );
00213                                                                                         return nWindows; }
00214 
00216         int GetWindowFromPoint( int x, int y );
00217         
00232         void Draw( bool updateRect = true, std::vector< grinliz::Rectangle2I >* rectangles = 0 );
00233         
00237         const grinliz::Rectangle2I& ScreenBounds( int window=0 )        { return screenBounds[window]; }
00238 
00241         const grinliz::Rectangle2I& FullScreenBounds()  { return windowBounds; }
00242 
00246         void InvalidateRectangle( const grinliz::Rectangle2I& rect, int window=0 )      
00247                 { dirtyRectangle[window].AddRectangle( rect ); }
00248 
00249 
00251         SDL_Surface*    Surface()       { return screen; }
00252 
00254         void InvalidateScreen() { Tree()->Root()->Invalidate( KR_ALL_WINDOWS ); }
00255 
00257         void QueryRenderDesc( std::string* desc );
00258 
00259         static void QueryRenderDesc( SDL_Surface* surface, std::string* desc );
00260 
00261         // ------------- Engine Options ----------- //
00267         void FillBackground( const KrRGBA* fillColor );
00268 
00270         void FillBackgroundWindow( int window, const KrRGBA* fillColor );
00271 
00273         void static Version( int* major, int* minor, int* patch )       
00274         { 
00275                 *major = KyraVersionMajor;
00276                 *minor = KyraVersionMinor;
00277                 *patch = KyraVersionBuild;
00278         }
00279 
00291         static void SetMaxOglTextureSize( int size )    { maxOglTextureSize = size; }
00292 
00294         static int MaxOglTextureSize()                                  { return maxOglTextureSize; }
00295 
00296         //----------------------------------
00297         // For use by the engine components:
00298         KrDirtyRectangle*       DirtyRectangle( int window )    { return &dirtyRectangle[window]; }
00299 
00300         // Call SDL_Rect for each rectangle.
00301         void UpdateScreen( std::vector< grinliz::Rectangle2I >* rects );
00302 
00303         // Debugging: try to see if this is corrupted
00304         void Validate() {   GLASSERT( nWindows >= 0 );
00305                                                 GLASSERT( nWindows <= KR_MAX_WINDOWS );
00306                                                 GLASSERT( windowBounds.IsValid() );
00307                                                 //GLOUTPUT( "Engine Validated (nWindows=%d)\n", nWindows );
00308                                 }
00309 
00310         //restarts or reinits the video rendering system
00311         void Restart( SDL_Surface* _screen,             // The SDL surface
00312                                 int _nWindows,                          // number of windows
00313                                 const grinliz::Rectangle2I* bounds,             // rect for each window
00314                                 const KrRGBA* extra );          // The color for non-window areas, if specified.
00315 
00316 
00317   private:
00318         void Init(      SDL_Surface* _screen,           // The SDL surface
00319                                 int _nWindows,                          // number of windows
00320                                 const grinliz::Rectangle2I* bounds,             // rect for each window
00321                                 const KrRGBA* extra);           // The color for non-window areas, if specified.
00322 
00323         void InitOpenGL();
00324 
00325         static int maxOglTextureSize;
00326 
00327         SDL_Surface* screen;
00328         int nWindows;
00329 
00330         std::vector< SDL_Rect > sdlRects;
00331         KrDirtyRectangle        dirtyRectangle[ KR_MAX_WINDOWS ];
00332         grinliz::Rectangle2I                            screenBounds[ KR_MAX_WINDOWS ];
00333         grinliz::Rectangle2I                            windowBounds;
00334 
00335         KrImageTree*            tree;
00336         KrResourceVault*        vault;
00337 
00338         KrPaintInfo                     paintInfo;
00339         bool                            fillBackground[ KR_MAX_WINDOWS ];
00340         KrRGBA                          backgroundColor[ KR_MAX_WINDOWS ];      // The background color of each window
00341         KrRGBA                          extraBackground;                                        // The background color outside of the windows
00342         bool                            needFullScreenUpdate;
00343 
00344         U32                                     splashStart;
00345         KrResourceVault         *splashVault;
00346         KrSprite                        *splash, *splashText;
00347 };
00348 
00349 #endif

Generated on Thu Jul 20 20:45:31 2006 for Kyra by  doxygen 1.4.7