basics
This commit is contained in:
59
src/COMMON.h
59
src/COMMON.h
@ -5,25 +5,23 @@
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <GL/gl.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <glm/glm/glm.hpp>
|
||||
#include <glm/glm/gtc/type_ptr.hpp>
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
#include <pugixml.hpp>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <tinyxml2.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <ranges>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "STRINGS.h"
|
||||
#include "RESOURCES.h"
|
||||
|
||||
using namespace glm;
|
||||
using namespace pugi;
|
||||
using namespace std;
|
||||
|
||||
typedef uint8_t u8;
|
||||
typedef uint16_t u16;
|
||||
@ -40,15 +38,40 @@ typedef double f64;
|
||||
|
||||
#define PI (GLM_PI)
|
||||
#define TAU (PI * 2)
|
||||
#define ATAN(x1, x2, y1, y2) (fmod((atan2(y2 - y1, x2 - x1) + TAU), TAU)) /* [0, 2PI] */
|
||||
|
||||
struct State
|
||||
using namespace glm; // fuck you
|
||||
|
||||
#define MIN(x, min) (x < min ? min : x)
|
||||
#define MAX(x, max) (x > max ? max : x)
|
||||
#define CLAMP(x, min, max) (MIN(MAX(x, max), min))
|
||||
|
||||
static inline const char* enum_to_string(const char* arr[], s32 count, s32 index) { return (index >= 0 && index < count) ? arr[index] : "undefined"; }
|
||||
static inline s32 string_to_enum(const char* str, const char* const* arr, s32 n) { for (s32 i=0; i<n; ++i) if (!strcmp(str, arr[i])) return i; return -1; }
|
||||
static inline bool string_to_bool(const char* str) { if (strcmp(str, "true") == 0) return true; return false; }
|
||||
|
||||
template<typename T>
|
||||
static inline s32 map_next_id_get(const std::map<s32, T>& map) {
|
||||
s32 id = 0; for (const auto& [key, _] : map) if (key != id) break; else ++id; return id;
|
||||
}
|
||||
|
||||
template<typename Map, typename Key>
|
||||
static inline void map_swap(Map& map, const Key& key1, const Key& key2)
|
||||
{
|
||||
SDL_Window* window;
|
||||
SDL_Renderer* renderer;
|
||||
SDL_GLContext glContext;
|
||||
vec3 clearColor = {0.69, 0.69, 0.69};
|
||||
u64 tick = 0;
|
||||
u64 lastTick = 0;
|
||||
bool isRunning = true;
|
||||
};
|
||||
auto it1 = map.find(key1);
|
||||
auto it2 = map.find(key2);
|
||||
if (it1 == map.end() || it2 == map.end())
|
||||
return;
|
||||
|
||||
using std::swap;
|
||||
swap(it1->second, it2->second);
|
||||
}
|
||||
|
||||
#define DEFINE_ENUM_TO_STRING_FN(fn_name, arr, count) \
|
||||
static inline const char* fn_name(s32 index) { \
|
||||
return enum_to_string(arr, count, index); \
|
||||
}
|
||||
|
||||
#define DEFINE_STRING_TO_ENUM_FN(fn_name, enum_type, str_array, count) \
|
||||
static inline enum_type fn_name(const char* str) { \
|
||||
return (enum_type)string_to_enum(str, str_array, count); \
|
||||
}
|
||||
|
Reference in New Issue
Block a user