Main Page   Class Hierarchy   Compound List   File List   Compound Members  

kyraresource.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 #ifndef KR_RESOURCE_INCLUDED
00070 #define KR_RESOURCE_INCLUDED
00071 
00072 #include "../util/glstring.h"
00073 #include "../util/gltypes.h"
00074 #include "../util/glutil.h"
00075 #include "../util/glfixed.h"
00076 
00077 
00078 struct SDL_RWops;
00079 struct KrRect;
00080 class KrSpriteResource;
00081 class KrTileResource;
00082 class KrCanvasResource;
00083 class KrFontResource;
00084 class KrBoxResource;
00085 class KrTextDataResource;
00086 class KrBinaryDataResource;
00087 class KrEncoder;
00088 class KrImage;
00089 
00090 
00093 enum
00094 {
00095         KYRATAG_END    = 1,
00096         KYRATAG_SPRITE,
00097         KYRATAG_TILE,
00098         KYRATAG_CANVAS,         // never in a .dat file - created at run-time
00099         KYRATAG_FONT,
00100         KYRATAG_BOX,
00101         KYRATAG_TEXTDATA,
00102         KYRATAG_BINARYDATA
00103 };
00104 
00105 
00106 // A structure -- cached in the resource -- that describes a collision bit map.
00107 class KrCollisionMap
00108 {
00109   public:
00110         KrCollisionMap( GlFixed xScale, GlFixed yScale,         // the scale is information only
00111                                         int width, int height );                        // pixel size of the map to create
00112 
00113         ~KrCollisionMap()                                                       { delete [] map; }
00114 
00115         // Input: creating the map.
00116         U32* GetRow( int i )                    {       GLASSERT( i>=0 && i<cy );
00117                                                                                 return map + cx * i;
00118                                                                         }
00119 
00120         // Output: using the map
00121         // Check a collision of something to the right.
00122         bool Collide( int dx, int dy, const KrRect& intersection, KrCollisionMap* );
00123 
00124         // Informational
00125         GlFixed XScale()                { return xScale; }
00126         GlFixed YScale()                { return yScale; }
00127 
00128   private:
00129         int cx, cy;
00130         U32* map;
00131         GlFixed xScale, yScale;
00132 };
00133 
00134 
00139 class KrResource
00140 {
00141   public:
00142         KrResource()                            : resId( 0 ) {}
00143         virtual ~KrResource()           {}
00144 
00146         virtual U32                                     Type() = 0;
00148         virtual const std::string&      TypeName() = 0;
00149 
00151         const std::string&      ResourceName()          { return resName; }
00153         const U32                       ResourceId()            { return resId; }       
00154 
00155         virtual KrSpriteResource* ToSpriteResource()    { return 0; }   
00156         virtual KrTileResource*   ToTileResource()              { return 0; }   
00157         virtual KrCanvasResource* ToCanvasResource()    { return 0; }   
00158         virtual KrFontResource*   ToFontResource()              { return 0; }   
00159         virtual KrBoxResource*    ToBoxResource()               { return 0; }   
00160         virtual KrTextDataResource*       ToTextDataResource()          { return 0; }   
00161         virtual KrBinaryDataResource* ToBinaryDataResource()    { return 0; }   
00162 
00169         virtual void CacheScale( GlFixed xScale, GlFixed yScale )       {}
00170 
00172         virtual bool IsScaleCached( GlFixed xScale, GlFixed yScale )    { return false; }
00173 
00175         virtual void FreeScaleCache()   {}
00176         
00177         // Used by the encoder:
00178         virtual void Save( KrEncoder* ) { GLASSERT( 0 ); }
00179 
00180         // If this is a type that supports a collision map, this will create it (if
00181         // necessary) and return a pointer to the map. The KrImage and window are
00182         // passed in to determine which map to fetch.
00183         virtual KrCollisionMap* GetCollisionMap( KrImage* state, int window )           { return 0; }
00184 
00185   protected:
00186         void SetNameAndId( const std::string& _name, U32 _id )  { resName = _name; resId = _id; }
00187         KrCollisionMap* collisionMap;
00188 
00189   private:
00190         std::string resName;
00191         U32                     resId;
00192 
00193 };
00194 
00195 
00196 class KrResourceFactory
00197 {
00198   public:
00199         virtual ~KrResourceFactory();
00200 
00201         static KrResourceFactory*       Instance();
00202 
00203         virtual KrResource*     Create( U32 id, 
00204                                                                 U32 size, 
00205                                                                 SDL_RWops* file );
00206 
00207   private:
00208         KrResourceFactory();
00209         static KrResourceFactory* instance;
00210 };
00211 
00212 
00213 
00214 #endif

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