Skip to content

Commit

Permalink
Fixed friction stopping threshold
Browse files Browse the repository at this point in the history
The test for checking whether momentum was small enough
to stop completely was not working correctly.

Moved the logic to libcommon: Mobj_XYMoveStopping().
  • Loading branch information
skyjake committed Dec 18, 2011
1 parent 3d113d8 commit 8da6eb8
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 196 deletions.
2 changes: 2 additions & 0 deletions doomsday/plugins/common/common.pri
Expand Up @@ -30,6 +30,7 @@ HEADERS += \
$$common_inc/hu_stuff.h \
$$common_inc/m_argv.h \
$$common_inc/m_defs.h \
$$common_inc/mobj.h \
$$common_inc/p_actor.h \
$$common_inc/p_automap.h \
$$common_inc/p_ceiling.h \
Expand Down Expand Up @@ -81,6 +82,7 @@ SOURCES += \
$$common_src/m_ctrl.c \
$$common_src/m_fixed.c \
$$common_src/m_multi.c \
$$common_src/mobj.c \
$$common_src/p_actor.c \
$$common_src/p_automap.c \
$$common_src/p_ceiling.c \
Expand Down
1 change: 1 addition & 0 deletions doomsday/plugins/common/include/g_common.h
Expand Up @@ -31,6 +31,7 @@

#include "dd_share.h"
#include "g_controls.h"
#include "mobj.h"
#include "common.h"

#define OBSOLETE CVF_HIDE|CVF_NO_ARCHIVE
Expand Down
33 changes: 33 additions & 0 deletions doomsday/plugins/common/include/mobj.h
@@ -0,0 +1,33 @@
/**\file
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2003-2011 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2006-2011 Daniel Swanson <danij@dengine.net>
*\author Copyright © 1993-1996 by id Software, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/

#ifndef __LIBCOMMON_MOBJ__
#define __LIBCOMMON_MOBJ__

#include "g_common.h"

void Mobj_XYMoveStopping(mobj_t* mo);

#endif // __LIBCOMMON_MOBJ__
144 changes: 144 additions & 0 deletions doomsday/plugins/common/src/mobj.c
@@ -0,0 +1,144 @@
/**\file
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2003-2011 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2005-2011 Daniel Swanson <danij@dengine.net>
*\author Copyright © 1999 by Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman (PrBoom 2.2.6)
*\author Copyright © 1999-2000 by Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze (PrBoom 2.2.6)
*\author Copyright © 1993-1996 by id Software, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/

#ifdef MSVC
# pragma optimize("g", off)
#endif

// HEADER FILES ------------------------------------------------------------

#include <math.h>
#include <assert.h>
#include "mobj.h"
#include "dmu_lib.h"

#define VANISHTICS (2*TICSPERSEC)

#define MAX_BOB_OFFSET (8)

#define NOMOMENTUM_THRESHOLD (0.000001f)
#define WALKSTOP_THRESHOLD (0.062484741f) // FIX2FLT(0x1000-1)
#define DROPOFFMOMENTUM_THRESHOLD (1.0f / 4)

static float getFriction(mobj_t* mo)
{
if((mo->flags2 & MF2_FLY) && !(mo->pos[VZ] <= mo->floorZ) && !mo->onMobj)
{ // Airborne friction.
return FRICTION_FLY;
}

#ifdef __JHERETIC__
if(P_ToXSector(P_GetPtrp(mo->subsector, DMU_SECTOR))->special == 15)
{ // Friction_Low
return FRICTION_LOW;
}
#endif

return P_MobjGetFriction(mo);
}
/**
* Handles the stopping of mobj movement. Also stops player walking animation.
*
* @param mo Mobj.
*/
void Mobj_XYMoveStopping(mobj_t* mo)
{
player_t* player = mo->player;
boolean isVoodooDoll = false;
boolean belowWalkStop = false;

assert(mo != 0);

if(player && (P_GetPlayerCheats(player) & CF_NOMOMENTUM))
{
// Debug option for no sliding at all.
mo->mom[MX] = mo->mom[MY] = 0;
return;
}

if(mo->flags & (MF_MISSILE | MF_SKULLFLY))
{ // No friction for missiles.
return;
}

if(mo->pos[VZ] > mo->floorZ && !mo->onMobj && !(mo->flags2 & MF2_FLY))
{ // No friction when falling.
return;
}

#if __JDOOM__ || __JDOOM64__
if(cfg.slidingCorpses)
{
/**
* $dropoff_fix:
* Add objects falling off ledges. Does not apply to players!
*/
if(((mo->flags & MF_CORPSE) || (mo->intFlags & MIF_FALLING)) && !mo->player)
{
// Do not stop sliding if halfway off a step with some momentum.
if(!INRANGE_OF(mo->mom[MX], 0, DROPOFFMOMENTUM_THRESHOLD) ||
!INRANGE_OF(mo->mom[MY], 0, DROPOFFMOMENTUM_THRESHOLD))
{
if(mo->floorZ != P_GetFloatp(mo->subsector, DMU_FLOOR_HEIGHT))
return;
}
}
}
#endif

isVoodooDoll = (player && player->plr->mo != mo);
belowWalkStop = (INRANGE_OF(mo->mom[MX], 0, WALKSTOP_THRESHOLD) &&
INRANGE_OF(mo->mom[MY], 0, WALKSTOP_THRESHOLD));

// Stop player walking animation.
if(isVoodooDoll
|| (player && belowWalkStop &&
FEQUAL(player->plr->forwardMove, 0) &&
FEQUAL(player->plr->sideMove, 0)))
{
/// @todo Voodoo doll animation is not stopped, should it be?

// If in a walking frame, stop moving.
if(player && P_PlayerInWalkState(player) && player->plr->mo == mo)
P_MobjChangeState(player->plr->mo, PCLASS_INFO(player->class_)->normalState);

// $voodoodolls: Do not zero mom!
if(!isVoodooDoll)
{
mo->mom[MX] = mo->mom[MY] = 0;

// $voodoodolls: Stop view bobbing if this isn't a voodoo doll.
player->bob = 0;
}
}
else
{
float friction = getFriction(mo);
mo->mom[MX] *= friction;
mo->mom[MY] *= friction;
}
}
57 changes: 1 addition & 56 deletions doomsday/plugins/jdoom/src/p_mobj.c
Expand Up @@ -295,62 +295,7 @@ void P_MobjMoveXY(mobj_t *mo)
!INRANGE_OF(mom[MY], 0, NOMOMENTUM_THRESHOLD));

