pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] r3695 - trunk/pingus/src


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3695 - trunk/pingus/src
Date: Sat, 5 Jul 2008 21:54:26 +0200

Author: grumbel
Date: 2008-07-05 21:54:25 +0200 (Sat, 05 Jul 2008)
New Revision: 3695

Modified:
   trunk/pingus/src/ground_map.cpp
   trunk/pingus/src/ground_map.hpp
Log:
Move MapTile into the .cpp file and changed its allocation a bit

Modified: trunk/pingus/src/ground_map.cpp
===================================================================
--- trunk/pingus/src/ground_map.cpp     2008-07-05 19:41:57 UTC (rev 3694)
+++ trunk/pingus/src/ground_map.cpp     2008-07-05 19:54:25 UTC (rev 3695)
@@ -25,7 +25,24 @@
 #include "collision_map.hpp"
 #include "math.hpp"
 #include "SDL.h"
+
+class MapTile
+{
+private:
+  Sprite   sprite;
+  Surface  surface;
 
+  void prepare();
+public:
+  MapTile();
+  ~MapTile();
+
+  void remove(Surface, int x, int y, int real_x, int real_y, GroundMap*);  
+  void put(Surface, int x, int y);  
+
+  Sprite get_sprite() const { return sprite; }
+};
+
 MapTile::MapTile () 
 {
 }
@@ -62,7 +79,7 @@
   surface.blit(obj, x, y);
   sprite = Sprite(surface);
 }
-
+
 GroundMap::GroundMap(const PingusLevel& plf)
 {
   width  = plf.get_size().width;
@@ -87,9 +104,9 @@
   tile_height = height/tile_size;
 
   // Allocating tile map
-  tile.resize(tile_width);
-  for(unsigned int i=0; i < tile.size(); ++i)
-    tile[i].resize(tile_height);
+  tiles.resize(tile_width * tile_height);
+  for(std::vector<MapTile*>::iterator i = tiles.begin(); i != tiles.end(); ++i)
+    *i = new MapTile();
 
   // fix the height back to the correct values
   width  = plf.get_size().width;
@@ -99,6 +116,8 @@
 GroundMap::~GroundMap(void)
 {
   delete colmap;
+  for(std::vector<MapTile*>::iterator i = tiles.begin(); i != tiles.end(); ++i)
+    delete *i;
 }
 
 void
@@ -113,7 +132,6 @@
 {
   const Rect& display = gc.color().get_world_clip_rect();
 
-  // FIXME: delete the next four lines and replace them with gc.get_clip_rect()
   if (draw_collision_map)
     draw_colmap(gc);
 
@@ -124,13 +142,13 @@
   int tilemap_height = display.get_height() / tile_size + 1;
 
   // drawing the stuff
-  for (int x = start_x; x <= (start_x + tilemap_width) && x < 
int(tile.size()); ++x)
-    for (int y = start_y; y <= start_y + tilemap_height && y < 
int(tile[x].size()); ++y)
+  for (int x = start_x; x <= (start_x + tilemap_width) && x < tile_width; ++x)
+    for (int y = start_y; y <= start_y + tilemap_height && y < tile_height; 
++y)
       {
-        if (tile[x][y].get_sprite())
+        if (get_tile(x, y)->get_sprite())
           {
             //std::cout << "Drawing GroundMap Tile " << std::endl;
-            gc.color().draw(tile[x][y].get_sprite(),
+            gc.color().draw(get_tile(x, y)->get_sprite(),
                             Vector2i(x * tile_size, y * tile_size));
           }
         else
@@ -173,7 +191,7 @@
   for(int ix = start_x; ix <= end_x; ++ix)
     for(int iy = start_y; iy <= end_y; ++iy)
       {
-        tile[ix][iy].remove(sprovider, x - (ix * tile_size),
+        get_tile(ix, iy)->remove(sprovider, x - (ix * tile_size),
                             y - (iy * tile_size), x, y, this);
       }
 }
@@ -276,8 +294,8 @@
   for(int ix = start_x; ix < end_x; ++ix)
     for(int iy = start_y; iy < end_y; ++iy)
       {
-        tile[ix][iy].put(source,
-                         x - (ix * tile_size), y - (iy * tile_size));
+        get_tile(ix, iy)->put(source,
+                              x - (ix * tile_size), y - (iy * tile_size));
       }
 }
 
@@ -287,5 +305,10 @@
   return colmap;
 }
 
-
+MapTile*
+GroundMap::get_tile(int x, int y)
+{
+  return tiles[y*tile_width + x];
+}
+
 /* EOF */

Modified: trunk/pingus/src/ground_map.hpp
===================================================================
--- trunk/pingus/src/ground_map.hpp     2008-07-05 19:41:57 UTC (rev 3694)
+++ trunk/pingus/src/ground_map.hpp     2008-07-05 19:54:25 UTC (rev 3695)
@@ -27,24 +27,8 @@
 class PingusLevel;
 class CollisionMap;
 class GroundMap;
-
-class MapTile
-{
-private:
-  Sprite       sprite;
-  Surface  surface;
-
-  void prepare();
-public:
-  MapTile();
-  ~MapTile();
-
-  void remove(Surface, int x, int y, int real_x, int real_y, GroundMap*);  
-  void put(Surface, int x, int y);  
-
-  Sprite get_sprite() const { return sprite; }
-};
-
+class MapTile;
+
 /** This map type is the defaulh maptype, it is should be used for the
     most levels. It allows to construct a map, from a set of simple
     small images, this allows the generation of large map without
@@ -55,7 +39,7 @@
   CollisionMap* colmap;
 
   /** The tiles out of which the map is constructed */
-  std::vector<std::vector<MapTile> > tile;
+  std::vector<MapTile*> tiles;
 
   /** Width of the map */
   int width;
@@ -86,11 +70,12 @@
 
   float get_z_pos () const { return 0; }
 
-       /** Low level version of the remove() call, acts on a single tile
+  /** Low level version of the remove() call, acts on a single tile
       instead of the complete map-tiles */
   void put_alpha_surface(Surface provider, Surface sprovider,
                         int x, int y, int real_x, int real_y);
 
+  MapTile* get_tile(int x, int y);
 private:
   /** Draw the collision map onto the screen */
   void draw_colmap(SceneContext& gc);
@@ -98,8 +83,7 @@
   GroundMap (const GroundMap&);
   GroundMap& operator= (const GroundMap&);
 };
-
-
+
 #endif
 
 /* EOF */





reply via email to

[Prev in Thread] Current Thread [Next in Thread]