set anim speed

This commit is contained in:
2026-03-11 23:25:46 +03:00
parent 7ba7f3ac39
commit f89f3c8523
7 changed files with 31 additions and 3 deletions

View File

@@ -115,6 +115,10 @@ function weapon_base:on_state_switch(state)
if fsm_state.anim_sound then
engine.play_sound(fsm_state.anim_sound)
end
if fsm_state.anim_speed then
self:set_animation_speed(fsm_state.anim_speed)
end
end
function weapon_base:set_relative_position_to_camera( ent )

View File

@@ -14,7 +14,7 @@ weapon_ump.m_fsm[WEAPON_FSM_STATE_IDLE] = {
weapon_ump.m_fsm[WEAPON_FSM_STATE_ATTACK] = {
anim = "shoot1", -- имя анимации
anim_playback = ANIM_PLAYBACK_NONE,
anim_speed = 1.0, -- обычная скорость анимации
anim_speed = 6.0, -- обычная скорость анимации
anim_sound = "data/sounds/weapons/ump45_shoot.wav"
}

View File

@@ -235,6 +235,7 @@ void Entity::RegisterBaseFunctions()
m_luaObject.Register("get_current_animation", *this, &Entity::Lua_GetCurrentAnimation);
m_luaObject.Register("get_current_animation_time", *this, &Entity::Lua_GetCurrentAnimationTime);
m_luaObject.Register("get_animation_time", *this, &Entity::Lua_GetAnimationTime);
m_luaObject.Register("set_animation_speed", *this, &Entity::Lua_SetAnimationSpeed);
//int Lua_FindAnimation(LuaPlus::LuaState * state);
//int Lua_PlayAnimation(LuaPlus::LuaState * state);
@@ -615,6 +616,17 @@ int Entity::Lua_GetAnimationTime(LuaPlus::LuaState* state)
return 1;
}
int Entity::Lua_SetAnimationSpeed(LuaPlus::LuaState* state)
{
LuaPlus::LuaStack stack(state);
float speed = stack[2].GetFloat();
if (m_skeleton)
m_skeleton->SetAnimationSpeed(speed);
return 0;
}
const LuaPlus::LuaObject& Entity::GetLuaObject()
{
return m_luaObject;

View File

@@ -141,6 +141,7 @@ public:
int Lua_GetCurrentAnimation(LuaPlus::LuaState* state);
int Lua_GetCurrentAnimationTime(LuaPlus::LuaState* state);
int Lua_GetAnimationTime(LuaPlus::LuaState* state);
int Lua_SetAnimationSpeed(LuaPlus::LuaState* state);
const LuaPlus::LuaObject& GetLuaObject();

View File

@@ -6,6 +6,7 @@ SkeletonInstance::SkeletonInstance() :
m_model(nullptr),
m_animation(INVALID_ANIMATION_HANDLE),
m_time(0.0f),
m_speed(1.0f),
m_looped(false)
{
}
@@ -52,7 +53,7 @@ float SkeletonInstance::GetAnimationTime(AnimationId_t id)
float frameTime = 1.0f / animation->framerate;
float totalDuration = animation->numFrames * frameTime;
return totalDuration;
return totalDuration / m_speed;
}
void SkeletonInstance::PlayAnimation(AnimationId_t id, bool looped)
@@ -60,6 +61,7 @@ void SkeletonInstance::PlayAnimation(AnimationId_t id, bool looped)
m_time = 0.0f;
m_animation = id;
m_looped = looped;
m_speed = 1.0f;
}
void SkeletonInstance::StopAnimation()
@@ -67,6 +69,12 @@ void SkeletonInstance::StopAnimation()
m_time = 0.0f;
m_animation = INVALID_ANIMATION_HANDLE;
m_looped = -1;
m_speed = 1.0f;
}
void SkeletonInstance::SetAnimationSpeed(float speed)
{
m_speed = speed;
}
AnimationId_t SkeletonInstance::GetCurrentAnimation()

View File

@@ -43,6 +43,7 @@ public:
std::vector<glm::mat4> m_finalMatrices;
AnimationId_t m_animation;
float m_time;
float m_speed;
bool m_looped;
public:
@@ -60,6 +61,8 @@ public:
void PlayAnimation(AnimationId_t id, bool looped);
void StopAnimation();
void SetAnimationSpeed(float speed);
AnimationId_t GetCurrentAnimation();
float GetCurrentTime();

View File

@@ -817,7 +817,7 @@ void Model::UpdateSkeletonInstance(SkeletonInstance* instance, float dt)
const Animation& animation = m_animations[instance->m_animation];
instance->m_time += dt;
instance->m_time += dt * instance->m_speed;
float frameTime = 1.0f / animation.framerate;
float totalDuration = (animation.numFrames - 1) * frameTime;