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

CSWorld Class Reference

#include <CSWorld.h>


Public Member Functions

 CSWorld (const CSWorld &world)
virtual ~CSWorld ()
virtual std::string getType ()
void display ()
void displayScaled (CSSprite *centerSprite)
void update ()
void setSecPerFrame (float secPerFrame)
void setDisplayArea (SDL_Rect area)
void setWorldPosition (int x, int y)
void addSprite (CSSprite *sprite)
void removeSprite (CSSprite *sprite)
void setWorldNo (unsigned int no)
void scaleBackgroundTiles (int w, int h)
void buildScaledWorld (double factor, const SDL_Rect &srcRect, SDL_Surface *destination, const SDL_Rect &destRect)
void setScaleFactor (double factor)
void setScaleDisplayArea (SDL_Rect area)
void resetScaledWorld ()
void setScaleDisplayLayer (bool b, int layer)
unsigned int getDisplayXLowerBound ()
unsigned int getDisplayXUpperBound ()
unsigned int getDisplayYLowerBound ()
unsigned int getDisplayYUpperBound ()
unsigned int getHeight ()
unsigned int getWidth ()
void setTile (unsigned int x, unsigned int y, unsigned int z, char idChar)
void setTile (unsigned int x, unsigned int y, unsigned int z, CSTile *tile)
CSTilegetTileAtPixel (unsigned int x, unsigned int y, unsigned int z)
CSTilegetTile (unsigned int x, unsigned int y, unsigned int z)
unsigned int getLayerCount ()
CSTileMapgetLayer (unsigned int layer)
int getWorldPositionX ()
int getWorldPositionY ()
bool isBorderTile (CSTile *tile, int z)
void setActive (bool active)

Static Public Attributes

const char * CLASS = "CSWorld"


Constructor & Destructor Documentation

CSWorld::CSWorld const CSWorld world  ) 
 

Definition at line 26 of file CSWorld.cpp.

References LOG_ENTER, LOG_EXIT, mId, and mLayers.

00027 {
00028     static char *functionName="CSWorld";
00029     LOG_ENTER 
00030     initialize();
00031     mId = strdup(world.mId);
00032     mLayers = world.mLayers;
00033     LOG_EXIT
00034 }

CSWorld::~CSWorld  )  [virtual]
 

Definition at line 126 of file CSWorld.cpp.

References LOG_ENTER, LOG_EXIT, and CSMusic::stop().

00127 {
00128     static char *functionName="~CSWorld";
00129     LOG_ENTER 
00130     if (mId != 0)
00131     {
00132         free(mId);
00133         mId = 0;
00134     }
00135     
00136     if (mWorld != 0)
00137     {
00138         for (int l=0; l< mLayers; l++)
00139         {
00140             delete mWorld[l];
00141         }
00142         delete[] mWorld;
00143         mWorld = 0;
00144     }
00145     if (mMusic != 0)
00146     {
00147         // delete mMusic; is a singleton!
00148         mMusic->stop();
00149         mMusic = 0;
00150     }
00151     LOG_EXIT
00152 }

Here is the call graph for this function:


Member Function Documentation

virtual std::string CSWorld::getType  )  [inline, virtual]
 

Definition at line 125 of file CSWorld.h.

References CLASS.

00125 {return (std::string) CLASS;}

void CSWorld::display  ) 
 

Definition at line 154 of file CSWorld.cpp.

References CSTileMap::display().

Referenced by CSGame::run().

00155 {
00156     static char *functionName="display";
00157     SDL_SetClipRect(SDLMain::getScreen(), &mMapArea);
00158 
00159     if (mWorld != 0)
00160     {
00161         for (int l=0; l< mLayers; l++)
00162         {
00163             mWorld[l]->display();
00164         }
00165     }
00166     SDL_SetClipRect(SDLMain::getScreen(), 0);
00167 }

Here is the call graph for this function:

void CSWorld::displayScaled CSSprite centerSprite  ) 
 

Definition at line 444 of file CSWorld.cpp.

References buildScaledWorld(), CSSprite::getMaxHeight(), CSSprite::getMaxWidth(), CSSprite::getXPos(), and CSSprite::getYPos().

Referenced by CSGame::run().

