aboutsummaryrefslogtreecommitdiffstats
path: root/include/common.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/common.hpp')
-rw-r--r--include/common.hpp137
1 files changed, 15 insertions, 122 deletions
diff --git a/include/common.hpp b/include/common.hpp
index 71039c7..1244464 100644
--- a/include/common.hpp
+++ b/include/common.hpp
@@ -14,7 +14,6 @@
#include <algorithm>
#include <list>
#include <iterator>
-#include <unordered_map>
// alternative windows thread library
#ifndef __WIN32__
@@ -45,6 +44,7 @@
// windows stuff
#ifdef __WIN32__
+using uint = unsigned int;
#undef near
#endif
@@ -53,77 +53,12 @@
*/
#define DEBUG_printf(message, ...) DEBUG_prints(__FILE__, __LINE__, message, __VA_ARGS__)
-#define BREAKPOINT __asm__("int $3")
-
#define coalesce(v1, v2) ((v1 != nullptr) ? v1 : v2)
-/**
- * Creates a coordinate of integers.
- */
-typedef struct {
- int x; /**< The x coordinate */
- int y; /**< The y coordinate */
-} ivec2;
+#include <vector2.hpp>
-/**
- * A pair of x and y for dimensions (i.e. width and height).
- */
-typedef ivec2 dim2;
-
-/**
- * Creates a coordinate out of floating point integers.
- */
-struct vec2 {
- float x;
- float y;
-
- vec2(float _x = 0.0f, float _y = 0.0f)
- : x(_x), y(_y) {}
-
- bool operator==(const vec2 &v) const {
- return (x == v.x) && (y == v.y);
- }
-
- template<typename T>
- const vec2 operator=(const T &n) {
- x = y = n;
- return *this;
- }
-
- template<typename T>
- vec2 operator+(T n) const {
- return vec2 (x + n, y + n);
- }
-
- vec2 operator+(const vec2 &v) {
- return vec2 (x + v.x, y + v.y);
- }
-
- 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) {
- float t = x;
- x = v.x, v.x = t;
- }
-
- inline void swapY(vec2 &v) {
- float t = y;
- y = v.y, v.y = t;
- }
-
- std::string toString(void) const {
- return "(" + std::to_string(x) + ", " + std::to_string(y) + ")";
- }
-
-} __attribute__ ((packed));
+using vec2 = vector2<float>;
+using dim2 = vector2<int>;
/**
* A structure for three-dimensional points.
@@ -135,8 +70,7 @@ struct vec3 {
vec3(float _x = 0.0f, float _y = 0.0f, float _z = 1.0f)
: x(_x), y(_y), z(_z) {}
-
-} __attribute__ ((packed));
+};
/**
* This structure contains two sets of coordinates for ray drawing.
@@ -157,47 +91,27 @@ public:
float blue; /**< The amount of blue */
float alpha; /**< Transparency */
- Color() {
- red = green = blue = alpha = 0.0f;
- }
+ Color(float r = 0, float g = 0, float b = 0, float a = 255)
+ : red(r), green(g), blue(b), alpha(a) {}
- Color(float r, float g ,float b) {
- red = r;
- green = g;
- blue = b;
- alpha = 255;
+ Color operator-(const float& a) {
+ return Color(red - a, green - a, blue - a, alpha);
}
- Color(float r, float g, float b, float a) {
- red = r;
- green = g;
- blue = b;
- alpha = a;
- }
-
- Color operator-=(float a) {
- red -= a;
- green -= a;
- blue -= a;
- return{red+a,green+a,blue+a};
- }
- Color operator+=(float a) {
- return{red+a,green+a,blue+a};
- }
- Color operator=(float a) {
- return{red=a,green=a,blue=a};
+ Color operator+(const float& a) {
+ return Color(red + a, green + a, blue + a, alpha);
}
};
/**
* The amount of game ticks that should occur each second.
*/
-constexpr const unsigned int TICKS_PER_SEC = 20;
+constexpr unsigned int TICKS_PER_SEC = 20;
/**
* The amount of milliseconds it takes for a game tick to fire.
*/
-constexpr const float MSEC_PER_TICK = 1000.0f / TICKS_PER_SEC;
+constexpr float MSEC_PER_TICK = 1000.0f / TICKS_PER_SEC;
/**
* Separates a string into tokens using the given delimiter.
@@ -209,24 +123,6 @@ constexpr const float MSEC_PER_TICK = 1000.0f / TICKS_PER_SEC;
std::vector<std::string> StringTokenizer(const std::string& str, char delim);
/**
- * Seperates a string like, "23,12" to a vec2.
- *
- * @param s the string to parse
- * @return the vec2 of the values passed in the string
- */
-vec2 str2coord(std::string s);
-
-/**
- * A function to draw a colored box for OpenGL.
- * To use it, the lower left hand and upper right hand coords are given.
- *
- * @param the lower left coordinate
- * @param the upper right coordinate
- * @param the z coordinate
- */
-void drawRect(vec2 ll, vec2 ur, float z);
-
-/**
* Returns a measurement in HLINEs
*
* @param the number of HLINEs, integer or decimal
@@ -251,7 +147,7 @@ inline T HLINES(const T &n)
#define randGet rand
// defines pi for calculations that need it.
-constexpr const float PI = 3.1415926535f;
+constexpr float PI = 3.1415926535f;
// references the variable in main.cpp, used for drawing with the player
extern vec2 offset;
@@ -265,10 +161,7 @@ void DEBUG_prints(const char* file, int line, const char *s,...);
unsigned int millis(void);
// reads the names of files in a directory into the given string vector
-int getdir(std::string dir, std::vector<std::string> &files);
-
-// sorts a vector of strings alphabetically
-void strVectorSortAlpha(std::vector<std::string> *v);
+int getdir(std::string dir, std::list<std::string>& files);
// reads the given file into a buffer and returns a pointer to the buffer
std::string readFile(const std::string& path);