Skip to content

Commit

Permalink
std::array for damagedirs
Browse files Browse the repository at this point in the history
  • Loading branch information
no-lex committed Sep 13, 2023
1 parent 7861d66 commit 8efb028
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/engine/render/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ namespace
VARP(damagecompassmin, 1, 25, 1000);
VARP(damagecompassmax, 1, 200, 1000);

float damagedirs[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
std::array<float, 8> damagedirs = { 0, 0, 0, 0, 0, 0, 0, 0 };

void drawdamagecompass(int w, int h)
{
hudnotextureshader->set();

int dirs = 0;
float size = damagecompasssize/100.0f*std::min(h, w)/2.0f;
for(int i = 0; i < 8; ++i)
for(float &dir : damagedirs)
{
if(damagedirs[i]>0)
if(dir > 0)
{
if(!dirs)
{
Expand All @@ -61,12 +61,12 @@ namespace
dirs++;

float logscale = 32,
scale = log(1 + (logscale - 1)*damagedirs[i]) / std::log(logscale),
scale = log(1 + (logscale - 1)*dir) / std::log(logscale),
offset = -size/2.0f-std::min(h, w)/4.0f;
matrix4x3 m;
m.identity();
m.settranslation(w/2, h/2, 0);
m.rotate_around_z(i*45/RAD);
m.rotate_around_z(dir*45/RAD);
m.translate(0, offset, 0);
m.scale(size*scale);

Expand All @@ -76,7 +76,7 @@ namespace

// fade in log space so short blips don't disappear too quickly
scale -= static_cast<float>(curtime)/damagecompassfade;
damagedirs[i] = scale > 0 ? (std::pow(logscale, scale) - 1) / (logscale - 1) : 0;
dir = scale > 0 ? (std::pow(logscale, scale) - 1) / (logscale - 1) : 0;
}
}
if(dirs)
Expand Down Expand Up @@ -461,7 +461,7 @@ void damagecompass(int n, const vec &loc)
{
yaw = 360 - std::fmod(-yaw, 360);
}
int dir = (static_cast<int>(yaw+22.5f)%360)/45;
int dir = (static_cast<int>(yaw+22.5f)%360)/45; //360/45 = 8, so divide into 8 octants with 0 degrees centering octant 0
damagedirs[dir] += std::max(n, damagecompassmin)/static_cast<float>(damagecompassmax);
if(damagedirs[dir]>1)
{
Expand Down

0 comments on commit 8efb028

Please sign in to comment.