Skip to content

Commit

Permalink
UPBGE: Use C++11 range loop instead of std iterator.
Browse files Browse the repository at this point in the history
  • Loading branch information
panzergame committed Sep 18, 2017
1 parent 6817669 commit a3a1b45
Show file tree
Hide file tree
Showing 17 changed files with 103 additions and 174 deletions.
67 changes: 21 additions & 46 deletions source/gameengine/GameLogic/SCA_IObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand All @@ -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();
}
}
}
Expand All @@ -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);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions source/gameengine/GameLogic/SCA_LogicManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ SCA_LogicManager::SCA_LogicManager()

SCA_LogicManager::~SCA_LogicManager()
{
for (std::vector<SCA_EventManager*>::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());
}
Expand Down
2 changes: 1 addition & 1 deletion source/gameengine/Ketsji/BL_ActionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 9 additions & 12 deletions source/gameengine/Ketsji/KX_CollisionEventManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ KX_CollisionEventManager::~KX_CollisionEventManager()

void KX_CollisionEventManager::RemoveNewCollisions()
{
for (std::set<NewCollision>::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();
}
Expand Down Expand Up @@ -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<SCA_ISensor *>::iterator it = info1->m_sensors.begin();
it != info1->m_sensors.end();
++it)
{
if ((*it)->GetSensorType() == SCA_ISensor::ST_TOUCH) {
KX_CollisionSensor *collisionsensor = static_cast<KX_CollisionSensor *>(*it);
for (SCA_ISensor *sensor : info1->m_sensors) {
if (sensor->GetSensorType() == SCA_ISensor::ST_TOUCH) {
KX_CollisionSensor *collisionsensor = static_cast<KX_CollisionSensor *>(sensor);
if (collisionsensor->BroadPhaseSensorFilterCollision(object1, object2)) {
return true;
}
Expand Down Expand Up @@ -194,10 +191,10 @@ void KX_CollisionEventManager::NextFrame()
static_cast<KX_CollisionSensor *>(sensor)->SynchronizeTransform();
}

for (std::set<NewCollision>::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<SCA_ISensor *>::iterator sit;

Expand All @@ -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);
Expand Down
35 changes: 13 additions & 22 deletions source/gameengine/Ketsji/KX_GameObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<KX_GameObject*>( (*childit)->GetSGClientObject());
for (SG_Node *childnode : children) {
KX_GameObject *clientgameobj = static_cast<KX_GameObject *>(childnode->GetSGClientObject());
if (clientgameobj != nullptr) // This is a GameObject
clientgameobj->ActivateGraphicController(false);

Expand Down Expand Up @@ -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<KX_GameObject*>( (*childit)->GetSGClientObject());
for (SG_Node *childnode : children) {
KX_GameObject *clientgameobj = static_cast<KX_GameObject*>(childnode->GetSGClientObject());
if (clientgameobj != nullptr) // This is a GameObject
clientgameobj->SetVisible(v, 0);

Expand All @@ -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<KX_GameObject*>( (*childit)->GetSGClientObject());
for (SG_Node *childnode : children) {
KX_GameObject *clientgameobj = static_cast<KX_GameObject*>(childnode->GetSGClientObject());
if (clientgameobj != nullptr) // This is a GameObject
clientgameobj->SetOccluder(v, false);

Expand All @@ -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<KX_GameObject*>( (*childit)->GetSGClientObject());
for (SG_Node *childnode : children) {
KX_GameObject *clientgameobj = static_cast<KX_GameObject*>(childnode->GetSGClientObject());
if (clientgameobj != nullptr) {
if (debug) {
if (!scene->ObjectInDebugList(clientgameobj))
Expand Down Expand Up @@ -1511,9 +1504,7 @@ static void walk_children(SG_Node* node, CListValue<KX_GameObject> *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<KX_GameObject *>(childnode->GetSGClientObject());
if (childobj != nullptr) // This is a GameObject
{
Expand Down
4 changes: 2 additions & 2 deletions source/gameengine/Ketsji/KX_LodManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ KX_LodManager::KX_LodManager(Object *ob, KX_Scene *scene, BL_BlenderSceneConvert

KX_LodManager::~KX_LodManager()
{
for (std::vector<KX_LodLevel *>::iterator it = m_levels.begin(), end = m_levels.end(); it != end; ++it) {
delete *it;
for (KX_LodLevel *lodLevel : m_levels) {
delete lodLevel;
}
}

Expand Down
30 changes: 10 additions & 20 deletions source/gameengine/Ketsji/KX_Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,26 +600,22 @@ 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<SCA_ISensor*> linkedsensors = cont->GetLinkedSensors();
std::vector<SCA_IActuator*> 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
cont->GetLinkedSensors().clear();
cont->GetLinkedActuators().clear();

// now relink each sensor
for (std::vector<SCA_ISensor*>::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];
Expand Down Expand Up @@ -653,9 +649,7 @@ void KX_Scene::ReplicateLogic(KX_GameObject* newobj)
}

// now relink each actuator
for (std::vector<SCA_IActuator*>::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];

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions source/gameengine/Ketsji/KX_TimeCategoryLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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;
Expand Down
Loading

0 comments on commit a3a1b45

Please sign in to comment.