Skip to content

Commit

Permalink
UPBGE: Use C++11 range loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
panzergame committed Oct 10, 2017
1 parent 3571665 commit e817e15
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 176 deletions.
12 changes: 3 additions & 9 deletions source/gameengine/GameLogic/SCA_ANDController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,16 @@ void SCA_ANDController::Trigger(SCA_LogicManager* logicmgr)

bool sensorresult = true;

for (std::vector<SCA_ISensor*>::const_iterator is=m_linkedsensors.begin();
!(is==m_linkedsensors.end());is++)
{
SCA_ISensor* sensor = *is;
for (SCA_ISensor *sensor : m_linkedsensors) {
if (!sensor->GetState())
{
sensorresult = false;
break;
}
}

for (std::vector<SCA_IActuator*>::const_iterator i=m_linkedactuators.begin();
!(i==m_linkedactuators.end());i++)
{
SCA_IActuator* actua = *i;
logicmgr->AddActiveActuator(actua,sensorresult);
for (SCA_IActuator *actuator : m_linkedactuators) {
logicmgr->AddActiveActuator(actuator, sensorresult);
}
}

Expand Down
3 changes: 1 addition & 2 deletions source/gameengine/GameLogic/SCA_KeyboardSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,7 @@ void SCA_KeyboardSensor::LogKeystrokes()
/* Convert all typed key in the prop string, if the key are del or
* backspace we remove the last string item.
*/
for (std::wstring::const_iterator it = typedtext.begin(), end = typedtext.end(); it != end; ++it) {
const wchar_t item = *it;
for (const wchar_t item : typedtext) {
if (item == '\b' || item == 127) {
if (!proptext.empty()) {
proptext.resize(proptext.size() - 1);
Expand Down
11 changes: 3 additions & 8 deletions source/gameengine/GameLogic/SCA_LogicManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,8 @@ void SCA_LogicManager::RegisterActionName(const std::string& actname,void* actio

void SCA_LogicManager::EndFrame()
{
for (std::vector<SCA_EventManager*>::const_iterator ie=m_eventmanagers.begin();
!(ie==m_eventmanagers.end());ie++)
{
(*ie)->EndFrame();
for (SCA_EventManager *emgr : m_eventmanagers) {
emgr->EndFrame();
}
}

Expand All @@ -292,10 +290,7 @@ SCA_EventManager* SCA_LogicManager::FindEventManager(int eventmgrtype)
// find an eventmanager of a certain type
SCA_EventManager* eventmgr = nullptr;

for (std::vector<SCA_EventManager*>::const_iterator i=
m_eventmanagers.begin();!(i==m_eventmanagers.end());i++)
{
SCA_EventManager* emgr = *i;
for (SCA_EventManager *emgr : m_eventmanagers) {
if (emgr->GetType() == eventmgrtype)
{
eventmgr = emgr;
Expand Down
12 changes: 3 additions & 9 deletions source/gameengine/GameLogic/SCA_NANDController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,16 @@ void SCA_NANDController::Trigger(SCA_LogicManager* logicmgr)

bool sensorresult = false;

for (std::vector<SCA_ISensor*>::const_iterator is=m_linkedsensors.begin();
!(is==m_linkedsensors.end());is++)
{
SCA_ISensor* sensor = *is;
for (SCA_ISensor *sensor : m_linkedsensors) {
if (!sensor->GetState())
{
sensorresult = true;
break;
}
}

for (std::vector<SCA_IActuator*>::const_iterator i=m_linkedactuators.begin();
!(i==m_linkedactuators.end());i++)
{
SCA_IActuator* actua = *i;
logicmgr->AddActiveActuator(actua,sensorresult);
for (SCA_IActuator *actuator : m_linkedactuators) {
logicmgr->AddActiveActuator(actuator, sensorresult);
}
}

Expand Down
12 changes: 3 additions & 9 deletions source/gameengine/GameLogic/SCA_NORController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,16 @@ void SCA_NORController::Trigger(SCA_LogicManager* logicmgr)

bool sensorresult = true;

for (std::vector<SCA_ISensor*>::const_iterator is=m_linkedsensors.begin();
!(is==m_linkedsensors.end());is++)
{
SCA_ISensor* sensor = *is;
for (SCA_ISensor *sensor : m_linkedsensors) {
if (sensor->GetState())
{
sensorresult = false;
break;
}
}

for (std::vector<SCA_IActuator*>::const_iterator i=m_linkedactuators.begin();
!(i==m_linkedactuators.end());i++)
{
SCA_IActuator* actua = *i;
logicmgr->AddActiveActuator(actua,sensorresult);
for (SCA_IActuator *actuator : m_linkedactuators) {
logicmgr->AddActiveActuator(actuator, sensorresult);
}
}

Expand Down
20 changes: 7 additions & 13 deletions source/gameengine/GameLogic/SCA_ORController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,15 @@ void SCA_ORController::Trigger(SCA_LogicManager* logicmgr)
{

bool sensorresult = false;
SCA_ISensor* sensor;

std::vector<SCA_ISensor*>::const_iterator is=m_linkedsensors.begin();
while ( (!sensorresult) && (!(is==m_linkedsensors.end())) )
{
sensor = *is;
if (sensor->GetState()) sensorresult = true;
is++;

for (SCA_ISensor *sensor : m_linkedsensors) {
if (sensor->GetState()) {
sensorresult = true;
}
}

for (std::vector<SCA_IActuator*>::const_iterator i=m_linkedactuators.begin();
!(i==m_linkedactuators.end());i++)
{
SCA_IActuator* actua = *i;
logicmgr->AddActiveActuator(actua,sensorresult);
for (SCA_IActuator *actuator : m_linkedactuators) {
logicmgr->AddActiveActuator(actuator, sensorresult);
}
}

Expand Down
26 changes: 8 additions & 18 deletions source/gameengine/GameLogic/SCA_TimeEventManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ SCA_TimeEventManager::SCA_TimeEventManager(SCA_LogicManager* logicmgr)

SCA_TimeEventManager::~SCA_TimeEventManager()
{
for (std::vector<CValue*>::iterator it = m_timevalues.begin();
!(it == m_timevalues.end()); ++it)
{
(*it)->Release();
for (CValue *prop : m_timevalues) {
prop->Release();
}
}

Expand Down Expand Up @@ -81,12 +79,10 @@ void SCA_TimeEventManager::NextFrame(double curtime, double fixedtime)
CFloatValue* floatval = new CFloatValue(curtime);

// update sensors, but ... need deltatime !
for (std::vector<CValue*>::iterator it = m_timevalues.begin();
!(it == m_timevalues.end()); ++it)
{
float newtime = (*it)->GetNumber() + fixedtime;
for (CValue *prop : m_timevalues) {
float newtime = prop->GetNumber() + fixedtime;
floatval->SetFloat(newtime);
(*it)->SetValue(floatval);
prop->SetValue(floatval);
}

floatval->Release();
Expand All @@ -104,15 +100,9 @@ void SCA_TimeEventManager::AddTimeProperty(CValue* timeval)

void SCA_TimeEventManager::RemoveTimeProperty(CValue* timeval)
{
for (std::vector<CValue*>::iterator it = m_timevalues.begin();
!(it == m_timevalues.end()); ++it)
{
if ((*it) == timeval)
{
this->m_timevalues.erase(it);
timeval->Release();
break;
}
std::vector<CValue *>::iterator it = std::find(m_timevalues.begin(), m_timevalues.end(), timeval);
if (it != m_timevalues.end()) {
m_timevalues.erase(it);
}
}

Expand Down
12 changes: 3 additions & 9 deletions source/gameengine/GameLogic/SCA_XNORController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ void SCA_XNORController::Trigger(SCA_LogicManager* logicmgr)

bool sensorresult = true;

for (std::vector<SCA_ISensor*>::const_iterator is=m_linkedsensors.begin();
!(is==m_linkedsensors.end());is++)
{
SCA_ISensor* sensor = *is;
for (SCA_ISensor *sensor : m_linkedsensors) {
if (sensor->GetState())
{
if (sensorresult == false)
Expand All @@ -76,11 +73,8 @@ void SCA_XNORController::Trigger(SCA_LogicManager* logicmgr)
}
}

for (std::vector<SCA_IActuator*>::const_iterator i=m_linkedactuators.begin();
!(i==m_linkedactuators.end());i++)
{
SCA_IActuator* actua = *i;
logicmgr->AddActiveActuator(actua,sensorresult);
for (SCA_IActuator *actuator : m_linkedactuators) {
logicmgr->AddActiveActuator(actuator, sensorresult);
}
}

Expand Down
12 changes: 3 additions & 9 deletions source/gameengine/GameLogic/SCA_XORController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ void SCA_XORController::Trigger(SCA_LogicManager* logicmgr)

bool sensorresult = false;

for (std::vector<SCA_ISensor*>::const_iterator is=m_linkedsensors.begin();
!(is==m_linkedsensors.end());is++)
{
SCA_ISensor* sensor = *is;
for (SCA_ISensor *sensor : m_linkedsensors) {
if (sensor->GetState())
{
if (sensorresult == true)
Expand All @@ -76,11 +73,8 @@ void SCA_XORController::Trigger(SCA_LogicManager* logicmgr)
}
}

for (std::vector<SCA_IActuator*>::const_iterator i=m_linkedactuators.begin();
!(i==m_linkedactuators.end());i++)
{
SCA_IActuator* actua = *i;
logicmgr->AddActiveActuator(actua,sensorresult);
for (SCA_IActuator *actuator : m_linkedactuators) {
logicmgr->AddActiveActuator(actuator, sensorresult);
}
}

Expand Down
12 changes: 4 additions & 8 deletions source/gameengine/Ketsji/BL_Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,13 +505,11 @@ KX_PYMETHODDEF_DOC(BL_Shader, setUniformEyef, "setUniformEyef(name)")
int loc = GetUniformLocation(uniform);
if (loc != -1) {
bool defined = false;
RAS_UniformVecDef::iterator it = m_preDef.begin();
while (it != m_preDef.end()) {
if ((*it)->m_loc == loc) {
for (RAS_DefUniform *defuni : m_preDef) {
if (defuni->m_loc == loc) {
defined = true;
break;
}
it++;
}

if (defined) {
Expand Down Expand Up @@ -916,13 +914,11 @@ KX_PYMETHODDEF_DOC(BL_Shader, setUniformDef, "setUniformDef(name, enum)")

if (loc != -1) {
bool defined = false;
RAS_UniformVecDef::iterator it = m_preDef.begin();
while (it != m_preDef.end()) {
if ((*it)->m_loc == loc) {
for (RAS_DefUniform *defuni : m_preDef) {
if (defuni->m_loc == loc) {
defined = true;
break;
}
it++;
}

if (defined) {
Expand Down
12 changes: 4 additions & 8 deletions source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,12 @@ const std::vector<KX_NetworkMessageManager::Message> KX_NetworkMessageManager::G
std::map<std::string, std::vector<Message> >& messagesReceiver = m_messages[1 - m_currentList][to];
if (subject.empty()) {
// Add all message without receiver and subject.
for (std::map<std::string, std::vector<Message> >::iterator it = messagesNoReceiver.begin(), end = messagesNoReceiver.end();
it != end; ++it)
{
messages.insert(messages.end(), it->second.begin(), it->second.end());
for (const auto& pair : messagesNoReceiver) {
messages.insert(messages.end(), pair.second.begin(), pair.second.end());
}
// Add all message with the given receiver and no subject.
for (std::map<std::string, std::vector<Message> >::iterator it = messagesReceiver.begin(), end = messagesReceiver.end();
it != end; ++it)
{
messages.insert(messages.end(), it->second.begin(), it->second.end());
for (const auto& pair : messagesReceiver) {
messages.insert(messages.end(), pair.second.begin(), pair.second.end());
}
}
else {
Expand Down
6 changes: 2 additions & 4 deletions source/gameengine/Ketsji/KX_BatchGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ CListValue<KX_GameObject> *KX_BatchGroup::GetObjects() const

void KX_BatchGroup::MergeObjects(const std::vector<KX_GameObject *>& objects)
{
for (std::vector<KX_GameObject *>::const_iterator it = objects.begin(), end = objects.end(); it != end; ++it) {
KX_GameObject *gameobj = *it;
for (KX_GameObject *gameobj : objects) {
RAS_MeshUser *meshUser = gameobj->GetMeshUser();

if (!meshUser) {
Expand Down Expand Up @@ -87,8 +86,7 @@ void KX_BatchGroup::SplitObjects(const std::vector<KX_GameObject *>& objects)
// Add a fake mesh user to avoid free the batch group while running the function.
AddMeshUser();

for (std::vector<KX_GameObject *>::const_iterator it = objects.begin(), end = objects.end(); it != end; ++it) {
KX_GameObject *gameobj = *it;
for (KX_GameObject *gameobj : objects) {
RAS_MeshUser *meshUser = gameobj->GetMeshUser();

if (!meshUser) {
Expand Down
Loading

0 comments on commit e817e15

Please sign in to comment.