15 #include "physicsObjectCollection.h" 24 PhysicsObjectCollection::
25 PhysicsObjectCollection() {
33 PhysicsObjectCollection::
35 _physics_objects(copy._physics_objects)
44 void PhysicsObjectCollection::
46 _physics_objects = copy._physics_objects;
61 if (_physics_objects.get_ref_count() > 1) {
62 PhysicsObjects old_physics_objects = _physics_objects;
63 _physics_objects = PhysicsObjects::empty_array(0);
64 _physics_objects.v() = old_physics_objects.v();
67 _physics_objects.push_back(physics_object);
79 int object_index = -1;
80 for (
int i = 0; object_index == -1 && i < (int)_physics_objects.size(); i++) {
81 if (_physics_objects[i] == physics_object) {
86 if (object_index == -1) {
96 if (_physics_objects.get_ref_count() > 1) {
97 PhysicsObjects old_physics_objects = _physics_objects;
98 _physics_objects = PhysicsObjects::empty_array(0);
99 _physics_objects.v() = old_physics_objects.v();
102 _physics_objects.erase(_physics_objects.begin() + object_index);
118 for (
int i = 0; i < other_num_physics_objects; i++) {
132 PhysicsObjects new_physics_objects;
134 for (
int i = 0; i < num_physics_objects; i++) {
137 new_physics_objects.push_back(physics_object);
140 _physics_objects = new_physics_objects;
153 PhysicsObjects new_physics_objects;
156 for (
int i = 0; i < num_physics_objects; i++) {
158 bool duplicated =
false;
160 for (
int j = 0; j < i && !duplicated; j++) {
161 duplicated = (physics_object == get_physics_object(j));
165 new_physics_objects.push_back(physics_object);
169 _physics_objects = new_physics_objects;
181 if (physics_object == get_physics_object(i)) {
195 _physics_objects.clear();
206 return _physics_objects.empty();
216 return _physics_objects.size();
225 get_physics_object(
int index)
const {
226 nassertr(index >= 0 && index < (
int)_physics_objects.size(), PT(
PhysicsObject)());
228 return _physics_objects[index];
239 operator [] (
int index)
const {
240 nassertr(index >= 0 && index < (
int)_physics_objects.size(), PT(
PhysicsObject)());
242 return _physics_objects[index];
252 int PhysicsObjectCollection::
254 return _physics_objects.size();
263 void PhysicsObjectCollection::
264 output(ostream &out)
const {
266 out <<
"1 PhysicsObject";
278 void PhysicsObjectCollection::
279 write(ostream &out,
int indent_level)
const {
281 indent(out, indent_level) << get_physics_object(i) <<
"\n";
bool remove_physics_object(PT(PhysicsObject) physics_object)
Removes the indicated PhysicsObject from the collection.
A body on which physics will be applied.
void clear()
Removes all PhysicsObjects from the collection.
This is a set of zero or more PhysicsObjects.
void add_physics_objects_from(const PhysicsObjectCollection &other)
Adds all the PhysicsObjects indicated in the other collection to this collection. ...
int get_num_physics_objects() const
Returns the number of PhysicsObjects in the collection.
void remove_physics_objects_from(const PhysicsObjectCollection &other)
Removes from this collection all of the PhysicsObjects listed in the other collection.
void remove_duplicate_physics_objects()
Removes any duplicate entries of the same PhysicsObjects on this collection.
bool is_empty() const
Returns true if there are no PhysicsObjects in the collection, false otherwise.
bool has_physics_object(PT(PhysicsObject) physics_object) const
Returns true if the indicated PhysicsObject appears in this collection, false otherwise.
void add_physics_object(PT(PhysicsObject) physics_object)
Adds a new PhysicsObject to the collection.