take a bulldozer to some code

This commit is contained in:
Greg Wells
2025-05-20 17:39:40 -04:00
parent 43c6f88d18
commit a4166ae5c2
30 changed files with 495 additions and 503 deletions

View File

@@ -1,29 +1,27 @@
#pragma once
typedef enum gnReturnCode {
GN_SUCCESS, GN_WARNING, GN_FAILED,
GN_ERROR = GN_FAILED
typedef enum gnReturnCode_t {
GN_SUCCESS,
GN_UNKNOWN_RENDERINGAPI,
GN_UNSUPPORTED_RENDERING_API,
GN_UNABLE_TO_LOAD_DYNAMIC_LIBARRY
// GN_UNKNOWN_ERROR,
// GN_UNKNOWN_FRAMEBUFFER_ATTACHMENT,
// GN_UNKNOWN_SHADER_MODULE,
// GN_UNKNOWN_FUNCTION,
// GN_SHADER_FAILED_TO_COMPILE,
// GN_UNSUPPORTED_COLOR_FORMAT,
// GN_UNKNOWN_COLOR_FORMAT,
// GN_FUNCTION_NOT_FOUND,
// GN_FAILED_CREATE_DEVICE,
// GN_FAILED_CREATE_GRAPHICS_PIPELINE,
// GN_FAILED_CREATE_PRESENTATION_QUEUE,
// GN_FAILED_TO_CREATE_FRAMEBUFFER,
// GN_FAILED_CREATE_RENDERPASS,
// GN_FAILED_CREATE_INSTANCE,
// GN_FAILED_TO_ATTACH_WINDOW,
// GN_FAILED_TO_CREATE_IMAGE
} gnReturnCode;
typedef enum gnReturnMessage {
GN_UNKNOWN_ERROR,
GN_UNKNOWN_FRAMEBUFFER_ATTACHMENT,
GN_UNKNOWN_SHADER_MODULE,
GN_SHADER_FAILED_TO_COMPILE,
GN_UNSUPPORTED_COLOR_FORMAT,
GN_UNKNOWN_COLOR_FORMAT,
GN_UNSUPPORTED_RENDERING_API,
GN_FUNCTION_NOT_FOUND,
GN_UNABLE_TO_LOAD_DLL,
GN_FAILED_CREATE_DEVICE,
GN_FAILED_CREATE_GRAPHICS_PIPELINE,
GN_FAILED_CREATE_PRESENTATION_QUEUE,
GN_FAILED_TO_CREATE_FRAMEBUFFER,
GN_FAILED_CREATE_RENDERPASS,
GN_FAILED_CREATE_INSTANCE,
GN_FAILED_TO_ATTACH_WINDOW,
GN_FAILED_TO_CREATE_IMAGE
} gnReturnMessage;
typedef gnReturnCode gnErrorCode;
typedef gnReturnMessage gnErrorMessage;

View File

@@ -1,16 +1,16 @@
#pragma once
#include "stdlib.h"
typedef struct gnCList {
typedef struct gnArrayList {
int count;
int maxCount;
void* data;
} gnCList;
} gnArrayList;
const int GROWTH_RATE = 2; // i heard somewhere that 1.5 is better but imma use 2 because I also heard that its better somewhere else
inline gnCList gnCreateCList(int count) {
gnCList newList;
inline gnArrayList gnCreateArrayList(int count) {
gnArrayList newList;
if (count == 0) {
@@ -23,7 +23,7 @@ inline gnCList gnCreateCList(int count) {
return newList;
}
inline void gnCListResize(gnCList* cList, int count) {
inline void gnArrayListResize(gnArrayList* cList, int count) {
cList->count = count;
while (cList->count > cList->maxCount) {
int oldMaxCount = cList->maxCount;
@@ -36,7 +36,7 @@ inline void gnCListResize(gnCList* cList, int count) {
cList->data = realloc(cList->data, cList->maxCount);
}
inline void gnCListReserve(gnCList* cList, int count) {
inline void gnArrayListReserve(gnArrayList* cList, int count) {
while (cList->count > cList->maxCount) {
int oldMaxCount = cList->maxCount;
cList->maxCount *= GROWTH_RATE;

View File

@@ -0,0 +1,22 @@
#pragma once
#include "stdlib.h"
// why would one use a linked list
typedef struct gnLinkedList {
void* data;
gnLinkedList* nextNode;
} gnLinkedList;
static gnLinkedList gnCreateLinkedList(int count) {
gnLinkedList list;
gnLinkedList* currentNode = &list;
for (int i = 0; i < count; i++) {
if ((i + 1) < count) {
currentNode->nextNode = (gnLinkedList*)malloc(sizeof(gnLinkedList));
currentNode = currentNode->nextNode;
}
}
return list;
}

View File

@@ -1,85 +0,0 @@
#pragma once
#include "math.h"
#include "stdio.h"
// TODO: Wack ass list class, needs some serious refactoring, buttttt it works for what I need it to do
// Imma touch this later cuz like I dont like working with C code cuz its wierd but like its also fun
// who needs std::vector when you've got malloc, calloc, and free
// shit just forgot that I dont clean any of this up, imma do this later cuz like its boring
// ive decided to do it now, I hate this, I hate coding, C is fun, this is a Cpp file, what am I doing with life
// I never did it id be super easy just like one anitconstructor????? i dont remeber what is called its the one with the squigly bracked
// TODO: future me rewirte these comments to be less stupid
// TODO: Add insert function, also remove function, orrrrrr i could have people copy lists whever they wanna remove stuff, nah thats gunna piss me off too
#define GRYPHN_LIST_GROWTH_RATE 2 // number straight from my ass I wanted to use 1.5f cuz thats what STL does but like it complained
// im in an abbusive relationship with the compiler, I need to get out of this
// but like I also kinda like it imma pick of drinking (not actually imma just play minecraft)
template <typename Type> // fuck templates
struct gnList {
protected:
Type* items = nullptr;
int size = 0, max_size = 0;
public:
gnList() {}
// why did I make shit protected
// theres gotta be a better way to do this with compiler macros but like that sounds hard
// im never touching this wack ass code ever again
template <typename T>
friend gnList<T> gnCreateList(int size);
template <typename T>
friend void gnListAdd(gnList<T>& list, T item);
template <typename T>
friend int gnListLength(const gnList<T>& list);
template <typename T>
friend T& gnListGet(const gnList<T>& list, int index);
template <typename T>
friend T* gnListGetPtr(const gnList<T>& list, int index);
template <typename T>
friend void gnListSet(const gnList<T>& list, int index, T item);
template <typename T>
friend T* gnListData(const gnList<T>& list);
public:
Type operator[](int index) const { return items[index]; } // idfk what that const is doin there but the compiler complained I was tryna change a const value
// .... I was not, I really am in an abusive relationship
Type& operator[](int index) { return items[index]; }
};
template <typename T>
gnList<T> gnCreateList(int size = 0) {
gnList<T> new_list = gnList<T>();
new_list.size = size;
if (size == 0) size = round(GRYPHN_LIST_GROWTH_RATE);
new_list.items = (T*)malloc(sizeof(T) * size);
new_list.max_size = size;
return new_list;
}
template <typename T>
void gnListAdd(gnList<T>& list, T item) {
if (gnListLength(list) == list.max_size) {
list.max_size = list.max_size * GRYPHN_LIST_GROWTH_RATE;
list.items = (T*)realloc(list.items, sizeof(T) * list.max_size);
}
list.items[list.size] = item;
list.size++;
}
template <typename T>
int gnListLength(const gnList<T>& list) { return list.size; }
template <typename T>
T& gnListGet(const gnList<T>& list, int index) { return list.items[index]; }
template <typename T>
T* gnListGetPtr(const gnList<T>& list, int index) { return &list.items[index]; }
template <typename T>
void gnListSet(const gnList<T>& list, int index, T item) { list.items[index] = item; }
template <typename T>
T* gnListData(const gnList<T>& list) { return list.items; } // wack ass function for binary shit
// if this ever breaks change it to return &list.items[0] cuz that might work
// I have zero clue what any of this shit does

View File

@@ -1,44 +1,77 @@
#pragma once
#include <unordered_map>
#include <string>
// very shitty vec2 class
#include "stdint.h"
template <typename T>
struct gnType2 {
typedef struct gnVec2 {
union {
struct { T a, b; };
struct { T x, y; };
struct { float a, b; };
struct { float x, y; };
};
public:
gnType2(T a, T b) { this->a = a; this->b = b; }
gnType2() {};
gnType2 operator-(const gnType2& other) {
gnType2 returnGnVec2;
#ifdef GN_UTILS_CPP
gnVec2(float x, float y) { this->x = x; this->y = y; }
gnVec2(float s) { this->x = s; this->y = s; }
gnVec2() {};
gnVec2 operator-(const gnVec2& other) {
gnVec2 returnGnVec2;
returnGnVec2.x = this->x - other.x;
returnGnVec2.y = this->y - other.y;
return returnGnVec2;
}
bool operator==(const gnType2& other) const {
bool operator==(const gnVec2& other) const {
return this->a == other.a && this->b == other.b;
}
};
#endif
} gnVec2;
typedef gnVec2 gnFVec2;
typedef gnVec2 gnFloat2;
typedef gnType2<float> gnVec2;
typedef gnType2<float> gnFloat2;
typedef gnType2<uint32_t> gnUInt2;
typedef gnType2<int32_t> gnInt2;
namespace std {
template<>
struct hash<gnUInt2> {
std::size_t operator()(const gnUInt2& k) const {
return std::hash<uint32_t>()(k.x) ^ (std::hash<uint32_t>()(k.y) << 1);
}
typedef struct gnUInt2 {
union {
struct { uint32_t a, b; };
struct { uint32_t x, y; };
};
}
#ifdef GN_UTILS_CPP
gnUInt2(uint32_t x, uint32_t y) { this->x = x; this->y = y; }
gnUInt2(uint32_t s) { this->x = s; this->y = s; }
gnUInt2() {};
gnUInt2 operator-(const gnUInt2& other) {
gnUInt2 returnGnVec2;
returnGnVec2.x = this->x - other.x;
returnGnVec2.y = this->y - other.y;
return returnGnVec2;
}
bool operator==(const gnUInt2& other) const {
return this->a == other.a && this->b == other.b;
}
#endif
} gnUInt2;
typedef struct gnInt2 {
union {
struct { int a, b; };
struct { int x, y; };
};
#ifdef GN_UTILS_CPP
gnInt2(int x, int y) { this->x = x; this->y = y; }
gnInt2(int s) { this->x = s; this->y = s; }
gnInt2() {};
gnInt2 operator-(const gnInt2& other) {
gnInt2 returnGnVec2;
returnGnVec2.x = this->x - other.x;
returnGnVec2.y = this->y - other.y;
return returnGnVec2;
}
bool operator==(const gnInt2& other) const {
return this->a == other.a && this->b == other.b;
}
#endif
} gnInt2;

View File

@@ -36,7 +36,7 @@ typedef struct gnUInt3 {
};
#ifdef GN_UTILS_CPP
gnUInt3(uint32_t x, uint32_t y) { this->x = x; this->y = y; this->z = z; }
gnUInt3(uint32_t x, uint32_t y, uint32_t z) { this->x = x; this->y = y; this->z = z; }
gnUInt3(uint32_t s) { this->x = s; this->y = s; this->z = s; }
gnUInt3() {};

View File

@@ -25,7 +25,7 @@ typedef char gnChar;
typedef struct gnString {
gnChar* value;
#ifdef GN_UTILS_CPP
#ifdef __cplusplus
gnString(const gnChar* input) {
this->value = new gnChar[strlen(input) + 1]; // so like my dumbass forgot to put this earlier and some shit was broken but now it fixed
// I was wondering why one specific string crashed my program, it was my fault

View File

@@ -1,3 +1,4 @@
#pragma once
typedef struct gnColor {
union {
struct {