00445 {
00446     static char *functionName="displayScaled";
00447     if ((mScaledWorldDestination.w == 0) || (mScaledWorldDestination.h == 0) || (mFactor == 0))
00448     {
00449         return;
00450     }
00451     int x = ((double)centerSprite->getXPos() + centerSprite->getMaxWidth()/2) * mFactor;
00452     int y = ((double)centerSprite->getYPos() + centerSprite->getMaxHeight()/2) * mFactor;
00453     int xOffset;
00454     int yOffset;
00455     int thresholdX = mScaledWorldDestination.w/2;
00456     int thresholdY = mScaledWorldDestination.h/2;
00457 
00458     SDL_Rect srcRect;
00459     srcRect.w = mScaledWorldDestination.w;
00460     srcRect.h = mScaledWorldDestination.h;
00461 
00462     xOffset = x-thresholdX;
00463     yOffset = y-thresholdY;
00464     
00465     if (xOffset + mScaledWorldDestination.w > ((double)mWidth) * mFactor)
00466     {
00467         xOffset = ((double) (((double)mWidth) * mFactor)) - mScaledWorldDestination.w;
00468     }
00469     if (yOffset + mScaledWorldDestination.h >((double)mHeight) * mFactor)
00470     {
00471         yOffset = ((double) (((double)mHeight) * mFactor)) - mScaledWorldDestination.h;
00472     }
00473 
00474     if (xOffset < 0)
00475     {
00476         xOffset = 0;
00477     }
00478     if (yOffset < 0)
00479     {
00480         yOffset = 0;
00481     }
00482 
00483     srcRect.x = xOffset; 
00484     srcRect.y = yOffset;
00485     
00486     SDL_SetClipRect(SDLMain::getScreen(), &mScaledWorldDestination);
00487     SDL_Rect destRect = mScaledWorldDestination;
00488 
00489     buildScaledWorld(mFactor, srcRect, SDLMain::getScreen(),destRect);
00490     SDL_SetClipRect(SDLMain::getScreen(), 0);
00491 }

Here is the call graph for this function:

void CSWorld::update  ) 
 

Definition at line 196 of file CSWorld.cpp.

References CSTileMap::update().

Referenced by CSGame::run().

00197 {
00198     static char *functionName="update";
00199     if (mWorld != 0)
00200     {
00201         for (int l=0; l< mLayers; l++)
00202         {
00203             mWorld[l]->update();
00204         }
00205     }
00206 }

Here is the call graph for this function:

void CSWorld::setSecPerFrame float  secPerFrame  ) 
 

Definition at line 249 of file CSWorld.cpp.

References LOG_ENTER, LOG_EXIT, CSSprite::setSecPerFrame(), and CSTileMap::setSecPerFrame().

Referenced by CSGame::run().

00250 {
00251     static char *functionName="setSecPerFrame";
00252     LOG_ENTER 
00253     if (mWorld != 0)
00254     {
00255         for (int l=0; l< mLayers; l++)
00256         {
00257             mWorld[l]->setSecPerFrame(secPerFrame);
00258         }
00259     }
00260     CSSprites::iterator iter = mSprites.begin();
00261     while (iter != mSprites.end())
00262     {
00263         CSSprite *sprite = *iter;
00264         sprite->setSecPerFrame(secPerFrame);
00265         iter++;
00266     }
00267     LOG_EXIT
00268 }

Here is the call graph for this function:

void CSWorld::setDisplayArea SDL_Rect  area  ) 
 

Definition at line 208 of file CSWorld.cpp.

References LOG_ENTER, LOG_EXIT, CSTileMap::setDisplayOffset(), and CSTileMap::setDisplaySize().

Referenced by CSGame::setCurrentWorld().

00209 {
00210     static char *functionName="setDisplayArea";
00211     LOG_ENTER 
00212     mMapArea = area;
00213     mXOffset = area.x;
00214     mYOffset = area.y;
00215 
00216     if (mWorld != 0)
00217     {
00218         for (int l=0; l< mLayers; l++)
00219         {
00220             mWorld[l]->setDisplayOffset(mXOffset, mYOffset);
00221             mWorld[l]->setDisplaySize(mMapArea.w, mMapArea.h);
00222         }
00223     }
00224     LOG_EXIT
00225 }

Here is the call graph for this function:

