Move more of the utility headers into /include/mcaselector-lite.

These headers have no associated C files, and are mainly used for
utility logic.
Having them in `/include` makes them more easily located, and more
globally used.

We are using "classic" header guards here over `#pragma once` for better
support. Since `#pragma once` is defined by the compiler, rather than
standard C.
Why isn't it used across the project? I have no idea.
This commit is contained in:
2026-01-21 16:26:23 +01:00
parent cf79f7fdc8
commit f5784844a8
16 changed files with 41 additions and 30 deletions

View File

@@ -3,7 +3,8 @@
* Copyright (C)2025 quinnthepigeon@proton.me Quinn * Copyright (C)2025 quinnthepigeon@proton.me Quinn
* For further information, view COPYING and CONTRIBUTORS * For further information, view COPYING and CONTRIBUTORS
* at: www.github.com/thepigeongenerator/mcaselector-lite */ * at: www.github.com/thepigeongenerator/mcaselector-lite */
#pragma once #ifndef MCASELECTOR_LITE_ATRB_H
#define MCASELECTOR_LITE_ATRB_H
#if defined(__GNUC__) #if defined(__GNUC__)
#if __has_attribute(__pure__) #if __has_attribute(__pure__)
@@ -64,3 +65,5 @@
#define ASSUME(args) __attribute__((__assume__ args)) #define ASSUME(args) __attribute__((__assume__ args))
#endif #endif
#endif #endif
#endif /* MCASELECTOR_LITE_ATRB_H */

View File

@@ -3,8 +3,8 @@
* Copyright (C)2025 quinnthepigeon@proton.me Quinn * Copyright (C)2025 quinnthepigeon@proton.me Quinn
* For further information, view COPYING and CONTRIBUTORS * For further information, view COPYING and CONTRIBUTORS
* at: www.github.com/thepigeongenerator/mcaselector-lite */ * at: www.github.com/thepigeongenerator/mcaselector-lite */
#ifndef PORTABLE_ENDIAN_H #ifndef MCASELECTOR_LITE_ENDIAN_H
#define PORTABLE_ENDIAN_H 1 #define MCASELECTOR_LITE_ENDIAN_H
#if defined(__GNUC__) #if defined(__GNUC__)
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
@@ -40,4 +40,4 @@
#else #else
#error GNU C is unavailable #error GNU C is unavailable
#endif /* __GNUC__ */ #endif /* __GNUC__ */
#endif /* PORTABLE_ENDIAN_H */ #endif /* MCASELECTOR_LITE_ENDIAN_H */

View File

@@ -3,10 +3,13 @@
* Copyright (C)2025 quinnthepigeon@proton.me Quinn * Copyright (C)2025 quinnthepigeon@proton.me Quinn
* For further information, view COPYING and CONTRIBUTORS * For further information, view COPYING and CONTRIBUTORS
* at: www.github.com/thepigeongenerator/mcaselector-lite */ * at: www.github.com/thepigeongenerator/mcaselector-lite */
#pragma once #ifndef MCASELECTOR_LITE_MACRO_H
#define MCASELECTOR_LITE_MACRO_H
#define WIDTHOF(t) (sizeof(t) * 8) // gets the bit width of a type #define WIDTHOF(t) (sizeof(t) * 8) // gets the bit width of a type
#define MACRO_CAT(x, y) x##y // concatenate two macro variables together #define MACRO_CAT(x, y) x##y // concatenate two macro variables together
#define MACRO_CAT2(x, y) MACRO_CAT(x, y) // concatenate two macro variables together #define MACRO_CAT2(x, y) MACRO_CAT(x, y) // concatenate two macro variables together
#define MACRO_STR(v) #v // for converting macro variable into a string #define MACRO_STR(v) #v // for converting macro variable into a string
#define MACRO_STR2(v) MACRO_STR(v) // for a recursive string generation #define MACRO_STR2(v) MACRO_STR(v) // for a recursive string generation
#endif /* MCASELECTOR_LITE_MACRO_H */

View File

