diff options
author | Elisey Puzko <puzko.e02@gmail.com> | 2018-02-25 12:49:36 +0100 |
---|---|---|
committer | Elisey Puzko <puzko.e02@gmail.com> | 2018-02-25 12:50:23 +0100 |
commit | 78221efae3c038e2c21cb553891d9de8c37cf809 (patch) | |
tree | f5d7dea2c6dc5a3d2feb8f4c0413f83beef61793 /src/GameState.cpp | |
parent | Some nice hack to avoid conflict of std::min and min macro (diff) | |
download | AltCraft-78221efae3c038e2c21cb553891d9de8c37cf809.tar AltCraft-78221efae3c038e2c21cb553891d9de8c37cf809.tar.gz AltCraft-78221efae3c038e2c21cb553891d9de8c37cf809.tar.bz2 AltCraft-78221efae3c038e2c21cb553891d9de8c37cf809.tar.lz AltCraft-78221efae3c038e2c21cb553891d9de8c37cf809.tar.xz AltCraft-78221efae3c038e2c21cb553891d9de8c37cf809.tar.zst AltCraft-78221efae3c038e2c21cb553891d9de8c37cf809.zip |
Diffstat (limited to 'src/GameState.cpp')
-rw-r--r-- | src/GameState.cpp | 30 |
1 files changed, 8 insertions, 22 deletions
diff --git a/src/GameState.cpp b/src/GameState.cpp index 192a0c5..6c2ad42 100644 --- a/src/GameState.cpp +++ b/src/GameState.cpp @@ -594,28 +594,14 @@ BlockFacing detectHitFace(VectorF raycastHit, Vector selectedBlock) { static const auto vecRight = VectorF(1, 0, 0); static const auto vecForward = VectorF(0, 0, -1); - double up = vec.cosBetween(vecUp); - double down = -up; - double right = vec.cosBetween(vecRight); - double left = -right; - double forward = vec.cosBetween(vecForward); - double backward = -forward; - - // TODO: create a min/max function for the variable number of arguments - // NOTE: function names are surrounded by parentheses to avoid conflict of - // `std::min` and a `min` macro from `windows.h`. If there will be more uses - // of `std::min`, a macro `NOMINMAX` should be defined because these hacks can - // have the real impact on the performance. - double min_cos = (std::min)( - (std::min)( - (std::min)( - (std::min)( - (std::min)(up, down), - right), - left), - forward), - backward); - + const double up = vec.cosBetween(vecUp); + const double down = -up; + const double right = vec.cosBetween(vecRight); + const double left = -right; + const double forward = vec.cosBetween(vecForward); + const double backward = -forward; + + const double min_cos = _min(up, down, right, left, forward, backward); if (min_cos == down) return BlockFacing::Bottom; else if (min_cos == up) |