Skip to content

Commit

Permalink
Step height: Add as a player object property
Browse files Browse the repository at this point in the history
Add settable player step height using the existing object property.
Breaks compatibility with old clients, add to protocol version 35.
  • Loading branch information
paramat committed Aug 9, 2017
1 parent 7cd1251 commit 3d0e8a6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/constants.h
Expand Up @@ -80,6 +80,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
// the main loop (related to TempMods and day/night)
//#define MAP_BLOCKSIZE 32

// Player step height in nodes
#define PLAYER_DEFAULT_STEPHEIGHT 0.6f

/*
Old stuff that shouldn't be hardcoded
*/
Expand Down
5 changes: 5 additions & 0 deletions src/content_cao.h
Expand Up @@ -147,6 +147,11 @@ class GenericCAO : public ClientActiveObject

scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode();

inline f32 getStepHeight() const
{
return m_prop.stepheight;
}

inline bool isLocalPlayer() const
{
return m_is_local_player;
Expand Down
1 change: 1 addition & 0 deletions src/content_sao.cpp
Expand Up @@ -799,6 +799,7 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, u16 peer_id
// end of default appearance
m_prop.is_visible = true;
m_prop.makes_footstep_sound = true;
m_prop.stepheight = PLAYER_DEFAULT_STEPHEIGHT * BS;
m_hp = PLAYER_MAX_HP;
}

Expand Down
12 changes: 9 additions & 3 deletions src/localplayer.cpp
Expand Up @@ -279,9 +279,15 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
// This should always apply, otherwise there are glitches
sanity_check(d > pos_max_d);

// TODO: this shouldn't be hardcoded but transmitted from server
float player_stepheight = (touching_ground) ? (BS * 0.6f) : (BS * 0.2f);

// Player object property step height is multiplied by BS in
// /src/script/common/c_content.cpp and /src/content_sao.cpp
float player_stepheight = (m_cao == nullptr) ? 0.0f :
(touching_ground ? m_cao->getStepHeight() : (0.2f * BS));

// TODO this is a problematic hack.
// Use a better implementation for autojump, or apply a custom stepheight
// to all players, as this currently creates unintended special movement
// abilities and advantages for Android players on a server.
#ifdef __ANDROID__
player_stepheight += (0.6f * BS);
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/network/networkprotocol.h
Expand Up @@ -174,6 +174,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
Add settable player collisionbox. Breaks compatibility with older
clients as a 1-node vertical offset has been removed from player's
position
Add settable player stepheight using existing object property.
Breaks compatibility with older clients.
*/

#define LATEST_PROTOCOL_VERSION 35
Expand Down

0 comments on commit 3d0e8a6

Please sign in to comment.