The Omega Refactor(TM) + Input Options

This commit is contained in:
2025-06-30 21:29:59 -04:00
parent 6b5437a2fd
commit 30880c003d
35 changed files with 1490 additions and 1421 deletions

View File

@@ -2,34 +2,29 @@
#include <SDL3/SDL.h>
#include <SDL3/SDL.h>
#include <GL/glew.h>
#include <GL/gl.h>
#include <glm/glm/glm.hpp>
#include <glm/glm/gtc/type_ptr.hpp>
#include <glm/glm/gtc/matrix_transform.hpp>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <tinyxml2.h>
#include <algorithm>
#include <filesystem>
#include <algorithm>
#include <chrono>
#include <cstring>
#include <filesystem>
#include <format>
#include <fstream>
#include <iostream>
#include <map>
#include <ranges>
#include <vector>
#include <iostream>
#include <map>
#include <ranges>
#include <string>
#include <vector>
#include "STRINGS.h"
#ifndef PATH_MAX
#define PATH_MAX 4096
#endif
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
@@ -46,14 +41,58 @@ typedef double f64;
#define PI (GLM_PI)
#define TAU (PI * 2)
using namespace glm; // fuck you
using namespace glm;
#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))
// Converts a string to a bool
static inline bool string_to_bool(const std::string& string)
{
return string == "true" || string == "1";
};
// Given a file path, sets the working directory to it
static inline void working_directory_from_file_set(const std::string& path)
{
std::filesystem::path filePath = path;
std::filesystem::path parentPath = filePath.parent_path();
std::filesystem::current_path(parentPath);
};
// Converts an enum to a string value
static inline const char* enum_to_string(const char* array[], s32 count, s32 index)
{
return (index >= 0 && index < count) ? array[index] : "";
};
// Converts a string to an enum value
static inline s32 string_to_enum(const std::string& string, const char* const* array, s32 n)
{
for (s32 i = 0; i < n; i++)
if (string == array[i])
return i;
return -1;
};
// Macro to define enum to string functions
#define DEFINE_ENUM_TO_STRING_FUNCTION(function, array, count) \
static inline std::string function(s32 index) \
{ \
return enum_to_string(array, count, index); \
};
// Macro to define string to enum functions
#define DEFINE_STRING_TO_ENUM_FUNCTION(function, enumType, stringArray, count) \
static inline enumType function(const std::string& string) \
{ \
return static_cast<enumType>(string_to_enum(string, stringArray, count)); \
};
#define COLOR_FLOAT_TO_INT(x) (static_cast<int>((x) * 255.0f))
#define COLOR_INT_TO_FLOAT(x) ((x) / 255.0f)
#define PERCENT_TO_UNIT(x) (x / 100.0f)
#define TICK_DELAY 33.3f
#define SECOND 1000.0f
@@ -82,8 +121,8 @@ static const f32 GL_UV_VERTICES[] =
1, 1, 1.0f, 1.0f,
0, 1, 0.0f, 1.0f
};
#define IMVEC2_VEC2(value) ImVec2(value.x, value.y)
#define VEC2_IMVEC2(value) glm::vec2(value.x, value.y)
#define IMVEC4_VEC4(value) ImVec4(value.r, value.g, value.b, value.a)
static const GLuint GL_TEXTURE_INDICES[] = {0, 1, 2, 2, 3, 0};
@@ -95,19 +134,15 @@ static const vec4 COLOR_OPAQUE = {1.0f, 1.0f, 1.0f, 1.0f};
static const vec4 COLOR_TRANSPARENT = {0.0f, 0.0f, 0.0f, 1.0f};
static const vec3 COLOR_OFFSET_NONE = {0.0f, 0.0f, 0.0f};
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;
}
/* Swaps elements in a map */
/* If neither key exists, do nothing */
/* If one key exists, change its ID */
/* If both keys exist, swap */
// Swaps elements in a map
// If neither key exists, do nothing
// If one key exists, change its ID
// If both keys exist, swap
template<typename Map, typename Key>
static inline void map_swap(Map& map, const Key& key1, const Key& key2)
{
@@ -132,14 +167,4 @@ static inline void map_swap(Map& map, const Key& key1, const Key& key2)
map[key1] = std::move(it2->second);
map.erase(it2);
}
};
#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); \
}
};