start using C based classes

This commit is contained in:
Greg Wells
2025-05-20 12:02:44 -04:00
parent daef5e4858
commit 74689a86ef
10 changed files with 213 additions and 113 deletions

View File

@@ -16,4 +16,4 @@ public:
gnString gnGetPhysicalOutputDeviceName(const gnPhysicalOutputDevice& device);
inline bool (*gnDeviceSupportsAPI)(const gnPhysicalOutputDevice& device);
inline gnList<gnPhysicalOutputDevice> (*gnGetPhysicalOutputDevices)(const gnInstance& instance);
inline gnPhysicalOutputDevice* (*gnGetPhysicalOutputDevices)(const gnInstance& instance, uint32_t* count);

View File

@@ -1,12 +1,10 @@
#include "utils/strings/gryphn_string.h"
#pragma once
typedef enum gnReturnCode {
GN_SUCCESS, GN_FAILED, GN_FATAL,
GN_SUCCESS, GN_WARNING, GN_FAILED,
GN_ERROR = GN_FAILED
} gnReturnCode;
typedef gnReturnCode gnErrorCode;
typedef enum gnReturnMessage {
GN_UNKNOWN_ERROR,
GN_UNKNOWN_FRAMEBUFFER_ATTACHMENT,
@@ -24,18 +22,8 @@ typedef enum gnReturnMessage {
GN_FAILED_CREATE_RENDERPASS,
GN_FAILED_CREATE_INSTANCE,
GN_FAILED_TO_ATTACH_WINDOW,
GN_FAILED_TO_CREATE_IMAGE,
GN_FAILED_CREATE_WINDOW_SURFACE
GN_FAILED_TO_CREATE_IMAGE
} gnReturnMessage;
inline gnString lastReturnAPIMessage = gnCreateEmptyString();
inline gnReturnMessage lastReturnMessage = GN_UNKNOWN_ERROR;
static const gnString gnGetErrorString() { return lastReturnAPIMessage; }
static const gnReturnMessage gnGetErrorMessage() { return lastReturnMessage; }
static gnReturnCode gnReturnError(gnReturnMessage message, gnString errorMessage) {
lastReturnAPIMessage = errorMessage;
lastReturnMessage = message;
return GN_ERROR;
}
typedef gnReturnCode gnErrorCode;
typedef gnReturnMessage gnErrorMessage;

View File

@@ -1,37 +1,80 @@
#pragma once
// very shitty vec3 class
// i really want to write some math for this shit but im a lazy little cunt and im not doing all that shit
#include "stdint.h"
template <typename T>
struct gnType3 {
typedef struct gnVec3 {
union {
struct { T a, b, c; };
struct { T x, y, z; };
struct { float a, b, c; };
struct { float x, y, z; };
};
public:
gnType3(T a, T b, T c) { this->a = a; this->b = b; this->c = c; }
gnType3() {};
bool operator==(const gnType3& other) const {
#ifdef GN_UTILS_CPP
gnVec3(float x, float y, float z) { this->x = x; this->y = y; this->z = z; }
gnVec3(float s) { this->x = s; this->y = s; this->z = s; }
gnVec3() {};
gnVec3 operator-(const gnVec3& other) {
gnVec3 returnGnVec3;
returnGnVec3.x = this->x - other.x;
returnGnVec3.y = this->y - other.y;
returnGnVec3.z = this->z - other.z;
return returnGnVec3;
}
bool operator==(const gnVec3& other) const {
return this->a == other.a && this->b == other.b && this->c == other.c;
}
};
#endif
} gnVec3;
template <typename T1, typename T2, typename T3>
struct gnMultiType3 {
union {
struct { T1 a; T2 b; T3 c; };
struct { T1 x; T2 y; T3 z; };
};
public:
gnMultiType3(T1 a, T2 b, T3 c) { this->a = a; this->b = b; this->c = c; }
gnMultiType3() {};
};
typedef gnType3<float> gnVec3;
typedef gnVec3 gnFVec3;
typedef gnVec3 gnFloat3;
typedef gnType3<uint32_t> gnUInt3;
typedef gnType3<int32_t> gnInt3;
typedef struct gnUInt3 {
union {
struct { uint32_t a, b, c; };
struct { uint32_t x, y, z; };
};
#ifdef GN_UTILS_CPP
gnUInt3(uint32_t x, uint32_t y) { this->x = x; this->y = y; this->z = z; }
gnUInt3(uint32_t s) { this->x = s; this->y = s; this->z = s; }
gnUInt3() {};
gnUInt3 operator-(const gnUInt3& other) {
gnUInt3 returnGnVec3;
returnGnVec3.x = this->x - other.x;
returnGnVec3.y = this->y - other.y;
returnGnVec3.z = this->z - other.z;
return returnGnVec3;
}
bool operator==(const gnUInt3& other) const {
return this->a == other.a && this->b == other.b && this->c == other.c;
}
#endif
} gnUInt3;
typedef struct gnInt3 {
union {
struct { int a, b, c; };
struct { int x, y, z; };
};
#ifdef GN_UTILS_CPP
gnInt3(int x, int y, int z) { this->x = x; this->y = y; this->z = z; }
gnInt3(int s) { this->x = s; this->y = s; this->z = s; }
gnInt3() {};
gnInt3 operator-(const gnInt3& other) {
gnInt3 returnGnVec3;
returnGnVec3.x = this->x - other.x;
returnGnVec3.y = this->y - other.y;
returnGnVec3.z = this->z - other.z;
return returnGnVec3;
}
bool operator==(const gnInt3& other) const {
return this->a == other.a && this->b == other.b && this->c == other.c;
}
#endif
} gnInt3;

View File

@@ -1,33 +1,87 @@
// typedef gnType4<uint32_t> gnUInt4;
// typedef gnType4<int32_t> gnInt4;
#pragma once
// very shitty vec4 class
// I also use this same thing to make my color class dont worry abt it
#include "stdint.h"
template <typename T>
struct gnType4 {
typedef struct gnVec4 {
union {
struct { T a, b, c, d; };
struct { T x, y, z, w; };
struct { float a, b, c, d; };
struct { float x, y, z, w; };
};
public:
gnType4(T a, T b, T c, T d) { this->a = a; this->b = b; this->c = c; this->d = d; }
gnType4() {};
};
template <typename T1, typename T2, typename T3, typename T4>
struct gnMultiType4 {
union {
struct { T1 r; T2 g; T3 b; T4 a; };
struct { T1 x; T2 y; T3 z; T4 w; };
};
public:
gnMultiType4(T1 r, T2 g, T3 b, T4 a) { this->r = r; this->g = g; this->b = b; this->a = a; }
gnMultiType4() {};
};
#ifdef GN_UTILS_CPP
gnVec4(float x, float y, float z, float w) { this->x = x; this->y = y; this->z = z; this->w = w; }
gnVec4(float s) { this->x = s; this->y = s; this->z = s; this->w = w; }
gnVec4() {};
typedef gnType4<float> gnVec4;
gnVec4 operator-(const gnVec4& other) {
gnVec4 returnGnVec4;
returnGnVec4.x = this->x - other.x;
returnGnVec4.y = this->y - other.y;
returnGnVec4.z = this->z - other.z;
returnGnVec4.w = this->w - other.w;
return returnGnVec4;
}
bool operator==(const gnVec4& other) const {
return this->a == other.a && this->b == other.b && this->c == other.c && this->d == other.d;
}
#endif
} gnVec4;
typedef gnVec4 gnFVec4;
typedef gnVec4 gnFloat4;
typedef gnType4<uint32_t> gnUInt4;
typedef gnType4<int32_t> gnInt4;
typedef struct gnUInt4 {
union {
struct { uint32_t a, b, c, d; };
struct { uint32_t x, y, z, w; };
};
#ifdef GN_UTILS_CPP
gnUInt4(uint32_t x, uint32_t y, uint32_t z, uint32_t w) { this->x = x; this->y = y; this->z = z; this->w = w; }
gnUInt4(uint32_t s) { this->x = s; this->y = s; this->z = s; this->w = s; }
gnUInt4() {};
gnUInt4 operator-(const gnUInt4& other) {
gnUInt4 returnGnVec4;
returnGnVec4.x = this->x - other.x;
returnGnVec4.y = this->y - other.y;
returnGnVec4.z = this->z - other.z;
returnGnVec4.w = this->w - other.w;
return returnGnVec4;
}
bool operator==(const gnUInt4& other) const {
return this->a == other.a && this->b == other.b && this->c == other.c && this->d == other.d;
}
#endif
} gnUInt4;
typedef struct gnInt4 {
union {
struct { int a, b, c, d; };
struct { int x, y, z, w; };
};
#ifdef GN_UTILS_CPP
gnInt4(int x, int y, int z, int w) { this->x = x; this->y = y; this->z = z; this->w = w; }
gnInt4(int s) { this->x = s; this->y = s; this->z = s; this->w = s; }
gnInt4() {};
gnInt4 operator-(const gnInt4& other) {
gnInt4 returnGnVec4;
returnGnVec4.x = this->x - other.x;
returnGnVec4.y = this->y - other.y;
returnGnVec4.z = this->z - other.z;
returnGnVec4.w = this->w - other.w;
return returnGnVec4;
}
bool operator==(const gnInt4& other) const {
return this->a == other.a && this->b == other.b && this->c == other.c;
}
#endif
} gnInt4;

View File

@@ -1,3 +1,29 @@
#include "../math/gryphn_vec4.h"
typedef struct gnColor {
union {
struct {
int r, g, b;
float a;
};
typedef gnMultiType4<int, int, int, float> gnColor;
struct {
int red, green, blue;
float alpha;
};
};
#ifdef GN_UTILS_CPP
gnColor(int red, int green, int blue, float alpha = 1.0) {
this->red = red;
this->green = green;
this->blue = blue;
this->alpha = alpha;
}
gnColor(int color = 0, float alpha = 1.0) {
this->red = color;
this->green = color;
this->blue = color;
this->alpha = alpha;
}
#endif
} gnColor;