]> git.lizzy.rs Git - minetest.git/blob - src/collision.cpp
Fix memory leaks due to messed up memory handling for particles as well as their...
[minetest.git] / src / collision.cpp
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include "collision.h"
21 #include "mapblock.h"
22 #include "map.h"
23 #include "nodedef.h"
24 #include "gamedef.h"
25 #include "log.h"
26 #include "environment.h"
27 #include "serverobject.h"
28 #include <vector>
29 #include <set>
30 #include "util/timetaker.h"
31 #include "main.h" // g_profiler
32 #include "profiler.h"
33
34 // float error is 10 - 9.96875 = 0.03125
35 //#define COLL_ZERO 0.032 // broken unit tests
36 #define COLL_ZERO 0
37
38 // Helper function:
39 // Checks for collision of a moving aabbox with a static aabbox
40 // Returns -1 if no collision, 0 if X collision, 1 if Y collision, 2 if Z collision
41 // The time after which the collision occurs is stored in dtime.
42 int axisAlignedCollision(
43                 const aabb3f &staticbox, const aabb3f &movingbox,
44                 const v3f &speed, f32 d, f32 &dtime)
45 {
46         //TimeTaker tt("axisAlignedCollision");
47
48         f32 xsize = (staticbox.MaxEdge.X - staticbox.MinEdge.X) - COLL_ZERO;     // reduce box size for solve collision stuck (flying sand)
49         f32 ysize = (staticbox.MaxEdge.Y - staticbox.MinEdge.Y); // - COLL_ZERO; // Y - no sense for falling, but maybe try later
50         f32 zsize = (staticbox.MaxEdge.Z - staticbox.MinEdge.Z) - COLL_ZERO;
51
52         aabb3f relbox(
53                         movingbox.MinEdge.X - staticbox.MinEdge.X,
54                         movingbox.MinEdge.Y - staticbox.MinEdge.Y,
55                         movingbox.MinEdge.Z - staticbox.MinEdge.Z,
56                         movingbox.MaxEdge.X - staticbox.MinEdge.X,
57                         movingbox.MaxEdge.Y - staticbox.MinEdge.Y,
58                         movingbox.MaxEdge.Z - staticbox.MinEdge.Z
59         );
60
61         if(speed.X > 0) // Check for collision with X- plane
62         {
63                 if(relbox.MaxEdge.X <= d)
64                 {
65                         dtime = - relbox.MaxEdge.X / speed.X;
66                         if((relbox.MinEdge.Y + speed.Y * dtime < ysize) &&
67                                         (relbox.MaxEdge.Y + speed.Y * dtime > COLL_ZERO) &&
68                                         (relbox.MinEdge.Z + speed.Z * dtime < zsize) &&
69                                         (relbox.MaxEdge.Z + speed.Z * dtime > COLL_ZERO))
70                                 return 0;
71                 }
72                 else if(relbox.MinEdge.X > xsize)
73                 {
74                         return -1;
75                 }
76         }
77         else if(speed.X < 0) // Check for collision with X+ plane
78         {
79                 if(relbox.MinEdge.X >= xsize - d)
80                 {
81                         dtime = (xsize - relbox.MinEdge.X) / speed.X;
82                         if((relbox.MinEdge.Y + speed.Y * dtime < ysize) &&
83                                         (relbox.MaxEdge.Y + speed.Y * dtime > COLL_ZERO) &&
84                                         (relbox.MinEdge.Z + speed.Z * dtime < zsize) &&
85                                         (relbox.MaxEdge.Z + speed.Z * dtime > COLL_ZERO))
86                                 return 0;
87                 }
88                 else if(relbox.MaxEdge.X < 0)
89                 {
90                         return -1;
91                 }
92         }
93
94         // NO else if here
95
96         if(speed.Y > 0) // Check for collision with Y- plane
97         {
98                 if(relbox.MaxEdge.Y <= d)
99                 {
100                         dtime = - relbox.MaxEdge.Y / speed.Y;
101                         if((relbox.MinEdge.X + speed.X * dtime < xsize) &&
102                                         (relbox.MaxEdge.X + speed.X * dtime > COLL_ZERO) &&
103                                         (relbox.MinEdge.Z + speed.Z * dtime < zsize) &&
104                                         (relbox.MaxEdge.Z + speed.Z * dtime > COLL_ZERO))
105                                 return 1;
106                 }
107                 else if(relbox.MinEdge.Y > ysize)
108                 {
109                         return -1;
110                 }
111         }
112         else if(speed.Y < 0) // Check for collision with Y+ plane
113         {
114                 if(relbox.MinEdge.Y >= ysize - d)
115                 {
116                         dtime = (ysize - relbox.MinEdge.Y) / speed.Y;
117                         if((relbox.MinEdge.X + speed.X * dtime < xsize) &&
118                                         (relbox.MaxEdge.X + speed.X * dtime > COLL_ZERO) &&
119                                         (relbox.MinEdge.Z + speed.Z * dtime < zsize) &&
120                                         (relbox.MaxEdge.Z + speed.Z * dtime > COLL_ZERO))
121                                 return 1;
122                 }
123                 else if(relbox.MaxEdge.Y < 0)
124                 {
125                         return -1;
126                 }
127         }
128
129         // NO else if here
130
131         if(speed.Z > 0) // Check for collision with Z- plane
132         {
133                 if(relbox.MaxEdge.Z <= d)
134                 {
135                         dtime = - relbox.MaxEdge.Z / speed.Z;
136                         if((relbox.MinEdge.X + speed.X * dtime < xsize) &&
137                                         (relbox.MaxEdge.X + speed.X * dtime > COLL_ZERO) &&
138                                         (relbox.MinEdge.Y + speed.Y * dtime < ysize) &&
139                                         (relbox.MaxEdge.Y + speed.Y * dtime > COLL_ZERO))
140                                 return 2;
141                 }
142                 //else if(relbox.MinEdge.Z > zsize)
143                 //{
144                 //      return -1;
145                 //}
146         }
147         else if(speed.Z < 0) // Check for collision with Z+ plane
148         {
149                 if(relbox.MinEdge.Z >= zsize - d)
150                 {
151                         dtime = (zsize - relbox.MinEdge.Z) / speed.Z;
152                         if((relbox.MinEdge.X + speed.X * dtime < xsize) &&
153                                         (relbox.MaxEdge.X + speed.X * dtime > COLL_ZERO) &&
154                                         (relbox.MinEdge.Y + speed.Y * dtime < ysize) &&
155                                         (relbox.MaxEdge.Y + speed.Y * dtime > COLL_ZERO))
156                                 return 2;
157                 }
158                 //else if(relbox.MaxEdge.Z < 0)
159                 //{
160                 //      return -1;
161                 //}
162         }
163
164         return -1;
165 }
166
167 // Helper function:
168 // Checks if moving the movingbox up by the given distance would hit a ceiling.
169 bool wouldCollideWithCeiling(
170                 const std::vector<aabb3f> &staticboxes,
171                 const aabb3f &movingbox,
172                 f32 y_increase, f32 d)
173 {
174         //TimeTaker tt("wouldCollideWithCeiling");
175
176         assert(y_increase >= 0);
177
178         for(std::vector<aabb3f>::const_iterator
179                         i = staticboxes.begin();
180                         i != staticboxes.end(); i++)
181         {
182                 const aabb3f& staticbox = *i;
183                 if((movingbox.MaxEdge.Y - d <= staticbox.MinEdge.Y) &&
184                                 (movingbox.MaxEdge.Y + y_increase > staticbox.MinEdge.Y) &&
185                                 (movingbox.MinEdge.X < staticbox.MaxEdge.X) &&
186                                 (movingbox.MaxEdge.X > staticbox.MinEdge.X) &&
187                                 (movingbox.MinEdge.Z < staticbox.MaxEdge.Z) &&
188                                 (movingbox.MaxEdge.Z > staticbox.MinEdge.Z))
189                         return true;
190         }
191
192         return false;
193 }
194
195
196 collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
197                 f32 pos_max_d, const aabb3f &box_0,
198                 f32 stepheight, f32 dtime,
199                 v3f &pos_f, v3f &speed_f,
200                 v3f &accel_f,ActiveObject* self,
201                 bool collideWithObjects)
202 {
203         Map *map = &env->getMap();
204         //TimeTaker tt("collisionMoveSimple");
205     ScopeProfiler sp(g_profiler, "collisionMoveSimple avg", SPT_AVG);
206
207         collisionMoveResult result;
208
209         /*
210                 Calculate new velocity
211         */
212         if( dtime > 0.5 ) {
213                 infostream<<"collisionMoveSimple: WARNING: maximum step interval exceeded, lost movement details!"<<std::endl;
214                 dtime = 0.5;
215         }
216         speed_f += accel_f * dtime;
217
218         // If there is no speed, there are no collisions
219         if(speed_f.getLength() == 0)
220                 return result;
221
222         // Limit speed for avoiding hangs
223         speed_f.Y=rangelim(speed_f.Y,-5000,5000);
224         speed_f.X=rangelim(speed_f.X,-5000,5000);
225         speed_f.Z=rangelim(speed_f.Z,-5000,5000);
226
227         /*
228                 Collect node boxes in movement range
229         */
230         std::vector<aabb3f> cboxes;
231         std::vector<bool> is_unloaded;
232         std::vector<bool> is_step_up;
233         std::vector<bool> is_object;
234         std::vector<int> bouncy_values;
235         std::vector<v3s16> node_positions;
236         {
237         //TimeTaker tt2("collisionMoveSimple collect boxes");
238     ScopeProfiler sp(g_profiler, "collisionMoveSimple collect boxes avg", SPT_AVG);
239
240         v3s16 oldpos_i = floatToInt(pos_f, BS);
241         v3s16 newpos_i = floatToInt(pos_f + speed_f * dtime, BS);
242         s16 min_x = MYMIN(oldpos_i.X, newpos_i.X) + (box_0.MinEdge.X / BS) - 1;
243         s16 min_y = MYMIN(oldpos_i.Y, newpos_i.Y) + (box_0.MinEdge.Y / BS) - 1;
244         s16 min_z = MYMIN(oldpos_i.Z, newpos_i.Z) + (box_0.MinEdge.Z / BS) - 1;
245         s16 max_x = MYMAX(oldpos_i.X, newpos_i.X) + (box_0.MaxEdge.X / BS) + 1;
246         s16 max_y = MYMAX(oldpos_i.Y, newpos_i.Y) + (box_0.MaxEdge.Y / BS) + 1;
247         s16 max_z = MYMAX(oldpos_i.Z, newpos_i.Z) + (box_0.MaxEdge.Z / BS) + 1;
248
249         for(s16 x = min_x; x <= max_x; x++)
250         for(s16 y = min_y; y <= max_y; y++)
251         for(s16 z = min_z; z <= max_z; z++)
252         {
253                 v3s16 p(x,y,z);
254
255                 bool is_position_valid;
256                 MapNode n = map->getNodeNoEx(p, &is_position_valid);
257
258                 if (is_position_valid) {
259                         // Object collides into walkable nodes
260
261                         const ContentFeatures &f = gamedef->getNodeDefManager()->get(n);
262                         if(f.walkable == false)
263                                 continue;
264                         int n_bouncy_value = itemgroup_get(f.groups, "bouncy");
265
266                         std::vector<aabb3f> nodeboxes = n.getCollisionBoxes(gamedef->ndef());
267                         for(std::vector<aabb3f>::iterator
268                                         i = nodeboxes.begin();
269                                         i != nodeboxes.end(); i++)
270                         {
271                                 aabb3f box = *i;
272                                 box.MinEdge += v3f(x, y, z)*BS;
273                                 box.MaxEdge += v3f(x, y, z)*BS;
274                                 cboxes.push_back(box);
275                                 is_unloaded.push_back(false);
276                                 is_step_up.push_back(false);
277                                 bouncy_values.push_back(n_bouncy_value);
278                                 node_positions.push_back(p);
279                                 is_object.push_back(false);
280                         }
281                 }
282                 else {
283                         // Collide with unloaded nodes
284                         aabb3f box = getNodeBox(p, BS);
285                         cboxes.push_back(box);
286                         is_unloaded.push_back(true);
287                         is_step_up.push_back(false);
288                         bouncy_values.push_back(0);
289                         node_positions.push_back(p);
290                         is_object.push_back(false);
291                 }
292         }
293         } // tt2
294
295         if(collideWithObjects)
296         {
297                 ScopeProfiler sp(g_profiler, "collisionMoveSimple objects avg", SPT_AVG);
298                 //TimeTaker tt3("collisionMoveSimple collect object boxes");
299
300                 /* add object boxes to cboxes */
301
302
303                 std::list<ActiveObject*> objects;
304 #ifndef SERVER
305                 ClientEnvironment *c_env = dynamic_cast<ClientEnvironment*>(env);
306                 if (c_env != 0)
307                 {
308                         f32 distance = speed_f.getLength();
309                         std::vector<DistanceSortedActiveObject> clientobjects;
310                         c_env->getActiveObjects(pos_f,distance * 1.5,clientobjects);
311                         for (size_t i=0; i < clientobjects.size(); i++)
312                         {
313                                 if ((self == 0) || (self != clientobjects[i].obj)) {
314                                         objects.push_back((ActiveObject*)clientobjects[i].obj);
315                                 }
316                         }
317                 }
318                 else
319 #endif
320                 {
321                         ServerEnvironment *s_env = dynamic_cast<ServerEnvironment*>(env);
322                         if (s_env != 0)
323                         {
324                                 f32 distance = speed_f.getLength();
325                                 std::set<u16> s_objects = s_env->getObjectsInsideRadius(pos_f,distance * 1.5);
326                                 for (std::set<u16>::iterator iter = s_objects.begin(); iter != s_objects.end(); iter++)
327                                 {
328                                         ServerActiveObject *current = s_env->getActiveObject(*iter);
329                                         if ((self == 0) || (self != current)) {
330                                                 objects.push_back((ActiveObject*)current);
331                                         }
332                                 }
333                         }
334                 }
335
336                 for (std::list<ActiveObject*>::const_iterator iter = objects.begin();iter != objects.end(); ++iter)
337                 {
338                         ActiveObject *object = *iter;
339
340                         if (object != NULL)
341                         {
342                                 aabb3f object_collisionbox;
343                                 if (object->getCollisionBox(&object_collisionbox) &&
344                                                 object->collideWithObjects())
345                                 {
346                                         cboxes.push_back(object_collisionbox);
347                                         is_unloaded.push_back(false);
348                                         is_step_up.push_back(false);
349                                         bouncy_values.push_back(0);
350                                         node_positions.push_back(v3s16(0,0,0));
351                                         is_object.push_back(true);
352                                 }
353                         }
354                 }
355         } //tt3
356
357         assert(cboxes.size() == is_unloaded.size());
358         assert(cboxes.size() == is_step_up.size());
359         assert(cboxes.size() == bouncy_values.size());
360         assert(cboxes.size() == node_positions.size());
361         assert(cboxes.size() == is_object.size());
362
363         /*
364                 Collision detection
365         */
366
367         /*
368                 Collision uncertainty radius
369                 Make it a bit larger than the maximum distance of movement
370         */
371         f32 d = pos_max_d * 1.1;
372         // A fairly large value in here makes moving smoother
373         //f32 d = 0.15*BS;
374
375         // This should always apply, otherwise there are glitches
376         assert(d > pos_max_d);
377
378         int loopcount = 0;
379
380         while(dtime > BS*1e-10)
381         {
382                 //TimeTaker tt3("collisionMoveSimple dtime loop");
383         ScopeProfiler sp(g_profiler, "collisionMoveSimple dtime loop avg", SPT_AVG);
384
385                 // Avoid infinite loop
386                 loopcount++;
387                 if(loopcount >= 100)
388                 {
389                         infostream<<"collisionMoveSimple: WARNING: Loop count exceeded, aborting to avoid infiniite loop"<<std::endl;
390                         dtime = 0;
391                         break;
392                 }
393
394                 aabb3f movingbox = box_0;
395                 movingbox.MinEdge += pos_f;
396                 movingbox.MaxEdge += pos_f;
397
398                 int nearest_collided = -1;
399                 f32 nearest_dtime = dtime;
400                 u32 nearest_boxindex = -1;
401
402                 /*
403                         Go through every nodebox, find nearest collision
404                 */
405                 for(u32 boxindex = 0; boxindex < cboxes.size(); boxindex++)
406                 {
407                         // Ignore if already stepped up this nodebox.
408                         if(is_step_up[boxindex])
409                                 continue;
410
411                         // Find nearest collision of the two boxes (raytracing-like)
412                         f32 dtime_tmp;
413                         int collided = axisAlignedCollision(
414                                         cboxes[boxindex], movingbox, speed_f, d, dtime_tmp);
415
416                         if(collided == -1 || dtime_tmp >= nearest_dtime)
417                                 continue;
418
419                         nearest_dtime = dtime_tmp;
420                         nearest_collided = collided;
421                         nearest_boxindex = boxindex;
422                 }
423
424                 if(nearest_collided == -1)
425                 {
426                         // No collision with any collision box.
427                         pos_f += speed_f * dtime;
428                         dtime = 0;  // Set to 0 to avoid "infinite" loop due to small FP numbers
429                 }
430                 else
431                 {
432                         // Otherwise, a collision occurred.
433
434                         const aabb3f& cbox = cboxes[nearest_boxindex];
435
436                         // Check for stairs.
437                         bool step_up = (nearest_collided != 1) && // must not be Y direction
438                                         (movingbox.MinEdge.Y < cbox.MaxEdge.Y) &&
439                                         (movingbox.MinEdge.Y + stepheight > cbox.MaxEdge.Y) &&
440                                         (!wouldCollideWithCeiling(cboxes, movingbox,
441                                                         cbox.MaxEdge.Y - movingbox.MinEdge.Y,
442                                                         d));
443
444                         // Get bounce multiplier
445                         bool bouncy = (bouncy_values[nearest_boxindex] >= 1);
446                         float bounce = -(float)bouncy_values[nearest_boxindex] / 100.0;
447
448                         // Move to the point of collision and reduce dtime by nearest_dtime
449                         if(nearest_dtime < 0)
450                         {
451                                 // Handle negative nearest_dtime (can be caused by the d allowance)
452                                 if(!step_up)
453                                 {
454                                         if(nearest_collided == 0)
455                                                 pos_f.X += speed_f.X * nearest_dtime;
456                                         if(nearest_collided == 1)
457                                                 pos_f.Y += speed_f.Y * nearest_dtime;
458                                         if(nearest_collided == 2)
459                                                 pos_f.Z += speed_f.Z * nearest_dtime;
460                                 }
461                         }
462                         else
463                         {
464                                 pos_f += speed_f * nearest_dtime;
465                                 dtime -= nearest_dtime;
466                         }
467                         
468                         bool is_collision = true;
469                         if(is_unloaded[nearest_boxindex])
470                                 is_collision = false;
471
472                         CollisionInfo info;
473                         if (is_object[nearest_boxindex]) {
474                                 info.type = COLLISION_OBJECT;
475                         }
476                         else {
477                                 info.type = COLLISION_NODE;
478                         }
479                         info.node_p = node_positions[nearest_boxindex];
480                         info.bouncy = bouncy;
481                         info.old_speed = speed_f;
482
483                         // Set the speed component that caused the collision to zero
484                         if(step_up)
485                         {
486                                 // Special case: Handle stairs
487                                 is_step_up[nearest_boxindex] = true;
488                                 is_collision = false;
489                         }
490                         else if(nearest_collided == 0) // X
491                         {
492                                 if(fabs(speed_f.X) > BS*3)
493                                         speed_f.X *= bounce;
494                                 else
495                                         speed_f.X = 0;
496                                 result.collides = true;
497                                 result.collides_xz = true;
498                         }
499                         else if(nearest_collided == 1) // Y
500                         {
501                                 if(fabs(speed_f.Y) > BS*3)
502                                         speed_f.Y *= bounce;
503                                 else
504                                         speed_f.Y = 0;
505                                 result.collides = true;
506                         }
507                         else if(nearest_collided == 2) // Z
508                         {
509                                 if(fabs(speed_f.Z) > BS*3)
510                                         speed_f.Z *= bounce;
511                                 else
512                                         speed_f.Z = 0;
513                                 result.collides = true;
514                                 result.collides_xz = true;
515                         }
516
517                         info.new_speed = speed_f;
518                         if(info.new_speed.getDistanceFrom(info.old_speed) < 0.1*BS)
519                                 is_collision = false;
520
521                         if(is_collision){
522                                 result.collisions.push_back(info);
523                         }
524                 }
525         }
526
527         /*
528                 Final touches: Check if standing on ground, step up stairs.
529         */
530         aabb3f box = box_0;
531         box.MinEdge += pos_f;
532         box.MaxEdge += pos_f;
533         for(u32 boxindex = 0; boxindex < cboxes.size(); boxindex++)
534         {
535                 const aabb3f& cbox = cboxes[boxindex];
536
537                 /*
538                         See if the object is touching ground.
539
540                         Object touches ground if object's minimum Y is near node's
541                         maximum Y and object's X-Z-area overlaps with the node's
542                         X-Z-area.
543
544                         Use 0.15*BS so that it is easier to get on a node.
545                 */
546                 if(
547                                 cbox.MaxEdge.X-d > box.MinEdge.X &&
548                                 cbox.MinEdge.X+d < box.MaxEdge.X &&
549                                 cbox.MaxEdge.Z-d > box.MinEdge.Z &&
550                                 cbox.MinEdge.Z+d < box.MaxEdge.Z
551                 ){
552                         if(is_step_up[boxindex])
553                         {
554                                 pos_f.Y += (cbox.MaxEdge.Y - box.MinEdge.Y);
555                                 box = box_0;
556                                 box.MinEdge += pos_f;
557                                 box.MaxEdge += pos_f;
558                         }
559                         if(fabs(cbox.MaxEdge.Y-box.MinEdge.Y) < 0.15*BS)
560                         {
561                                 result.touching_ground = true;
562                                 if(is_unloaded[boxindex])
563                                         result.standing_on_unloaded = true;
564                         }
565                 }
566         }
567
568         return result;
569 }
570
571 #if 0
572 // This doesn't seem to work and isn't used
573 collisionMoveResult collisionMovePrecise(Map *map, IGameDef *gamedef,
574                 f32 pos_max_d, const aabb3f &box_0,
575                 f32 stepheight, f32 dtime,
576                 v3f &pos_f, v3f &speed_f, v3f &accel_f)
577 {
578         //TimeTaker tt("collisionMovePrecise");
579     ScopeProfiler sp(g_profiler, "collisionMovePrecise avg", SPT_AVG);
580         
581         collisionMoveResult final_result;
582
583         // If there is no speed, there are no collisions
584         if(speed_f.getLength() == 0)
585                 return final_result;
586
587         // Don't allow overly huge dtime
588         if(dtime > 2.0)
589                 dtime = 2.0;
590
591         f32 dtime_downcount = dtime;
592
593         u32 loopcount = 0;
594         do
595         {
596                 loopcount++;
597
598                 // Maximum time increment (for collision detection etc)
599                 // time = distance / speed
600                 f32 dtime_max_increment = 1.0;
601                 if(speed_f.getLength() != 0)
602                         dtime_max_increment = pos_max_d / speed_f.getLength();
603
604                 // Maximum time increment is 10ms or lower
605                 if(dtime_max_increment > 0.01)
606                         dtime_max_increment = 0.01;
607
608                 f32 dtime_part;
609                 if(dtime_downcount > dtime_max_increment)
610                 {
611                         dtime_part = dtime_max_increment;
612                         dtime_downcount -= dtime_part;
613                 }
614                 else
615                 {
616                         dtime_part = dtime_downcount;
617                         /*
618                                 Setting this to 0 (no -=dtime_part) disables an infinite loop
619                                 when dtime_part is so small that dtime_downcount -= dtime_part
620                                 does nothing
621                         */
622                         dtime_downcount = 0;
623                 }
624
625                 collisionMoveResult result = collisionMoveSimple(map, gamedef,
626                                 pos_max_d, box_0, stepheight, dtime_part,
627                                 pos_f, speed_f, accel_f);
628
629                 if(result.touching_ground)
630                         final_result.touching_ground = true;
631                 if(result.collides)
632                         final_result.collides = true;
633                 if(result.collides_xz)
634                         final_result.collides_xz = true;
635                 if(result.standing_on_unloaded)
636                         final_result.standing_on_unloaded = true;
637         }
638         while(dtime_downcount > 0.001);
639
640         return final_result;
641 }
642 #endif