Ticket #2023: const.patch
File const.patch, 14.5 KB (added by , 11 years ago) |
---|
-
source/graphics/UnitAnimation.cpp
144 144 } 145 145 } 146 146 147 void CUnitAnimation::Update( float time)147 void CUnitAnimation::Update(const float time) 148 148 { 149 149 // 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) 151 152 { 152 CSkeletonAnimDef*animDef = it->anims[it->animIdx]->m_AnimDef;153 const CSkeletonAnimDef * const animDef = it->anims[it->animIdx]->m_AnimDef; 153 154 if (animDef == NULL) 154 155 continue; // ignore static animations 156 const CSkeletonAnim * const anim = it->anims[it->animIdx]; 155 157 156 float duration = animDef->GetDuration();158 const float duration = animDef->GetDuration(); 157 159 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); 162 164 163 165 // Find the current animation speed 164 166 float speed; 165 167 if (m_SyncRepeatTime && hasActionPos) 166 168 speed = duration / m_SyncRepeatTime; 167 169 else 168 speed = m_Speed * it->anims[it->animIdx]->m_Speed;170 speed = m_Speed * anim->m_Speed; 169 171 170 172 // Convert from real time to scaled animation time 171 float advance = time * speed;173 const float advance = time * speed; 172 174 173 175 // If we're going to advance past the load point in this update, then load the ammo 174 176 if (hasLoadPos && !it->pastLoadPos && it->time + advance >= loadPos) … … 209 211 // If there's a choice of multiple animations, pick a new random one 210 212 if (it->anims.size() > 1) 211 213 { 212 size_t newAnimIdx = rand(0, it->anims.size());214 const size_t newAnimIdx = rand(0, it->anims.size()); 213 215 if (newAnimIdx != it->animIdx) 214 216 { 215 217 it->animIdx = newAnimIdx; … … 227 229 // If we've finished the current animation and don't want to loop... 228 230 229 231 // 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; 231 233 if (fabs(it->time - nearlyEnd) > 1.f) 232 234 { 233 235 it->time = nearlyEnd; -
source/simulation2/system/ComponentManager.h
261 261 // TODO: some of these should be vectors 262 262 std::map<ComponentTypeId, ComponentType> m_ComponentTypesById; 263 263 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 264 265 std::map<ComponentTypeId, std::map<entity_id_t, IComponent*> > m_ComponentsByTypeId; 265 266 std::map<MessageTypeId, std::vector<ComponentTypeId> > m_LocalMessageSubscriptions; 266 267 std::map<MessageTypeId, std::vector<ComponentTypeId> > m_GlobalMessageSubscriptions; -
source/simulation2/system/ComponentManager.cpp
735 735 } 736 736 } 737 737 738 IComponent* CComponentManager::QueryInterface( entity_id_t ent,InterfaceId iid) const738 IComponent* CComponentManager::QueryInterface(const entity_id_t ent, const InterfaceId iid) const 739 739 { 740 740 if ((size_t)iid >= m_ComponentsByInterface.size()) 741 741 { … … 814 814 void CComponentManager::BroadcastMessage(const CMessage& msg) const 815 815 { 816 816 // 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) 820 820 { 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) 823 823 { 824 824 // Find the component instances of this type (if any) 825 825 std::map<ComponentTypeId, std::map<entity_id_t, IComponent*> >::const_iterator emap = m_ComponentsByTypeId.find(*ctit); … … 827 827 continue; 828 828 829 829 // 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) 832 834 eit->second->HandleMessage(msg, false); 833 835 } 834 836 } -
source/maths/BoundingBoxAligned.cpp
149 149 // Now find the extreme points by considering the product of the 150 150 // min and max with each component of matrix 151 151 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]; 154 154 155 155 if (a<b) { 156 156 result[0][i]+=a; -
source/maths/BoundingBoxOriented.cpp
50 50 float tMin = -FLT_MAX; 51 51 float tMax = FLT_MAX; 52 52 53 CVector3D p = m_Center - origin;53 const CVector3D p (m_Center - origin); 54 54 55 55 for (int i = 0; i < 3; ++i) 56 56 { 57 57 // 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 normal59 float f = m_Basis[i].Dot(dir); // cosine of the angle between the slab normal and the ray direction58 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 60 60 61 61 if(fabsf(f) > 1e-10f) 62 62 { 63 63 // Determine the distances t1 and t2 from the origin of the ray to the points where it intersects 64 64 // 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; 66 66 float t1 = (e + m_HalfSizes[i]) * invF; 67 67 float t2 = (e - m_HalfSizes[i]) * invF; 68 68 69 69 // make sure t1 <= t2, swap if necessary 70 70 if (t1 > t2) 71 71 { 72 float tmp = t1;72 const float tmp = t1; 73 73 t1 = t2; 74 74 t2 = tmp; 75 75 } 76 77 76 // update the overall tMin and tMax if necessary 78 77 if (t1 > tMin) tMin = t1; 79 78 if (t2 < tMax) tMax = t2; 80 79 81 80 // 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 84 85 } 85 86 else 86 87 { -
source/tools/atlas/GameInterface/Brushes.cpp
52 52 --max_j_inclusive; 53 53 } 54 54 55 void ProcessTile( ssize_t i,ssize_t j)55 void ProcessTile(const ssize_t i, const ssize_t j) 56 56 { 57 57 ssize_t i0, j0; 58 58 m_Brush->GetBottomLeft(i0, j0); 59 59 // Colour this tile based on the average of the surrounding vertices 60 float avg = (60 const float avg = ( 61 61 m_Brush->Get(i-i0, j-j0) + m_Brush->Get(i-i0+1, j-j0) + 62 62 m_Brush->Get(i-i0, j-j0+1) + m_Brush->Get(i-i0+1, j-j0+1) 63 63 ) / 4.f; -
source/tools/atlas/AtlasObject/AtlasObjectText.cpp
19 19 #include "AtlasObjectImpl.h" 20 20 #include "AtlasObject.h" 21 21 22 static std::wstring ConvertRecursive(const AtNode::Ptr obj, bool use_brackets = true)22 static std::wstring ConvertRecursive(const AtNode::Ptr& obj, bool use_brackets = true) 23 23 { 24 24 // Convert (1, ()) into "1" 25 25 // Convert (3, (d: (...), e: (...))) into "3 (conv(...), conv(...))" -
source/main.cpp
299 299 ogl_WarnIfError(); 300 300 301 301 // get elapsed time 302 const double time = timer_Time(); 303 g_frequencyFilter->Update(time); 302 #if 0 304 303 // .. old method - "exact" but contains jumps 305 #if 0306 304 static double last_time; 307 305 const double time = timer_Time(); 308 const float TimeSinceLastFrame = (float)(time-last_time);306 const float realTimeSinceLastFrame = (float)(time-last_time); 309 307 last_time = time; 310 308 ONCE(return); // first call: set last_time and return 311 309 312 // .. new method - filtered and more smooth, but errors may accumulate313 310 #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); 314 316 const float realTimeSinceLastFrame = 1.0 / g_frequencyFilter->SmoothedFrequency(); 315 317 #endif 316 318 ENSURE(realTimeSinceLastFrame > 0.0f); -
source/renderer/OverlayRenderer.cpp
233 233 // won't be very large or very variable 234 234 235 235 // 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) 237 237 { 238 238 QuadBatchData& quadBatchData = (it->second); 239 239 quadBatchData.m_Quads.clear(); … … 505 505 GLsizei indexStride = m->quadIndices.GetStride(); 506 506 GLsizei vertexStride = m->quadVertices.GetStride(); 507 507 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) 509 509 { 510 510 QuadBatchData& batchRenderData = it->second; 511 511 const size_t batchNumQuads = batchRenderData.m_NumRenderQuads; -
source/renderer/TerrainOverlay.h
123 123 * @param i <i>i</i> coordinate of tile being processed 124 124 * @param j <i>j</i> coordinate of tile being processed 125 125 */ 126 virtual void ProcessTile( ssize_t i,ssize_t j) = 0;126 virtual void ProcessTile(const ssize_t i, const ssize_t j) = 0; 127 127 128 128 /** 129 129 * Draw a filled quad on top of the current tile. -
source/renderer/VertexArray.cpp
225 225 226 226 //debug_printf(L"Layouting VertexArray\n"); 227 227 228 for (s size_t idx = m_Attributes.size()-1; idx >= 0; --idx)228 for (size_t idx = 0; idx < m_Attributes.size(); ++idx) 229 229 { 230 230 Attribute* attr = m_Attributes[idx]; 231 232 231 if (!attr->type || !attr->elems) 233 232 continue; 234 233 -
source/renderer/ModelRenderer.cpp
422 422 423 423 { 424 424 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) 427 427 { 428 428 CModel* model = m->submissions[i]; 429 429 430 430 CShaderDefines defs = model->GetMaterial().GetShaderDefines(); 431 431 CShaderConditionalDefines condefs = model->GetMaterial().GetConditionalDefines(); 432 432 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) 434 435 { 435 436 CShaderConditionalDefines::CondDefine &item = condefs.GetItem(j); 436 int type = item.m_CondType;437 const int type = item.m_CondType; 437 438 switch (type) 438 439 { 439 440 case DCOND_DISTANCE: 440 441 { 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; 443 444 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]; 446 447 447 448 if ((dmin < 0 || dist >= dmin) && (dmax < 0 || dist < dmax)) 448 449 defs.Add(item.m_DefName.c_str(), item.m_DefValue.c_str()); -
source/renderer/TerrainRenderer.cpp
591 591 592 592 /////////////////////////////////////////////////////////////////// 593 593 // Scissor rectangle of water patches 594 CBoundingBoxAligned TerrainRenderer::ScissorWater(const CMatrix3D &viewproj)594 CBoundingBoxAligned TerrainRenderer::ScissorWater(const CMatrix3D& viewproj) 595 595 { 596 596 CBoundingBoxAligned scissor; 597 597 for (size_t i = 0; i < m->visiblePatches.size(); ++i)