refactor: use squared distance if possible

refactor: add some const-correctness to code
This commit is contained in:
jeefo 2023-06-24 02:36:51 +03:00
commit 4a35a87b25
No known key found for this signature in database
GPG key ID: 927BCA0779BEA8ED
24 changed files with 579 additions and 567 deletions

View file

@ -32,7 +32,7 @@ void BotSounds::listenNoise (edict_t *ent, StringRef sample, float volume) {
if (origin.empty ()) {
return;
}
auto noise = m_noiseCache[sample.substr (0, 11)];
const auto noise = m_noiseCache[sample.substr (0, 11)];
// we're not handling theese
if (!(noise & Noise::NeedHandle)) {
@ -49,12 +49,12 @@ void BotSounds::listenNoise (edict_t *ent, StringRef sample, float volume) {
if (!(client.flags & ClientFlags::Used) || !(client.flags & ClientFlags::Alive)) {
continue;
}
auto distance = client.origin.distanceSq (origin);
const auto distanceSq = client.origin.distanceSq (origin);
// now find nearest player
if (distance < nearest) {
if (distanceSq < nearest) {
result = &client;
nearest = distance;
nearest = distanceSq;
}
}
return result;