Map Class Reference

#include <map.h>

Collaboration diagram for Map:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Map ()
 ~Map ()
void Reset ()
void Refresh ()
void FreeMem ()
void Draw ()
void DrawWater ()
void DrawSky ()
void DrawAuthorName ()
void ToRedrawOnMap (Rectanglei r)
void ToRedrawOnScreen (Rectanglei r)
bool EstDansVide (int x, int y)
bool LigneH_EstDansVide (int left, int y, int right)
bool LigneV_EstDansVide (int x, int top, int bottom)
bool RectEstDansVide (const Rectanglei &rect)
bool ParanoiacRectIsInVacuum (const Rectanglei &rect)
bool EstDansVide_haut (const PhysicalObj &obj, int dx, int dy)
bool EstDansVide_bas (const PhysicalObj &obj, int dx, int dy)
bool IsInVacuum_left (const PhysicalObj &obj, int dx, int dy)
bool IsInVacuum_right (const PhysicalObj &obj, int dx, int dy)
bool EstHorsMondeX (int x) const
bool EstHorsMondeY (int x) const
bool EstHorsMondeXlarg (int x, uint larg) const
bool EstHorsMondeYhaut (int x, uint haut) const
bool EstHorsMondeXY (int x, int y) const
bool EstHorsMonde (const Point2i &pos) const
bool EstOuvert () const
void Dig (const Point2i position, const Surface &alpha_sur)
void Dig (const Point2i center, const uint radius)
void PutSprite (const Point2i pos, Sprite *spr)
void MergeSprite (const Point2i pos, Sprite *spr)
int GetWidth () const
int GetHeight () const
Point2i GetSize () const

Public Attributes

Ground ground
Sky sky
double dst_min_entre_vers
Water water
std::list< Rectanglei > * to_redraw
std::list< Rectanglei > * to_redraw_now
std::list< Rectanglei > * to_redraw_particles
std::list< Rectanglei > * to_redraw_particles_now

Private Member Functions

void SwitchDrawingCache ()
void SwitchDrawingCacheParticles ()
void OptimizeCache (std::list< Rectanglei > &rectangleCache)

Private Attributes

Textauthor_info1
Textauthor_info2

Detailed Description

Definition at line 36 of file map.h.


Constructor & Destructor Documentation

Map::Map (  ) 

Definition at line 44 of file map.cpp.

00045 {
00046   dst_min_entre_vers = DST_MIN_ENTRE_VERS;
00047 
00048   to_redraw = new std::list<Rectanglei>;
00049   to_redraw_now = new std::list<Rectanglei>;
00050   to_redraw_particles = new std::list<Rectanglei>;
00051   to_redraw_particles_now = new std::list<Rectanglei>;
00052 }

Map::~Map (  ) 

Definition at line 54 of file map.cpp.

00055 {
00056   delete to_redraw;
00057   delete to_redraw_now;
00058   delete to_redraw_particles;
00059   delete to_redraw_particles_now;
00060 }


Member Function Documentation

void Map::Dig ( const Point2i  center,
const uint  radius 
)

Definition at line 134 of file map.cpp.

00135 {
00136    ground.Dig (center, radius);
00137    to_redraw->push_back(Rectanglei(center - Point2i(radius+EXPLOSION_BORDER_SIZE,radius+EXPLOSION_BORDER_SIZE)
00138                                       , Point2i(2*(radius+EXPLOSION_BORDER_SIZE),2*(radius+EXPLOSION_BORDER_SIZE))));
00139 }

Here is the call graph for this function:

void Map::Dig ( const Point2i  position,
const Surface alpha_sur 
)

Definition at line 128 of file map.cpp.

