Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

CSTileSet.h

Go to the documentation of this file.
00001 #ifndef CSTILESET_H
00002 #define CSTILESET_H
00003 
00004 #include <string>
00005 #include <vector>
00006 #include "CSTypes.h"
00007 #include "SDLMain.h"
00008 #include "CSTile.h"
00009 #include "CSLoadable.h"
00010 #include "CSLog.h"
00011 
00012 class CSTileSetLoader;
00013 class CSTileSet;
00014 typedef std::vector<CSTileSet *> CSTileSets;
00015 
00016 class CSTileSetData
00017 {
00018     public:
00019         char *id;                   // defining 
00020         StringVector *tileNames;
00021         bool onesize;
00022         int width;
00023         int height;
00024 
00025         CSTileSetData()
00026         {
00027             id = 0;
00028             onesize=false;
00029             width=0;
00030             height=0;
00031             tileNames = new StringVector();
00032         }
00033 
00034         ~CSTileSetData()
00035         {
00036             if (id != 0)
00037             {
00038                 free (id);
00039                 id = 0;
00040             }
00041 
00042             if (tileNames != 0)
00043             {
00044                 for (StringVector::iterator iter = tileNames->begin(); iter != tileNames->end(); iter++)
00045                 {
00046                     char *help = (char *) *iter;
00047                     free(help);
00048                 }
00049                 free(tileNames);
00050             }
00051         }
00052 };
00053 
00054 const int MAX_TILE = 256;
00055 class CSTileSet
00056 {
00057     friend CSTileSetLoader;
00058     private:
00059         CSTile *mTiles[MAX_TILE];
00060         int mTileCount;
00061         char *mId;                          // defining 
00062         bool mIsSolid;
00063         bool mIsOneSize;
00064         int mXSize;
00065         int mYSize;
00066         float mSecPerFrame;
00067         // constructor using "*.xml" file
00068         CSTileSet(const std::string &filename);
00069         static void loadTileSetData(const std::string &filename, CSTileSetData &data);
00070 
00071         void initialize(const CSTileSetData &data);
00072         void initialize();
00073     
00074     public:
00075         CSTileSet(const CSTileSet &tileSet);
00076         virtual ~CSTileSet();
00077         static const char *CLASS;
00078         virtual std::string getType() {return (std::string) CLASS;}
00079 
00080         CSTile *getTile(unsigned char c) 
00081         {
00082             if (mTiles[c] == 0)
00083             {
00084                 SDLMain::shutdown((std::string)"TileSet characters not found in TileSet!", 1);
00085             }
00086             return new CSTile(*mTiles[c]);
00087         }   // return a new Tile -> must be freed by outside!
00088         void setSolid(bool b);
00089         void setSecPerFrame(float secPerFrame);
00090         int getTileCount() {return mTileCount;}
00091         void scaleToFit(int width, int tilesX, int height, int tilesY);
00092         int getFreeTile();
00093         int getMaxTileSize() {return MAX_TILE;}
00094         void setTile(CSTile* tile, unsigned char c);
00095         bool isOneSize() {return mIsOneSize;}
00096         int getTileXSize() {return mXSize;}
00097         int getTileYSize() {return mYSize;}
00098     
00099 };      
00100 
00101 class CSTileSetLoader : public Loadable<CSTileSet>
00102 {
00103     protected:
00104         virtual CSTileSet *create(const std::string &filename)
00105         {
00106             return new CSTileSet(filename);
00107         }
00108 
00109     public:
00110         static CSTileSetLoader INSTANCE;
00111 };
00112 
00113 #endif // CSTILESET_H

Generated on Wed Jul 14 00:43:43 2004 for CSLib by doxygen 1.3.6