From a3a1b45f5f4d0339795658a33038d2ff71e85503 Mon Sep 17 00:00:00 2001 From: Porteries Tristan Date: Mon, 18 Sep 2017 08:45:01 +0200 Subject: [PATCH] UPBGE: Use C++11 range loop instead of std iterator. --- source/gameengine/GameLogic/SCA_IObject.cpp | 67 ++++++------------- .../gameengine/GameLogic/SCA_LogicManager.cpp | 6 +- source/gameengine/Ketsji/BL_ActionManager.cpp | 2 +- .../Ketsji/KX_CollisionEventManager.cpp | 21 +++--- source/gameengine/Ketsji/KX_GameObject.cpp | 35 ++++------ source/gameengine/Ketsji/KX_LodManager.cpp | 4 +- source/gameengine/Ketsji/KX_Scene.cpp | 30 +++------ .../Ketsji/KX_TimeCategoryLogger.cpp | 12 ++-- .../Physics/Bullet/CcdPhysicsEnvironment.cpp | 11 ++- source/gameengine/Rasterizer/RAS_2DFilter.cpp | 5 +- .../Rasterizer/RAS_2DFilterManager.cpp | 4 +- .../gameengine/Rasterizer/RAS_BatchGroup.cpp | 20 ++---- .../gameengine/Rasterizer/RAS_BoundingBox.cpp | 4 +- .../Rasterizer/RAS_BoundingBoxManager.cpp | 15 ++--- .../Rasterizer/RAS_BucketManager.cpp | 27 +++----- .../gameengine/Rasterizer/RAS_MeshObject.cpp | 11 ++- source/gameengine/Rasterizer/RAS_MeshUser.cpp | 3 +- 17 files changed, 103 insertions(+), 174 deletions(-) diff --git a/source/gameengine/GameLogic/SCA_IObject.cpp b/source/gameengine/GameLogic/SCA_IObject.cpp index 220ffb3bb030..701be0e127f8 100644 --- a/source/gameengine/GameLogic/SCA_IObject.cpp +++ b/source/gameengine/GameLogic/SCA_IObject.cpp @@ -199,52 +199,36 @@ void SCA_IObject::ReParentLogic() SCA_ISensor* SCA_IObject::FindSensor(const std::string& sensorname) { - SCA_ISensor* foundsensor = nullptr; - - for (SCA_SensorList::iterator its = m_sensors.begin();!(its==m_sensors.end());++its) - { - if ((*its)->GetName() == sensorname) - { - foundsensor = (*its); - break; + for (SCA_ISensor *sensor : m_sensors) { + if (sensor->GetName() == sensorname) { + return sensor; } } - return foundsensor; + return nullptr; } SCA_IController* SCA_IObject::FindController(const std::string& controllername) { - SCA_IController* foundcontroller = nullptr; - - for (SCA_ControllerList::iterator itc = m_controllers.begin();!(itc==m_controllers.end());++itc) - { - if ((*itc)->GetName() == controllername) - { - foundcontroller = (*itc); - break; + for (SCA_IController *controller : m_controllers) { + if (controller->GetName() == controllername) { + return controller; } } - return foundcontroller; + return nullptr; } SCA_IActuator* SCA_IObject::FindActuator(const std::string& actuatorname) { - SCA_IActuator* foundactuator = nullptr; - - for (SCA_ActuatorList::iterator ita = m_actuators.begin();!(ita==m_actuators.end());++ita) - { - if ((*ita)->GetName() == actuatorname) - { - foundactuator = (*ita); - break; + for (SCA_IActuator *actuator : m_actuators) { + if (actuator->GetName() == actuatorname) { + return actuator; } } - - return foundactuator; + return nullptr; } @@ -254,10 +238,8 @@ void SCA_IObject::Suspend() && (!m_suspended)) { m_suspended = true; /* flag suspend for all sensors */ - SCA_SensorList::iterator i = m_sensors.begin(); - while (i != m_sensors.end()) { - (*i)->Suspend(); - ++i; + for (SCA_ISensor *sensor : m_sensors) { + sensor->Suspend(); } } } @@ -269,40 +251,33 @@ void SCA_IObject::Resume(void) if (m_suspended) { m_suspended = false; /* unflag suspend for all sensors */ - SCA_SensorList::iterator i = m_sensors.begin(); - while (i != m_sensors.end()) { - (*i)->Resume(); - ++i; + for (SCA_ISensor *sensor : m_sensors) { + sensor->Resume(); } } } void SCA_IObject::SetState(unsigned int state) { - unsigned int tmpstate; - SCA_ControllerList::iterator contit; - // we will update the state in two steps: // 1) set the new state bits that are 1 // 2) clr the new state bits that are 0 // This to ensure continuity if a sensor is attached to two states // that are switching state: no need to deactive and reactive the sensor - tmpstate = m_state | state; + unsigned int tmpstate = m_state | state; if (tmpstate != m_state) { // update the status of the controllers - for (contit = m_controllers.begin(); contit != m_controllers.end(); ++contit) - { - (*contit)->ApplyState(tmpstate); + for (SCA_IController *controller : m_controllers) { + controller->ApplyState(tmpstate); } } m_state = state; if (m_state != tmpstate) { - for (contit = m_controllers.begin(); contit != m_controllers.end(); ++contit) - { - (*contit)->ApplyState(m_state); + for (SCA_IController *controller : m_controllers) { + controller->ApplyState(m_state); } } } diff --git a/source/gameengine/GameLogic/SCA_LogicManager.cpp b/source/gameengine/GameLogic/SCA_LogicManager.cpp index 4890c4163704..f7a1dc06272d 100644 --- a/source/gameengine/GameLogic/SCA_LogicManager.cpp +++ b/source/gameengine/GameLogic/SCA_LogicManager.cpp @@ -48,10 +48,10 @@ SCA_LogicManager::SCA_LogicManager() SCA_LogicManager::~SCA_LogicManager() { - for (std::vector::iterator it = m_eventmanagers.begin();!(it==m_eventmanagers.end());++it) - { - delete (*it); + for (SCA_EventManager *mgr : m_eventmanagers) { + delete mgr; } + m_eventmanagers.clear(); BLI_assert(m_activeActuators.Empty()); } diff --git a/source/gameengine/Ketsji/BL_ActionManager.cpp b/source/gameengine/Ketsji/BL_ActionManager.cpp index 021a7cc08593..f7dbbf45a76b 100644 --- a/source/gameengine/Ketsji/BL_ActionManager.cpp +++ b/source/gameengine/Ketsji/BL_ActionManager.cpp @@ -126,7 +126,7 @@ void BL_ActionManager::RemoveTaggedActions() for (BL_ActionMap::iterator it = m_layers.begin(); it != m_layers.end();) { if (IS_TAGGED(it->second->GetAction())) { delete it->second; - m_layers.erase(it++); + it = m_layers.erase(it); } else ++it; diff --git a/source/gameengine/Ketsji/KX_CollisionEventManager.cpp b/source/gameengine/Ketsji/KX_CollisionEventManager.cpp index afc382bc6fb7..14f110efc247 100644 --- a/source/gameengine/Ketsji/KX_CollisionEventManager.cpp +++ b/source/gameengine/Ketsji/KX_CollisionEventManager.cpp @@ -57,8 +57,8 @@ KX_CollisionEventManager::~KX_CollisionEventManager() void KX_CollisionEventManager::RemoveNewCollisions() { - for (std::set::iterator it = m_newCollisions.begin(), end = m_newCollisions.end(); it != end; ++it) { - delete it->colldata; + for (const NewCollision& collision : m_newCollisions) { + delete collision.colldata; } m_newCollisions.clear(); } @@ -129,12 +129,9 @@ bool KX_CollisionEventManager::newBroadphaseResponse(void *client_data, case KX_ClientObjectInfo::OBACTORSENSOR: // this object may have multiple collision sensors, // check is any of them is interested in this object - for (std::list::iterator it = info1->m_sensors.begin(); - it != info1->m_sensors.end(); - ++it) - { - if ((*it)->GetSensorType() == SCA_ISensor::ST_TOUCH) { - KX_CollisionSensor *collisionsensor = static_cast(*it); + for (SCA_ISensor *sensor : info1->m_sensors) { + if (sensor->GetSensorType() == SCA_ISensor::ST_TOUCH) { + KX_CollisionSensor *collisionsensor = static_cast(sensor); if (collisionsensor->BroadPhaseSensorFilterCollision(object1, object2)) { return true; } @@ -194,10 +191,10 @@ void KX_CollisionEventManager::NextFrame() static_cast(sensor)->SynchronizeTransform(); } - for (std::set::iterator cit = m_newCollisions.begin(); cit != m_newCollisions.end(); ++cit) { + for (const NewCollision& collision : m_newCollisions) { // Controllers - PHY_IPhysicsController *ctrl1 = (*cit).first; - PHY_IPhysicsController *ctrl2 = (*cit).second; + PHY_IPhysicsController *ctrl1 = collision.first; + PHY_IPhysicsController *ctrl2 = collision.second; // Sensor iterator std::list::iterator sit; @@ -222,7 +219,7 @@ void KX_CollisionEventManager::NextFrame() } } // Run python callbacks - const PHY_CollData *colldata = cit->colldata; + const PHY_CollData *colldata = collision.colldata; KX_CollisionContactPointList contactPointList0 = KX_CollisionContactPointList(colldata, true); KX_CollisionContactPointList contactPointList1 = KX_CollisionContactPointList(colldata, false); kxObj1->RunCollisionCallbacks(kxObj2, contactPointList0); diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 2ee7bebf017a..faa135d56ac2 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -537,12 +537,10 @@ void KX_GameObject::ProcessReplica() static void setGraphicController_recursive(SG_Node* node) { - NodeList& children = node->GetSGChildren(); + const NodeList& children = node->GetSGChildren(); - for (NodeList::iterator childit = children.begin();!(childit==children.end());++childit) - { - SG_Node* childnode = (*childit); - KX_GameObject *clientgameobj = static_cast( (*childit)->GetSGClientObject()); + for (SG_Node *childnode : children) { + KX_GameObject *clientgameobj = static_cast(childnode->GetSGClientObject()); if (clientgameobj != nullptr) // This is a GameObject clientgameobj->ActivateGraphicController(false); @@ -866,12 +864,10 @@ KX_GameObject::GetVisible( static void setVisible_recursive(SG_Node* node, bool v) { - NodeList& children = node->GetSGChildren(); + const NodeList& children = node->GetSGChildren(); - for (NodeList::iterator childit = children.begin();!(childit==children.end());++childit) - { - SG_Node* childnode = (*childit); - KX_GameObject *clientgameobj = static_cast( (*childit)->GetSGClientObject()); + for (SG_Node *childnode : children) { + KX_GameObject *clientgameobj = static_cast(childnode->GetSGClientObject()); if (clientgameobj != nullptr) // This is a GameObject clientgameobj->SetVisible(v, 0); @@ -897,12 +893,10 @@ KX_GameObject::SetVisible( static void setOccluder_recursive(SG_Node* node, bool v) { - NodeList& children = node->GetSGChildren(); + const NodeList& children = node->GetSGChildren(); - for (NodeList::iterator childit = children.begin();!(childit==children.end());++childit) - { - SG_Node* childnode = (*childit); - KX_GameObject *clientgameobj = static_cast( (*childit)->GetSGClientObject()); + for (SG_Node *childnode : children) { + KX_GameObject *clientgameobj = static_cast(childnode->GetSGClientObject()); if (clientgameobj != nullptr) // This is a GameObject clientgameobj->SetOccluder(v, false); @@ -925,11 +919,10 @@ KX_GameObject::SetOccluder( static void setDebug_recursive(KX_Scene *scene, SG_Node *node, bool debug) { - NodeList& children = node->GetSGChildren(); + const NodeList& children = node->GetSGChildren(); - for (NodeList::iterator childit = children.begin();!(childit==children.end());++childit) { - SG_Node *childnode = (*childit); - KX_GameObject *clientgameobj = static_cast( (*childit)->GetSGClientObject()); + for (SG_Node *childnode : children) { + KX_GameObject *clientgameobj = static_cast(childnode->GetSGClientObject()); if (clientgameobj != nullptr) { if (debug) { if (!scene->ObjectInDebugList(clientgameobj)) @@ -1511,9 +1504,7 @@ static void walk_children(SG_Node* node, CListValue *list, bool r return; NodeList& children = node->GetSGChildren(); - for (NodeList::iterator childit = children.begin();!(childit==children.end());++childit) - { - SG_Node* childnode = (*childit); + for (SG_Node *childnode : children) { KX_GameObject *childobj = static_cast(childnode->GetSGClientObject()); if (childobj != nullptr) // This is a GameObject { diff --git a/source/gameengine/Ketsji/KX_LodManager.cpp b/source/gameengine/Ketsji/KX_LodManager.cpp index d7ed17d7c345..98e336b58489 100644 --- a/source/gameengine/Ketsji/KX_LodManager.cpp +++ b/source/gameengine/Ketsji/KX_LodManager.cpp @@ -129,8 +129,8 @@ KX_LodManager::KX_LodManager(Object *ob, KX_Scene *scene, BL_BlenderSceneConvert KX_LodManager::~KX_LodManager() { - for (std::vector::iterator it = m_levels.begin(), end = m_levels.end(); it != end; ++it) { - delete *it; + for (KX_LodLevel *lodLevel : m_levels) { + delete lodLevel; } } diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index d8ef25ec93c4..0a1bd5143bf6 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -600,16 +600,14 @@ void KX_Scene::ReplicateLogic(KX_GameObject* newobj) AddObjectDebugProperties(newobj); } // also relink the controller to sensors/actuators - SCA_ControllerList& controllers = newobj->GetControllers(); + const SCA_ControllerList& controllers = newobj->GetControllers(); //SCA_SensorList& sensors = newobj->GetSensors(); //SCA_ActuatorList& actuators = newobj->GetActuators(); - for (SCA_ControllerList::iterator itc = controllers.begin(); !(itc==controllers.end());itc++) - { - SCA_IController* cont = (*itc); + for (SCA_IController *cont : controllers) { cont->SetUeberExecutePriority(m_ueberExecutionPriority); - std::vector linkedsensors = cont->GetLinkedSensors(); - std::vector linkedactuators = cont->GetLinkedActuators(); + const SCA_SensorList& linkedsensors = cont->GetLinkedSensors(); + const SCA_ActuatorList& linkedactuators = cont->GetLinkedActuators(); // disconnect the sensors and actuators // do it directly on the list at this controller is not connected to anything at this stage @@ -617,9 +615,7 @@ void KX_Scene::ReplicateLogic(KX_GameObject* newobj) cont->GetLinkedActuators().clear(); // now relink each sensor - for (std::vector::iterator its = linkedsensors.begin();!(its==linkedsensors.end());its++) - { - SCA_ISensor* oldsensor = (*its); + for (SCA_ISensor *oldsensor : linkedsensors) { SCA_IObject* oldsensorobj = oldsensor->GetParent(); // the original owner of the sensor has been replicated? SCA_IObject* newsensorobj = m_map_gameobject_to_replica[oldsensorobj]; @@ -653,9 +649,7 @@ void KX_Scene::ReplicateLogic(KX_GameObject* newobj) } // now relink each actuator - for (std::vector::iterator ita = linkedactuators.begin();!(ita==linkedactuators.end());ita++) - { - SCA_IActuator* oldactuator = (*ita); + for (SCA_IActuator *oldactuator : linkedactuators) { SCA_IObject* oldactuatorobj = oldactuator->GetParent(); SCA_IObject* newactuatorobj = m_map_gameobject_to_replica[oldactuatorobj]; @@ -756,12 +750,10 @@ void KX_Scene::DupliGroupRecurse(KX_GameObject *groupobj, int level) m_parentlist->Add(CM_AddRef(replica)); // recurse replication into children nodes - NodeList& children = gameobj->GetSGNode()->GetSGChildren(); + const NodeList& children = gameobj->GetSGNode()->GetSGChildren(); replica->GetSGNode()->ClearSGChildren(); - for (NodeList::iterator childit = children.begin();!(childit==children.end());++childit) - { - SG_Node* orgnode = (*childit); + for (SG_Node *orgnode : children) { SG_Node* childreplicanode = orgnode->GetSGReplica(); if (childreplicanode) replica->GetSGNode()->AddChild(childreplicanode); @@ -872,12 +864,10 @@ KX_GameObject *KX_Scene::AddReplicaObject(KX_GameObject *originalobject, KX_Game // recurse replication into children nodes - NodeList& children = originalobj->GetSGNode()->GetSGChildren(); + const NodeList& children = originalobj->GetSGNode()->GetSGChildren(); replica->GetSGNode()->ClearSGChildren(); - for (NodeList::iterator childit = children.begin();!(childit==children.end());++childit) - { - SG_Node* orgnode = (*childit); + for (SG_Node *orgnode : children) { SG_Node* childreplicanode = orgnode->GetSGReplica(); if (childreplicanode) replica->GetSGNode()->AddChild(childreplicanode); diff --git a/source/gameengine/Ketsji/KX_TimeCategoryLogger.cpp b/source/gameengine/Ketsji/KX_TimeCategoryLogger.cpp index 8e2a678f221a..93286fc04f30 100644 --- a/source/gameengine/Ketsji/KX_TimeCategoryLogger.cpp +++ b/source/gameengine/Ketsji/KX_TimeCategoryLogger.cpp @@ -44,8 +44,8 @@ KX_TimeCategoryLogger::~KX_TimeCategoryLogger() void KX_TimeCategoryLogger::SetMaxNumMeasurements(unsigned int maxNumMeasurements) { - for (TimeLoggerMap::iterator it = m_loggers.begin(), end = m_loggers.end(); it != end; ++it) { - it->second.SetMaxNumMeasurements(maxNumMeasurements); + for (TimeLoggerMap::value_type& pair : m_loggers) { + pair.second.SetMaxNumMeasurements(maxNumMeasurements); } m_maxNumMeasurements = maxNumMeasurements; } @@ -85,8 +85,8 @@ void KX_TimeCategoryLogger::EndLog(double now) void KX_TimeCategoryLogger::NextMeasurement(double now) { - for (TimeLoggerMap::iterator it = m_loggers.begin(), end = m_loggers.end(); it != end; ++it) { - it->second.NextMeasurement(now); + for (TimeLoggerMap::value_type& pair : m_loggers) { + pair.second.NextMeasurement(now); } } @@ -99,8 +99,8 @@ double KX_TimeCategoryLogger::GetAverage() { double time = 0.0; - for (TimeLoggerMap::iterator it = m_loggers.begin(), end = m_loggers.end(); it != end; ++it) { - time += it->second.GetAverage(); + for (TimeLoggerMap::value_type& pair : m_loggers) { + time += pair.second.GetAverage(); } return time; diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index a4120b5e99a4..af4bbedbeb10 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -704,9 +704,7 @@ void CcdPhysicsEnvironment::RemoveCcdGraphicController(CcdGraphicController *ctr void CcdPhysicsEnvironment::UpdateCcdPhysicsControllerShape(CcdShapeConstructionInfo *shapeInfo) { - for (std::set::iterator it = m_controllers.begin(); it != m_controllers.end(); ++it) { - CcdPhysicsController *ctrl = *it; - + for (CcdPhysicsController *ctrl : m_controllers) { if (ctrl->GetShapeInfo() != shapeInfo) continue; @@ -950,9 +948,10 @@ void CcdPhysicsEnvironment::SetDeactivationLinearTreshold(float linTresh) m_linearDeactivationThreshold = linTresh; // Update from all controllers. - for (std::set::iterator it = m_controllers.begin(); it != m_controllers.end(); it++) { - if ((*it)->GetRigidBody()) - (*it)->GetRigidBody()->setSleepingThresholds(m_linearDeactivationThreshold, m_angularDeactivationThreshold); + for (CcdPhysicsController *ctrl : m_controllers) { + if (ctrl->GetRigidBody()) { + ctrl->GetRigidBody()->setSleepingThresholds(m_linearDeactivationThreshold, m_angularDeactivationThreshold); + } } } void CcdPhysicsEnvironment::SetDeactivationAngularTreshold(float angTresh) diff --git a/source/gameengine/Rasterizer/RAS_2DFilter.cpp b/source/gameengine/Rasterizer/RAS_2DFilter.cpp index 9e41fa58957e..843d3a8bbb20 100644 --- a/source/gameengine/Rasterizer/RAS_2DFilter.cpp +++ b/source/gameengine/Rasterizer/RAS_2DFilter.cpp @@ -176,9 +176,8 @@ void RAS_2DFilter::ParseShaderProgram() if (m_gameObject) { std::vector foundProperties; - for (std::vector::iterator it = m_properties.begin(), end = m_properties.end(); it != end; ++it) { - std::string prop = *it; - unsigned int loc = GetUniformLocation(prop, false); + for (const std::string& prop : m_properties) { + const unsigned int loc = GetUniformLocation(prop, false); if (loc != -1) { m_propertiesLoc.push_back(loc); foundProperties.push_back(prop); diff --git a/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp b/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp index 18d136302162..08d2aff020e0 100644 --- a/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp +++ b/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp @@ -53,8 +53,8 @@ RAS_2DFilterManager::RAS_2DFilterManager() RAS_2DFilterManager::~RAS_2DFilterManager() { - for (RAS_PassTo2DFilter::iterator it = m_filters.begin(), end = m_filters.end(); it != end; ++it) { - RAS_2DFilter *filter = it->second; + for (const RAS_PassTo2DFilter::value_type& pair : m_filters) { + RAS_2DFilter *filter = pair.second; delete filter; } } diff --git a/source/gameengine/Rasterizer/RAS_BatchGroup.cpp b/source/gameengine/Rasterizer/RAS_BatchGroup.cpp index ed2eb4ed4596..caf293df3388 100644 --- a/source/gameengine/Rasterizer/RAS_BatchGroup.cpp +++ b/source/gameengine/Rasterizer/RAS_BatchGroup.cpp @@ -48,8 +48,8 @@ RAS_BatchGroup::RAS_BatchGroup() RAS_BatchGroup::~RAS_BatchGroup() { - for (std::map::iterator it = m_batchs.begin(), end = m_batchs.end(); it != end; ++it) { - Batch& batch = it->second; + for (const auto& pair : m_batchs) { + const Batch& batch = pair.second; delete batch.m_displayArrayBucket; } } @@ -145,9 +145,7 @@ bool RAS_BatchGroup::SplitMeshSlot(RAS_MeshSlot *slot) bool RAS_BatchGroup::MergeMeshUser(RAS_MeshUser *meshUser, const MT_Matrix4x4& mat) { - const RAS_MeshSlotList& meshSlots = meshUser->GetMeshSlots(); - for (RAS_MeshSlotList::const_iterator it = meshSlots.begin(), end = meshSlots.end(); it != end; ++it) { - RAS_MeshSlot *meshSlot = *it; + for (RAS_MeshSlot *meshSlot : meshUser->GetMeshSlots()) { RAS_DisplayArrayBucket *arrayBucket = meshSlot->m_displayArrayBucket; RAS_MaterialBucket *bucket = arrayBucket->GetBucket(); RAS_IPolyMaterial *material = bucket->GetPolyMaterial(); @@ -173,9 +171,7 @@ bool RAS_BatchGroup::MergeMeshUser(RAS_MeshUser *meshUser, const MT_Matrix4x4& m bool RAS_BatchGroup::SplitMeshUser(RAS_MeshUser *meshUser) { - const RAS_MeshSlotList& meshSlots = meshUser->GetMeshSlots(); - for (RAS_MeshSlotList::const_iterator it = meshSlots.begin(), end = meshSlots.end(); it != end; ++it) { - RAS_MeshSlot *meshSlot = *it; + for (RAS_MeshSlot *meshSlot : meshUser->GetMeshSlots()) { if (!SplitMeshSlot(meshSlot)) { return false; } @@ -196,11 +192,9 @@ void RAS_BatchGroup::Destruct() */ AddMeshUser(); - for (std::map::iterator bit = m_batchs.begin(), bend = m_batchs.end(); bit != bend; ++bit) { - Batch& batch = bit->second; - const RAS_MeshSlotList& meshSlots = batch.m_meshSlots; - for (std::vector::const_iterator mit = meshSlots.begin(), mend = meshSlots.end(); mit != mend; ++mit) { - RAS_MeshSlot *slot = *mit; + for (auto& pair : m_batchs) { + Batch& batch = pair.second; + for (RAS_MeshSlot *slot : batch.m_meshSlots) { RAS_DisplayArrayBucket *origArrayBucket = batch.m_originalDisplayArrayBucketList[slot]; slot->SetDisplayArrayBucket(origArrayBucket); diff --git a/source/gameengine/Rasterizer/RAS_BoundingBox.cpp b/source/gameengine/Rasterizer/RAS_BoundingBox.cpp index 5926c99b3d45..ea5c42f914ff 100644 --- a/source/gameengine/Rasterizer/RAS_BoundingBox.cpp +++ b/source/gameengine/Rasterizer/RAS_BoundingBox.cpp @@ -150,8 +150,8 @@ void RAS_MeshBoundingBox::Update(bool force) { bool modified = false; // Detect if a display array was modified. - for (RAS_IDisplayArrayList::iterator it = m_displayArrayList.begin(), end = m_displayArrayList.end(); it != end; ++it) { - if ((*it)->GetModifiedFlag() & RAS_IDisplayArray::AABB_MODIFIED) { + for (RAS_IDisplayArray *array : m_displayArrayList) { + if (array->GetModifiedFlag() & RAS_IDisplayArray::AABB_MODIFIED) { modified = true; break; } diff --git a/source/gameengine/Rasterizer/RAS_BoundingBoxManager.cpp b/source/gameengine/Rasterizer/RAS_BoundingBoxManager.cpp index b0fcd1481cf3..431aaa6933a0 100644 --- a/source/gameengine/Rasterizer/RAS_BoundingBoxManager.cpp +++ b/source/gameengine/Rasterizer/RAS_BoundingBoxManager.cpp @@ -34,8 +34,8 @@ RAS_BoundingBoxManager::RAS_BoundingBoxManager() RAS_BoundingBoxManager::~RAS_BoundingBoxManager() { - for (RAS_BoundingBoxList::iterator it = m_boundingBoxList.begin(), end = m_boundingBoxList.end(); it != end; ++it) { - delete *it; + for (RAS_BoundingBox *boundingBox : m_boundingBoxList) { + delete boundingBox; } BLI_assert(m_activeBoundingBoxList.size() == 0); @@ -56,22 +56,21 @@ RAS_BoundingBox *RAS_BoundingBoxManager::CreateMeshBoundingBox(const RAS_IDispla void RAS_BoundingBoxManager::Update(bool force) { - for (RAS_BoundingBoxList::iterator it = m_activeBoundingBoxList.begin(), end = m_activeBoundingBoxList.end(); it != end; ++it) { - (*it)->Update(force); + for (RAS_BoundingBox *boundingBox : m_activeBoundingBoxList) { + boundingBox->Update(force); } } void RAS_BoundingBoxManager::ClearModified() { - for (RAS_BoundingBoxList::iterator it = m_activeBoundingBoxList.begin(), end = m_activeBoundingBoxList.end(); it != end; ++it) { - (*it)->ClearModified(); + for (RAS_BoundingBox *boundingBox : m_activeBoundingBoxList) { + boundingBox->ClearModified(); } } void RAS_BoundingBoxManager::Merge(RAS_BoundingBoxManager *other) { - for (RAS_BoundingBoxList::iterator it = other->m_boundingBoxList.begin(), end = other->m_boundingBoxList.end(); it != end; ++it) { - RAS_BoundingBox *boundingBox = *it; + for (RAS_BoundingBox *boundingBox : other->m_boundingBoxList) { boundingBox->SetManager(this); m_boundingBoxList.push_back(boundingBox); } diff --git a/source/gameengine/Rasterizer/RAS_BucketManager.cpp b/source/gameengine/Rasterizer/RAS_BucketManager.cpp index f24ddf5185d2..63b32fd17a21 100644 --- a/source/gameengine/Rasterizer/RAS_BucketManager.cpp +++ b/source/gameengine/Rasterizer/RAS_BucketManager.cpp @@ -92,12 +92,9 @@ RAS_BucketManager::~RAS_BucketManager() delete m_text.m_arrayBucket; delete m_text.m_material; - BucketList& buckets = m_buckets[ALL_BUCKET]; - for (BucketList::iterator it = buckets.begin(), end = buckets.end(); it != end; ++it) { - delete *it; + for (RAS_MaterialBucket *bucket : m_buckets[ALL_BUCKET]) { + delete bucket; } - buckets.clear(); - } void RAS_BucketManager::RenderSortedBuckets(RAS_Rasterizer *rasty, RAS_BucketManager::BucketType bucketType) @@ -134,9 +131,8 @@ void RAS_BucketManager::RenderSortedBuckets(RAS_Rasterizer *rasty, RAS_BucketMan void RAS_BucketManager::RenderBasicBuckets(RAS_Rasterizer *rasty, RAS_BucketManager::BucketType bucketType) { - BucketList& solidBuckets = m_buckets[bucketType]; RAS_UpwardTreeLeafs leafs; - for (RAS_MaterialBucket *bucket : solidBuckets) { + for (RAS_MaterialBucket *bucket : m_buckets[bucketType]) { bucket->GenerateTree(m_downwardNode, m_upwardNode, leafs, rasty, false); } @@ -308,9 +304,8 @@ void RAS_BucketManager::Renderbuckets(RAS_Rasterizer::DrawType drawingMode, cons } } - BucketList& buckets = m_buckets[ALL_BUCKET]; - for (BucketList::iterator it = buckets.begin(), end = buckets.end(); it != end; ++it) { - (*it)->RemoveActiveMeshSlots(); + for (RAS_MaterialBucket *bucket : m_buckets[ALL_BUCKET]) { + bucket->RemoveActiveMeshSlots(); } rasty->SetClientObject(nullptr); @@ -320,9 +315,7 @@ RAS_MaterialBucket *RAS_BucketManager::FindBucket(RAS_IPolyMaterial *material, b { bucketCreated = false; - BucketList& buckets = m_buckets[ALL_BUCKET]; - for (BucketList::iterator it = buckets.begin(), end = buckets.end(); it != end; ++it) { - RAS_MaterialBucket *bucket = *it; + for (RAS_MaterialBucket *bucket : m_buckets[ALL_BUCKET]) { if (bucket->GetPolyMaterial() == material) { return bucket; } @@ -364,9 +357,7 @@ RAS_DisplayArrayBucket *RAS_BucketManager::GetTextDisplayArrayBucket() const void RAS_BucketManager::UpdateShaders(RAS_IPolyMaterial *mat) { - BucketList& buckets = m_buckets[ALL_BUCKET]; - for (BucketList::iterator it = buckets.begin(), end = buckets.end(); it != end; ++it) { - RAS_MaterialBucket *bucket = *it; + for (RAS_MaterialBucket *bucket : m_buckets[ALL_BUCKET]) { if (bucket->GetPolyMaterial() != mat && mat) { continue; } @@ -376,9 +367,7 @@ void RAS_BucketManager::UpdateShaders(RAS_IPolyMaterial *mat) void RAS_BucketManager::ReleaseMaterials(RAS_IPolyMaterial *mat) { - BucketList& buckets = m_buckets[ALL_BUCKET]; - for (BucketList::iterator it = buckets.begin(), end = buckets.end(); it != end; ++it) { - RAS_MaterialBucket *bucket = *it; + for (RAS_MaterialBucket *bucket : m_buckets[ALL_BUCKET]) { if (mat == nullptr || (mat == bucket->GetPolyMaterial())) { bucket->GetPolyMaterial()->ReleaseMaterial(); } diff --git a/source/gameengine/Rasterizer/RAS_MeshObject.cpp b/source/gameengine/Rasterizer/RAS_MeshObject.cpp index ab3da295ac76..7500e96b81b4 100644 --- a/source/gameengine/Rasterizer/RAS_MeshObject.cpp +++ b/source/gameengine/Rasterizer/RAS_MeshObject.cpp @@ -59,8 +59,8 @@ RAS_MeshObject::~RAS_MeshObject() m_sharedvertex_map.clear(); m_polygons.clear(); - for (RAS_MeshMaterialList::iterator it = m_materials.begin(), end = m_materials.end(); it != end; ++it) { - delete *it; + for (RAS_MeshMaterial *meshmat : m_materials) { + delete meshmat; } m_materials.clear(); } @@ -91,8 +91,7 @@ RAS_MeshMaterial *RAS_MeshObject::GetMeshMaterial(unsigned int matid) const RAS_MeshMaterial *RAS_MeshObject::GetMeshMaterialBlenderIndex(unsigned int index) { - for (RAS_MeshMaterialList::iterator mit = m_materials.begin(); mit != m_materials.end(); mit++) { - RAS_MeshMaterial *meshmat = *mit; + for (RAS_MeshMaterial *meshmat : m_materials) { if (meshmat->GetIndex() == index) { return meshmat; } @@ -310,9 +309,7 @@ void RAS_MeshObject::EndConversion(RAS_BoundingBoxManager *boundingBoxManager) RAS_IDisplayArrayList arrayList; // Construct a list of all the display arrays used by this mesh. - for (RAS_MeshMaterialList::iterator it = m_materials.begin(), end = m_materials.end(); it != end; ++it) { - RAS_MeshMaterial *meshmat = *it; - + for (RAS_MeshMaterial *meshmat : m_materials) { RAS_IDisplayArray *array = meshmat->GetDisplayArray(); if (array) { array->UpdateCache(); diff --git a/source/gameengine/Rasterizer/RAS_MeshUser.cpp b/source/gameengine/Rasterizer/RAS_MeshUser.cpp index 7ff917e65dbe..90deca554090 100644 --- a/source/gameengine/Rasterizer/RAS_MeshUser.cpp +++ b/source/gameengine/Rasterizer/RAS_MeshUser.cpp @@ -122,8 +122,7 @@ void RAS_MeshUser::SetBatchGroup(RAS_BatchGroup *batchGroup) void RAS_MeshUser::ActivateMeshSlots() { - for (RAS_MeshSlotList::iterator it = m_meshSlots.begin(), end = m_meshSlots.end(); it != end; ++it) { - RAS_MeshSlot *ms = *it; + for (RAS_MeshSlot *ms : m_meshSlots) { ms->m_displayArrayBucket->ActivateMesh(ms); } }