make gryphn utils a submodule
This commit is contained in:
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[submodule "src/utils"]
|
||||
path = src/utils
|
||||
url = https://github.com/GregoryWells2007/GryphnUtils.git
|
@@ -1,7 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef GN_REVEAL_IMPL
|
||||
#define ACCESS_LEVEL public
|
||||
#else
|
||||
#define ACCESS_LEVEL protected
|
||||
#endif
|
@@ -1,14 +0,0 @@
|
||||
#pragma once
|
||||
#include "stdlib.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
typedef int gnBool;
|
||||
#define gnFalse 0
|
||||
#define gnTrue 1
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef size_t gnSize;
|
@@ -1,84 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
typedef enum gnReturnCode_t {
|
||||
GN_SUCCESS,
|
||||
GN_UNKNOWN_RENDERINGAPI,
|
||||
GN_UNSUPPORTED_RENDERING_API,
|
||||
GN_UNABLE_TO_LOAD_DYNAMIC_LIBARRY,
|
||||
GN_FAILED_CREATE_INSTANCE,
|
||||
GN_FAILED_TO_CREATE_DEBUGGER,
|
||||
GN_FAILED_TO_CREATE_DEVICE,
|
||||
GN_FAILED_TO_ATTACH_WINDOW,
|
||||
GN_INVALID_INSTANCE,
|
||||
GN_DEBUGGER_EXISTS,
|
||||
GN_NO_SUPPORTED_FORMATS,
|
||||
GN_NO_SUPPORTED_PRESENT_MODES,
|
||||
GN_UNKNOWN_IMAGE_FORMAT,
|
||||
GN_FAILED_TO_CREATE_PRESENTATION_QUEUE,
|
||||
GN_UNSUPPORTED_IMAGE_COUNT,
|
||||
GN_FAILED_TO_CREATE_IMAGE_VIEW,
|
||||
GN_FAILED_TO_CREATE_SHADER_MODULE,
|
||||
GN_FAILED_TO_CONVERT_SHADER_CODE,
|
||||
GN_FAILED_TO_FIND_ENTRY_POINT,
|
||||
GN_FAILED_TO_CREATE_UNIFORM_LAYOUT,
|
||||
GN_FAILED_TO_CREATE_RENDER_PASS,
|
||||
GN_FAILED_TO_CREATE_GRAPHICS_PIPELINE,
|
||||
GN_UNSUPPORTED_SHADER_MODULE,
|
||||
GN_UNKNOWN_SUBPASS,
|
||||
GN_FAILED_TO_CREATE_FRAMEBUFFER,
|
||||
GN_DIVERGENT_RENDERPASS,
|
||||
GN_FAILED_TO_CREATE_COMMAND_POOL,
|
||||
GN_FAILED_TO_BEGIN_RECORDING,
|
||||
GN_FAIELD_TO_END_RECORDING,
|
||||
GN_FAILED_TO_ALLOCATE_COMMAND_BUFFERS,
|
||||
GN_FAILED_TO_CREATE_FENCE,
|
||||
GN_FAILED_TO_CREATE_SEMAPHORE,
|
||||
GN_FAILED_TO_SUBMIT_COMMAND_BUFFER,
|
||||
GN_OUT_OF_DATE_PRESENTATION_QUEUE,
|
||||
GN_SUBOPTIMAL_PRESENTATION_QUEUE,
|
||||
GN_FAILED_TO_CREATE_BUFFER,
|
||||
GN_FAILED_TO_ALLOCATE_MEMORY
|
||||
} gnReturnCode;
|
||||
|
||||
typedef gnReturnCode gnErrorCode;
|
||||
static const char* gnErrorCodeToCString(enum gnReturnCode_t returnCode) {
|
||||
switch (returnCode) {
|
||||
case GN_SUCCESS: return "GN_SUCCESS";
|
||||
case GN_UNKNOWN_RENDERINGAPI: return "GN_UNKNOWN_RENDERINGAPI";
|
||||
case GN_UNSUPPORTED_RENDERING_API: return "GN_UNSUPPORTED_RENDERING_API";
|
||||
case GN_UNABLE_TO_LOAD_DYNAMIC_LIBARRY: return "GN_UNABLE_TO_LOAD_DYNAMIC_LIBARRY";
|
||||
case GN_FAILED_CREATE_INSTANCE: return "GN_FAILED_CREATE_INSTANCE";
|
||||
case GN_FAILED_TO_CREATE_DEBUGGER: return "GN_FAILED_TO_CREATE_DEBUGGER";
|
||||
case GN_FAILED_TO_CREATE_DEVICE: return "GN_FAILED_TO_CREATE_DEVICE";
|
||||
case GN_FAILED_TO_ATTACH_WINDOW: return "GN_FAILED_TO_ATTACH_WINDOW";
|
||||
case GN_INVALID_INSTANCE: return "GN_INVALID_INSTANCE";
|
||||
case GN_DEBUGGER_EXISTS: return "GN_DEBUGGER_EXISTS";
|
||||
case GN_NO_SUPPORTED_FORMATS: return "GN_NO_SUPPORTED_FORMATS";
|
||||
case GN_NO_SUPPORTED_PRESENT_MODES: return "GN_NO_SUPPORTED_PRESENT_MODES";
|
||||
case GN_UNKNOWN_IMAGE_FORMAT: return "GN_UNKNOWN_IMAGE_FORMAT";
|
||||
case GN_FAILED_TO_CREATE_PRESENTATION_QUEUE: return "GN_FAILED_TO_CREATE_PRESENTATION_QUEUE";
|
||||
case GN_UNSUPPORTED_IMAGE_COUNT: return "GN_UNSUPPORTED_IMAGE_COUNT";
|
||||
case GN_FAILED_TO_CREATE_IMAGE_VIEW: return "GN_FAILED_TO_CREATE_IMAGE_VIEW";
|
||||
case GN_FAILED_TO_CREATE_SHADER_MODULE: return "GN_FAILED_TO_CREATE_SHADER_MODULE";
|
||||
case GN_FAILED_TO_CONVERT_SHADER_CODE: return "GN_FAILED_TO_CONVERT_SHADER_CODE";
|
||||
case GN_FAILED_TO_FIND_ENTRY_POINT: return "GN_FAILED_TO_FIND_ENTRY_POINT";
|
||||
case GN_FAILED_TO_CREATE_UNIFORM_LAYOUT: return "GN_FAILED_TO_CREATE_UNIFORM_LAYOUT";
|
||||
case GN_FAILED_TO_CREATE_RENDER_PASS: return "GN_FAILED_TO_CREATE_RENDER_PASS";
|
||||
case GN_FAILED_TO_CREATE_GRAPHICS_PIPELINE: return "GN_FAILED_TO_CREATE_GRAPHICS_PIPELINE";
|
||||
case GN_UNSUPPORTED_SHADER_MODULE: return "GN_UNSUPPORTED_SHADER_MODULE";
|
||||
case GN_UNKNOWN_SUBPASS: return "GN_UNKNOWN_SUBPASS";
|
||||
case GN_FAILED_TO_CREATE_FRAMEBUFFER: return "GN_FAILED_TO_CREATE_FRAMEBUFFER";
|
||||
case GN_DIVERGENT_RENDERPASS: return "GN_DIVERGENT_RENDERPASS";
|
||||
case GN_FAILED_TO_CREATE_COMMAND_POOL: return "GN_FAILED_TO_CREATE_COMMAND_POOL";
|
||||
case GN_FAILED_TO_BEGIN_RECORDING: return "GN_FAILED_TO_BEGIN_RECORDING";
|
||||
case GN_FAIELD_TO_END_RECORDING: return "GN_FAIELD_TO_END_RECORDING";
|
||||
case GN_FAILED_TO_ALLOCATE_COMMAND_BUFFERS: return "GN_FAILED_TO_ALLOCATE_COMMAND_BUFFERS";
|
||||
case GN_FAILED_TO_CREATE_FENCE: return "GN_FAILED_TO_CREATE_FENCE";
|
||||
case GN_FAILED_TO_CREATE_SEMAPHORE: return "GN_FAILED_TO_CREATE_SEMAPHORE";
|
||||
case GN_FAILED_TO_SUBMIT_COMMAND_BUFFER: return "GN_FAILED_TO_SUBMIT_COMMAND_BUFFER";
|
||||
case GN_OUT_OF_DATE_PRESENTATION_QUEUE: return "GN_OUT_OF_DATE_PRESENTATION_QUEUE";
|
||||
case GN_SUBOPTIMAL_PRESENTATION_QUEUE: return "GN_SUBOPTIMAL_PRESENTATION_QUEUE";
|
||||
case GN_FAILED_TO_ALLOCATE_MEMORY: return "GN_FAILED_TO_ALLOCATE_MEMORY";
|
||||
case GN_FAILED_TO_CREATE_BUFFER: return "GN_FAILED_TO_CREATE_BUFFER";
|
||||
}
|
||||
}
|
@@ -1,49 +0,0 @@
|
||||
#pragma once
|
||||
#include "stdlib.h"
|
||||
|
||||
typedef struct gnArrayList {
|
||||
int count;
|
||||
int maxCount;
|
||||
void* data;
|
||||
} 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 gnArrayList gnCreateArrayList(int count) {
|
||||
gnArrayList newList;
|
||||
|
||||
if (count == 0) {
|
||||
|
||||
} else {
|
||||
newList.count = count;
|
||||
newList.maxCount = count;
|
||||
newList.data = malloc(sizeof(void*) * count);
|
||||
}
|
||||
|
||||
return newList;
|
||||
}
|
||||
|
||||
inline void gnArrayListResize(gnArrayList* cList, int count) {
|
||||
cList->count = count;
|
||||
while (cList->count > cList->maxCount) {
|
||||
int oldMaxCount = cList->maxCount;
|
||||
cList->maxCount *= GROWTH_RATE;
|
||||
if (cList->count == oldMaxCount) {
|
||||
cList->maxCount += 1;
|
||||
}
|
||||
}
|
||||
|
||||
cList->data = realloc(cList->data, cList->maxCount);
|
||||
}
|
||||
|
||||
inline void gnArrayListReserve(gnArrayList* cList, int count) {
|
||||
while (cList->count > cList->maxCount) {
|
||||
int oldMaxCount = cList->maxCount;
|
||||
cList->maxCount *= GROWTH_RATE;
|
||||
if (cList->count == oldMaxCount) {
|
||||
cList->maxCount += 1;
|
||||
}
|
||||
}
|
||||
|
||||
cList->data = realloc(cList->data, cList->maxCount);
|
||||
}
|
@@ -1,22 +0,0 @@
|
||||
#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;
|
||||
}
|
@@ -1,77 +0,0 @@
|
||||
#pragma once
|
||||
#include "stdint.h"
|
||||
|
||||
typedef struct gnVec2_t {
|
||||
union {
|
||||
struct { float a, b; };
|
||||
struct { float x, y; };
|
||||
};
|
||||
|
||||
#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 gnVec2& other) const {
|
||||
return this->a == other.a && this->b == other.b;
|
||||
}
|
||||
#endif
|
||||
} gnVec2;
|
||||
|
||||
typedef gnVec2 gnFVec2;
|
||||
typedef gnVec2 gnFloat2;
|
||||
|
||||
typedef struct gnUInt2_t {
|
||||
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_t {
|
||||
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;
|
@@ -1,80 +0,0 @@
|
||||
#pragma once
|
||||
#include "stdint.h"
|
||||
|
||||
typedef struct gnVec3 {
|
||||
union {
|
||||
struct { float a, b, c; };
|
||||
struct { float x, y, z; };
|
||||
};
|
||||
|
||||
#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;
|
||||
|
||||
typedef gnVec3 gnFVec3;
|
||||
typedef gnVec3 gnFloat3;
|
||||
|
||||
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, 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() {};
|
||||
|
||||
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;
|
@@ -1,87 +0,0 @@
|
||||
// typedef gnType4<uint32_t> gnUInt4;
|
||||
// typedef gnType4<int32_t> gnInt4;
|
||||
|
||||
|
||||
#pragma once
|
||||
#include "stdint.h"
|
||||
|
||||
typedef struct gnVec4 {
|
||||
union {
|
||||
struct { float a, b, c, d; };
|
||||
struct { float x, y, z, w; };
|
||||
};
|
||||
|
||||
#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() {};
|
||||
|
||||
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 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;
|
@@ -1,239 +0,0 @@
|
||||
#pragma once
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "../gryphn_bool.h"
|
||||
|
||||
static char* add_string_to_string(char* str1, char* str2) {
|
||||
char* buffer = (char*)malloc(sizeof(char) * (strlen(str1) + strlen(str2) + 1));
|
||||
strcpy(buffer, str1);
|
||||
strcat(buffer, str2);
|
||||
buffer[strlen(str1) + strlen(str2)] = '\0';
|
||||
return buffer;
|
||||
}
|
||||
// add char to char buffer
|
||||
// better name
|
||||
static char* add_char_to_string(char* str1, char str2) {
|
||||
char* buffer = (char*)malloc(sizeof(char) * (strlen(str1) + 2));
|
||||
strcpy(buffer, str1);
|
||||
buffer[strlen(str1)] = str2;
|
||||
buffer[strlen(str1) + 1] = '\0';
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
typedef char gnChar;
|
||||
|
||||
typedef struct gnString {
|
||||
gnChar* value;
|
||||
#ifdef GN_UTILS_CPP
|
||||
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
|
||||
strcpy(this->value, input);
|
||||
this->value[strlen(input)] = '\0';
|
||||
}
|
||||
gnString(gnChar* input) {
|
||||
this->value = new gnChar[strlen(input) + 1];
|
||||
strcpy(this->value, input);
|
||||
this->value[strlen(input)] = '\0';
|
||||
}
|
||||
gnString(gnChar input) {
|
||||
this->value = new char[2];
|
||||
this->value[0] = input;
|
||||
this->value[1] = '\0';
|
||||
}
|
||||
gnString() {
|
||||
this->value = new char[1];
|
||||
this->value[0] = '\0';
|
||||
}
|
||||
|
||||
operator const char*() const { return value; }
|
||||
|
||||
char operator[](int index) { return value [index]; }
|
||||
const char operator[](int index) const { return value [index]; }
|
||||
void operator +=(gnChar val) { value = add_char_to_string(value, val); }
|
||||
void operator +=(gnChar* val) { value = add_string_to_string(value, val); }
|
||||
void operator +=(const gnChar* val) { value = add_string_to_string(value, const_cast<char*>(val)); }
|
||||
void operator +=(const gnString& string) { value = add_string_to_string(value, string.value); }
|
||||
|
||||
gnString operator +(gnChar val) { return gnString(add_char_to_string(value, val)); }
|
||||
gnString operator +(gnChar* val){ return gnString(add_string_to_string(value, val)); }
|
||||
gnString operator +(const gnChar* val) { return gnString(add_string_to_string(value, const_cast<char*>(val))); }
|
||||
gnString operator +(const gnString& val) { return gnString(add_string_to_string(value, val.value)); }
|
||||
|
||||
gnBool operator ==(char* val) { return (strcmp(value, val) == 0); }
|
||||
gnBool operator ==(const char* val) { return (strcmp(value, const_cast<char*>(val)) == 0); }
|
||||
gnBool operator ==(const gnString& val) { return (strcmp(value, val.value) == 0); }
|
||||
|
||||
void operator =(char val) {
|
||||
this->value = new char[2];
|
||||
this->value[0] = val;
|
||||
this->value[1] = '\0';
|
||||
}
|
||||
void operator =(char* val) { this->value = val; }
|
||||
void operator =(const char* val) { this->value = const_cast<char*>(val); }
|
||||
void operator =(const gnString& val) { this->value = val.value; }
|
||||
#endif
|
||||
} gnString;
|
||||
|
||||
static gnString gnCreateStringFromConstCharPtr(const gnChar* input) {
|
||||
gnString string;
|
||||
string.value = (char*)malloc(sizeof(char) * (strlen(input) + 1));
|
||||
strcpy(string.value, input);
|
||||
string.value[strlen(input)] = '\0';
|
||||
return string;
|
||||
}
|
||||
static gnString gnCreateStringFromCharPtr(gnChar* input) {
|
||||
gnString sting;
|
||||
sting.value = (char*)malloc(sizeof(char) * (strlen(input) + 1));
|
||||
strcpy(sting.value, input);
|
||||
sting.value[strlen(input)] = '\0';
|
||||
return sting;
|
||||
}
|
||||
static gnString gnCreateStringFromChar(gnChar input) {
|
||||
gnString string;
|
||||
string.value = (char*)malloc(sizeof(char) * 2);
|
||||
string.value[0] = input;
|
||||
string.value[1] = '\0';
|
||||
return string;
|
||||
}
|
||||
static gnString gnCreateEmptyString() {
|
||||
gnString string;
|
||||
string.value = (char*)malloc(sizeof(char));
|
||||
string.value[0] = '\0';
|
||||
return string;
|
||||
}
|
||||
|
||||
#define gnCreateString(input) _Generic((input), \
|
||||
const gnChar*: gnCreateStringFromConstCharPtr, \
|
||||
gnChar*: gnCreateStringFromCharPtr, \
|
||||
gnChar: gnCreateStringFromChar \
|
||||
)(input)
|
||||
|
||||
static const char* gnToCString(const gnString string) { return string.value; }
|
||||
static int gnStringLength(const gnString string) { return strlen(string.value); }
|
||||
static int gnStringFindChar(const gnString string, const gnChar letter) {
|
||||
for (int i = 0; i < strlen(string.value); i++)
|
||||
if (string.value[i] == letter)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
static int gnStringFindString(const gnString string, const gnString value) {
|
||||
char first_char = value.value[0];
|
||||
for (int i = 0; i < strlen(string.value); i++)
|
||||
if (string.value[i] == first_char) {
|
||||
gnBool same = gnTrue;
|
||||
for (int c = 1; c < strlen(value.value); c++)
|
||||
if (string.value[i + c] != value.value[c]) {
|
||||
same = gnFalse;
|
||||
break;
|
||||
}
|
||||
|
||||
if (same)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
static gnString gnSubstring(const gnString string, int index1, int index2) {
|
||||
if (index2 == -1) index2 = gnStringLength(string);
|
||||
char* out_value = (char*)malloc(sizeof(char) * ((index2 - index1) + 1));
|
||||
for (int i = 0; i < (index2 - index1); i++)
|
||||
out_value[i] = string.value[i + index1];
|
||||
out_value[(index2 - index1)] = '\0';
|
||||
return gnCreateString(out_value); // zero error checking on this function should really add that in later but like I dont have a logging library that I want to use
|
||||
// my code never breaks either so I dont need error checks, il just not make errors cuz im not tim
|
||||
}
|
||||
static int gnLetterCount(const gnString string, const gnChar letter) {
|
||||
int count = 0;
|
||||
for (int i = 0; i < gnStringLength(string); i++) if (string.value[i] == letter) count++;
|
||||
return count;
|
||||
}
|
||||
|
||||
#define gnStringFind(string, value) _Generic((value), \
|
||||
const gnChar: gnStringFindChar, \
|
||||
const gnString: gnStringFindValue \
|
||||
)(string, value)
|
||||
|
||||
static void gnAddCharToString(gnString* string, gnChar val) {
|
||||
string->value = add_char_to_string(string->value, val);
|
||||
}
|
||||
static void gnAddCharPtrToString(gnString* string, gnChar* val) {
|
||||
string->value = add_string_to_string(string->value, val);
|
||||
}
|
||||
static void gnAddConstCharPtrToString(gnString* string, const gnChar* val) {
|
||||
string->value = add_string_to_string(string->value, (gnChar*)val);
|
||||
}
|
||||
static void gnAddContGnStringToString(gnString* string, gnString val) {
|
||||
string->value = add_string_to_string(string->value, val.value);
|
||||
}
|
||||
|
||||
#define gnAddToString(string, value) _Generic((value), \
|
||||
gnChar: gnAddCharToString, \
|
||||
int: gnAddCharToString, \
|
||||
gnChar*: gnAddCharPtrToString, \
|
||||
const gnChar*: gnAddConstCharPtrToString, \
|
||||
gnString: gnAddContGnStringToString \
|
||||
)(string, value)
|
||||
|
||||
static gnString gnCombineStringsChar(const gnString string, gnChar val) {
|
||||
return gnCreateString(add_char_to_string(string.value, val));
|
||||
}
|
||||
static gnString gnCombineStringsCharPtr(const gnString string, gnChar* val) {
|
||||
return gnCreateString(add_string_to_string(string.value, val));
|
||||
}
|
||||
static gnString gnCombineStringsConstCharPtr(const gnString string, const gnChar* val) {
|
||||
return gnCreateString(add_string_to_string(string.value, (gnChar*)val));
|
||||
}
|
||||
static gnString gnCombineStringsString(const gnString string, const gnString val) {
|
||||
return gnCreateString(add_string_to_string(string.value, val.value));
|
||||
}
|
||||
|
||||
#define gnCombineStrings(string, value) _Generic((value), \
|
||||
gnChar: gnCombineStringsChar, \
|
||||
int: gnCombineStringsChar, \
|
||||
gnChar*: gnCombineStringsCharPtr, \
|
||||
const gnChar*: gnCombineStringsConstCharPtr, \
|
||||
gnString: gnCombineStringsString \
|
||||
)(string, value)
|
||||
|
||||
static gnBool gnStringEqualsCharPtr(const gnString string, gnChar* val) { return (strcmp(string.value, val) == 0); }
|
||||
static gnBool gnStringEqualsConstCharPtr(const gnString string,const gnChar* val) { return (strcmp(string.value, (gnChar*)val) == 0); }
|
||||
static gnBool gnStringEqualsString(const gnString string, const gnString val) { return (strcmp(string.value, val.value) == 0); }
|
||||
|
||||
#define gnStringEquals(string, value) _Generic((value), \
|
||||
gnChar*: gnStringEqualsCharPtr, \
|
||||
const gnChar*: gnStringEqualsConstCharPtr, \
|
||||
gnString: gnStringEqualsString \
|
||||
)(string, value)
|
||||
|
||||
static gnChar gnGetCharAt(const gnString string, int index) { return string.value[0]; }
|
||||
static void gnSetCharAt(gnString* string, int index, gnChar letter) { string->value[0] = letter; }
|
||||
|
||||
static void gnSetStringToChar(gnString* string, gnChar input) {
|
||||
string->value = (gnChar*)malloc(sizeof(gnChar) * 2);
|
||||
string->value[0] = input;
|
||||
string->value[1] = '\0';
|
||||
}
|
||||
static void gnSetStringToCharPtr(gnString* string, gnChar* input) {
|
||||
string->value = (gnChar*)malloc(sizeof(gnChar) * (strlen(input) + 1));
|
||||
strcpy(string->value, input);
|
||||
string->value[strlen(input)] = '\0';
|
||||
}
|
||||
static void gnSetStringToConstCharPtr(gnString* string, const gnChar* input) {
|
||||
string->value = (gnChar*)malloc(sizeof(gnChar) * (strlen(input) + 1));
|
||||
strcpy(string->value, input);
|
||||
string->value[strlen(input)] = '\0';
|
||||
}
|
||||
static void gnSetStringToString(gnString* string, const gnString input) {
|
||||
string->value = (gnChar*)malloc(sizeof(gnChar) * (strlen(input.value) + 1));
|
||||
strcpy(string->value, input.value);
|
||||
string->value[strlen(input.value)] = '\0';
|
||||
}
|
||||
|
||||
#define gnSetString(string, value) _Generic((value), \
|
||||
gnChar: gnSetStringToChar, \
|
||||
int: gnSetStringToChar, \
|
||||
gnChar*: gnSetStringToCharPtr, \
|
||||
const gnChar*: gnSetStringToConstCharPtr, \
|
||||
gnString: gnSetStringToString \
|
||||
)(string, value)
|
@@ -1,42 +0,0 @@
|
||||
typedef struct gnClearValue {
|
||||
union {
|
||||
struct {
|
||||
float r, g, b, a;
|
||||
};
|
||||
|
||||
struct {
|
||||
float red, green, blue, alpha;
|
||||
};
|
||||
};
|
||||
} gnClearValue;
|
||||
|
||||
#pragma once
|
||||
typedef struct gnColor {
|
||||
union {
|
||||
struct {
|
||||
int r, g, b;
|
||||
float a;
|
||||
};
|
||||
|
||||
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;
|
@@ -1,7 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
enum gnColorMode {
|
||||
GN_RED, GN_RGB8, GN_RGBA8, GN_BGRA8,
|
||||
GN_DEPTH8_STENCIL24,
|
||||
GN_DEPTH_STENCIL = GN_DEPTH8_STENCIL24
|
||||
};
|
@@ -1,18 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
typedef enum gnImageFormat_e {
|
||||
GN_FORMAT_NONE,
|
||||
GN_FORMAT_BGRA8_SRGB
|
||||
} gnImageFormat;
|
||||
|
||||
typedef enum gnColorSpace_e {
|
||||
GN_COLOR_SPACE_SRGB_NONLINEAR
|
||||
} gnColorSpace;
|
||||
|
||||
typedef enum gnImageSharingMode_e {
|
||||
GN_SHARING_MODE_EXCLUSIVE, GN_SHARING_MODE_CONCURRENT
|
||||
} gnImageSharingMode;
|
||||
|
||||
typedef enum gnImageLayout_e {
|
||||
GN_LAYOUT_UNDEFINED, GN_LAYOUT_PRESENTATION_QUEUE_IMAGE, GN_LAYOUT_TRANSFER_DESTINATION, GN_COLOR_ATTACHMENT
|
||||
} gnImageLayout;
|
@@ -1,6 +0,0 @@
|
||||
#pragma once
|
||||
#include "stdint.h"
|
||||
|
||||
typedef uint32_t gnVersion; // uint32_t is the loser way to right this I can write it anyway I want
|
||||
|
||||
#define gnCreateVersion(major, minor, patch) ((((uint32_t)(major)) << 22U) | (((uint32_t)(minor)) << 12U) | ((uint32_t)(patch)))
|
Reference in New Issue
Block a user