From 7a532056e29d00006382caad9ccde66e54ca8aa5 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 20 Jun 2016 18:11:05 +0200 Subject: [PATCH] Use mathematical function to determine yaw direction --- src/game.cpp | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index 93d9e6d2..9b9f3a75 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -4298,23 +4298,12 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, inline static const char *yawToDirectionString(int yaw) { - // NOTE: TODO: This can be done mathematically without the else/else-if - // cascade. - - const char *player_direction; + static const char *direction[4] = {"North [+Z]", "West [-X]", "South [-Z]", "East [+X]"}; yaw = wrapDegrees_0_360(yaw); + yaw = (yaw + 45) % 360 / 90; - if (yaw >= 45 && yaw < 135) - player_direction = "West [-X]"; - else if (yaw >= 135 && yaw < 225) - player_direction = "South [-Z]"; - else if (yaw >= 225 && yaw < 315) - player_direction = "East [+X]"; - else - player_direction = "North [+Z]"; - - return player_direction; + return direction[yaw]; }