]> git.lizzy.rs Git - minetest.git/commitdiff
Use mathematical function to determine yaw direction
authorsfan5 <sfan5@live.de>
Mon, 20 Jun 2016 16:11:05 +0000 (18:11 +0200)
committerest31 <MTest31@outlook.com>
Tue, 5 Jul 2016 18:36:05 +0000 (20:36 +0200)
src/game.cpp

index 93d9e6d2c437d09f2f78e264f97002a7cc00a342..9b9f3a75f0f788ef1bd14803adb157be9674df93 100644 (file)
@@ -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];
 }