Ticket #2023: const.patch

File const.patch, 14.5 KB (added by tuan kuranes, 11 years ago)

patch

  • source/graphics/UnitAnimation.cpp

     
    144144    }
    145145}
    146146
    147 void CUnitAnimation::Update(float time)
     147void CUnitAnimation::Update(const float time)
    148148{
    149149    // Advance all of the prop models independently
    150     for (std::vector<SModelAnimState>::iterator it = m_AnimStates.begin(); it != m_AnimStates.end(); ++it)
     150    std::vector<SModelAnimState>::iterator itend = m_AnimStates.end();
     151    for (std::vector<SModelAnimState>::iterator it = m_AnimStates.begin(); it != itend; ++it)
    151152    {
    152         CSkeletonAnimDef* animDef = it->anims[it->animIdx]->m_AnimDef;
     153        const CSkeletonAnimDef * const animDef = it->anims[it->animIdx]->m_AnimDef;
    153154        if (animDef == NULL)
    154155            continue; // ignore static animations
     156        const CSkeletonAnim * const anim = it->anims[it->animIdx];
    155157
    156         float duration = animDef->GetDuration();
     158        const float duration = animDef->GetDuration();
    157159
    158         float actionPos = it->anims[it->animIdx]->m_ActionPos;
    159         float loadPos = it->anims[it->animIdx]->m_ActionPos2;
    160         bool hasActionPos = (actionPos != -1.f);
    161         bool hasLoadPos = (loadPos != -1.f);
     160        const float actionPos = anim->m_ActionPos;
     161        const float loadPos = anim->m_ActionPos2;
     162        const bool hasActionPos = (actionPos != -1.f);
     163        const bool hasLoadPos = (loadPos != -1.f);
    162164
    163165        // Find the current animation speed
    164166        float speed;
    165167        if (m_SyncRepeatTime && hasActionPos)
    166168            speed = duration / m_SyncRepeatTime;
    167169        else
    168             speed = m_Speed * it->anims[it->animIdx]->m_Speed;
     170            speed = m_Speed * anim->m_Speed;
    169171
    170172        // Convert from real time to scaled animation time
    171         float advance = time * speed;
     173        const float advance = time * speed;
    172174
    173175        // If we're going to advance past the load point in this update, then load the ammo
    174176        if (hasLoadPos && !it->pastLoadPos && it->time + advance >= loadPos)
     
    209211            // If there's a choice of multiple animations, pick a new random one
    210212            if (it->anims.size() > 1)
    211213            {
    212                 size_t newAnimIdx = rand(0, it->anims.size());
     214                const size_t newAnimIdx = rand(0, it->anims.size());
    213215                if (newAnimIdx != it->animIdx)
    214216                {
    215217                    it->animIdx = newAnimIdx;
     
    227229            // If we've finished the current animation and don't want to loop...
    228230
    229231            // Update to very nearly the end of the last frame (but not quite the end else we'll wrap around when skinning)
    230             float nearlyEnd = duration - 1.f;
     232            const float nearlyEnd = duration - 1.f;
    231233            if (fabs(it->time - nearlyEnd) > 1.f)
    232234            {
    233235                it->time = nearlyEnd;
  • source/simulation2/system/ComponentManager.h

     
    261261    // TODO: some of these should be vectors
    262262    std::map<ComponentTypeId, ComponentType> m_ComponentTypesById;
    263263    std::vector<boost::unordered_map<entity_id_t, IComponent*> > m_ComponentsByInterface; // indexed by InterfaceId
     264    // TODO: specially this the seccond of this one, which burdens broadcast performance exponentially with entities
    264265    std::map<ComponentTypeId, std::map<entity_id_t, IComponent*> > m_ComponentsByTypeId;
    265266    std::map<MessageTypeId, std::vector<ComponentTypeId> > m_LocalMessageSubscriptions;
    266267    std::map<MessageTypeId, std::vector<ComponentTypeId> > m_GlobalMessageSubscriptions;
  • source/simulation2/system/ComponentManager.cpp

     
    735735    }
    736736}
    737737
    738 IComponent* CComponentManager::QueryInterface(entity_id_t ent, InterfaceId iid) const
     738IComponent* CComponentManager::QueryInterface(const entity_id_t ent, const InterfaceId iid) const
    739739{
    740740    if ((size_t)iid >= m_ComponentsByInterface.size())
    741741    {
     
    814814void CComponentManager::BroadcastMessage(const CMessage& msg) const
    815815{
    816816    // Send the message to components of all entities that subscribed locally to this message
    817     std::map<MessageTypeId, std::vector<ComponentTypeId> >::const_iterator it;
    818     it = m_LocalMessageSubscriptions.find(msg.GetType());
    819     if (it != m_LocalMessageSubscriptions.end())
     817    std::map<MessageTypeId, std::vector<ComponentTypeId> >::const_iterator it = m_LocalMessageSubscriptions.find(msg.GetType()),
     818        itend =  m_LocalMessageSubscriptions.end();
     819    if (it != itend)
    820820    {
    821         std::vector<ComponentTypeId>::const_iterator ctit = it->second.begin();
    822         for (; ctit != it->second.end(); ++ctit)
     821        std::vector<ComponentTypeId>::const_iterator ctit = it->second.begin(),  cend = it->second.end();
     822        for (; ctit != cend; ++ctit)
    823823        {
    824824            // Find the component instances of this type (if any)
    825825            std::map<ComponentTypeId, std::map<entity_id_t, IComponent*> >::const_iterator emap = m_ComponentsByTypeId.find(*ctit);
     
    827827                continue;
    828828
    829829            // Send the message to all of them
    830             std::map<entity_id_t, IComponent*>::const_iterator eit = emap->second.begin();
    831             for (; eit != emap->second.end(); ++eit)
     830            // TODO: switch from map to a contigous container (ie vector)
     831            // as that's very slow and very impacting performance
     832            std::map<entity_id_t, IComponent*>::const_iterator eit = emap->second.begin(),  eiteend = emap->second.end();
     833            for (; eit != eiteend; ++eit)
    832834                eit->second->HandleMessage(msg, false);
    833835        }
    834836    }
  • source/maths/BoundingBoxAligned.cpp

     
    149149        // Now find the extreme points by considering the product of the
    150150        // min and max with each component of matrix
    151151        for(int j=0;j<3;j++) {
    152             float a=m(i,j)*m_Data[0][j];
    153             float b=m(i,j)*m_Data[1][j];
     152            const float a=m(i,j)*m_Data[0][j];
     153            const float b=m(i,j)*m_Data[1][j];
    154154
    155155            if (a<b) {
    156156                result[0][i]+=a;
  • source/maths/BoundingBoxOriented.cpp

     
    5050    float tMin = -FLT_MAX;
    5151    float tMax = FLT_MAX;
    5252
    53     CVector3D p = m_Center - origin;
     53    const CVector3D p (m_Center - origin);
    5454
    5555    for (int i = 0; i < 3; ++i)
    5656    {
    5757        // test the ray for intersections with the slab whose normal vector is m_Basis[i]
    58         float e = m_Basis[i].Dot(p); // distance between the ray origin and the box center projected onto the slab normal
    59         float f = m_Basis[i].Dot(dir); // cosine of the angle between the slab normal and the ray direction
     58        const float e = m_Basis[i].Dot(p); // distance between the ray origin and the box center projected onto the slab normal
     59        const float f = m_Basis[i].Dot(dir); // cosine of the angle between the slab normal and the ray direction
    6060
    6161        if(fabsf(f) > 1e-10f)
    6262        {
    6363            // Determine the distances t1 and t2 from the origin of the ray to the points where it intersects
    6464            // the slab. See docs/ray_intersect.pdf for why/how this works.
    65             float invF = 1.f/f;
     65            const float invF = 1.f/f;
    6666            float t1 = (e + m_HalfSizes[i]) * invF;
    6767            float t2 = (e - m_HalfSizes[i]) * invF;
    6868
    6969            // make sure t1 <= t2, swap if necessary
    7070            if (t1 > t2)
    7171            {
    72                 float tmp = t1;
     72                const float tmp = t1;
    7373                t1 = t2;
    7474                t2 = tmp;
    7575            }
    76 
    7776            // update the overall tMin and tMax if necessary
    7877            if (t1 > tMin) tMin = t1;
    7978            if (t2 < tMax) tMax = t2;
    80 
     79           
    8180            // try to break out of the loop as fast as possible by checking for some conditions
    82             if (tMin > tMax) return false; // ray misses the box
    83             if (tMax < 0) return false; // box is behind the ray origin
     81            if (tMin > tMax)
     82                return false; // ray misses the box
     83            if (tMax < 0)
     84                return false; // box is behind the ray origin
    8485        }
    8586        else
    8687        {
  • source/tools/atlas/GameInterface/Brushes.cpp

     
    5252        --max_j_inclusive;
    5353    }
    5454
    55     void ProcessTile(ssize_t i, ssize_t j)
     55    void ProcessTile(const ssize_t i, const ssize_t j)
    5656    {
    5757        ssize_t i0, j0;
    5858        m_Brush->GetBottomLeft(i0, j0);
    5959        // Colour this tile based on the average of the surrounding vertices
    60         float avg = (
     60        const float avg = (
    6161            m_Brush->Get(i-i0, j-j0)   + m_Brush->Get(i-i0+1, j-j0) +
    6262            m_Brush->Get(i-i0, j-j0+1) + m_Brush->Get(i-i0+1, j-j0+1)
    6363        ) / 4.f;
  • source/tools/atlas/AtlasObject/AtlasObjectText.cpp

     
    1919#include "AtlasObjectImpl.h"
    2020#include "AtlasObject.h"
    2121
    22 static std::wstring ConvertRecursive(const AtNode::Ptr obj, bool use_brackets = true)
     22static std::wstring ConvertRecursive(const AtNode::Ptr& obj, bool use_brackets = true)
    2323{
    2424    // Convert (1, ()) into "1"
    2525    // Convert (3, (d: (...), e: (...))) into "3 (conv(...), conv(...))"
  • source/main.cpp

     
    299299    ogl_WarnIfError();
    300300
    301301    // get elapsed time
    302     const double time = timer_Time();
    303     g_frequencyFilter->Update(time);
     302#if 0
    304303    // .. old method - "exact" but contains jumps
    305 #if 0
    306304    static double last_time;
    307305    const double time = timer_Time();
    308     const float TimeSinceLastFrame = (float)(time-last_time);
     306    const float realTimeSinceLastFrame = (float)(time-last_time);
    309307    last_time = time;
    310308    ONCE(return);   // first call: set last_time and return
    311309
    312     // .. new method - filtered and more smooth, but errors may accumulate
    313310#else
     311    // .. new method - filtered and more smooth,
     312    // but errors does accumulate
     313    // and profiler ms/frame are false.
     314    const double time = timer_Time();
     315    g_frequencyFilter->Update(time);
    314316    const float realTimeSinceLastFrame = 1.0 / g_frequencyFilter->SmoothedFrequency();
    315317#endif
    316318    ENSURE(realTimeSinceLastFrame > 0.0f);
  • source/renderer/OverlayRenderer.cpp

     
    233233    // won't be very large or very variable
    234234   
    235235    // Empty the batch rendering data structures, but keep their key mappings around for the next frames
    236     for (OverlayRendererInternals::QuadBatchMap::iterator it = m->quadBatchMap.begin(); it != m->quadBatchMap.end(); it++)
     236    for (OverlayRendererInternals::QuadBatchMap::iterator it = m->quadBatchMap.begin(); it != m->quadBatchMap.end(); ++it)
    237237    {
    238238        QuadBatchData& quadBatchData = (it->second);
    239239        quadBatchData.m_Quads.clear();
     
    505505        GLsizei indexStride = m->quadIndices.GetStride();
    506506        GLsizei vertexStride = m->quadVertices.GetStride();
    507507
    508         for (OverlayRendererInternals::QuadBatchMap::iterator it = m->quadBatchMap.begin(); it != m->quadBatchMap.end(); it++)
     508        for (OverlayRendererInternals::QuadBatchMap::iterator it = m->quadBatchMap.begin(); it != m->quadBatchMap.end(); ++it)
    509509        {
    510510            QuadBatchData& batchRenderData = it->second;
    511511            const size_t batchNumQuads = batchRenderData.m_NumRenderQuads;
  • source/renderer/TerrainOverlay.h

     
    123123     * @param i  <i>i</i> coordinate of tile being processed
    124124     * @param j  <i>j</i> coordinate of tile being processed
    125125     */
    126     virtual void ProcessTile(ssize_t i, ssize_t j) = 0;
     126    virtual void ProcessTile(const ssize_t i, const ssize_t j) = 0;
    127127
    128128    /**
    129129     * Draw a filled quad on top of the current tile.
  • source/renderer/VertexArray.cpp

     
    225225   
    226226    //debug_printf(L"Layouting VertexArray\n");
    227227   
    228     for (ssize_t idx = m_Attributes.size()-1; idx >= 0; --idx)
     228    for (size_t idx = 0; idx < m_Attributes.size(); ++idx)
    229229    {
    230230        Attribute* attr = m_Attributes[idx];
    231        
    232231        if (!attr->type || !attr->elems)
    233232            continue;
    234233   
  • source/renderer/ModelRenderer.cpp

     
    422422
    423423    {
    424424        PROFILE3("bucketing by material");
    425 
    426         for (size_t i = 0; i < m->submissions.size(); ++i)
     425        const size_t submissionsSize = m->submissions.size();
     426        for (size_t i = 0; i < submissionsSize; ++i)
    427427        {
    428428            CModel* model = m->submissions[i];
    429429           
    430430            CShaderDefines defs = model->GetMaterial().GetShaderDefines();
    431431            CShaderConditionalDefines condefs = model->GetMaterial().GetConditionalDefines();
    432432           
    433             for (size_t j = 0; j < condefs.GetSize(); ++j)
     433            const size_t defssSize = condefs.GetSize();
     434            for (size_t j = 0; j < defssSize; ++j)
    434435            {
    435436                CShaderConditionalDefines::CondDefine &item = condefs.GetItem(j);
    436                 int type = item.m_CondType;
     437                const int type = item.m_CondType;
    437438                switch (type)
    438439                {
    439440                    case DCOND_DISTANCE:
    440441                    {
    441                         CVector3D modelpos = model->GetTransform().GetTranslation();
    442                         float dist = worldToCam.Transform(modelpos).Z;
     442                        const CVector3D modelpos (model->GetTransform().GetTranslation());
     443                        const float dist = worldToCam.Transform(modelpos).Z;
    443444                       
    444                         float dmin = item.m_CondArgs[0];
    445                         float dmax = item.m_CondArgs[1];
     445                        const float dmin = item.m_CondArgs[0];
     446                        const float dmax = item.m_CondArgs[1];
    446447                       
    447448                        if ((dmin < 0 || dist >= dmin) && (dmax < 0 || dist < dmax))
    448449                            defs.Add(item.m_DefName.c_str(), item.m_DefValue.c_str());
  • source/renderer/TerrainRenderer.cpp

     
    591591
    592592///////////////////////////////////////////////////////////////////
    593593// Scissor rectangle of water patches
    594 CBoundingBoxAligned TerrainRenderer::ScissorWater(const CMatrix3D &viewproj)
     594CBoundingBoxAligned TerrainRenderer::ScissorWater(const CMatrix3D& viewproj)
    595595{
    596596    CBoundingBoxAligned scissor;
    597597    for (size_t i = 0; i < m->visiblePatches.size(); ++i)