Make it build with -DCOMPILE_AMALGATION=ON. Still not certain how intern_draw/next_po...
[supertux.git] / src / supertux / sector.cpp
index 9dcc66e..76ebf06 100644 (file)
 #include "scripting/squirrel_util.hpp"
 #include "supertux/collision.hpp"
 #include "supertux/constants.hpp"
+#include "supertux/game_session.hpp"
 #include "supertux/globals.hpp"
 #include "supertux/level.hpp"
 #include "supertux/object_factory.hpp"
+#include "supertux/player_status.hpp"
 #include "supertux/spawn_point.hpp"
 #include "supertux/tile.hpp"
 #include "trigger/sequence_trigger.hpp"
@@ -83,7 +85,7 @@ Sector::Sector(Level* parent) :
   camera(0), 
   effect(0)
 {
-  add_object(new Player(player_status, "Tux"));
+  add_object(new Player(GameSession::current()->get_player_status(), "Tux"));
   add_object(new DisplayEffect("Effect"));
   add_object(new TextObject("Text"));
 
@@ -172,7 +174,7 @@ Sector::parse_object(const std::string& name, const Reader& reader)
     return new Jumpy(reader);
   } else {
     try {
-      return create_object(name, reader);
+      return ObjectFactory::instance().create(name, reader);
     } catch(std::exception& e) {
       log_warning << e.what() << "" << std::endl;
       return 0;
@@ -504,7 +506,7 @@ void
 Sector::add_object(GameObject* object)
 {
   // make sure the object isn't already in the list
-#ifdef DEBUG
+#ifndef NDEBUG
   for(GameObjects::iterator i = gameobjects.begin(); i != gameobjects.end();
       ++i) {
     if(*i == object) {
@@ -634,10 +636,10 @@ Sector::deactivate()
   _current = NULL;
 }
 
-Rect
+Rectf
 Sector::get_active_region()
 {
-  return Rect(
+  return Rectf(
     camera->get_translation() - Vector(1600, 1200),
     camera->get_translation() + Vector(1600, 1200) + Vector(SCREEN_WIDTH,SCREEN_HEIGHT));
 }
@@ -766,11 +768,11 @@ Sector::before_object_add(GameObject* object)
 void
 Sector::try_expose(GameObject* object)
 {
-  ScriptInterface* interface = dynamic_cast<ScriptInterface*> (object);
-  if(interface != NULL) {
+  ScriptInterface* object_ = dynamic_cast<ScriptInterface*> (object);
+  if(object_ != NULL) {
     HSQUIRRELVM vm = scripting::global_vm;
     sq_pushobject(vm, sector_table);
-    interface->expose(vm, -1);
+    object_->expose(vm, -1);
     sq_pop(vm, 1);
   }
 }
@@ -780,8 +782,8 @@ Sector::try_expose_me()
 {
   HSQUIRRELVM vm = scripting::global_vm;
   sq_pushobject(vm, sector_table);
-  scripting::SSector* interface = static_cast<scripting::SSector*> (this);
-  expose_object(vm, -1, interface, "settings", false);
+  scripting::SSector* this_ = static_cast<scripting::SSector*> (this);
+  expose_object(vm, -1, this_, "settings", false);
   sq_pop(vm, 1);
 }
 
@@ -809,13 +811,13 @@ Sector::before_object_remove(GameObject* object)
 void
 Sector::try_unexpose(GameObject* object)
 {
-  ScriptInterface* interface = dynamic_cast<ScriptInterface*> (object);
-  if(interface != NULL) {
+  ScriptInterface* object_ = dynamic_cast<ScriptInterface*> (object);
+  if(object_ != NULL) {
     HSQUIRRELVM vm = scripting::global_vm;
     SQInteger oldtop = sq_gettop(vm);
     sq_pushobject(vm, sector_table);
     try {
-      interface->unexpose(vm, -1);
+      object_->unexpose(vm, -1);
     } catch(std::exception& e) {
       log_warning << "Couldn't unregister object: " << e.what() << std::endl;
     }
@@ -864,7 +866,7 @@ Sector::draw(DrawingContext& context)
     for(MovingObjects::iterator i = moving_objects.begin();
         i != moving_objects.end(); ++i) {
       MovingObject* object = *i;
-      const Rect& rect = object->get_bbox();
+      const Rectf& rect = object->get_bbox();
 
       context.draw_filled_rect(rect, col, LAYER_FOREGROUND1 + 10);
     }
@@ -879,7 +881,7 @@ Sector::draw(DrawingContext& context)
 
 /** r1 is supposed to be moving, r2 a solid object */
 void check_collisions(collision::Constraints* constraints,
-                      const Vector& movement, const Rect& r1, const Rect& r2,
+                      const Vector& movement, const Rectf& r1, const Rectf& r2,
                       GameObject* object = NULL, MovingObject* other = NULL, const Vector& addl_ground_movement = Vector(0,0))
 {
   if(!collision::intersects(r1, r2))
@@ -952,7 +954,7 @@ void check_collisions(collision::Constraints* constraints,
 
 void
 Sector::collision_tilemap(collision::Constraints* constraints,
-                          const Vector& movement, const Rect& dest) const
+                          const Vector& movement, const Rectf& dest) const
 {
   // calculate rectangle where the object will move
   float x1 = dest.get_left();
@@ -992,7 +994,7 @@ Sector::collision_tilemap(collision::Constraints* constraints,
 
           collision::rectangle_aatriangle(constraints, dest, triangle, solids->get_movement());
         } else { // normal rectangular tile
-          Rect rect(x*32 + solids->get_x_offset(), y*32 + solids->get_y_offset(), (x+1)*32 + solids->get_x_offset(), (y+1)*32 + solids->get_y_offset());
+          Rectf rect(x*32 + solids->get_x_offset(), y*32 + solids->get_y_offset(), (x+1)*32 + solids->get_x_offset(), (y+1)*32 + solids->get_y_offset());
           check_collisions(constraints, movement, dest, rect, NULL, NULL, solids->get_movement());
         }
       }
@@ -1001,7 +1003,7 @@ Sector::collision_tilemap(collision::Constraints* constraints,
 }
 
 uint32_t
-Sector::collision_tile_attributes(const Rect& dest) const
+Sector::collision_tile_attributes(const Rectf& dest) const
 {
   float x1 = dest.p1.x;
   float y1 = dest.p1.y;
@@ -1032,7 +1034,7 @@ Sector::collision_tile_attributes(const Rect& dest) const
 }
 
 /** fills in CollisionHit and Normal vector of 2 intersecting rectangle */
-static void get_hit_normal(const Rect& r1, const Rect& r2, CollisionHit& hit,
+static void get_hit_normal(const Rectf& r1, const Rectf& r2, CollisionHit& hit,
                            Vector& normal)
 {
   float itop = r1.get_bottom() - r2.get_top();
@@ -1066,8 +1068,8 @@ Sector::collision_object(MovingObject* object1, MovingObject* object2) const
 {
   using namespace collision;
 
-  const Rect& r1 = object1->dest;
-  const Rect& r2 = object2->dest;
+  const Rectf& r1 = object1->dest;
+  const Rectf& r2 = object2->dest;
 
   CollisionHit hit;
   if(intersects(object1->dest, object2->dest)) {
@@ -1103,7 +1105,7 @@ Sector::collision_object(MovingObject* object1, MovingObject* object2) const
 
 void
 Sector::collision_static(collision::Constraints* constraints,
-                         const Vector& movement, const Rect& dest,
+                         const Vector& movement, const Rectf& dest,
                          GameObject& object)
 {
   collision_tilemap(constraints, movement, dest);
@@ -1132,7 +1134,7 @@ Sector::collision_static_constrains(MovingObject& object)
 
   Constraints constraints;
   Vector movement = object.get_movement();
-  Rect& dest = object.dest;
+  Rectf& dest = object.dest;
   float owidth = object.get_bbox().get_width();
   float oheight = object.get_bbox().get_height();
 
@@ -1340,7 +1342,7 @@ Sector::handle_collisions()
 }
 
 bool
-Sector::is_free_of_tiles(const Rect& rect, const bool ignoreUnisolid) const
+Sector::is_free_of_tiles(const Rectf& rect, const bool ignoreUnisolid) const
 {
   using namespace collision;
 
@@ -1374,7 +1376,7 @@ Sector::is_free_of_tiles(const Rect& rect, const bool ignoreUnisolid) const
 }
 
 bool
-Sector::is_free_of_statics(const Rect& rect, const MovingObject* ignore_object, const bool ignoreUnisolid) const
+Sector::is_free_of_statics(const Rectf& rect, const MovingObject* ignore_object, const bool ignoreUnisolid) const
 {
   using namespace collision;
 
@@ -1394,7 +1396,7 @@ Sector::is_free_of_statics(const Rect& rect, const MovingObject* ignore_object,
 }
 
 bool
-Sector::is_free_of_movingstatics(const Rect& rect, const MovingObject* ignore_object) const
+Sector::is_free_of_movingstatics(const Rectf& rect, const MovingObject* ignore_object) const
 {
   using namespace collision;
 
@@ -1416,7 +1418,7 @@ Sector::is_free_of_movingstatics(const Rect& rect, const MovingObject* ignore_ob
 }
 
 bool
-Sector::add_bullet(const Vector& pos, float xm, Direction dir)
+Sector::add_bullet(const Vector& pos, const PlayerStatus* player_status, float xm, Direction dir)
 {
   // TODO remove this function and move these checks elsewhere...
 
@@ -1482,7 +1484,7 @@ Sector::get_total_badguys()
 }
 
 bool
-Sector::inside(const Rect& rect) const
+Sector::inside(const Rectf& rect) const
 {
   for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
     TileMap* solids = *i;