]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
clamp bug fix
authorClyne Sullivan <tullivan99@gmail.com>
Wed, 11 May 2016 11:49:18 +0000 (07:49 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Wed, 11 May 2016 11:49:18 +0000 (07:49 -0400)
include/bmpimage.hpp [new file with mode: 0644]
include/common.hpp
include/ui.hpp
src/world.cpp

diff --git a/include/bmpimage.hpp b/include/bmpimage.hpp
new file mode 100644 (file)
index 0000000..69b78ac
--- /dev/null
@@ -0,0 +1,34 @@
+#ifndef BMP_IMAGE_HPP
+#define BMP_IMAGE_HPP
+
+#include <cstdint>
+
+/**
+ * Defines the layout of a bitmap (.bmp) file's header.
+ */
+typedef struct {
+       uint16_t bfType;
+       uint32_t bfSize;
+       uint16_t bfReserved1;
+       uint16_t bfReserved2;
+       uint32_t bfOffBits;
+} __attribute__((packed)) BITMAPFILEHEADER;
+
+/**
+ * Defines the layout of a bitmap's info header.
+ */
+typedef struct {
+       uint32_t biSize;
+        int32_t biWidth;
+        int32_t biHeight;
+       uint16_t biPlanes;
+       uint16_t biBitCount;
+       uint32_t biCompression;
+       uint32_t biSizeImage;
+        int32_t biXPelsPerMeter;
+        int32_t biYPelsPerMeter;
+       uint32_t biClrUsed;
+       uint32_t biClrImportant;
+} __attribute__((packed)) BITMAPINFOHEADER;
+
+#endif // BMP_IMAGE_HPP
index 73b4928fd42ad2ccd78c3d0efa2480af57e783d0..e082a8723b840bb3b1b0121c684fb09a0c8adef1 100644 (file)
@@ -240,7 +240,7 @@ void UserError(std::string reason);
 namespace std {
        template<class T>
        constexpr const T& clamp(const T& v, const T& lo, const T& hi) {
-               return (v > hi) ? ((v > lo) ? v : lo) : hi;
+               return (v > hi) ? hi : ((v > lo) ? v : lo);
        }
 }
 
index 67406f491d41f948484007e4431ddd33cb8077f4..099bebf4161442f9b853d315b7e4fb11c87f4524 100644 (file)
 #include <ft2build.h>
 #include FT_FREETYPE_H
 
-/* ----------------------------------------------------------------------------
-** Structures section
-** --------------------------------------------------------------------------*/
-
 #ifndef __WIN32__
-
-/**
- * Defines the layout of a bitmap (.bmp) file's header.
- */
-typedef struct {
-       uint16_t bfType;
-       uint32_t bfSize;
-       uint16_t bfReserved1;
-       uint16_t bfReserved2;
-       uint32_t bfOffBits;
-} __attribute__((packed)) BITMAPFILEHEADER;
-
-/**
- * Defines the layout of a bitmap's info header.
- */
-typedef struct {
-       uint32_t biSize;
-        int32_t biWidth;
-        int32_t biHeight;
-       uint16_t biPlanes;
-       uint16_t biBitCount;
-       uint32_t biCompression;
-       uint32_t biSizeImage;
-        int32_t biXPelsPerMeter;
-        int32_t biYPelsPerMeter;
-       uint32_t biClrUsed;
-       uint32_t biClrImportant;
-} __attribute__((packed)) BITMAPINFOHEADER;
-
+#      include <bmpimage.hpp>
 #endif // __WIN32__
 
 /* ----------------------------------------------------------------------------
index 8c3d2f85c57a2467b71b3e50055780b7b78b36ca..4fe27432d21bc922efd507e6273ccc8777a6eac3 100644 (file)
@@ -747,7 +747,7 @@ singleDetect(Entity *e)
         e->handleHits();
 
                // calculate the line that this entity is currently standing on
-        l = std::clamp(static_cast<int>((e->loc.x + e->width / 2 - worldStart) / game::HLINE), 0, static_cast<int>(lineCount - 1));
+        l = (e->loc.x + e->width / 2 - worldStart) / game::HLINE;
 
                // if the entity is under the world/line, pop it back to the surface
                if (e->loc.y < worldData[l].groundHeight) {