4 // Copyright (C) 2005 Matthias Braun <matze@braunis.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 #ifndef __COLLISION_GRID_H__
22 #define __COLLISION_GRID_H__
25 #include "moving_object.h"
27 using namespace SuperTux;
29 class CollisionGridIterator;
32 * A rectangular grid to keep track of all moving game objects. It allows fast
33 * queries for all objects in a rectangular area.
38 CollisionGrid(float width, float height);
41 void add_object(MovingObject* object);
42 void remove_object(MovingObject* object);
44 void check_collisions();
47 friend class CollisionGridIterator;
53 /** (pseudo) timestamp. When reading from the grid the timestamp is
54 * changed so that you can easily avoid reading an object multiple times
55 * when it is in several cells that you check.
58 /// index in the objects vector
62 /** Element for the single linked list in each grid cell */
66 ObjectWrapper* object_wrapper;
69 void remove_object_from_gridcell(int gridcell, ObjectWrapper* wrapper);
70 void collide_object(ObjectWrapper* wrapper);
71 void collide_object_object(ObjectWrapper* wrapper, ObjectWrapper* wrapper2);
72 void move_object(ObjectWrapper* wrapper);
74 typedef std::vector<GridEntry*> GridEntries;
76 typedef std::vector<ObjectWrapper*> Objects;
78 size_t cells_x, cells_y;
83 int iterator_timestamp;
86 extern CollisionGrid* bla;