@@ -3,7 +3,8 @@
* Copyright (C)2025 quinnthepigeon@proton.me Quinn * Copyright (C)2025 quinnthepigeon@proton.me Quinn
* For further information, view COPYING and CONTRIBUTORS * For further information, view COPYING and CONTRIBUTORS
* at: www.github.com/thepigeongenerator/mcaselector-lite */ * at: www.github.com/thepigeongenerator/mcaselector-lite */
#pragma once #ifndef MCASELECTOR_LITE_TYPES_H
#define MCASELECTOR_LITE_TYPES_H
typedef signed long long int llong; typedef signed long long int llong;
typedef unsigned short int ushort; typedef unsigned short int ushort;
@@ -36,3 +37,4 @@ typedef float f32;
#if __SIZEOF_DOUBLE__ == 8 #if __SIZEOF_DOUBLE__ == 8
typedef double f64; typedef double f64;
#endif #endif
#endif /* MCASELECTOR_LITE_TYPES_H */

View File

@@ -3,9 +3,12 @@
* Copyright (C)2025 quinnthepigeon@proton.me Quinn * Copyright (C)2025 quinnthepigeon@proton.me Quinn
* For further information, view COPYING and CONTRIBUTORS * For further information, view COPYING and CONTRIBUTORS
* at: www.github.com/thepigeongenerator/mcaselector-lite */ * at: www.github.com/thepigeongenerator/mcaselector-lite */
#pragma once #ifndef MCASELECTOR_LITE_UTIL_H
#define MCASELECTOR_LITE_UTIL_H
/* Acquires the next power of two of value `x`. /* Acquires the next power of two of value `x`.
* Automatically determines the type (and therefore the width) of `x`. * Automatically determines the type (and therefore the width) of `x`.
* Explicitly cast `x` to a desired width, if necessary. */ * Explicitly cast `x` to a desired width, if necessary. */
#define bit_ceil(x) (1 << (sizeof(__typeof__(x)) * 8 - __builtin_clzg(((x) - !!(x)) | 1))) #define bit_ceil(x) (1 << (sizeof(__typeof__(x)) * 8 - __builtin_clzg(((x) - !!(x)) | 1)))
#endif /* MCASELECTOR_LITE_UTIL_H */

View File

@@ -3,9 +3,10 @@
* Copyright (C)2025 quinnthepigeon@proton.me Quinn * Copyright (C)2025 quinnthepigeon@proton.me Quinn
* For further information, view COPYING and CONTRIBUTORS * For further information, view COPYING and CONTRIBUTORS
* at: www.github.com/thepigeongenerator/mcaselector-lite */ * at: www.github.com/thepigeongenerator/mcaselector-lite */
#pragma once #ifndef MCASELECTOR_LITE_VEC_H
#define MCASELECTOR_LITE_VEC_H
#include "../types.h" #include <mcaselector-lite/types.h>
#if defined(__has_attribute) && __has_attribute(vector_size) #if defined(__has_attribute) && __has_attribute(vector_size)
typedef float fvec2 __attribute__((vector_size(sizeof(float) * 2))); // SMID vector for 2 `float` typedef float fvec2 __attribute__((vector_size(sizeof(float) * 2))); // SMID vector for 2 `float`
@@ -21,3 +22,5 @@ typedef u8 u8vec4 __attribute__((vector_size(sizeof(u8) * 4))); // SMID vector f
#define VY 1 #define VY 1
#define VZ 2 #define VZ 2
#define VW 3 #define VW 3
#endif /* MCASELECTOR_LITE_VEC_H */

View File

@@ -7,13 +7,13 @@
#include <archive.h> #include <archive.h>
#include <assert.h> #include <assert.h>
#include <endian.h> #include <mcaselector-lite/endian.h>
#include <mcaselector-lite/types.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include "../types.h"
#include "../util/error.h" #include "../util/error.h"
#define SECTOR 0x1000 // sector size #define SECTOR 0x1000 // sector size

View File

