aboutsummaryrefslogtreecommitdiffstats
path: root/include/common.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/common.hpp')
-rw-r--r--include/common.hpp23
1 files changed, 13 insertions, 10 deletions
diff --git a/include/common.hpp b/include/common.hpp
index 7b98ea9..df41aa1 100644
--- a/include/common.hpp
+++ b/include/common.hpp
@@ -58,10 +58,9 @@ typedef unsigned int uint;
#define BREAKPOINT __asm__("int $3")
-template<typename T>
-inline const T * const& coalesce(const void * &p1, const void * &p2)
+inline const char* coalesce(const char * p1, const char * p2)
{
- return ((p1 == nullptr) ? reinterpret_cast<T*>(p2) : p1);
+ return ((p1 == nullptr) ? p2 : p1);
}
/**
@@ -81,12 +80,9 @@ typedef ivec2 dim2;
* Creates a coordinate out of floating point integers.
*/
struct vec2 {
- float x; /**< The x coordinate */
- float y; /**< The y coordinate */
+ float x;
+ float y;
- /**
- * Constructs a vec2 with the specified coordinates.
- */
vec2(float _x = 0.0f, float _y = 0.0f)
: x(_x), y(_y) {}
@@ -109,11 +105,14 @@ struct vec2 {
return vec2 (x + v.x, y + v.y);
}
- template<typename T>
- const vec2 operator*(const T &n) {
+ vec2 operator*(const float&n) const {
return vec2 (x * n, y * n);
}
+ vec2 operator/(const float& n) const {
+ return vec2 (x / n, y / n);
+ }
+
// std::swap can't work due to being packed
inline void swapX(vec2 &v) {
@@ -126,6 +125,10 @@ struct vec2 {
y = v.y, v.y = t;
}
+ std::string toString(void) const {
+ return "(" + std::to_string(x) + ", " + std::to_string(y) + ")";
+ }
+
} __attribute__ ((packed));
/**