Main Page   Class Hierarchy   Compound List   File List   Compound Members  

engine.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 KYRA_ENGINE_INCLUDED
00071 #define KYRA_ENGINE_INCLUDED
00072 
00073 #include "SDL.h"
00074 #include "vault.h"
00075 #include "imagetree.h"
00076 #include "dirtyrectangle.h"
00077 #include "kyrabuild.h"
00078 
00079 const int KyraVersionMajor = 2;
00080 const int KyraVersionMinor = 0;
00081 const int KyraVersionBuild = 4;
00082 
00203 enum
00204 {
00205         KrQualityNone,          // Use the parent quality, if available.
00206         KrQualityFast,          // Nearest neighbor algorithm.
00207         KrQualityLinear,        // Bi-linear interpolation
00208         KrQualityAdaptive,      // Bi-linear or oversample
00209 };
00210 
00214 class KrEngine
00215 {
00216   public:
00222         KrEngine( SDL_Surface* screen );
00223         
00232         KrEngine( SDL_Surface* screen, const KrRect& bounds, const KrRGBA* extraFill );
00233 
00246         KrEngine( SDL_Surface* screen, int nWindows, const KrRect* bounds, const KrRGBA* extraFill );
00247         
00248         ~KrEngine()                                                     {       delete tree;            // Note that the tree must be deleted before the vault.
00249                                                                                         delete vault; }
00250 
00257         KrImageTree*            Tree()                  { return tree; }
00258 
00267         KrResourceVault*        Vault()                 { return vault; }
00268 
00270         int NumWindows()                                        {       GLASSERT( nWindows <= KR_MAX_WINDOWS );
00271                                                                                         return nWindows; }
00272 
00274         int GetWindowFromPoint( int x, int y );
00275         
00290         void Draw( bool updateRect = true, GlDynArray< KrRect >* rectangles = 0 );
00291         
00295         const KrRect& ScreenBounds( int window=0 )      { return screenBounds[window]; }
00296 
00299         const KrRect& FullScreenBounds()        { return windowBounds; }
00300 
00304         void InvalidateRectangle( const KrRect& rect, int window=0 )    { dirtyRectangle[window].AddRectangle( rect ); }
00305 
00306 
00308         SDL_Surface*    Surface()       { return screen; }
00309 
00311         void InvalidateScreen() { Tree()->Root()->Invalidate( KR_ALL_WINDOWS ); }
00312 
00314         void QueryRenderDesc( std::string* desc );
00315 
00316         static void QueryRenderDesc( SDL_Surface* surface, std::string* desc );
00317 
00318         // ------------- The splash screen. ---------- //
00326         void StartSplash( U32 msec );
00327 
00331         bool UpdateSplash( U32 msec );
00332 
00335         void EndSplash();
00336 
00337 
00338         // ------------- Engine Options ----------- //
00344         void FillBackground( const KrRGBA* fillColor );
00345 
00347         void FillBackgroundWindow( int window, const KrRGBA* fillColor );
00348 
00350         void static Version( int* major, int* minor, int* patch )       
00351         { 
00352                 *major = KyraVersionMajor;
00353                 *minor = KyraVersionMinor;
00354                 *patch = KyraVersionBuild;
00355         }
00356 
00368         static void SetMaxOglTextureSize( int size )    { maxOglTextureSize = size; }
00369 
00371         static int MaxOglTextureSize()                                  { return maxOglTextureSize; }
00372 
00373         //----------------------------------
00374         // For use by the engine components:
00375         KrDirtyRectangle*       DirtyRectangle( int window )    { return &dirtyRectangle[window]; }
00376 
00377         // Call SDL_Rect for each rectangle.
00378         void UpdateScreen( GlDynArray< KrRect >* rects );
00379 
00380         // Debugging: try to see if this is corrupted
00381         void Validate() {   GLASSERT( nWindows >= 0 );
00382                                                 GLASSERT( nWindows <= KR_MAX_WINDOWS );
00383                                                 GLASSERT( windowBounds.IsValid() );
00384                                                 //GLOUTPUT( "Engine Validated (nWindows=%d)\n", nWindows );
00385                                 }
00386 
00387   private:
00388         void Init(      SDL_Surface* _screen,           // The SDL surface
00389                                 int _nWindows,                          // number of windows
00390                                 const KrRect* bounds,           // rect for each window
00391                                 const KrRGBA* extra );          // The color for non-window areas, if specified.
00392 
00393         void InitOpenGL();
00394 
00395         static int maxOglTextureSize;
00396 
00397         SDL_Surface* screen;
00398         int nWindows;
00399 
00400         KrDirtyRectangle        dirtyRectangle[ KR_MAX_WINDOWS ];
00401         KrRect                          screenBounds[ KR_MAX_WINDOWS ];
00402         KrRect                          windowBounds;
00403 
00404         KrImageTree*            tree;
00405         KrResourceVault*        vault;
00406 
00407         KrPaintInfo                     paintInfo;
00408         bool                            fillBackground[ KR_MAX_WINDOWS ];
00409         KrRGBA                          backgroundColor[ KR_MAX_WINDOWS ];      // The background color of each window
00410         KrRGBA                          extraBackground;                                        // The background color outside of the windows
00411         bool                            needFullScreenUpdate;
00412 
00413         U32                                     splashStart;
00414         KrResourceVault         *splashVault;
00415         KrSprite                        *splash, *splashText;
00416 };
00417 
00418 #endif

Generated on Fri Feb 7 20:44:20 2003 for Kyra by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001