00129 {
00130    ground.Dig (position, surface);
00131    to_redraw->push_back(Rectanglei(position, surface.GetSize()));
00132 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Map::Draw (  ) 

Definition at line 167 of file map.cpp.

00168 {
00169   std::list<Rectanglei> *tmp = to_redraw;
00170   to_redraw_particles->clear();
00171   to_redraw = to_redraw_particles;
00172 
00173   wind.DrawParticles();
00174   to_redraw = tmp;
00175 
00176   OptimizeCache(*to_redraw_now);
00177 
00178   ground.Draw();
00179 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Map::DrawAuthorName (  ) 

Definition at line 315 of file map.cpp.

00316 {
00317   if (AUTHOR_INFO_TIME < Time::GetInstance()->Read()) {
00318     if (author_info1 != NULL) {
00319       delete author_info1;
00320       delete author_info2;
00321       author_info1 = author_info2 = NULL;
00322     }
00323     return;
00324   }
00325 
00326   if (author_info1 == NULL) {
00327     std::string txt;
00328     txt  = Format(_("Map %s, a creation of: "),
00329                   ActiveMap().ReadName().c_str());
00330     author_info1 = new Text(txt, white_color, Font::GetInstance(Font::FONT_SMALL));
00331     txt = ActiveMap().ReadAuthorInfo();
00332     author_info2 = new Text(txt, white_color, Font::GetInstance(Font::FONT_SMALL));
00333   }
00334 
00335   author_info1->DrawTopLeft(AUTHOR_INFO_X,AUTHOR_INFO_Y);
00336   author_info2->DrawTopLeft(AUTHOR_INFO_X,AUTHOR_INFO_Y+(*Font::GetInstance(Font::FONT_SMALL)).GetHeight());
00337 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Map::DrawSky (  ) 

Definition at line 154 of file map.cpp.

00155 {
00156   SwitchDrawingCache();
00157   SwitchDrawingCacheParticles();
00158   
00159   OptimizeCache(*to_redraw_now);
00160 
00161   sky.Draw();
00162 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Map::DrawWater (  ) 

Definition at line 164 of file map.cpp.

00165 { water.Draw(); }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Map::EstDansVide ( int  x,
int  y 
)

Definition at line 205 of file map.cpp.

00205                                  {
00206   return ground.IsEmpty(Point2i(x, y));
00207 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Map::EstDansVide_bas ( const PhysicalObj obj,
int  dx,
int  dy 
)

Definition at line 294 of file map.cpp.

00295 {
00296   return LigneH_EstDansVide (obj.GetTestRect().GetPositionX() + dx,
00297                              obj.GetTestRect().GetPositionY() + dy,
00298                              obj.GetTestRect().GetSizeX());
00299 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Map::EstDansVide_haut ( const PhysicalObj obj,
int  dx,
int  dy 
)

Definition at line 287 of file map.cpp.

00288 {
00289   return LigneH_EstDansVide (obj.GetTestRect().GetPositionX() + dx,
00290                              obj.GetTestRect().GetPositionY() + obj.GetTestRect().GetSizeY() + dy,
00291                              obj.GetTestRect().GetSizeX());
00292 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Map::EstHorsMonde ( const Point2i pos  )  const

Definition at line 201 of file map.cpp.

00201                                                {
00202   return EstHorsMondeXY(pos.x, pos.y);
00203 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Map::EstHorsMondeX ( int  x  )  const

Definition at line 181 of file map.cpp.

00181                                   {
00182   return (x < 0) || ((int)GetWidth() <= x);
00183 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Map::EstHorsMondeXlarg ( int  x,
uint  larg 
) const

Definition at line 189 of file map.cpp.

00189                                                  {
00190   return (x + (int)larg - 1 < 0) || ((int)GetWidth() <= x);
00191 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Map::EstHorsMondeXY ( int  x,
int  y 
) const

Definition at line 197 of file map.cpp.

00197                                           {
00198   return EstHorsMondeX(x) || EstHorsMondeY(y);
00199 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Map::EstHorsMondeY ( int  x  )  const

Definition at line 185 of file map.cpp.

00185                                   {
00186   return (y < 0) || ((int)GetHeight() <= y);
00187 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Map::EstHorsMondeYhaut ( int  x,
uint  haut 
) const

Definition at line 193 of file map.cpp.

00193                                                  {
00194   return ((y + (int)haut - 1 < 0) || ((int)GetHeight() <= y));
00195 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Map::EstOuvert (  )  const [inline]

Definition at line 91 of file map.h.

00091 { return ground.EstOuvert(); }

Here is the call graph for this function:

Here is the caller graph for this function:

void Map::FreeMem (  ) 

Definition at line 89 of file map.cpp.

00090 {
00091   ground.Free();
00092   sky.Free();
00093   water.Free();
00094 
00095   to_redraw->clear();
00096   to_redraw_now->clear();
00097   to_redraw_particles->clear();
00098   to_redraw_particles_now->clear();
00099 }

Here is the call graph for this function:

Here is the caller graph for this function:

int Map::GetHeight (  )  const [inline]

Definition at line 105 of file map.h.

00105 { return ground.GetSizeY(); }

Here is the call graph for this function:

Here is the caller graph for this function:

Point2i Map::GetSize (  )  const [inline]

Definition at line 106 of file map.h.

00106 { return ground.GetSize(); }

Here is the call graph for this function:

Here is the caller graph for this function:

int Map::GetWidth (  )  const [inline]

Definition at line 104 of file map.h.

00104 { return ground.GetSizeX(); }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Map::IsInVacuum_left ( const PhysicalObj obj,
int  dx,
int  dy 
)

Definition at line 301 of file map.cpp.

00302 {
00303   return LigneV_EstDansVide (obj.GetTestRect().GetPositionX() + dx,
00304                              obj.GetTestRect().GetPositionY() + dy,
00305                              obj.GetTestRect().GetPositionY() + obj.GetTestRect().GetSizeY() + dy);
00306 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Map::IsInVacuum_right ( const PhysicalObj obj,
int  dx,
int  dy 
)

Definition at line 308 of file map.cpp.

00309 {
00310   return LigneV_EstDansVide (obj.GetTestRect().GetPositionX() + obj.GetTestRect().GetSizeX() + dx,
00311                              obj.GetTestRect().GetPositionY() + dy,
00312                              obj.GetTestRect().GetPositionY() + obj.GetTestRect().GetSizeY() + dy);
00313 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Map::LigneH_EstDansVide ( int  left,
int  y,
int  right 
)

Definition at line 209 of file map.cpp.

00210 {
00211   // Traite une ligne
00212   for (int i=0; i<width; i++)
00213         if (!EstDansVide(ox+i, (uint)y))
00214           return false;
00215 
00216    return true;
00217 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Map::LigneV_EstDansVide ( int  x,
int  top,
int  bottom 
)

Definition at line 220 of file map.cpp.

00221 {
00222   assert (top <= bottom);
00223 
00224   // V�ifie qu'on reste dans le monde
00225   if (EstHorsMondeX(x) || EstHorsMondeYhaut(top, bottom-top+1))
00226     return Config::GetInstance()->GetExterieurMondeVide();
00227   if (top < 0) top = 0;
00228   if ((int)GetHeight() <= bottom) bottom = GetHeight()-1;
00229 
00230   // Traite une ligne
00231   for (uint iy=(uint)top; iy<=(uint)bottom; iy++)
00232   {
00233     if (!EstDansVide((uint)x, iy)) return false;
00234   }
00235   return true;
00236 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Map::MergeSprite ( const Point2i  pos,
Sprite spr 
)

Definition at line 147 of file map.cpp.

00148 {
00149   Surface tmp = spr->GetSurface();
00150   ground.MergeSprite (pos, tmp);
00151   to_redraw->push_back(Rectanglei(pos, spr->GetSizeMax()));
00152 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Map::OptimizeCache ( std::list< Rectanglei > &  rectangleCache  )  [private]

Definition at line 344 of file map.cpp.

00345 {
00346   rectangleCache.sort(CompareRectangle);
00347         
00348   std::list<Rectanglei>::iterator it = rectangleCache.begin(),
00349     jt = rectangleCache.begin(),
00350     end = rectangleCache.end(),
00351     tmp;
00352 
00353   if (jt != end) {
00354     jt++;
00355   }
00356 //  std::cout << "Before: " <<  rectangleCache.size()  << std::endl;
00357 
00358   while (it != end && jt != end) {
00359     if ( (*it).Contains(*jt) ) {
00360     //   std::cout << "X: " << (*jt).GetPositionX() << " ; " << (*jt).GetBottomRightPoint().GetX() << " - " ; 
00361 //       std::cout << "Y: " << (*jt).GetPositionY() << " ; " << (*jt).GetBottomRightPoint().GetY();
00362 //       std::cout << std::endl;
00363       tmp = jt;
00364       ++tmp;
00365       rectangleCache.erase(jt);
00366       jt = tmp;
00367 
00368     } else if ( (*jt).Contains(*it) ) {
00369 //       std::cout << "X: " << (*it).GetPositionX() << " ; " << (*it).GetBottomRightPoint().GetX() << " - " ; 
00370 //       std::cout << "Y: " << (*it).GetPositionY() << " ; " << (*it).GetBottomRightPoint().GetY();
00371 //       std::cout << std::endl;
00372       tmp = it;
00373       --tmp;
00374       rectangleCache.erase(it);      
00375       it = tmp;
00376 
00377     } else {
00378       it++;
00379       jt++;
00380     }
00381   }
00382 //   std::cout << "After : " <<  rectangleCache.size()  << std::endl;
00383 
00384 //   std::cout << "//#############################" <<std::endl;
00385 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Map::ParanoiacRectIsInVacuum ( const Rectanglei rect  ) 

Definition at line 269 of file map.cpp.

00270 {
00271    // only check whether the rectangle touch the ground pixel by pixel
00272    // Prefere using the method above, as performing a pixel by pixel test is quite slow!
00273 
00274    Rectanglei rect(prect);
00275 
00276    // Clip rectangle in the the world area
00277    rect.Clip( Rectanglei(0, 0, GetWidth(), GetHeight()) );
00278 
00279    // Check line by line
00280    for( int i = rect.GetPositionY(); i < rect.GetPositionY() + rect.GetSizeY(); i++ )
00281      if( !LigneH_EstDansVide (rect.GetPositionX(), i, rect.GetSizeX()) )
00282        return false;
00283 
00284    return true;
00285 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Map::PutSprite ( const Point2i  pos,
Sprite spr 
)

Definition at line 141 of file map.cpp.

00142 {
00143    ground.PutSprite (pos, spr);
00144    to_redraw->push_back(Rectanglei(pos, spr->GetSizeMax()));
00145 }

Here is the call graph for this function:

bool Map::RectEstDansVide ( const Rectanglei rect  ) 

Definition at line 238 of file map.cpp.

00239 {
00240    // only check whether the border touch the ground
00241 
00242    Rectanglei rect(prect);
00243 
00244    // Clip rectangle in the the world area
00245    rect.Clip( Rectanglei(0, 0, GetWidth(), GetHeight()) );
00246 
00247    // Only check the borders of the rectangle
00248    if(rect.GetSizeX()==0 || rect.GetSizeY()==0)
00249      return true;
00250 
00251    if(!LigneH_EstDansVide (rect.GetPositionX(), rect.GetPositionY(), rect.GetSizeX()))
00252      return false;
00253 
00254    if(rect.GetSizeY() > 1)
00255    {
00256      if(!LigneH_EstDansVide (rect.GetPositionX(), rect.GetPositionY() + rect.GetSizeY() - 1, rect.GetSizeX()))
00257        return false;
00258      if(!LigneV_EstDansVide (rect.GetPositionX(), rect.GetPositionY(), rect.GetPositionY() + rect.GetSizeY() -1))
00259        return false;
00260 
00261      if(rect.GetSizeX() > 1)
00262      if(!LigneV_EstDansVide (rect.GetPositionX()+rect.GetSizeX()-1, rect.GetPositionY(), rect.GetPositionY() + rect.GetSizeY() -1))
00263        return false;
00264    }
00265 
00266    return true;
00267 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Map::Refresh (  ) 

Definition at line 83 of file map.cpp.

00084 {
00085   water.Refresh();
00086   wind.Refresh();
00087 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Map::Reset (  ) 

Definition at line 62 of file map.cpp.

00063 {
00064   sky.Reset();
00065   ground.Reset();
00066   water.Reset();
00067   wind.Reset();
00068 
00069   // Configure le jeu selon que le terrain soit ouvert ou non
00070   bool ouvert = ground.EstOuvert();
00071   BonusBox::Enable(ouvert);
00072   Config::GetInstance()->SetExterieurMondeVide(  ouvert );
00073 
00074   delete author_info1; author_info1 = NULL;
00075   delete author_info2; author_info2 = NULL;
00076 
00077   to_redraw->clear();
00078   to_redraw_now->clear();
00079   to_redraw_particles->clear();
00080   to_redraw_particles_now->clear();
00081 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Map::SwitchDrawingCache (  )  [private]

Definition at line 112 of file map.cpp.

00113 {
00114   std::list<Rectanglei> *tmp = to_redraw_now;
00115   to_redraw_now = to_redraw;
00116   to_redraw = tmp;
00117   to_redraw->clear();
00118 }

Here is the caller graph for this function:

void Map::SwitchDrawingCacheParticles (  )  [private]

Definition at line 120 of file map.cpp.

00121 {
00122   std::list<Rectanglei> *tmp = to_redraw_particles_now;
00123   to_redraw_particles_now = to_redraw_particles;
00124   to_redraw_particles = tmp;
00125   to_redraw_particles->clear();
00126 }

Here is the caller graph for this function:

void Map::ToRedrawOnMap ( Rectanglei  r  ) 

Definition at line 101 of file map.cpp.

00102 {
00103   to_redraw->push_back(r);
00104 }

Here is the caller graph for this function:

void Map::ToRedrawOnScreen ( Rectanglei  r  ) 

Definition at line 106 of file map.cpp.

00107 {
00108   r.SetPosition( r.GetPosition() + camera.GetPosition() );
00109   to_redraw->push_back( r );
00110 }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Text* Map::author_info1 [private]

Definition at line 38 of file map.h.

Text* Map::author_info2 [private]

Definition at line 39 of file map.h.

double Map::dst_min_entre_vers

Definition at line 47 of file map.h.

Ground Map::ground

Definition at line 45 of file map.h.

Sky Map::sky

Definition at line 46 of file map.h.

std::list<Rectanglei>* Map::to_redraw

Definition at line 50 of file map.h.

std::list<Rectanglei>* Map::to_redraw_now

Definition at line 51 of file map.h.

std::list<Rectanglei>* Map::to_redraw_particles

Definition at line 52 of file map.h.

std::list<Rectanglei>* Map::to_redraw_particles_now

Definition at line 53 of file map.h.

Water Map::water

Definition at line 48 of file map.h.


The documentation for this class was generated from the following files:
Generated on Mon Jan 1 13:58:04 2007 for Wormux by  doxygen 1.4.7