void CSWorld::setWorldPosition int  x,
int  y
 

Definition at line 227 of file CSWorld.cpp.

References CSTileMap::setMapPosition(), and CSSprite::setWorldPosition().

00228 {
00229     static char *functionName="setWorldPosition";
00230     mXPos = x;
00231     mYPos = y;
00232     if (mWorld != 0)
00233     {
00234         for (int l=0; l< mLayers; l++)
00235         {
00236             mWorld[l]->setMapPosition(x,y);
00237         }
00238     }
00239 
00240     CSSprites::iterator iter = mSprites.begin();
00241     while (iter != mSprites.end())
00242     {
00243         CSSprite *sprite = *iter;
00244         sprite->setWorldPosition(x, y);
00245         iter++;
00246     }
00247 }

Here is the call graph for this function:

void CSWorld::addSprite CSSprite sprite  ) 
 

Definition at line 319 of file CSWorld.cpp.

References CSTileMap::addSprite(), CSSprite::getLayer(), LOG_ENTER, LOG_EXIT, removeSprite(), and SDLMain::shutdown().

Referenced by CSGame::addSprite().

00320 {
00321     static char *functionName="addSprite";
00322     LOG_ENTER 
00323     // savety meassure, not to add twice!
00324     removeSprite(sprite);
00325     mSprites.push_back(sprite);
00326 
00327     if (mWorld != 0)
00328     {
00329         if (sprite->getLayer() < 0)
00330         {
00331             // add to topmost layer!
00332             mWorld[mLayers-1]->addSprite(sprite);
00333             return;
00334             LOG_EXIT
00335         }
00336         if (sprite->getLayer() < mLayers)
00337         {
00338             mWorld[sprite->getLayer()]->addSprite(sprite);
00339         }
00340         else
00341         {
00342             LOG_EXIT
00343             SDLMain::shutdown((std::string)"Sprite-Layer-Error!", 1);
00344         }
00345     }
00346     LOG_EXIT
00347 }

Here is the call graph for this function:

void CSWorld::removeSprite CSSprite sprite  ) 
 

Definition at line 349 of file CSWorld.cpp.

References CSSprite::getLayer(), LOG_ENTER, LOG_EXIT, CSTileMap::removeSprite(), and SDLMain::shutdown().

Referenced by addSprite(), and CSGame::removeSprite().

00350 {
00351     static char *functionName="removeSprite";
00352     LOG_ENTER 
00353     CSSprites::iterator iter = mSprites.begin();
00354     while (iter != mSprites.end())
00355     {
00356         if ((*iter) == sprite)
00357         {
00358             mSprites.erase(iter);
00359             iter = mSprites.begin();    // restart!
00360         }
00361         else
00362         {
00363             iter++;
00364         }
00365     }
00366     if (mWorld != 0)
00367     {
00368         if (sprite->getLayer() < 0)
00369         {
00370             // add to topmost layer!
00371             mWorld[mLayers-1]->removeSprite(sprite);
00372             LOG_EXIT
00373             return;
00374         }
00375         if (sprite->getLayer() < mLayers)
00376         {
00377             mWorld[sprite->getLayer()]->removeSprite(sprite);
00378         }
00379         else
00380         {
00381             LOG_EXIT
00382             SDLMain::shutdown((std::string)"Sprite-Layer-Error!", 1);
00383         }
00384     }
00385     LOG_EXIT
00386 }

Here is the call graph for this function:

void CSWorld::setWorldNo unsigned int  no  ) 
 

Definition at line 169 of file CSWorld.cpp.

References LOG_ENTER, LOG_EXIT, and CSTileMap::setWorldNo().

Referenced by CSGame::initLevel().

00170 {
00171     static char *functionName="setWorldNo";
00172     LOG_ENTER 
00173     mWorldNo = no;
00174     if (mWorld != 0)
00175     {
00176         for (int l=0; l< mLayers; l++)
00177         {
00178             mWorld[l]->setWorldNo(no);
00179         }
00180     }
00181     LOG_EXIT
00182 }

Here is the call graph for this function:

void CSWorld::scaleBackgroundTiles int  w,
int  h
 

Definition at line 65 of file CSWorld.cpp.

References CSTileMap::isBackground(), LOG_ENTER, LOG_EXIT, and CSTileMap::scaleMapToFit().

