Fixing SuperTux crashes when compiled on Mac OS X 10.9
[supertux.git] / src / supertux / sector.cpp
index 08b8946..0add01f 100644 (file)
@@ -45,7 +45,7 @@
 #include "object/snow_particle_system.hpp"
 #include "object/text_object.hpp"
 #include "object/tilemap.hpp"
-#include "physfs/ifile_stream.hpp"
+#include "physfs/ifile_streambuf.hpp"
 #include "scripting/squirrel_util.hpp"
 #include "supertux/collision.hpp"
 #include "supertux/constants.hpp"
@@ -415,13 +415,20 @@ Sector::fix_old_tiles()
           add_object(new InvisibleBlock(pos));
           solids->change(x, y, 0);
         } else if(tile->getAttributes() & Tile::COIN) {
-          add_object(new Coin(pos));
+          add_object(new Coin(pos, solids));
           solids->change(x, y, 0);
         } else if(tile->getAttributes() & Tile::FULLBOX) {
           add_object(new BonusBlock(pos, tile->getData()));
           solids->change(x, y, 0);
         } else if(tile->getAttributes() & Tile::BRICK) {
-          add_object(new Brick(pos, tile->getData()));
+          if( ( id == 78 ) || ( id == 105 ) ){
+            add_object( new Brick(pos, tile->getData(), "images/objects/bonus_block/brickIce.sprite") );
+          } else if( ( id == 77 ) || ( id == 104 ) ){
+            add_object( new Brick(pos, tile->getData(), "images/objects/bonus_block/brick.sprite") );
+          } else {
+            log_warning << "attribute 'brick #t' is not supported for tile-id " << id << std::endl;
+            add_object( new Brick(pos, tile->getData(), "images/objects/bonus_block/brick.sprite") );
+          }
           solids->change(x, y, 0);
         } else if(tile->getAttributes() & Tile::GOAL) {
           std::string sequence = tile->getData() == 0 ? "endsequence" : "stoptux";
@@ -594,7 +601,13 @@ Sector::activate(const Vector& player_pos)
     }
   }
 
+  //FIXME: This is a really dirty workaround for this strange camera jump
+  player->move(player->get_pos()+Vector(-32, 0));
   camera->reset(player->get_pos());
+  camera->update(1);
+  player->move(player->get_pos()+(Vector(32, 0)));
+  camera->update(1);
+  
   update_game_objects();
 
   //Run default.nut just before init script
@@ -602,7 +615,8 @@ Sector::activate(const Vector& player_pos)
   std::string basedir = FileSystem::dirname(get_level()->filename);
   if(PHYSFS_exists((basedir + "/info").c_str())) {
     try {
-      IFileStream in(basedir + "/default.nut");
+      IFileStreambuf ins(basedir + "/default.nut");
+      std::istream in(&ins);
       run_script(in, "default.nut");
     } catch(std::exception& ) {
       // doesn't exist or erroneous; do nothing
@@ -1153,8 +1167,6 @@ Sector::collision_static_constrains(MovingObject& object)
   Constraints constraints;
   Vector movement = object.get_movement();
   Rectf& dest = object.dest;
-  float owidth = object.get_bbox().get_width();
-  float oheight = object.get_bbox().get_height();
 
   for(int i = 0; i < 2; ++i) {
     collision_static(&constraints, Vector(0, movement.y), dest, object);
@@ -1164,16 +1176,16 @@ Sector::collision_static_constrains(MovingObject& object)
     // apply calculated horizontal constraints
     if(constraints.get_position_bottom() < infinity) {
       float height = constraints.get_height ();
-      if(height < oheight) {
+      if(height < object.get_bbox().get_height()) {
         // we're crushed, but ignore this for now, we'll get this again
         // later if we're really crushed or things will solve itself when
         // looking at the vertical constraints
       }
       dest.p2.y = constraints.get_position_bottom() - DELTA;
-      dest.p1.y = dest.p2.y - oheight;
+      dest.p1.y = dest.p2.y - object.get_bbox().get_height();
     } else if(constraints.get_position_top() > -infinity) {
       dest.p1.y = constraints.get_position_top() + DELTA;
-      dest.p2.y = dest.p1.y + oheight;
+      dest.p2.y = dest.p1.y + object.get_bbox().get_height();
     }
   }
   if(constraints.has_constraints()) {
@@ -1196,7 +1208,7 @@ Sector::collision_static_constrains(MovingObject& object)
     // apply calculated vertical constraints
     float width = constraints.get_width ();
     if(width < infinity) {
-      if(width + SHIFT_DELTA < owidth) {
+      if(width + SHIFT_DELTA < object.get_bbox().get_width()) {
 #if 0
         printf("Object %p crushed horizontally... L:%f R:%f\n", &object,
                constraints.get_position_left(), constraints.get_position_right());
@@ -1208,15 +1220,15 @@ Sector::collision_static_constrains(MovingObject& object)
         object.collision_solid(h);
       } else {
         float xmid = constraints.get_x_midpoint ();
-        dest.p1.x = xmid - owidth/2;
-        dest.p2.x = xmid + owidth/2;
+        dest.p1.x = xmid - object.get_bbox().get_width()/2;
+        dest.p2.x = xmid + object.get_bbox().get_width()/2;
       }
     } else if(constraints.get_position_right() < infinity) {
       dest.p2.x = constraints.get_position_right() - DELTA;
-      dest.p1.x = dest.p2.x - owidth;
+      dest.p1.x = dest.p2.x - object.get_bbox().get_width();
     } else if(constraints.get_position_left() > -infinity) {
       dest.p1.x = constraints.get_position_left() + DELTA;
-      dest.p2.x = dest.p1.x + owidth;
+      dest.p2.x = dest.p1.x + object.get_bbox().get_width();
     }
   }
 
@@ -1232,7 +1244,7 @@ Sector::collision_static_constrains(MovingObject& object)
   collision_static(&constraints, movement, dest, object);
   if(constraints.get_position_bottom() < infinity) {
     float height = constraints.get_height ();
-    if(height + SHIFT_DELTA < oheight) {
+    if(height + SHIFT_DELTA < object.get_bbox().get_height()) {
 #if 0
       printf("Object %p crushed vertically...\n", &object);
 #endif