X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fsector.cpp;h=2a56628ce825b85249ee93aaf88be3d3e60c83fd;hb=fa0babce2705e8f1406f7dbcb39de9cf86ae131e;hp=abb28f9384f3343cb25a92cf61f6d3030f266b7c;hpb=ef57479f613b900b73eba8e8f4d026aae0de25cc;p=supertux.git diff --git a/src/sector.cpp b/src/sector.cpp index abb28f938..2a56628ce 100644 --- a/src/sector.cpp +++ b/src/sector.cpp @@ -42,13 +42,13 @@ #include "gameloop.h" #include "resources.h" #include "statistics.h" +#include "collision_grid.h" #include "special/collision.h" #include "math/rectangle.h" #include "math/aatriangle.h" #include "object/coin.h" #include "object/block.h" #include "object/invisible_block.h" -#include "object/invisible_tile.h" #include "object/platform.h" #include "object/bullet.h" #include "badguy/jumpy.h" @@ -74,6 +74,8 @@ Sector::Sector() song_title = "Mortimers_chipdisko.mod"; player = new Player(); add_object(player); + + grid = new CollisionGrid(32000, 32000); } Sector::~Sector() @@ -81,6 +83,8 @@ Sector::~Sector() update_game_objects(); assert(gameobjects_new.size() == 0); + delete grid; + for(GameObjects::iterator i = gameobjects.begin(); i != gameobjects.end(); ++i) { delete *i; @@ -329,9 +333,6 @@ Sector::fix_old_tiles() if(tile->getID() == 112) { add_object(new InvisibleBlock(pos)); solids->change(x, y, 0); - } else if(tile->getID() == 1311) { - add_object(new InvisibleTile(pos)); - solids->change(x, y, 0); } else if(tile->getID() == 295) { add_object(new Spike(pos, Spike::NORTH)); solids->change(x, y, 0); @@ -489,29 +490,42 @@ Sector::update_game_objects() /** cleanup marked objects */ for(std::vector::iterator i = gameobjects.begin(); i != gameobjects.end(); /* nothing */) { - if((*i)->is_valid() == false) { - Bullet* bullet = dynamic_cast (*i); - if(bullet) { - bullets.erase( - std::remove(bullets.begin(), bullets.end(), bullet), - bullets.end()); - } - delete *i; - i = gameobjects.erase(i); - } else { + GameObject* object = *i; + + if(object->is_valid()) { ++i; + continue; + } + + Bullet* bullet = dynamic_cast (object); + if(bullet) { + bullets.erase( + std::remove(bullets.begin(), bullets.end(), bullet), + bullets.end()); + } + MovingObject* movingobject = dynamic_cast (object); + if(movingobject) { + grid->remove_object(movingobject); } + delete *i; + i = gameobjects.erase(i); } /* add newly created objects */ for(std::vector::iterator i = gameobjects_new.begin(); i != gameobjects_new.end(); ++i) { - Bullet* bullet = dynamic_cast (*i); + GameObject* object = *i; + + Bullet* bullet = dynamic_cast (object); if(bullet) bullets.push_back(bullet); - TileMap* tilemap = dynamic_cast (*i); + MovingObject* movingobject = dynamic_cast (object); + if(movingobject) + grid->add_object(movingobject); + + TileMap* tilemap = dynamic_cast (object); if(tilemap && tilemap->is_solid()) { if(solids == 0) { solids = tilemap; @@ -520,7 +534,7 @@ Sector::update_game_objects() } } - Camera* camera = dynamic_cast (*i); + Camera* camera = dynamic_cast (object); if(camera) { if(this->camera != 0) { std::cerr << "Warning: Multiple cameras added. Ignoring."; @@ -529,7 +543,7 @@ Sector::update_game_objects() this->camera = camera; } - gameobjects.push_back(*i); + gameobjects.push_back(object); } gameobjects_new.clear(); } @@ -678,6 +692,9 @@ Sector::collision_object(MovingObject* object1, MovingObject* object2) void Sector::collision_handler() { +#if 0 + grid->check_collisions(); +#else for(std::vector::iterator i = gameobjects.begin(); i != gameobjects.end(); ++i) { GameObject* gameobject = *i; @@ -713,6 +730,7 @@ Sector::collision_handler() movingobject->bbox.move(movingobject->get_movement()); movingobject->movement = Vector(0, 0); } +#endif } bool