Referenced by CSGame::initLevel().

00066 {
00067     static char *functionName="scaleBackgroundTiles";
00068     LOG_ENTER 
00069     if (mWorld != 0)
00070     {
00071         for (int l=0; l< mLayers; l++)
00072         {
00073             if (mWorld[l]->isBackground())
00074             {
00075                 mWorld[l]->scaleMapToFit(w, h);
00076             }
00077         }
00078     }
00079     LOG_EXIT
00080 }

Here is the call graph for this function:

void CSWorld::buildScaledWorld double  factor,
const SDL_Rect &  srcRect,
SDL_Surface *  destination,
const SDL_Rect &  destRect
 

Definition at line 388 of file CSWorld.cpp.

References CSTileMap::addScaledSprites(), CSTileMap::getScaledMap(), CSTileMap::isScaleDisplay(), and SDLMain::shutdown().

Referenced by displayScaled().

00389 {
00390     static char *functionName="buildScaledWorld";
00391     bool isNew = false;
00392     mFactor = factor;
00393     SDL_Rect destRect;
00394     SDL_Rect srcRect;
00395     bool first = true;
00396     if (mWorld != 0)
00397     {
00398         for (int l=0; l< mLayers; l++)
00399         {
00400             if (mWorld[l]->isScaleDisplay())
00401             {
00402                 destRect.x = displayRect.x;
00403                 destRect.y = displayRect.y;
00404                 destRect.w = displayRect.w;
00405                 destRect.h = displayRect.h;
00406                 srcRect.x = sourceRect.x;
00407                 srcRect.y = sourceRect.y;
00408                 srcRect.w = sourceRect.w;
00409                 srcRect.h = sourceRect.h;
00410                 SDL_Surface *src = mWorld[l]->getScaledMap(factor, first);
00411                 first = false;
00412                 
00413                 if (SDL_BlitSurface(src, &srcRect, destination, &destRect) < 0)
00414                 {
00415                     SDLMain::shutdown((std::string)"Display Format error (buildScaledWorld()): " + SDL_GetError(), 1);
00416                 }
00417             }
00418         }
00419     }
00420 
00421     if (mWorld != 0)
00422     {
00423         for (int l=0; l< mLayers; l++)
00424         {
00425             mWorld[l]->addScaledSprites(factor, sourceRect, destination, displayRect);
00426         }
00427     }
00428 }

Here is the call graph for this function:

void CSWorld::setScaleFactor double  factor  )  [inline]
 

Definition at line 139 of file CSWorld.h.

Referenced by CSGame::initLevel().

00139 {mFactor = factor;}

void CSWorld::setScaleDisplayArea SDL_Rect  area  ) 
 

Definition at line 493 of file CSWorld.cpp.

References LOG_ENTER, and LOG_EXIT.

Referenced by CSGame::initLevel().

00494 {
00495     static char *functionName="setScaleDisplayArea";
00496     LOG_ENTER 
00497     mScaledWorldDestination = area;
00498     LOG_EXIT
00499 }

void CSWorld::resetScaledWorld  ) 
 

Definition at line 430 of file CSWorld.cpp.

References LOG_ENTER, LOG_EXIT, and CSTileMap::resetScaledMap().

00431 {
00432     static char *functionName="resetScaledWorld";
00433     LOG_ENTER 
00434     if (mWorld != 0)
00435     {
00436         for (int l=0; l< mLayers; l++)
00437         {
00438             mWorld[l]->resetScaledMap();
00439         }
00440     }
00441     LOG_EXIT
00442 }

Here is the call graph for this function:

void CSWorld::setScaleDisplayLayer bool  b,
int  layer
[inline]
 

Definition at line 144 of file CSWorld.h.

References CSTileMap::isScaleDisplay(), and CSTileMap::setScaleDisplay().

Referenced by CSGame::setScaleDisplayLayer().

00145         {
00146             if (mWorld[layer]->isScaleDisplay() == b)
00147             {
00148                 return;
00149             }
00150             if (b)
00151             {
00152                 mScaleMapCount++;
00153             }
00154             else 
00155             {
00156                 mScaleMapCount--;
00157             }
00158             mWorld[layer]->setScaleDisplay(b);
00159         }

Here is the call graph for this function:

