Use integers instead of float values

This commit is contained in:
BlockMen 2014-04-12 13:50:22 +02:00
parent c0ab09af74
commit 8b02a015eb
9 changed files with 71 additions and 42 deletions

@ -1922,10 +1922,10 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
LocalPlayer *player = m_env.getLocalPlayer();
assert(player != NULL);
player->local_animations[0] = readV2F1000(is);
player->local_animations[1] = readV2F1000(is);
player->local_animations[2] = readV2F1000(is);
player->local_animations[3] = readV2F1000(is);
player->local_animations[0] = readV2S32(is);
player->local_animations[1] = readV2S32(is);
player->local_animations[2] = readV2S32(is);
player->local_animations[3] = readV2S32(is);
player->local_animation_speed = readF1000(is);
}
else if(command == TOCLIENT_EYE_OFFSET)

@ -534,10 +534,10 @@ enum ToClientCommand
TOCLIENT_LOCAL_PLAYER_ANIMATIONS = 0x51,
/*
u16 command
v2f1000 stand/idle
v2f1000 walk
v2f1000 dig
v2f1000 walk+dig
v2s32 stand/idle
v2s32 walk
v2s32 dig
v2s32 walk+dig
f1000 frame_speed
*/

@ -581,7 +581,7 @@ private:
v2s16 m_tx_basepos;
bool m_initial_tx_basepos_set;
bool m_tx_select_horiz_by_yawpitch;
v2f m_animation_range;
v2s32 m_animation_range;
int m_animation_speed;
int m_animation_blend;
std::map<std::string, core::vector2d<v3f> > m_bone_position; // stores position and rotation for each bone name
@ -624,7 +624,7 @@ public:
m_tx_basepos(0,0),
m_initial_tx_basepos_set(false),
m_tx_select_horiz_by_yawpitch(false),
m_animation_range(v2f(0,0)),
m_animation_range(v2s32(0,0)),
m_animation_speed(15),
m_animation_blend(0),
m_bone_position(std::map<std::string, core::vector2d<v3f> >()),
@ -1098,41 +1098,51 @@ public:
if(controls.up || controls.down || controls.left || controls.right)
walking = true;
m_animation_speed = player->local_animation_speed;
f32 new_speed = player->local_animation_speed;
v2s32 new_anim = v2s32(0,0);
bool allow_update = false;
if(!player->touching_ground &&
g_settings->getBool("free_move") &&
m_gamedef->checkLocalPrivilege("fly") &&
g_settings->getBool("fast_move") &&
m_gamedef->checkLocalPrivilege("fast"))
m_animation_speed *= 1.5;
new_speed *= 1.5;
if(controls.sneak && walking)
m_animation_speed /= 2;
player->last_animation_speed = m_animation_speed;
new_speed /= 2;
if(walking && (controls.LMB || controls.RMB)) {
m_animation_range = player->local_animations[3];
new_anim = player->local_animations[3];
player->last_animation = WD_ANIM;
} else if(walking) {
m_animation_range = player->local_animations[1];
new_anim = player->local_animations[1];
player->last_animation = WALK_ANIM;
} else if(controls.LMB || controls.RMB) {
m_animation_range = player->local_animations[2];
new_anim = player->local_animations[2];
player->last_animation = DIG_ANIM;
}
if ((new_anim.X + new_anim.Y) > 0) {
allow_update = true;
m_animation_range = new_anim;
m_animation_speed = new_speed;
player->last_animation_speed = m_animation_speed;
} else {
player->last_animation = NO_ANIM;
}
// reset animation when no input detected
if (!walking && !controls.LMB && !controls.RMB) {
player->last_animation = NO_ANIM;
if (old_anim != NO_ANIM) {
m_animation_range = player->local_animations[0];
updateAnimation();
updateAnimation();
}
}
// Update local player animations
if ((player->last_animation != old_anim && player->last_animation != NO_ANIM) || m_animation_speed != old_anim_speed)
updateAnimation();
if ((player->last_animation != old_anim || m_animation_speed != old_anim_speed) &&
player->last_animation != NO_ANIM && allow_update)
updateAnimation();
} else {
m_is_visible = false;
@ -1501,8 +1511,7 @@ public:
{
if(m_animated_meshnode == NULL)
return;
m_animated_meshnode->setFrameLoop((int)m_animation_range.X, (int)m_animation_range.Y);
m_animated_meshnode->setFrameLoop(m_animation_range.X, m_animation_range.Y);
m_animated_meshnode->setAnimationSpeed(m_animation_speed);
m_animated_meshnode->setTransitionTime(m_animation_blend);
}
@ -1775,24 +1784,30 @@ public:
}
else if(cmd == GENERIC_CMD_SET_ANIMATION)
{
if (!m_is_local_player) {
m_animation_range = readV2F1000(is);
// TODO: change frames send as v2s32 value
v2f range = readV2F1000(is);
if (!m_is_local_player) {
m_animation_range = v2s32((s32)range.X, (s32)range.Y);
m_animation_speed = readF1000(is);
m_animation_blend = readF1000(is);
updateAnimation();
} else {
LocalPlayer *player = m_env->getLocalPlayer();
if(player->last_animation == NO_ANIM) {
m_animation_range = readV2F1000(is);
m_animation_range = v2s32((s32)range.X, (s32)range.Y);
m_animation_speed = readF1000(is);
m_animation_blend = readF1000(is);
}
// update animation only if object is not player
// or the received animation is not registered
if(m_animation_range.X != player->local_animations[1].X &&
m_animation_range.X != player->local_animations[2].X &&
m_animation_range.X != player->local_animations[3].X)
// update animation only if local animations present
// and received animation is not unknown
int frames = 0;
for (int i = 0;i<4;i++) {
frames += (int)player->local_animations[i].Y;
}
if(frames < 1) {
player->last_animation = NO_ANIM;
updateAnimation();
}
}
}
else if(cmd == GENERIC_CMD_SET_BONE_POSITION)

@ -269,7 +269,7 @@ public:
bool physics_override_sneak;
bool physics_override_sneak_glitch;
v2f local_animations[4];
v2s32 local_animations[4];
float local_animation_speed;
u16 hp;

@ -59,6 +59,19 @@ v2s16 read_v2s16(lua_State *L, int index)
return p;
}
v2s32 read_v2s32(lua_State *L, int index)
{
v2s32 p;
luaL_checktype(L, index, LUA_TTABLE);
lua_getfield(L, index, "x");
p.X = lua_tonumber(L, -1);
lua_pop(L, 1);
lua_getfield(L, index, "y");
p.Y = lua_tonumber(L, -1);
lua_pop(L, 1);
return p;
}
v2f read_v2f(lua_State *L, int index)
{
v2f p;

@ -75,6 +75,7 @@ v3s16 check_v3s16 (lua_State *L, int index);
v3f read_v3f (lua_State *L, int index);
v2f read_v2f (lua_State *L, int index);
v2s16 read_v2s16 (lua_State *L, int index);
v2s32 read_v2s32 (lua_State *L, int index);
video::SColor readARGB8 (lua_State *L, int index);
aabb3f read_aabb3f (lua_State *L, int index, f32 scale);
v3s16 read_v3s16 (lua_State *L, int index);

@ -415,10 +415,10 @@ int ObjectRef::l_set_local_animation(lua_State *L)
if (player == NULL)
return 0;
// Do it
v2f frames[4];
v2s32 frames[4];
for (int i=0;i<4;i++) {
if(!lua_isnil(L, 2+1))
frames[i] = read_v2f(L, 2+i);
frames[i] = read_v2s32(L, 2+i);
}
float frame_speed = 30;
if(!lua_isnil(L, 6))

@ -3484,15 +3484,15 @@ void Server::SendMovePlayer(u16 peer_id)
m_clients.send(peer_id, 0, data, true);
}
void Server::SendLocalPlayerAnimations(u16 peer_id, v2f animation_frames[4], f32 animation_speed)
void Server::SendLocalPlayerAnimations(u16 peer_id, v2s32 animation_frames[4], f32 animation_speed)
{
std::ostringstream os(std::ios_base::binary);
writeU16(os, TOCLIENT_LOCAL_PLAYER_ANIMATIONS);
writeV2F1000(os, animation_frames[0]);
writeV2F1000(os, animation_frames[1]);
writeV2F1000(os, animation_frames[2]);
writeV2F1000(os, animation_frames[3]);
writeV2S32(os, animation_frames[0]);
writeV2S32(os, animation_frames[1]);
writeV2S32(os, animation_frames[2]);
writeV2S32(os, animation_frames[3]);
writeF1000(os, animation_speed);
// Make data buffer
@ -4610,7 +4610,7 @@ void Server::hudSetHotbarSelectedImage(Player *player, std::string name) {
SendHUDSetParam(player->peer_id, HUD_PARAM_HOTBAR_SELECTED_IMAGE, name);
}
bool Server::setLocalPlayerAnimations(Player *player, v2f animation_frames[4], f32 frame_speed)
bool Server::setLocalPlayerAnimations(Player *player, v2s32 animation_frames[4], f32 frame_speed)
{
if (!player)
return false;

@ -322,7 +322,7 @@ public:
inline Address getPeerAddress(u16 peer_id)
{ return m_con.GetPeerAddress(peer_id); }
bool setLocalPlayerAnimations(Player *player, v2f animation_frames[4], f32 frame_speed);
bool setLocalPlayerAnimations(Player *player, v2s32 animation_frames[4], f32 frame_speed);
bool setPlayerEyeOffset(Player *player, v3f first, v3f third);
bool setSky(Player *player, const video::SColor &bgcolor,
@ -364,7 +364,7 @@ private:
void SendPlayerHP(u16 peer_id);
void SendPlayerBreath(u16 peer_id);
void SendMovePlayer(u16 peer_id);
void SendLocalPlayerAnimations(u16 peer_id, v2f animation_frames[4], f32 animation_speed);
void SendLocalPlayerAnimations(u16 peer_id, v2s32 animation_frames[4], f32 animation_speed);
void SendEyeOffset(u16 peer_id, v3f first, v3f third);
void SendPlayerPrivileges(u16 peer_id);
void SendPlayerInventoryFormspec(u16 peer_id);