aboutsummaryrefslogtreecommitdiffstats
path: root/src/common.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common.cpp')
-rw-r--r--src/common.cpp75
1 files changed, 35 insertions, 40 deletions
diff --git a/src/common.cpp b/src/common.cpp
index 34b2a61..c86454b 100644
--- a/src/common.cpp
+++ b/src/common.cpp
@@ -1,17 +1,15 @@
+#include <common.hpp>
+
#include <cstring>
#include <cstdio>
#include <chrono>
#ifndef __WIN32__
-# include <sys/types.h>
-# include <dirent.h>
-# include <errno.h>
-# include <vector>
-#endif // __WIN32__
-#include <common.hpp>
-
-#ifndef __WIN32__
+#include <sys/types.h>
+#include <dirent.h>
+#include <errno.h>
+#include <vector>
unsigned int millis(void) {
std::chrono::system_clock::time_point now=std::chrono::system_clock::now();
@@ -20,37 +18,33 @@ unsigned int millis(void) {
#endif // __WIN32__
-void DEBUG_prints(const char* file, int line, const char *s,...) {
+void DEBUG_prints(const char* file, int line, const char *s,...)
+{
va_list args;
- printf("%s:%d: ",file,line);
- va_start(args,s);
- vprintf(s,args);
+ printf("%s:%d: ", file, line);
+ va_start(args, s);
+ vprintf(s, args);
va_end(args);
}
-void safeSetColor(int r,int g,int b) { // safeSetColor() is an alternative to directly using glColor3ub() to set
- if (r>255)r=255; // the color for OpenGL drawing. safeSetColor() checks for values that are
- if (g>255)g=255; // outside the range of an unsigned character and sets them to a safer value.
- if (b>255)b=255;
- if (r<0)r=0;
- if (g<0)g=0;
- if (b<0)b=0;
- glColor3ub(r,g,b);
+void safeSetColor(int r, int g, int b)
+{
+ r = static_cast<int>(fmax(fmin(r, 255), 0));
+ g = static_cast<int>(fmax(fmin(g, 255), 0));
+ b = static_cast<int>(fmax(fmin(b, 255), 0));
+ glColor3ub(r, g, b);
}
void safeSetColorA(int r,int g,int b,int a) {
- if (r>255)r=255;
- if (g>255)g=255;
- if (b>255)b=255;
- if (a>255)a=255;
- if (r<0)r=0;
- if (g<0)g=0;
- if (b<0)b=0;
- if (a<0)a=0;
- glColor4ub(r,g,b,a);
+ r = static_cast<int>(fmax(fmin(r, 255), 0));
+ g = static_cast<int>(fmax(fmin(g, 255), 0));
+ b = static_cast<int>(fmax(fmin(b, 255), 0));
+ a = static_cast<int>(fmax(fmin(a, 255), 0));
+ glColor4ub(r, g, b, a);
}
-int getdir(std::string dir, std::vector<std::string> &files) {
+int getdir(std::string dir, std::vector<std::string> &files)
+{
DIR *dp;
struct dirent *dirp;
if (!(dp = opendir(dir.c_str()))) {
@@ -63,20 +57,22 @@ int getdir(std::string dir, std::vector<std::string> &files) {
return 0;
}
-void strVectorSortAlpha(std::vector<std::string> *v) {
+void strVectorSortAlpha(std::vector<std::string> *v)
+{
static bool change;
- do{
+ do {
change = false;
- for(unsigned int i=0;i<v->size()-1;i++) {
- if (v[0][i] > v[0][i+1]) {
- std::swap(v[0][i],v[0][i+1]);
+ for (unsigned int i=0; i < v->size() - 1; i++) {
+ if (v[0][i] > v[0][i + 1]) {
+ std::swap(v[0][i], v[0][i + 1]);
change = true;
}
}
- }while(change);
+ } while (change);
}
-const char *readFile(const char *path) {
+const char *readFile(const char *path)
+{
std::ifstream in (path,std::ios::in);
unsigned int size;
GLchar *buf;
@@ -94,9 +90,8 @@ const char *readFile(const char *path) {
return buf;
}
-void
-UserError(std::string reason)
+void UserError(std::string reason)
{
- std::cout << "User error: " << reason << "!" << std::endl;
+ std::cout << "User error: " << reason << "!\n";
abort();
}