1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-15 06:52:34 +02:00

Use range loop

This commit is contained in:
Filip Gawin 2018-01-26 16:47:07 +01:00 committed by Daniel Evans
parent e3e3642ec2
commit 73a5daab82
16 changed files with 36 additions and 44 deletions

View File

@ -28,8 +28,7 @@ void AIGraph::createPathNodes(const glm::vec3& position,
glm::vec3 nodePosition = position + (rotation * node.position);
if (node.type == PathNode::EXTERNAL) {
for (size_t rn = 0; rn < externalNodes.size(); ++rn) {
auto& realNode = externalNodes[rn];
for (auto &realNode : externalNodes) {
auto d = glm::distance2(realNode->position, nodePosition);
if (d < 1.f) {
pathNodes.push_back(realNode);

View File

@ -2,8 +2,8 @@
GameString GameStringUtil::fromString(const std::string& str) {
GameString s;
for (std::string::size_type i = 0u; i < str.size(); ++i) {
s += str[i];
for (const char &i : str) {
s += i;
}
return s;
}

View File

@ -78,8 +78,7 @@ bool CollisionInstance::createPhysicsBody(GameObject* object,
t.setIdentity();
// Boxes
for (size_t i = 0; i < collision->boxes.size(); ++i) {
auto& box = collision->boxes[i];
for (const auto &box : collision->boxes) {
auto size = (box.max - box.min) / 2.f;
auto mid = (box.min + box.max) / 2.f;
btCollisionShape* bshape =
@ -94,8 +93,7 @@ bool CollisionInstance::createPhysicsBody(GameObject* object,
}
// Spheres
for (size_t i = 0; i < collision->spheres.size(); ++i) {
auto& sphere = collision->spheres[i];
for (const auto &sphere : collision->spheres) {
btCollisionShape* sshape = new btSphereShape(sphere.radius);
t.setOrigin(
btVector3(sphere.center.x, sphere.center.y, sphere.center.z));

View File

@ -121,9 +121,9 @@ GameState::GameState()
int GameState::addRadarBlip(BlipData& blip) {
int l = 0;
for (auto x = radarBlips.begin(); x != radarBlips.end(); ++x) {
if ((x->first) != l) {
l = x->first - 1;
for (const auto &radarBlip : radarBlips) {
if ((radarBlip.first) != l) {
l = radarBlip.first - 1;
} else {
l++;
}

View File

@ -86,8 +86,7 @@ bool GameWorld::placeItems(const std::string& name) {
if (ipll.load(path)) {
// Find the object.
for (size_t i = 0; i < ipll.m_instances.size(); ++i) {
std::shared_ptr<InstanceData> inst = ipll.m_instances[i];
for (auto inst : ipll.m_instances) {
if (!createInstance(inst->id, inst->pos, inst->rot)) {
logger->error("World", "No object data for instance " +
std::to_string(inst->id) + " in " +

View File

@ -8,13 +8,13 @@ void ScreenText::tick(float dt) {
// Remove all the immedate text
m_textQueues[static_cast<size_t>(ScreenTextType::Immediate)].clear();
for (unsigned int t = 0; t < m_textQueues.size(); ++t) {
for (unsigned int i = 0; i < m_textQueues[t].size();) {
auto& big = m_textQueues[t][i];
for (auto &textQueue : m_textQueues) {
for (unsigned int i = 0; i < textQueue.size();) {
auto& big = textQueue[i];
big.displayedMS += millis;
if (big.displayedMS >= big.durationMS) {
m_textQueues[t].erase(m_textQueues[t].begin() + i);
textQueue.erase(textQueue.begin() + i);
} else {
++i;
}

View File

@ -48,9 +48,9 @@ AnimationKeyframe AnimationBone::getInterpolatedKeyframe(float time) {
}
AnimationKeyframe AnimationBone::getKeyframe(float time) {
for (size_t f = 0; f < frames.size(); ++f) {
if (time >= frames[f].starttime) {
return frames[f];
for (auto &frame : frames) {
if (time >= frame.starttime) {
return frame;
}
}
return frames.back();

View File

@ -47,9 +47,9 @@ bool WeatherLoader::load(const std::string& filename, Weather& outWeather) {
weather.bottomCloudColor = readRGB(ss);
int d;
for (size_t i = 0; i < 4; i++) {
for (auto &i : weather.unknown) {
ss >> d;
weather.unknown[i] = d;
i = d;
}
outWeather.entries.push_back(weather);

View File

@ -521,16 +521,16 @@ void CharacterObject::resetToAINode() {
bool vehicleNode = !!getCurrentVehicle();
AIGraphNode* nearest = nullptr;
float d = std::numeric_limits<float>::max();
for (auto it = nodes.begin(); it != nodes.end(); ++it) {
for (const auto &node : nodes) {
if (vehicleNode) {
if ((*it)->type == AIGraphNode::Pedestrian) continue;
if (node->type == AIGraphNode::Pedestrian) continue;
} else {
if ((*it)->type == AIGraphNode::Vehicle) continue;
if (node->type == AIGraphNode::Vehicle) continue;
}
float dist = glm::length((*it)->position - getPosition());
float dist = glm::length(node->position - getPosition());
if (dist < d) {
nearest = *it;
nearest = node;
d = dist;
}
}

View File

@ -91,9 +91,7 @@ TextRenderer::TextRenderer(GameRenderer* renderer) : renderer(renderer) {
textShader = renderer->getRenderer()->createShader(TextVertexShader,
TextFragmentShader);
for (int g = 0; g < GAME_GLYPHS; g++) {
glyphData[g] = {.9f};
}
std::fill(glyphData.begin(), glyphData.end(), GlyphInfo{.9f});
glyphData[charToIndex(' ')].widthFrac = 0.4f;
glyphData[charToIndex('-')].widthFrac = 0.5f;

View File

@ -66,7 +66,7 @@ public:
private:
std::string fonts[GAME_FONTS];
GlyphInfo glyphData[GAME_GLYPHS];
std::array<GlyphInfo, GAME_GLYPHS> glyphData;
GameRenderer* renderer;
std::unique_ptr<Renderer::ShaderProgram> textShader;

View File

@ -50,8 +50,8 @@ public:
float d;
bool result = true;
for (size_t i = 0; i < 6; ++i) {
d = glm::dot(planes[i].normal, center) + planes[i].distance;
for (const auto &plane : planes) {
d = glm::dot(plane.normal, center) + plane.distance;
if (d < -radius) result = false;
}

View File

@ -26,8 +26,8 @@ void SCMFile::loadFile(char *data, unsigned int size) {
int i = modelSectionOffset + sizeof(uint32_t);
for (unsigned int m = 0; m < model_count; ++m) {
char model_name[24];
for (size_t c = 0; c < 24; ++c) {
model_name[c] = read<char>(i++);
for (char &c : model_name) {
c = read<char>(i++);
}
models.push_back(model_name);
}

View File

@ -126,9 +126,9 @@ public:
void click(const float x, const float y) {
glm::vec2 c(x - offset.x, y - offset.y);
for (auto it = entries.begin(); it != entries.end(); ++it) {
for (auto &entry : entries) {
if (c.y > 0.f && c.y < size) {
(*it).activate(c.x, c.y);
entry.activate(c.x, c.y);
return;
} else {
c.y -= size;

View File

@ -683,8 +683,7 @@ void RWGame::renderDebugPaths(float time) {
}
// Draw Garage bounds
for (size_t g = 0; g < state.garages.size(); ++g) {
auto& garage = state.garages[g];
for (const auto &garage : state.garages) {
btVector3 minColor(1.f, 0.f, 0.f);
btVector3 maxColor(0.f, 1.f, 0.f);
btVector3 min(garage.min.x, garage.min.y, garage.min.z);
@ -699,8 +698,7 @@ void RWGame::renderDebugPaths(float time) {
}
// Draw vehicle generators
for (size_t v = 0; v < state.vehicleGenerators.size(); ++v) {
auto& generator = state.vehicleGenerators[v];
for (const auto &generator : state.vehicleGenerators) {
btVector3 color(1.f, 0.f, 0.f);
btVector3 position(generator.position.x, generator.position.y,
generator.position.z);

View File

@ -40,9 +40,9 @@ bool LoaderIMG::load(const rwfs::path& filepath) {
/// Get the information of a asset in the examining archive
bool LoaderIMG::findAssetInfo(const std::string& assetname,
LoaderIMGFile& out) {
for (size_t i = 0; i < m_assets.size(); ++i) {
if (boost::iequals(m_assets[i].name, assetname)) {
out = m_assets[i];
for (auto &asset : m_assets) {
if (boost::iequals(asset.name, assetname)) {
out = asset;
return true;
}
}