From 3a91bdb89d0a8f9ca39a41ed143bcd3cd984dc89 Mon Sep 17 00:00:00 2001 From: zicodxx Date: Mon, 24 Jan 2011 20:37:47 +0100 Subject: [PATCH] Added some new conditions to the bumping code: Only bump objects which can slide (alive robots and players) and added a count making sure this function can never get stuck in an infinite loop --- CHANGELOG.txt | 1 + main/physics.c | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 1aa57d70a..8450393c4 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -3,6 +3,7 @@ D2X-Rebirth Changelog 20110124 -------- main/physics.c: Revamped what previously was the BUMP_HACK by checking if an object is actually intersecting a segment and move it out towards segment center just after the initial object movement composed by fvi and before velocity is made - should make inaccurate wall collisions a bit smoother and prevent objects from goind inside or through walls, too +main/physics.c: Added some new conditions to the bumping code: Only bump objects which can slide (alive robots and players) and added a count making sure this function can never get stuck in an infinite loop 20110123 -------- diff --git a/main/physics.c b/main/physics.c index d1619c0a7..98fd9e7e0 100644 --- a/main/physics.c +++ b/main/physics.c @@ -310,7 +310,7 @@ void do_physics_sim(object *obj) int fate=0; vms_vector frame_vec; //movement in this frame vms_vector new_pos,ipos; //position after this frame - int count=0; + int count=0,bumpcount=0; int objnum; int WallHitSeg, WallHitSide; fvi_info hit_info; @@ -514,14 +514,15 @@ void do_physics_sim(object *obj) * 1) object_intersects_wall() does not say how far we went inside the wall which is why we use while to move out until we do not intersect anymore. This should be improved so we only move one time. * 2) we move the object towards segment center. Depending on the level architecture this is safe. However this will heavily influence velocity and reduce sliding speed near joining edges. Also depending on velocity it's still possible we might not pass an endge leading into another segment since we are pulled back to the old one. */ - while (object_intersects_wall(obj)) - { - vms_vector center,bump_vec; - //bump player a little towards center of segment to unstick - compute_segment_center(¢er,&Segments[iseg]); - vm_vec_normalized_dir_quick(&bump_vec,¢er,&obj->pos); - vm_vec_scale_add2(&obj->pos,&bump_vec,F0_1); - } + if ((obj->type == OBJ_PLAYER || obj->type == OBJ_ROBOT) && !(obj->flags&OF_SHOULD_BE_DEAD)) + while (object_intersects_wall(obj) && bumpcount++ < 64) + { + vms_vector center,bump_vec; + //bump player a little towards center of segment to unstick + compute_segment_center(¢er,&Segments[iseg]); + vm_vec_normalized_dir_quick(&bump_vec,¢er,&obj->pos); + vm_vec_scale_add2(&obj->pos,&bump_vec,F0_1); + } //if start point not in segment, move object to center of segment if (get_seg_masks(&obj->pos, obj->segnum, 0, __FILE__, __LINE__).centermask !=0 )