unsigned int CSWorld::getDisplayXLowerBound  )  [inline]
 

Definition at line 161 of file CSWorld.h.

Referenced by CSGame::checkWorld().

00161 {return mMapArea.x;}

unsigned int CSWorld::getDisplayXUpperBound  )  [inline]
 

Definition at line 162 of file CSWorld.h.

Referenced by CSGame::checkWorld().

00162 {return mMapArea.x + mMapArea.w;}

unsigned int CSWorld::getDisplayYLowerBound  )  [inline]
 

Definition at line 163 of file CSWorld.h.

Referenced by CSGame::checkWorld().

00163 {return mMapArea.y;}

unsigned int CSWorld::getDisplayYUpperBound  )  [inline]
 

Definition at line 164 of file CSWorld.h.

Referenced by CSGame::checkWorld().

00164 {return mMapArea.y + mMapArea.h;}

unsigned int CSWorld::getHeight  )  [inline]
 

Definition at line 165 of file CSWorld.h.

Referenced by CSGame::checkOutOfBounds(), and CSGame::checkWorld().

00165 {return mHeight;}

unsigned int CSWorld::getWidth  )  [inline]
 

Definition at line 166 of file CSWorld.h.

Referenced by CSGame::checkOutOfBounds(), and CSGame::checkWorld().

00166 {return mWidth;}

void CSWorld::setTile unsigned int  x,
unsigned int  y,
unsigned int  z,
char  idChar
 

Definition at line 184 of file CSWorld.cpp.

References CSTileMap::setTile().

00185 {
00186     static char *functionName="setTile";
00187     mWorld[z]->setTile(x, y, idChar);
00188 }

Here is the call graph for this function:

void CSWorld::setTile unsigned int  x,
unsigned int  y,
unsigned int  z,
CSTile tile
 

Definition at line 190 of file CSWorld.cpp.

References CSTileMap::setTile().

00191 {
00192     static char *functionName="setTile";
00193     mWorld[z]->setTile(x, y, tile);
00194 }

Here is the call graph for this function:

CSTile* CSWorld::getTileAtPixel unsigned int  x,
unsigned int  y,
unsigned int  z
[inline]
 

Definition at line 169 of file CSWorld.h.

References CSTileMap::getTileAtPixel().

00170         {
00171             return mWorld[z]->getTileAtPixel(x, y);
00172         }

Here is the call graph for this function:

CSTile* CSWorld::getTile unsigned int  x,
unsigned int  y,
unsigned int  z
[inline]
 

Definition at line 173 of file CSWorld.h.

References CSTileMap::getTile().

00174         {
00175             return mWorld[z]->getTile(x, y);
00176         }

Here is the call graph for this function:

unsigned int CSWorld::getLayerCount  )  [inline]
 

Definition at line 178 of file CSWorld.h.

00178 {return mLayers;}

CSTileMap* CSWorld::getLayer unsigned int  layer  )  [inline]
 

Definition at line 179 of file CSWorld.h.

Referenced by CSGame::checkCollisions().

00180         {
00181             if (layer > mLayers) return 0;
00182             return mWorld[layer];
00183         }

int CSWorld::getWorldPositionX  )  [inline]
 

Definition at line 184 of file CSWorld.h.

00184 {return mXPos;}

int CSWorld::getWorldPositionY  )  [inline]
 

Definition at line 185 of file CSWorld.h.

00185 {return mYPos;}

bool CSWorld::isBorderTile CSTile tile,
int  z
[inline]
 

Definition at line 186 of file CSWorld.h.

References CSTileMap::isBorderTile().

00186 {return mWorld[z]->isBorderTile(tile);}

Here is the call graph for this function:

void CSWorld::setActive bool  active  )  [inline]
 

Definition at line 187 of file CSWorld.h.

References CSTileMap::setActive().

00188         {
00189             mActive = active;
00190             if (mWorld != 0)
00191             {
00192                 for (int l=0; l< mLayers; l++)
00193                 {
00194                     mWorld[l]->setActive(mActive);
00195                 }
00196             }
00197         }

Here is the call graph for this function:


Field Documentation

const char * CSWorld::CLASS = "CSWorld" [static]
 

Definition at line 13 of file CSWorld.cpp.

Referenced by getType().


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