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

CSTile.cpp

Go to the documentation of this file.
00001 #ifdef WIN32
00002 #pragma warning(disable : 4786 )
00003 #endif
00004 
00005 #include "CSTile.h"
00006 #include "CSXMLHelper.h"
00007 
00008 CSTileLoader CSTileLoader::INSTANCE;
00009 const char *CSTile::CLASS = "CSTile";
00010 
00011 CSTile::CSTile(const std::string &filename)
00012 {
00013     static char *functionName="CSTile";
00014     LOG_ENTER 
00015     CSTileData data;
00016     loadTileData(filename, data);
00017     initialize(data);
00018     LOG_EXIT
00019 }
00020 
00021 CSTile::CSTile(const CSTile &tile)
00022 {
00023     static char *functionName="CSTile";
00024     LOG_ENTER 
00025     initialize();
00026 
00027     // since all Animations are singletons, we can reuse the animation from our parent
00028     mAnimation = tile.mAnimation;
00029     mAnimationState = tile.mAnimationState;
00030     mId = strdup(tile.mId);
00031     mIdChar = tile.mIdChar;
00032     mIsSolid = tile.mIsSolid;
00033     mType = tile.mType;
00034     mSubtype = tile.mSubtype;
00035     LOG_EXIT
00036 }
00037 
00038 void CSTile::initialize(void)
00039 {
00040     static char *functionName="initialize";
00041     LOG_ENTER 
00042     mId = 0;
00043     mType = 0;
00044     mSubtype = 0;
00045     mAnimation = 0;
00046     mMapPosX = 0;
00047     mMapPosY = 0;
00048     mIsSolid = false;
00049     mChanged = false;
00050     LOG_EXIT
00051 }
00052 
00053 void CSTile::initialize(const CSTileData &data)
00054 {
00055     static char *functionName="initialize";
00056     LOG_ENTER 
00057     initialize();
00058     mAnimation = CSAnimationLoader::INSTANCE.load(data.animationName);
00059     mAnimation->resetState(mAnimationState);
00060     mId = strdup(data.id);
00061     mChanged = false;
00062     mIdChar = data.idChar;
00063     mType = data.type;
00064     mSubtype = data.subtype;
00065     LOG_EXIT
00066 }
00067 
00068 CSTile::~CSTile()
00069 {
00070     static char *functionName="~CSTile";
00071     LOG_ENTER 
00072     // since all Animations are singeltons!
00073     mAnimation = 0;
00074     if (mId != 0)
00075     {
00076         free(mId);
00077         mId = 0;
00078     }
00079     LOG_EXIT
00080 }
00081 
00082 void CSTile::setSecPerFrame(float secPerFrame)
00083 {
00084     static char *functionName="setSecPerFrame";
00085     LOG_ENTER 
00086     mAnimation->setSecPerFrame(secPerFrame);
00087     LOG_EXIT
00088 }
00089 
00090 void CSTile::setSolid(bool b)
00091 {
00092     static char *functionName="setSolid";
00093     LOG_ENTER 
00094     mIsSolid = b;
00095     mAnimation->setSolid(mIsSolid);
00096     LOG_EXIT
00097 }
00098 
00099 void CSTile::loadTileData(const std::string &filename, CSTileData &data)
00100 {
00101     static char *functionName="loadTileData";
00102     LOG_ENTER 
00103     CSXMLHelper xmlSupport(filename, "TILE");
00104     try
00105     {
00106         if (xmlSupport.getError())
00107         {
00108             LOG_EXIT
00109             throw "error";
00110         }
00111 
00112         data.id = strdup(xmlSupport.getString("ID").c_str());
00113         data.idChar = xmlSupport.getString("ID_CHAR").c_str()[0];
00114         data.animationName = strdup(xmlSupport.getString("ANIMATION").c_str());
00115         data.type = xmlSupport.getInt("TYPE");
00116         data.subtype = xmlSupport.getInt("SUBTYPE");
00117     }
00118     catch(...)
00119     {
00120         LOG_EXIT
00121         SDLMain::shutdown((std::string)"XML error \"" + filename + "\": " + xmlSupport.getErrorMessage().c_str(), 1);
00122     }
00123     LOG_EXIT
00124 }
00125 
00126 void CSTile::scale(int width, int tilesX, int height, int tilesY)
00127 {
00128     static char *functionName="scale";
00129     LOG_ENTER 
00130     mAnimation->scale(width, tilesX, height, tilesY);
00131     LOG_EXIT
00132 }

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