Use integers instead of float values 1114/head
authorBlockMen <nmuelll@web.de>
Sat, 12 Apr 2014 11:50:22 +0000 (13:50 +0200)
committerBlockMen <nmuelll@web.de>
Sat, 12 Apr 2014 18:04:12 +0000 (20:04 +0200)
src/client.cpp
src/clientserver.h
src/content_cao.cpp
src/player.h
src/script/common/c_converter.cpp
src/script/common/c_converter.h
src/script/lua_api/l_object.cpp
src/server.cpp
src/server.h

index dbe959067639211c13aaf19493dde1ede2cec8d5..72964026813e9c813b5fd3e65dee7bdfc315d0f6 100644 (file)
@@ -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)
index a8cd2ea70d119c11118cc7d67c9432dbe1443bd9..1f2e19e45ccaea3fbffeeef14947f4cf9278bc64 100644 (file)
@@ -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
        */
 
index dbaf13cc878125bb183015d1ce9bc55b0b9b8ed2..5f53fd6447a9aa376b13a736e4106d6f81881ecd 100644 (file)
@@ -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)
index b9783997e415d540533f3f54fe22a76fd62f5d58..dce167438a71b7a39c18e7d0d0087cacee24df37 100644 (file)
@@ -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;
index df86f2dafe1bff067b71d6d0c58cbf8a3837cf86..b2ef0573cf696c547509adfda8b2599e6c011522 100644 (file)
@@ -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;
index ab0083124da31bd629e3b2c465d91a3cf40b3bd9..0c051a80328e82c2eb69ae782c18117bc811eada 100644 (file)
@@ -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);
index 8f2bde036f2ea34a2f5897bd8a55d2734f810a8e..5e3ddd2358c30eb16e20b2f24ec1e5a649bb7c8f 100644 (file)
@@ -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))
index cbb9f427f5c946973a539e7f7572a0ae3b645074..ebde0d9efeb68d696e08d25e77274e0956b899cc 100644 (file)
@@ -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;
index 23194a3fff88b0cc9f9a8ceb4da2aeb5600d6a6f..4cfc879cdbc0f6197a8b5c30bbc8fa54693abe54 100644 (file)
@@ -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);