1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-07 03:12:36 +01: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); glm::vec3 nodePosition = position + (rotation * node.position);
if (node.type == PathNode::EXTERNAL) { if (node.type == PathNode::EXTERNAL) {
for (size_t rn = 0; rn < externalNodes.size(); ++rn) { for (auto &realNode : externalNodes) {
auto& realNode = externalNodes[rn];
auto d = glm::distance2(realNode->position, nodePosition); auto d = glm::distance2(realNode->position, nodePosition);
if (d < 1.f) { if (d < 1.f) {
pathNodes.push_back(realNode); pathNodes.push_back(realNode);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -50,8 +50,8 @@ public:
float d; float d;
bool result = true; bool result = true;
for (size_t i = 0; i < 6; ++i) { for (const auto &plane : planes) {
d = glm::dot(planes[i].normal, center) + planes[i].distance; d = glm::dot(plane.normal, center) + plane.distance;
if (d < -radius) result = false; 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); int i = modelSectionOffset + sizeof(uint32_t);
for (unsigned int m = 0; m < model_count; ++m) { for (unsigned int m = 0; m < model_count; ++m) {
char model_name[24]; char model_name[24];
for (size_t c = 0; c < 24; ++c) { for (char &c : model_name) {
model_name[c] = read<char>(i++); c = read<char>(i++);
} }
models.push_back(model_name); models.push_back(model_name);
} }

View File

@ -126,9 +126,9 @@ public:
void click(const float x, const float y) { void click(const float x, const float y) {
glm::vec2 c(x - offset.x, y - offset.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) { if (c.y > 0.f && c.y < size) {
(*it).activate(c.x, c.y); entry.activate(c.x, c.y);
return; return;
} else { } else {
c.y -= size; c.y -= size;

View File

@ -683,8 +683,7 @@ void RWGame::renderDebugPaths(float time) {
} }
// Draw Garage bounds // Draw Garage bounds
for (size_t g = 0; g < state.garages.size(); ++g) { for (const auto &garage : state.garages) {
auto& garage = state.garages[g];
btVector3 minColor(1.f, 0.f, 0.f); btVector3 minColor(1.f, 0.f, 0.f);
btVector3 maxColor(0.f, 1.f, 0.f); btVector3 maxColor(0.f, 1.f, 0.f);
btVector3 min(garage.min.x, garage.min.y, garage.min.z); btVector3 min(garage.min.x, garage.min.y, garage.min.z);
@ -699,8 +698,7 @@ void RWGame::renderDebugPaths(float time) {
} }
// Draw vehicle generators // Draw vehicle generators
for (size_t v = 0; v < state.vehicleGenerators.size(); ++v) { for (const auto &generator : state.vehicleGenerators) {
auto& generator = state.vehicleGenerators[v];
btVector3 color(1.f, 0.f, 0.f); btVector3 color(1.f, 0.f, 0.f);
btVector3 position(generator.position.x, generator.position.y, btVector3 position(generator.position.x, generator.position.y,
generator.position.z); 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 /// Get the information of a asset in the examining archive
bool LoaderIMG::findAssetInfo(const std::string& assetname, bool LoaderIMG::findAssetInfo(const std::string& assetname,
LoaderIMGFile& out) { LoaderIMGFile& out) {
for (size_t i = 0; i < m_assets.size(); ++i) { for (auto &asset : m_assets) {
if (boost::iequals(m_assets[i].name, assetname)) { if (boost::iequals(asset.name, assetname)) {
out = m_assets[i]; out = asset;
return true; return true;
} }
} }