// Slow down.
if(player && (P_GetPlayerCheats(player) & CF_NOMOMENTUM))
{
// Debug option for no sliding at all.
mo->mom[MX] = mo->mom[MY] = 0;
return;
}

if(mo->flags & (MF_MISSILE | MF_SKULLFLY))
return; // No friction for missiles ever.

if(mo->pos[VZ] > mo->floorZ && !mo->onMobj && !(mo->flags2 & MF2_FLY))
return; // No friction when falling.

if(cfg.slidingCorpses)
{
// $dropoff_fix: Add objects falling off ledges, does not apply to
// players!
if(((mo->flags & MF_CORPSE) || (mo->intFlags & MIF_FALLING)) &&
!mo->player)
{
// Do not stop sliding if halfway off a step with some momentum.
if(!INRANGE_OF(mo->mom[MX], 0, DROPOFFMOMENTUM_THRESHOLD) ||
!INRANGE_OF(mo->mom[MY], 0, DROPOFFMOMENTUM_THRESHOLD))
{
if(mo->floorZ !=
P_GetFloatp(mo->subsector, DMU_FLOOR_HEIGHT))
return;
}
}
}

// Stop player walking animation.
if((!player || (!(player->plr->forwardMove || player->plr->sideMove) &&
player->plr->mo != mo /* $voodoodolls: Stop animating. */)) &&
INRANGE_OF(mo->mom[MX], 0, WALKSTOP_THRESHOLD) &&
INRANGE_OF(mo->mom[MY], 0, WALKSTOP_THRESHOLD))
{
// If in a walking frame, stop moving.
if(player && P_PlayerInWalkState(player) && player->plr->mo == mo)
P_MobjChangeState(player->plr->mo, PCLASS_INFO(player->class_)->normalState);

// $voodoodolls: Do not zero mom!
if(!(player && player->plr->mo != mo))
mo->mom[MX] = mo->mom[MY] = 0;

// $voodoodolls: Stop view bobbing if this isn't a voodoo doll.
if(player && player->plr->mo == mo)
player->bob = 0;
}
else
{
float friction = getFriction(mo);

mo->mom[MX] *= friction;
mo->mom[MY] *= friction;
}
Mobj_XYMoveStopping(mo);
}

/*
Expand Down
59 changes: 2 additions & 57 deletions doomsday/plugins/jdoom64/src/p_mobj.c
Expand Up @@ -297,63 +297,8 @@ void P_MobjMoveXY(mobj_t* mo)
} while(!INRANGE_OF(mom[MX], 0, NOMOMENTUM_THRESHOLD) ||
!INRANGE_OF(mom[MY], 0, NOMOMENTUM_THRESHOLD));

// Slow down.
if(player && (P_GetPlayerCheats(player) & CF_NOMOMENTUM))
{
// Debug option for no sliding at all.
mo->mom[MX] = mo->mom[MY] = 0;
return;
}

if(mo->flags & (MF_MISSILE | MF_SKULLFLY))
return; // No friction for missiles ever.

if(mo->pos[VZ] > mo->floorZ && !mo->onMobj && !(mo->flags2 & MF2_FLY))
return; // No friction when falling.

if(cfg.slidingCorpses)
{
// $dropoff_fix: Add objects falling off ledges, does not apply to
// players.
if(((mo->flags & MF_CORPSE) || (mo->intFlags & MIF_FALLING)) &&
!mo->player)
{
// Do not stop sliding if halfway off a step with some momentum.
if(mo->mom[MX] > (1.0f / 4) || mo->mom[MX] < -(1.0f / 4) ||
mo->mom[MY] > (1.0f / 4) || mo->mom[MY] < -(1.0f / 4))
{
if(mo->floorZ !=
P_GetFloatp(mo->subsector, DMU_FLOOR_HEIGHT))
return;
}
}
}

// Stop player walking animation.
if((!player || (!(player->plr->forwardMove || player->plr->sideMove) &&
player->plr->mo != mo /* $voodoodolls: Stop animating. */)) &&
INRANGE_OF(mo->mom[MX], 0, WALKSTOP_THRESHOLD) &&
INRANGE_OF(mo->mom[MY], 0, WALKSTOP_THRESHOLD))
{
// If in a walking frame, stop moving.
if(player && P_PlayerInWalkState(player) && player->plr->mo == mo)
P_MobjChangeState(player->plr->mo, PCLASS_INFO(player->class_)->normalState);

// $voodoodolls: Do not zero mom!
if(!(player && player->plr->mo != mo))
mo->mom[MX] = mo->mom[MY] = 0;

// $voodoodolls: Stop view bobbing if this isn't a voodoo doll.
if(player && player->plr->mo == mo)
player->bob = 0;
}
else
{
float friction = getFriction(mo);

mo->mom[MX] *= friction;
mo->mom[MY] *= friction;
}
// Slow down.
Mobj_XYMoveStopping(mo);
}

/*
Expand Down

0 comments on commit 8da6eb8

Please sign in to comment.