Ticket #1944: sound_attribute.patch

File sound_attribute.patch, 6.6 KB (added by stwf, 11 years ago)

patch file

  • source/graphics/Model.cpp

     
    251251/////////////////////////////////////////////////////////////////////////////////////////////////////////////
    252252// BuildAnimation: load raw animation frame animation from given file, and build a
    253253// animation specific to this model
    254 CSkeletonAnim* CModel::BuildAnimation(const VfsPath& pathname, const CStr& name, float speed, float actionpos, float actionpos2)
     254CSkeletonAnim* CModel::BuildAnimation(const VfsPath& pathname, const CStr& name, float speed, float actionpos, float actionpos2, float soundpos)
    255255{
    256256    CSkeletonAnimDef* def = m_SkeletonAnimManager.GetAnimation(pathname);
    257257    if (!def)
     
    272272    else
    273273        anim->m_ActionPos2 = actionpos2 * anim->m_AnimDef->GetDuration();
    274274
     275    if (soundpos == -1.f)
     276        anim->m_SoundPos = -1.f;
     277    else
     278        anim->m_SoundPos = soundpos * anim->m_AnimDef->GetDuration();
     279
    275280    anim->m_ObjectBounds.SetEmpty();
    276281    InvalidateBounds();
    277282
  • source/graphics/Model.h

     
    197197     * @param speed animation speed as a factor of the default animation speed
    198198     * @param actionpos offset of 'action' event, in range [0, 1]
    199199     * @param actionpos2 offset of 'action2' event, in range [0, 1]
     200     * @param sound offset of 'sound' event, in range [0, 1]
    200201     * @return new animation, or NULL on error
    201202     */
    202     CSkeletonAnim* BuildAnimation(const VfsPath& pathname, const CStr& name, float speed, float actionpos, float actionpos2);
     203    CSkeletonAnim* BuildAnimation(const VfsPath& pathname, const CStr& name, float speed, float actionpos, float actionpos2, float soundpos);
    203204
    204205    /**
    205206     * Add a prop to the model on the given point.
  • source/graphics/ObjectBase.cpp

     
    7171    AT(speed);
    7272    AT(event);
    7373    AT(load);
     74    AT(sound);
    7475    AT(attachpoint);
    7576    AT(actor);
    7677    AT(frequency);
     
    222223                                    float pos = ae.Value.ToFloat();
    223224                                    anim.m_ActionPos2 = clamp(pos, 0.f, 1.f);
    224225                                }
     226                                else if (ae.Name == at_sound)
     227                                {
     228                                    float pos = ae.Value.ToFloat();
     229                                    anim.m_SoundPos = clamp(pos, 0.f, 1.f);
     230                                }
    225231                            }
    226232                            currentVariant->m_Anims.push_back(anim);
    227233                        }
  • source/graphics/ObjectBase.h

     
    3939    struct Anim
    4040    {
    4141        // constructor
    42         Anim() : m_Speed(1.f), m_ActionPos(-1.f), m_ActionPos2(-1.f) {}
    43 
     42        Anim() : m_Speed(1.f), m_ActionPos(-1.f), m_ActionPos2(-1.f), m_SoundPos(-1.f) {}
    4443        // name of the animation - "Idle", "Run", etc
    4544        CStr m_AnimName;
    4645        // filename of the animation - manidle.psa, manrun.psa, etc
     
    5150        // happens, or -1.0 if unspecified
    5251        float m_ActionPos;
    5352        float m_ActionPos2;
     53        float m_SoundPos;
    5454    };
    5555
    5656    struct Prop
  • source/graphics/ObjectEntry.cpp

     
    164164
    165165        if (! it->second.m_FileName.empty())
    166166        {
    167             CSkeletonAnim* anim = model->BuildAnimation(it->second.m_FileName, name, it->second.m_Speed, it->second.m_ActionPos, it->second.m_ActionPos2);
     167            CSkeletonAnim* anim = model->BuildAnimation(it->second.m_FileName, name, it->second.m_Speed, it->second.m_ActionPos, it->second.m_ActionPos2, it->second.m_SoundPos);
    168168            if (anim)
    169169                m_Animations.insert(std::make_pair(name, anim));
    170170        }
     
    179179        anim->m_Speed = 0.f;
    180180        anim->m_ActionPos = 0.f;
    181181        anim->m_ActionPos2 = 0.f;
     182        anim->m_SoundPos = 0.f;
    182183        m_Animations.insert(std::make_pair("idle", anim));
    183184
    184185        // Ignore errors, since they're probably saying this is a non-animated model
  • source/graphics/SkeletonAnim.h

     
    4646    // ActionPos2 is used for loading projectile ammunition.
    4747    float m_ActionPos;
    4848    float m_ActionPos2;
     49    float m_SoundPos;
    4950    // object space bounds of the model when this animation is applied to it
    5051    CBoundingBoxAligned m_ObjectBounds;
    5152};
  • source/graphics/UnitAnimation.cpp

     
    6767    state.time = 0.f;
    6868    state.pastLoadPos = false;
    6969    state.pastActionPos = false;
     70    state.pastSoundPos = false;
    7071
    7172    m_AnimStates.push_back(state);
    7273
     
    157158
    158159        float actionPos = it->anims[it->animIdx]->m_ActionPos;
    159160        float loadPos = it->anims[it->animIdx]->m_ActionPos2;
     161        float soundPos = it->anims[it->animIdx]->m_SoundPos;
    160162        bool hasActionPos = (actionPos != -1.f);
    161163        bool hasLoadPos = (loadPos != -1.f);
     164        bool hasSoundPos = (soundPos != -1.f);
    162165
    163166        // Find the current animation speed
    164167        float speed;
     
    183186            if (hasLoadPos)
    184187                it->model->HideAmmoProp();
    185188
    186             if (!m_ActionSound.empty())
     189            if ( !hasSoundPos && !m_ActionSound.empty() )
    187190            {
    188191                CmpPtr<ICmpSoundManager> cmpSoundManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
    189192                if (cmpSoundManager)
     
    192195
    193196            it->pastActionPos = true;
    194197        }
     198        if (hasSoundPos && !it->pastSoundPos && it->time + advance >= soundPos)
     199        {
     200            if (!m_ActionSound.empty() )
     201            {
     202                CmpPtr<ICmpSoundManager> cmpSoundManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
     203                if (cmpSoundManager)
     204                    cmpSoundManager->PlaySoundGroup(m_ActionSound, m_Entity);
     205            }
    195206
     207            it->pastSoundPos = true;
     208        }
     209
    196210        if (it->time + advance < duration)
    197211        {
    198212            // If we're still within the current animation, then simply update it
     
    219233
    220234            it->pastActionPos = false;
    221235            it->pastLoadPos = false;
     236            it->pastSoundPos = false;
    222237
    223238            it->model->UpdateTo(it->time);
    224239        }
  • source/graphics/UnitAnimation.h

     
    100100        float time;
    101101        bool pastLoadPos;
    102102        bool pastActionPos;
     103        bool pastSoundPos;
    103104    };
    104105
    105106    std::vector<SModelAnimState> m_AnimStates;