From 6b81e628c85c6ef2448b8d0a1cdbc1f7d9d8059e Mon Sep 17 00:00:00 2001 From: Alfredo Tupone Date: Sun, 21 Apr 2024 23:12:43 +0200 Subject: [PATCH] Save some glTranslate on drawTank/drawFlag --- src/bzflag/RadarRenderer.cxx | 26 ++++++++++++++------------ src/bzflag/RadarRenderer.h | 2 +- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/bzflag/RadarRenderer.cxx b/src/bzflag/RadarRenderer.cxx index 1be05c44c1..ad100d51b2 100644 --- a/src/bzflag/RadarRenderer.cxx +++ b/src/bzflag/RadarRenderer.cxx @@ -163,8 +163,6 @@ void RadarRenderer::setTankColor(const Player* player) void RadarRenderer::drawTank(const float pos[3], const Player* player, bool useSquares) { - glPushMatrix(); - // 'ps' is pixel scale, setup in render() const float tankRadius = BZDBCache::tankRadius; float minSize = 1.5f + (ps * BZDBCache::radarTankPixels); @@ -179,9 +177,6 @@ void RadarRenderer::drawTank(const float pos[3], const Player* player, bool useS // NOTE: myTank was checked in render() const float myAngle = LocalPlayer::getMyTank()->getAngle(); - // transform to the tanks location - glTranslatef(pos[0], pos[1], 0.0f); - // draw the tank if (useSquares || !useTankDimensions) { @@ -224,8 +219,6 @@ void RadarRenderer::drawTank(const float pos[3], const Player* player, bool useS glVertex2f(0.0f, +size); glVertex2f(-size, 0.0f); glEnd(); - - glPopMatrix(); } @@ -278,13 +271,12 @@ void RadarRenderer::drawFlag(const float pos[3]) glEnd(); } -void RadarRenderer::drawFlagOnTank(const float pos[3]) +void RadarRenderer::drawFlagOnTank() { glPushMatrix(); // align it to the screen axes const float angle = LocalPlayer::getMyTank()->getAngle(); - glTranslatef(pos[0], pos[1], 0.0f); glRotatef(float(angle * 180.0 / M_PI), 0.0f, 0.0f, 1.0f); float tankRadius = BZDBCache::tankRadius; @@ -644,16 +636,23 @@ void RadarRenderer::render(SceneRenderer& renderer, bool blank, bool observer) const float* position = player->getPosition(); + glPushMatrix(); + + // transform to the tanks location + glTranslatef(position[0], position[1], 0.0f); + if (player->getFlag() != Flags::Null) { glColor3fv(player->getFlag()->getRadarColor()); - drawFlagOnTank(position); + drawFlagOnTank(); } if (!observer) drawTank(position, player, true); else drawTank(position, player, false); + + glPopMatrix(); } bool coloredShot = BZDB.isTrue("coloredradarshots"); @@ -753,18 +752,21 @@ void RadarRenderer::render(SceneRenderer& renderer, bool blank, bool observer) { // revert to the centered transformation glRotatef((float)(90.0 - myAngle * 180.0 / M_PI), 0.0f, 0.0f, 1.0f); - glTranslatef(-myPos[0], -myPos[1], 0.0f); + + glPushMatrix(); // my flag if (myTank->getFlag() != Flags::Null) { glColor3fv(myTank->getFlag()->getRadarColor()); - drawFlagOnTank(myPos); + drawFlagOnTank(); } // my tank drawTank(myPos, myTank, false); + glPopMatrix(); + // re-setup the blending function // (was changed by drawing jump jets) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); diff --git a/src/bzflag/RadarRenderer.h b/src/bzflag/RadarRenderer.h index 1223277e1b..5f87052830 100644 --- a/src/bzflag/RadarRenderer.h +++ b/src/bzflag/RadarRenderer.h @@ -69,7 +69,7 @@ class RadarRenderer bool useSquares); void drawFancyTank(const class Player* player); void drawFlag(const float pos[3]); - void drawFlagOnTank(const float pos[3]); + void drawFlagOnTank(); static float colorScale(const float z, const float h); static float transScale(const float z, const float h);