@@ -379,16 +379,14 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
379
379
380
380
int loopcount = 0 ;
381
381
382
- while (dtime > BS*1e-10 )
383
- {
382
+ while (dtime > BS * 1e-10 ) {
384
383
// TimeTaker tt3("collisionMoveSimple dtime loop");
385
384
ScopeProfiler sp (g_profiler, " collisionMoveSimple dtime loop avg" , SPT_AVG);
386
385
387
386
// Avoid infinite loop
388
387
loopcount++;
389
- if (loopcount >= 100 )
390
- {
391
- warningstream<<" collisionMoveSimple: Loop count exceeded, aborting to avoid infiniite loop" <<std::endl;
388
+ if (loopcount >= 100 ) {
389
+ warningstream << " collisionMoveSimple: Loop count exceeded, aborting to avoid infiniite loop" << std::endl;
392
390
dtime = 0 ;
393
391
break ;
394
392
}
@@ -404,8 +402,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
404
402
/*
405
403
Go through every nodebox, find nearest collision
406
404
*/
407
- for (u32 boxindex = 0 ; boxindex < cboxes.size (); boxindex++)
408
- {
405
+ for (u32 boxindex = 0 ; boxindex < cboxes.size (); boxindex++) {
409
406
// Ignore if already stepped up this nodebox.
410
407
if (is_step_up[boxindex])
411
408
continue ;
@@ -415,26 +412,22 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
415
412
int collided = axisAlignedCollision (
416
413
cboxes[boxindex], movingbox, speed_f, d, dtime_tmp);
417
414
418
- if (collided == -1 || dtime_tmp >= nearest_dtime)
415
+ if (collided == -1 || dtime_tmp >= nearest_dtime)
419
416
continue ;
420
417
421
418
nearest_dtime = dtime_tmp;
422
419
nearest_collided = collided;
423
420
nearest_boxindex = boxindex;
424
421
}
425
422
426
- if (nearest_collided == -1 )
427
- {
423
+ if (nearest_collided == -1 ) {
428
424
// No collision with any collision box.
429
425
pos_f += speed_f * dtime;
430
426
dtime = 0 ; // Set to 0 to avoid "infinite" loop due to small FP numbers
431
- }
432
- else
433
- {
427
+ } else {
434
428
// Otherwise, a collision occurred.
435
429
436
430
const aabb3f& cbox = cboxes[nearest_boxindex];
437
-
438
431
// Check for stairs.
439
432
bool step_up = (nearest_collided != 1 ) && // must not be Y direction
440
433
(movingbox.MinEdge .Y < cbox.MaxEdge .Y ) &&
@@ -448,67 +441,56 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
448
441
float bounce = -(float )bouncy_values[nearest_boxindex] / 100.0 ;
449
442
450
443
// Move to the point of collision and reduce dtime by nearest_dtime
451
- if (nearest_dtime < 0 )
452
- {
444
+ if (nearest_dtime < 0 ) {
453
445
// Handle negative nearest_dtime (can be caused by the d allowance)
454
- if (!step_up)
455
- {
456
- if (nearest_collided == 0 )
446
+ if (!step_up) {
447
+ if (nearest_collided == 0 )
457
448
pos_f.X += speed_f.X * nearest_dtime;
458
- if (nearest_collided == 1 )
449
+ if (nearest_collided == 1 )
459
450
pos_f.Y += speed_f.Y * nearest_dtime;
460
- if (nearest_collided == 2 )
451
+ if (nearest_collided == 2 )
461
452
pos_f.Z += speed_f.Z * nearest_dtime;
462
453
}
463
- }
464
- else
465
- {
454
+ } else {
466
455
pos_f += speed_f * nearest_dtime;
467
456
dtime -= nearest_dtime;
468
457
}
469
458
470
459
bool is_collision = true ;
471
- if (is_unloaded[nearest_boxindex])
460
+ if (is_unloaded[nearest_boxindex])
472
461
is_collision = false ;
473
462
474
463
CollisionInfo info;
475
- if (is_object[nearest_boxindex]) {
464
+ if (is_object[nearest_boxindex])
476
465
info.type = COLLISION_OBJECT;
477
- }
478
- else {
466
+ else
479
467
info.type = COLLISION_NODE;
480
- }
468
+
481
469
info.node_p = node_positions[nearest_boxindex];
482
470
info.bouncy = bouncy;
483
471
info.old_speed = speed_f;
484
472
485
473
// Set the speed component that caused the collision to zero
486
- if (step_up)
487
- {
474
+ if (step_up) {
488
475
// Special case: Handle stairs
489
476
is_step_up[nearest_boxindex] = true ;
490
477
is_collision = false ;
491
- }
492
- else if (nearest_collided == 0 ) // X
493
- {
494
- if (fabs (speed_f.X ) > BS*3 )
478
+ } else if (nearest_collided == 0 ) { // X
479
+ if (fabs (speed_f.X ) > BS * 3 )
495
480
speed_f.X *= bounce;
496
481
else
497
482
speed_f.X = 0 ;
498
483
result.collides = true ;
499
484
result.collides_xz = true ;
500
485
}
501
- else if (nearest_collided == 1 ) // Y
502
- {
503
- if (fabs (speed_f.Y ) > BS*3 )
486
+ else if (nearest_collided == 1 ) { // Y
487
+ if (fabs (speed_f.Y ) > BS * 3 )
504
488
speed_f.Y *= bounce;
505
489
else
506
490
speed_f.Y = 0 ;
507
491
result.collides = true ;
508
- }
509
- else if (nearest_collided == 2 ) // Z
510
- {
511
- if (fabs (speed_f.Z ) > BS*3 )
492
+ } else if (nearest_collided == 2 ) { // Z
493
+ if (fabs (speed_f.Z ) > BS * 3 )
512
494
speed_f.Z *= bounce;
513
495
else
514
496
speed_f.Z = 0 ;
@@ -517,10 +499,10 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
517
499
}
518
500
519
501
info.new_speed = speed_f;
520
- if (info.new_speed .getDistanceFrom (info.old_speed ) < 0.1 * BS)
502
+ if (info.new_speed .getDistanceFrom (info.old_speed ) < 0.1 * BS)
521
503
is_collision = false ;
522
504
523
- if (is_collision){
505
+ if (is_collision) {
524
506
result.collisions .push_back (info);
525
507
}
526
508
}
@@ -532,8 +514,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
532
514
aabb3f box = box_0;
533
515
box.MinEdge += pos_f;
534
516
box.MaxEdge += pos_f;
535
- for (u32 boxindex = 0 ; boxindex < cboxes.size (); boxindex++)
536
- {
517
+ for (u32 boxindex = 0 ; boxindex < cboxes.size (); boxindex++) {
537
518
const aabb3f& cbox = cboxes[boxindex];
538
519
539
520
/*
@@ -545,23 +526,21 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
545
526
546
527
Use 0.15*BS so that it is easier to get on a node.
547
528
*/
548
- if (
549
- cbox.MaxEdge .X -d > box.MinEdge .X &&
550
- cbox.MinEdge .X +d < box.MaxEdge .X &&
551
- cbox.MaxEdge .Z -d > box.MinEdge .Z &&
552
- cbox.MinEdge .Z +d < box.MaxEdge .Z
553
- ){
554
- if (is_step_up[boxindex])
555
- {
529
+ if (cbox.MaxEdge .X - d > box.MinEdge .X && cbox.MinEdge .X + d < box.MaxEdge .X &&
530
+ cbox.MaxEdge .Z - d > box.MinEdge .Z &&
531
+ cbox.MinEdge .Z + d < box.MaxEdge .Z ) {
532
+ if (is_step_up[boxindex]) {
556
533
pos_f.Y += (cbox.MaxEdge .Y - box.MinEdge .Y );
557
534
box = box_0;
558
535
box.MinEdge += pos_f;
559
536
box.MaxEdge += pos_f;
560
537
}
561
- if (fabs (cbox.MaxEdge .Y -box.MinEdge .Y ) < 0.15 *BS)
562
- {
538
+ if (fabs (cbox.MaxEdge .Y - box.MinEdge .Y ) < 0.15 * BS) {
563
539
result.touching_ground = true ;
564
- if (is_unloaded[boxindex])
540
+
541
+ if (is_object[boxindex])
542
+ result.standing_on_object = true ;
543
+ if (is_unloaded[boxindex])
565
544
result.standing_on_unloaded = true ;
566
545
}
567
546
}
1 commit comments
HybridDog commentedon Oct 31, 2015
If you stand on an object and it suddenly moves up, you fall through it, don't you?
Maybe you could assign the player to it if he/she is standing on it.