X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fcollision_grid.cpp;h=9ad005ec982334a963b9c0070335d04c8a555ad1;hb=c0c4838b917943354c150d56ab970ca249267037;hp=660ea878453461d1e7bc5d9e2761786d065ff57a;hpb=c0093d25093395cb62fc2526ab42be65a9f015b8;p=supertux.git diff --git a/src/collision_grid.cpp b/src/collision_grid.cpp index 660ea8784..9ad005ec9 100644 --- a/src/collision_grid.cpp +++ b/src/collision_grid.cpp @@ -17,14 +17,14 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA // 02111-1307, USA. - #include #include -#include "collision_grid.h" -#include "collision.h" -#include "sector.h" -#include "collision_grid_iterator.h" +#include "collision_grid.hpp" +#include "log.hpp" +#include "collision.hpp" +#include "sector.hpp" +#include "collision_grid_iterator.hpp" static const float DELTA = .001; @@ -69,14 +69,14 @@ CollisionGrid::add_object(MovingObject* object) objects.push_back(wrapper); wrapper->id = objects.size()-1; - const Rectangle& bbox = object->bbox; + const Rect& bbox = object->bbox; for(float y = bbox.p1.y; y < bbox.p2.y; y += cell_height) { for(float x = bbox.p1.x; x < bbox.p2.x; x += cell_width) { int gridx = int(x / cell_width); int gridy = int(y / cell_height); if(gridx < 0 || gridy < 0 || gridx >= int(cells_x) || gridy >= int(cells_y)) { - std::cerr << "Object out of range: " << gridx << ", " << gridy << "\n"; + log_warning << "Object out of range: " << gridx << ", " << gridy << std::endl; continue; } GridEntry* entry = new GridEntry; @@ -102,19 +102,19 @@ CollisionGrid::remove_object(MovingObject* object) assert(wrapper != 0); #else if(wrapper == 0) { - std::cerr << "Tried to remove nonexistant object!\n"; - return; + log_warning << "Tried to remove nonexistant object" << std::endl; + return; } #endif - const Rectangle& bbox = wrapper->dest; + const Rect& bbox = wrapper->dest; for(float y = bbox.p1.y; y < bbox.p2.y; y += cell_height) { for(float x = bbox.p1.x; x < bbox.p2.x; x += cell_width) { int gridx = int(x / cell_width); int gridy = int(y / cell_height); if(gridx < 0 || gridy < 0 || gridx >= int(cells_x) || gridy >= int(cells_y)) { - std::cerr << "Object out of range: " << gridx << ", " << gridy << "\n"; + log_warning << "Object out of range: " << gridx << ", " << gridy << std::endl; continue; } remove_object_from_gridcell(gridy*cells_x + gridx, wrapper); @@ -129,28 +129,28 @@ CollisionGrid::move_object(ObjectWrapper* wrapper) { // FIXME not optimal yet... should leave the gridcells untouched that don't // need to be changed. - const Rectangle& obbox = wrapper->dest; + const Rect& obbox = wrapper->dest; for(float y = obbox.p1.y; y < obbox.p2.y; y += cell_height) { for(float x = obbox.p1.x; x < obbox.p2.x; x += cell_width) { int gridx = int(x / cell_width); int gridy = int(y / cell_height); - if(gridx < 0 || gridy < 0 - || gridx >= int(cells_x) || gridy >= int(cells_y)) { - std::cerr << "Object out of range: " << gridx << ", " << gridy << "\n"; + if(gridx < 0 || gridy < 0 || + gridx >= int(cells_x) || gridy >= int(cells_y)) { + log_warning << "Object out of range: " << gridx << ", " << gridy << std::endl; continue; } remove_object_from_gridcell(gridy*cells_x + gridx, wrapper); } } - const Rectangle& nbbox = wrapper->object->bbox; + const Rect& nbbox = wrapper->object->bbox; for(float y = nbbox.p1.y; y < nbbox.p2.y; y += cell_height) { for(float x = nbbox.p1.x; x < nbbox.p2.x; x += cell_width) { int gridx = int(x / cell_width); int gridy = int(y / cell_height); if(gridx < 0 || gridy < 0 || gridx >= int(cells_x) || gridy >= int(cells_y)) { - std::cerr << "Object out of range: " << gridx << ", " << gridy << "\n"; + log_warning << "Object out of range: " << gridx << ", " << gridy << std::endl; continue; } @@ -168,13 +168,14 @@ void CollisionGrid::check_collisions() { std::vector moved_objects; - + +#if 0 CollisionGridIterator iter(*this, Sector::current()->get_active_region()); while(ObjectWrapper* wrapper = iter.next_wrapper()) { MovingObject* object = wrapper->object; if(!object->is_valid()) continue; - if(object->get_flags() & GameObject::FLAG_NO_COLLDET) { + if(object->get_group() == COLGROUP_DISABLED) { object->bbox.move(object->movement); object->movement = Vector(0, 0); moved_objects.push_back(wrapper); @@ -192,6 +193,7 @@ CollisionGrid::check_collisions() moved_objects.push_back(wrapper); } } +#endif for(std::vector::iterator i = moved_objects.begin(); i != moved_objects.end(); ++i) { @@ -204,14 +206,14 @@ CollisionGrid::collide_object(ObjectWrapper* wrapper) { iterator_timestamp++; - const Rectangle& bbox = wrapper->object->bbox; + const Rect& bbox = wrapper->object->bbox; for(float y = bbox.p1.y - cell_height; y < bbox.p2.y + cell_height; y += cell_height) { for(float x = bbox.p1.x - cell_width; x < bbox.p2.x + cell_width; x += cell_width) { int gridx = int(x / cell_width); int gridy = int(y / cell_height); if(gridx < 0 || gridy < 0 || gridx >= int(cells_x) || gridy >= int(cells_y)) { - //std::cerr << "Object out of range: " << gridx << ", " << gridy << "\n"; + //log_warning << "Object out of range: " << gridx << ", " << gridy << std::endl; continue; } @@ -240,9 +242,9 @@ CollisionGrid::collide_object_object(ObjectWrapper* wrapper, MovingObject* object1 = wrapper->object; MovingObject* object2 = wrapper2->object; - Rectangle dest1 = object1->get_bbox(); + Rect dest1 = object1->get_bbox(); dest1.move(object1->get_movement()); - Rectangle dest2 = object2->get_bbox(); + Rect dest2 = object2->get_bbox(); dest2.move(object2->get_movement()); Vector movement = object1->get_movement() - object2->get_movement(); @@ -289,6 +291,6 @@ CollisionGrid::remove_object_from_gridcell(int gridcell, ObjectWrapper* wrapper) entry = entry->next; }; - std::cerr << "Couldn't find object in cell.\n"; + log_warning << "Couldn't find object in cell" << std::endl; }