mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-18 20:35:45 +01:00
Compare commits
2 Commits
8861e591f6
...
be653b6bd3
| Author | SHA1 | Date | |
|---|---|---|---|
|
be653b6bd3
|
|||
|
b1958bcd2f
|
20
src/util/vec.h
Normal file
20
src/util/vec.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
#if defined(__has_attribute) && __has_attribute(vector_size)
|
||||||
|
typedef float fvec2 __attribute__((vector_size(sizeof(float) * 2))); // SMID vector for 2 `float`
|
||||||
|
typedef float fvec3 __attribute__((vector_size(sizeof(float) * 3))); // SMID vector for 3 `float`
|
||||||
|
typedef float fvec4 __attribute__((vector_size(sizeof(float) * 3))); // SMID vector for 4 `float`
|
||||||
|
|
||||||
|
typedef u8 u8vec2 __attribute__((vector_size(sizeof(u8) * 2))); // SMID vector for 2 `u8`
|
||||||
|
typedef u8 u8vec3 __attribute__((vector_size(sizeof(u8) * 2))); // SMID vector for 3 `u8`
|
||||||
|
typedef u8 u8vec4 __attribute__((vector_size(sizeof(u8) * 4))); // SMID vector for 4 `u8`
|
||||||
|
#else
|
||||||
|
#error the platform is unsupported, attribute vector_size must be available (and so does __has_attribute)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define VX 0
|
||||||
|
#define VY 1
|
||||||
|
#define VZ 2
|
||||||
|
#define VW 3
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
// Copyright (c) 2025 Quinn
|
|
||||||
// Licensed under the MIT Licence. See LICENSE for details
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
#include "../atrb.h"
|
|
||||||
|
|
||||||
// stores a 2D point using a floating-point number
|
|
||||||
struct float2 {
|
|
||||||
float x;
|
|
||||||
float y;
|
|
||||||
};
|
|
||||||
typedef struct float2 float2;
|
|
||||||
|
|
||||||
// adds one float2 to another
|
|
||||||
atrb_const static inline float2 float2_add(float2 v1, float2 v2) {
|
|
||||||
return (float2){v1.x + v2.x, v1.y + v2.y};
|
|
||||||
}
|
|
||||||
|
|
||||||
// subtracts one float2 from another
|
|
||||||
atrb_const static inline float2 float2_sub(float2 v1, float2 v2) {
|
|
||||||
return (float2){v1.x - v2.x, v1.y - v2.y};
|
|
||||||
}
|
|
||||||
|
|
||||||
// multiplies one float2 by another
|
|
||||||
atrb_const static inline float2 float2_mul(float2 v1, float2 v2) {
|
|
||||||
return (float2){v1.x * v2.x, v1.y * v2.y};
|
|
||||||
}
|
|
||||||
|
|
||||||
// divides one float2 by another
|
|
||||||
atrb_const static inline float2 float2_div(float2 v1, float2 v2) {
|
|
||||||
return (float2){v1.x / v2.x, v1.y / v2.y};
|
|
||||||
}
|
|
||||||
|
|
||||||
// preforms a scalar multiplication upon the float2 (multiplies the float2 by some value)
|
|
||||||
atrb_const static inline float2 float2_mul_s(float2 v, float n) {
|
|
||||||
return (float2){v.x * n, v.y * n};
|
|
||||||
}
|
|
||||||
|
|
||||||
// preforms a scalar division upon the float2 (divides the float2 by some value)
|
|
||||||
atrb_const static inline float2 float2_div_s(float2 v, float n) {
|
|
||||||
return (float2){v.x / n, v.y / n};
|
|
||||||
}
|
|
||||||
|
|
||||||
atrb_const static inline float2 float2_neg(float2 v) {
|
|
||||||
return (float2){-v.x, -v.y};
|
|
||||||
}
|
|
||||||
|
|
||||||
// gets the squared magnitude/length of float2
|
|
||||||
atrb_const static inline float float2_mag2(float2 v) {
|
|
||||||
return (v.x * v.x) + (v.y * v.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
// gets the length of float2 (length)
|
|
||||||
atrb_const static inline float float2_mag(float2 v) {
|
|
||||||
return sqrtf(float2_mag2(v));
|
|
||||||
}
|
|
||||||
|
|
||||||
// normalizes the float2
|
|
||||||
atrb_const static inline float2 float2_norm(float2 v) {
|
|
||||||
float s = 1.0F / float2_mag(v); // get the scaling factor
|
|
||||||
return float2_mul_s(v, s); // scale the vector by the scaling factor (slightly more efficient than dividing)
|
|
||||||
}
|
|
||||||
|
|
||||||
// gets the dot product of two float2s
|
|
||||||
atrb_const static inline float float2_dot(float2 v1, float2 v2) {
|
|
||||||
return v1.x * v2.x + v1.y * v2.y;
|
|
||||||
}
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
// Copyright (c) 2025 Quinn
|
|
||||||
// Licensed under the MIT Licence. See LICENSE for details
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
#include "../atrb.h"
|
|
||||||
|
|
||||||
// stores a 3D point using a floating-point number
|
|
||||||
struct float3 {
|
|
||||||
float x;
|
|
||||||
float y;
|
|
||||||
float z;
|
|
||||||
};
|
|
||||||
typedef struct float3 float3;
|
|
||||||
|
|
||||||
// adds one float3 to another
|
|
||||||
atrb_const static inline float3 float3_add(float3 v1, float3 v2) {
|
|
||||||
return (float3){v1.x + v2.x, v1.y + v2.y, v1.z + v2.z};
|
|
||||||
}
|
|
||||||
|
|
||||||
// subtracts one float3 from another
|
|
||||||
atrb_const static inline float3 float3_sub(float3 v1, float3 v2) {
|
|
||||||
return (float3){v1.x - v2.x, v1.y - v2.y, v1.z - v2.z};
|
|
||||||
}
|
|
||||||
|
|
||||||
// multiplies one float3 by another
|
|
||||||
atrb_const static inline float3 float3_mul(float3 v1, float3 v2) {
|
|
||||||
return (float3){v1.x * v2.x, v1.y * v2.y, v1.z * v2.z};
|
|
||||||
}
|
|
||||||
|
|
||||||
// divides one float3 by another
|
|
||||||
atrb_const static inline float3 float3_div(float3 v1, float3 v2) {
|
|
||||||
return (float3){v1.x / v2.x, v1.y / v2.y, v1.z / v2.z};
|
|
||||||
}
|
|
||||||
|
|
||||||
// preforms a scalar multiplication upon the float3 (multiplies the float3 by some value)
|
|
||||||
atrb_const static inline float3 float3_mul_s(float3 v, float n) {
|
|
||||||
return (float3){v.x * n, v.y * n, v.z * n};
|
|
||||||
}
|
|
||||||
|
|
||||||
// preforms a scalar division upon the float3 (divides the float3 by some value)
|
|
||||||
atrb_const static inline float3 float3_div_s(float3 v, float n) {
|
|
||||||
return (float3){v.x / n, v.y / n, v.z / n};
|
|
||||||
}
|
|
||||||
|
|
||||||
atrb_const static inline float3 float3_neg(float3 v) {
|
|
||||||
return (float3){-v.x, -v.y, -v.z};
|
|
||||||
}
|
|
||||||
|
|
||||||
// gets the squared magnitude/length of float3
|
|
||||||
atrb_const static inline float float3_mag2(float3 v) {
|
|
||||||
return (v.x * v.x) + (v.y * v.y) + (v.z * v.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
// gets the length of float3 (length)
|
|
||||||
atrb_const static inline float float3_mag(float3 v) {
|
|
||||||
return sqrtf(float3_mag2(v));
|
|
||||||
}
|
|
||||||
|
|
||||||
// normalizes the float3
|
|
||||||
atrb_const static inline float3 float3_norm(float3 v) {
|
|
||||||
float s = 1.0F / float3_mag(v); // get the scaling factor
|
|
||||||
return float3_mul_s(v, s); // scale the vector by the scaling factor (slightly more efficient than dividing)
|
|
||||||
}
|
|
||||||
|
|
||||||
// gets the dot product of two float3s
|
|
||||||
atrb_const static inline float float3_dot(float3 v1, float3 v2) {
|
|
||||||
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
// Copyright (c) 2025 Quinn
|
|
||||||
// Licensed under the MIT Licence. See LICENSE for details
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "../atrb.h"
|
|
||||||
|
|
||||||
// stores a 2D point using a floating-point number
|
|
||||||
struct int2 {
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
};
|
|
||||||
typedef struct int2 int2;
|
|
||||||
|
|
||||||
// adds one int2 to another
|
|
||||||
atrb_const static inline int2 int2_add(int2 v1, int2 v2) {
|
|
||||||
return (int2){v1.x + v2.x, v1.y + v2.y};
|
|
||||||
}
|
|
||||||
|
|
||||||
// subtracts one int2 from another
|
|
||||||
atrb_const static inline int2 int2_sub(int2 v1, int2 v2) {
|
|
||||||
return (int2){v1.x - v2.x, v1.y - v2.y};
|
|
||||||
}
|
|
||||||
|
|
||||||
// multiplies one int2 by another
|
|
||||||
atrb_const static inline int2 int2_mul(int2 v1, int2 v2) {
|
|
||||||
return (int2){v1.x * v2.x, v1.y * v2.y};
|
|
||||||
}
|
|
||||||
|
|
||||||
// divides one int2 by another
|
|
||||||
atrb_const static inline int2 int2_div(int2 v1, int2 v2) {
|
|
||||||
return (int2){v1.x / v2.x, v1.y / v2.y};
|
|
||||||
}
|
|
||||||
|
|
||||||
// preforms a scalar multiplication upon the int2 (multiplies the int2 by some value)
|
|
||||||
atrb_const static inline int2 int2_mul_s(int2 v, float n) {
|
|
||||||
return (int2){v.x * n, v.y * n};
|
|
||||||
}
|
|
||||||
|
|
||||||
// preforms a scalar division upon the int2 (divides the int2 by some value)
|
|
||||||
atrb_const static inline int2 int2_div_s(int2 v, float n) {
|
|
||||||
return (int2){v.x / n, v.y / n};
|
|
||||||
}
|
|
||||||
|
|
||||||
atrb_const static inline int2 int2_neg(int2 v) {
|
|
||||||
return (int2){-v.x, -v.y};
|
|
||||||
}
|
|
||||||
|
|
||||||
// gets the dot product of two int2s
|
|
||||||
atrb_const static inline int int2_dot(int2 v1, int2 v2) {
|
|
||||||
return v1.x * v2.x + v1.y * v2.y;
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
// Copyright (c) 2025 Quinn
|
|
||||||
// Licensed under the MIT Licence. See LICENSE for details
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "../atrb.h"
|
|
||||||
|
|
||||||
// stores a 2D point using a floating-point number
|
|
||||||
struct int4 {
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
int z;
|
|
||||||
int w;
|
|
||||||
};
|
|
||||||
typedef struct int4 int4;
|
|
||||||
|
|
||||||
// adds one int4 to another
|
|
||||||
atrb_const static inline int4 int4_add(int4 v1, int4 v2) {
|
|
||||||
return (int4){v1.x + v2.x, v1.y + v2.y, v1.z - v2.z, v1.w - v2.w};
|
|
||||||
}
|
|
||||||
|
|
||||||
// subtracts one int4 from another
|
|
||||||
atrb_const static inline int4 int4_sub(int4 v1, int4 v2) {
|
|
||||||
return (int4){v1.x - v2.x, v1.y - v2.y, v1.z - v2.z, v1.w - v2.w};
|
|
||||||
}
|
|
||||||
|
|
||||||
// multiplies one int4 by another
|
|
||||||
atrb_const static inline int4 int4_mul(int4 v1, int4 v2) {
|
|
||||||
return (int4){v1.x * v2.x, v1.y * v2.y, v1.z * v2.z, v1.w * v2.w};
|
|
||||||
}
|
|
||||||
|
|
||||||
// divides one int4 by another
|
|
||||||
atrb_const static inline int4 int4_div(int4 v1, int4 v2) {
|
|
||||||
return (int4){v1.x / v2.x, v1.y / v2.y, v1.z / v2.z, v1.w / v2.w};
|
|
||||||
}
|
|
||||||
|
|
||||||
// preforms a scalar multiplication upon the int4 (multiplies the int4 by some value)
|
|
||||||
atrb_const static inline int4 int4_mul_s(int4 v, float n) {
|
|
||||||
return (int4){v.x * n, v.y * n, v.z * n, v.w * n};
|
|
||||||
}
|
|
||||||
|
|
||||||
// preforms a scalar division upon the int4 (divides the int4 by some value)
|
|
||||||
atrb_const static inline int4 int4_div_s(int4 v, float n) {
|
|
||||||
return (int4){v.x / n, v.y / n, v.z / n, v.w / n};
|
|
||||||
}
|
|
||||||
|
|
||||||
atrb_const static inline int4 int4_neg(int4 v) {
|
|
||||||
return (int4){-v.x, -v.y, -v.z, v.w};
|
|
||||||
}
|
|
||||||
|
|
||||||
// gets the dot product of two int2s
|
|
||||||
atrb_const static inline int int4_dot(int4 v1, int4 v2) {
|
|
||||||
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z + v1.w * v2.w;
|
|
||||||
}
|
|
||||||
@@ -2,14 +2,11 @@
|
|||||||
|
|
||||||
#include "../src/util/conf.h"
|
#include "../src/util/conf.h"
|
||||||
#include "../src/util/types.h"
|
#include "../src/util/types.h"
|
||||||
#include "../src/util/vec/float3.h"
|
|
||||||
#include "t_conf.h"
|
#include "t_conf.h"
|
||||||
#include "t_util.h"
|
#include "t_util.h"
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
||||||
testdat tests[] = {
|
testdat tests[] = {
|
||||||
{"", test_float3_norm, &(float3){2.0F, 0.67F, 5.0F} },
|
|
||||||
{"", test_float3_norm, &(float3){0.2F, 0.4F, 0.1F} },
|
|
||||||
{"", test_bswap16, (u16[]){0x11EE, 0xEE11} },
|
{"", test_bswap16, (u16[]){0x11EE, 0xEE11} },
|
||||||
{"", test_bswap32, (u32[]){0x1142ADEE, 0xEEAD4211} },
|
{"", test_bswap32, (u32[]){0x1142ADEE, 0xEEAD4211} },
|
||||||
{"", test_bswap64, (u64[]){0x114266897799ADEE, 0xEEAD997789664211} },
|
{"", test_bswap64, (u64[]){0x114266897799ADEE, 0xEEAD997789664211} },
|
||||||
|
|||||||
@@ -1,23 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <math.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "../src/util/colour32.h"
|
#include "../src/util/colour32.h"
|
||||||
#include "../src/util/compat/bswap.h"
|
#include "../src/util/compat/bswap.h"
|
||||||
#include "../src/util/types.h"
|
#include "../src/util/types.h"
|
||||||
#include "../src/util/vec/float3.h"
|
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
||||||
int test_float3_norm(void *d) {
|
|
||||||
float *arg = d;
|
|
||||||
float3 v = {arg[0], arg[1], arg[2]};
|
|
||||||
float3 r = float3_norm(v);
|
|
||||||
float n = r.x * r.x + r.y * r.y + r.z * r.z;
|
|
||||||
|
|
||||||
// check if the value is within 1 millionth of the one we expect
|
|
||||||
return assert_true(fabsf(n - 1.0F) < 1e-6F);
|
|
||||||
}
|
|
||||||
|
|
||||||
int test_colour32_endianess(void *d) {
|
int test_colour32_endianess(void *d) {
|
||||||
(void)d;
|
(void)d;
|
||||||
colour32 c = {0xFF000000}; // setting just the red channel
|
colour32 c = {0xFF000000}; // setting just the red channel
|
||||||
|
|||||||
Reference in New Issue
Block a user