+ std::vector<NearbyCollisionInfo> cinfo;
+ {
+ //TimeTaker tt2("collisionMoveSimple collect boxes");
+ ScopeProfiler sp(g_profiler, "collisionMoveSimple collect boxes avg", SPT_AVG);
+
+ v3s16 oldpos_i = floatToInt(*pos_f, BS);
+ v3s16 newpos_i = floatToInt(*pos_f + *speed_f * dtime, BS);
+ s16 min_x = MYMIN(oldpos_i.X, newpos_i.X) + (box_0.MinEdge.X / BS) - 1;
+ s16 min_y = MYMIN(oldpos_i.Y, newpos_i.Y) + (box_0.MinEdge.Y / BS) - 1;
+ s16 min_z = MYMIN(oldpos_i.Z, newpos_i.Z) + (box_0.MinEdge.Z / BS) - 1;
+ s16 max_x = MYMAX(oldpos_i.X, newpos_i.X) + (box_0.MaxEdge.X / BS) + 1;
+ s16 max_y = MYMAX(oldpos_i.Y, newpos_i.Y) + (box_0.MaxEdge.Y / BS) + 1;
+ s16 max_z = MYMAX(oldpos_i.Z, newpos_i.Z) + (box_0.MaxEdge.Z / BS) + 1;
+
+ bool any_position_valid = false;
+
+ for(s16 x = min_x; x <= max_x; x++)
+ for(s16 y = min_y; y <= max_y; y++)
+ for(s16 z = min_z; z <= max_z; z++)
+ {
+ v3s16 p(x,y,z);
+
+ bool is_position_valid;
+ MapNode n = map->getNodeNoEx(p, &is_position_valid);
+
+ if (is_position_valid) {
+ // Object collides into walkable nodes
+
+ any_position_valid = true;
+ INodeDefManager *nodedef = gamedef->getNodeDefManager();
+ const ContentFeatures &f = nodedef->get(n);
+ if(f.walkable == false)
+ continue;
+ int n_bouncy_value = itemgroup_get(f.groups, "bouncy");
+
+ int neighbors = 0;
+ if (f.drawtype == NDT_NODEBOX && f.node_box.type == NODEBOX_CONNECTED) {
+ v3s16 p2 = p;
+
+ p2.Y++;
+ getNeighborConnectingFace(p2, nodedef, map, n, 1, &neighbors);
+
+ p2 = p;
+ p2.Y--;
+ getNeighborConnectingFace(p2, nodedef, map, n, 2, &neighbors);
+
+ p2 = p;
+ p2.Z--;
+ getNeighborConnectingFace(p2, nodedef, map, n, 4, &neighbors);
+
+ p2 = p;
+ p2.X--;
+ getNeighborConnectingFace(p2, nodedef, map, n, 8, &neighbors);
+
+ p2 = p;
+ p2.Z++;
+ getNeighborConnectingFace(p2, nodedef, map, n, 16, &neighbors);
+
+ p2 = p;
+ p2.X++;
+ getNeighborConnectingFace(p2, nodedef, map, n, 32, &neighbors);
+ }
+ std::vector<aabb3f> nodeboxes;
+ n.getCollisionBoxes(gamedef->ndef(), &nodeboxes, neighbors);
+ for(std::vector<aabb3f>::iterator
+ i = nodeboxes.begin();
+ i != nodeboxes.end(); ++i)
+ {
+ aabb3f box = *i;
+ box.MinEdge += v3f(x, y, z)*BS;
+ box.MaxEdge += v3f(x, y, z)*BS;
+ cinfo.push_back(NearbyCollisionInfo(false,
+ false, n_bouncy_value, p, box));
+ }
+ } else {
+ // Collide with unloaded nodes
+ aabb3f box = getNodeBox(p, BS);
+ cinfo.push_back(NearbyCollisionInfo(true, false, 0, p, box));
+ }
+ }
+
+ // Do not move if world has not loaded yet, since custom node boxes
+ // are not available for collision detection.
+ if (!any_position_valid) {
+ *speed_f = v3f(0, 0, 0);
+ return result;
+ }
+
+ } // tt2
+
+ if(collideWithObjects)
+ {
+ ScopeProfiler sp(g_profiler, "collisionMoveSimple objects avg", SPT_AVG);
+ //TimeTaker tt3("collisionMoveSimple collect object boxes");
+
+ /* add object boxes to cinfo */
+
+ std::vector<ActiveObject*> objects;
+#ifndef SERVER
+ ClientEnvironment *c_env = dynamic_cast<ClientEnvironment*>(env);
+ if (c_env != 0) {
+ f32 distance = speed_f->getLength();
+ std::vector<DistanceSortedActiveObject> clientobjects;
+ c_env->getActiveObjects(*pos_f, distance * 1.5, clientobjects);
+ for (size_t i=0; i < clientobjects.size(); i++) {
+ if ((self == 0) || (self != clientobjects[i].obj)) {
+ objects.push_back((ActiveObject*)clientobjects[i].obj);
+ }
+ }
+ }
+ else
+#endif
+ {
+ ServerEnvironment *s_env = dynamic_cast<ServerEnvironment*>(env);
+ if (s_env != NULL) {
+ f32 distance = speed_f->getLength();
+ std::vector<u16> s_objects;
+ s_env->getObjectsInsideRadius(s_objects, *pos_f, distance * 1.5);
+ for (std::vector<u16>::iterator iter = s_objects.begin(); iter != s_objects.end(); ++iter) {
+ ServerActiveObject *current = s_env->getActiveObject(*iter);
+ if ((self == 0) || (self != current)) {
+ objects.push_back((ActiveObject*)current);
+ }
+ }
+ }
+ }
+
+ for (std::vector<ActiveObject*>::const_iterator iter = objects.begin();
+ iter != objects.end(); ++iter) {
+ ActiveObject *object = *iter;
+
+ if (object != NULL) {
+ aabb3f object_collisionbox;
+ if (object->getCollisionBox(&object_collisionbox) &&
+ object->collideWithObjects()) {
+ cinfo.push_back(NearbyCollisionInfo(false, true, 0, v3s16(), object_collisionbox));
+ }
+ }
+ }
+ } //tt3