@@ -5,10 +5,10 @@
* at: www.github.com/thepigeongenerator/mcaselector-lite */ * at: www.github.com/thepigeongenerator/mcaselector-lite */
#pragma once #pragma once
#include <mcaselector-lite/atrb.h>
#include <mcaselector-lite/types.h>
#include <stdlib.h> #include <stdlib.h>
#include "../types.h"
#include "../util/atrb.h"
/* contains chunk metadata */ /* contains chunk metadata */
struct mcx_chunk { struct mcx_chunk {

View File

@@ -6,13 +6,12 @@
#include "nbt.h" #include "nbt.h"
#include <assert.h> #include <assert.h>
#include <endian.h> #include <mcaselector-lite/endian.h>
#include <mcaselector-lite/types.h>
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "../types.h"
#define MAX_DEPTH 512 #define MAX_DEPTH 512
/* Extracts a big endian 16 bit integer from address `buf`, converts it to host byte size if needed and returns. */ /* Extracts a big endian 16 bit integer from address `buf`, converts it to host byte size if needed and returns. */

View File

@@ -6,12 +6,12 @@
#pragma once #pragma once
#include <assert.h> #include <assert.h>
#include <endian.h> #include <mcaselector-lite/atrb.h>
#include <mcaselector-lite/endian.h>
#include <mcaselector-lite/types.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include "../types.h"
#include "../util/atrb.h"
/* NBT (named binary tag) is a tree data structure. Tags have a numeric type ID, name and a payload. /* NBT (named binary tag) is a tree data structure. Tags have a numeric type ID, name and a payload.
* NBT files are a compressed `compound` tag. GZip is the compression used in most cases, * NBT files are a compressed `compound` tag. GZip is the compression used in most cases,

View File

@@ -7,11 +7,11 @@
#include <assert.h> #include <assert.h>
#include <inttypes.h> #include <inttypes.h>
#include <mcaselector-lite/atrb.h>
#include <mcaselector-lite/types.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "../types.h"
#include "../util/atrb.h"
/* Matches s1 with s2, returns a pointer to s1 where the match stopped. */ /* Matches s1 with s2, returns a pointer to s1 where the match stopped. */
static const char *strmat(const char *s1, const char *s2) PURE NONNULL((1, 2)); static const char *strmat(const char *s1, const char *s2) PURE NONNULL((1, 2));

View File

@@ -4,8 +4,8 @@
* For further information, view COPYING and CONTRIBUTORS * For further information, view COPYING and CONTRIBUTORS
* at: www.github.com/thepigeongenerator/mcaselector-lite */ * at: www.github.com/thepigeongenerator/mcaselector-lite */
#pragma once #pragma once
#include "../types.h" #include <mcaselector-lite/atrb.h>
#include "../util/atrb.h" #include <mcaselector-lite/types.h>
enum conf_type { enum conf_type {
CONF_STR = 0x00, CONF_STR = 0x00,

View File

@@ -7,9 +7,9 @@
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <glad/gl.h> #include <glad/gl.h>
#include <mcaselector-lite/types.h>
#include <stdint.h> #include <stdint.h>
#include "../../types.h"
#include "../../util/error.h" #include "../../util/error.h"
#include "shader.h" #include "shader.h"

View File

@@ -8,8 +8,8 @@
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <assert.h> #include <assert.h>
#include <glad/gl.h> #include <glad/gl.h>
#include <mcaselector-lite/types.h>
#include "../../types.h"
#include "../../util/error.h" #include "../../util/error.h"
#include "input.h" #include "input.h"
#include "render.h" #include "render.h"

View File

@@ -5,11 +5,10 @@
* at: www.github.com/thepigeongenerator/mcaselector-lite */ * at: www.github.com/thepigeongenerator/mcaselector-lite */
#include "error.h" #include "error.h"
#include <mcaselector-lite/types.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include "../types.h"
static void error_log(FILE *restrict stream, const char *restrict pfx, uint ln, const char *restrict file, const char *restrict fmt, va_list ap) static void error_log(FILE *restrict stream, const char *restrict pfx, uint ln, const char *restrict file, const char *restrict fmt, va_list ap)
{ {
fprintf(stream, "(%s:%u) [%s] '", file, ln, pfx); fprintf(stream, "(%s:%u) [%s] '", file, ln, pfx);

View File

@@ -5,12 +5,11 @@
* at: www.github.com/thepigeongenerator/mcaselector-lite */ * at: www.github.com/thepigeongenerator/mcaselector-lite */
#pragma once #pragma once
#include <mcaselector-lite/atrb.h>
#include <mcaselector-lite/types.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "../types.h"
#include "atrb.h"
void error_debug(uint ln, const char *restrict file, const char *restrict fmt, ...); void error_debug(uint ln, const char *restrict file, const char *restrict fmt, ...);
void error_info(uint ln, const char *restrict file, const char *restrict fmt, ...); void error_info(uint ln, const char *restrict file, const char *restrict fmt, ...);
void error_warn(uint ln, const char *restrict file, const char *restrict fmt, ...); void error_warn(uint ln, const char *restrict file, const char *restrict fmt, ...);