summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-10-18 00:23:30 +1100
committeromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-10-18 00:23:30 +1100
commit5234133f2d55dc7f24eaa63b86e3952decaaba91 (patch)
tree01b4732ff6b1686f62cedcab5afe48092094784d
parentdf81a840a5276c35df5f35d55610f1bf31487153 (diff)
chore: format
-rw-r--r--.clang-format2
-rw-r--r--Makefile11
-rw-r--r--examples/triangle.c11
-rw-r--r--src/core.c16
-rw-r--r--src/geometry.c87
-rw-r--r--src/log.c4
-rw-r--r--src/maths.c4
-rw-r--r--src/mem.c3
8 files changed, 67 insertions, 71 deletions
diff --git a/.clang-format b/.clang-format
index 059381e..404bcb1 100644
--- a/.clang-format
+++ b/.clang-format
@@ -1,7 +1,7 @@
---
Language: Cpp
BasedOnStyle: Google
-ColumnLimit: 100
+ColumnLimit: 120
Cpp11BracedListStyle: false # {.x = 1.0, .y = 2.0} -> { .x = 1.0, .y = 2.0 }
IncludeBlocks: Preserve # sort each block of include statements instead of all
DerivePointerAlignment: false
diff --git a/Makefile b/Makefile
index 46890cd..b4cf4d9 100644
--- a/Makefile
+++ b/Makefile
@@ -18,6 +18,9 @@ EXAMPLES_DIR := examples
SRCS := $(wildcard $(SRC_DIR)/*.c $(SRC_DIR)/**/*.c)
OBJS := $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SRCS))
+# Format-able files
+FORMAT_FILES := include/celeritas.h $(SRC_DIR)/*.c $(EXAMPLES_DIR)/*.c
+
# Shader files
METAL_SHADERS := $(wildcard $(SHADER_DIR)/*.metal)
METAL_AIR_FILES := $(patsubst $(SHADER_DIR)/%.metal,$(SHADER_OUT_DIR)/%.air,$(METAL_SHADERS))
@@ -85,6 +88,14 @@ cube: $(EXAMPLES_DIR)/cube.c $(SHARED_LIB) $(SHADER_OUT_DIR)/cube.air $(METAL_LI
$(CC) $(CFLAGS) $(EXAMPLES_DIR)/cube.c -L$(BUILD_DIR) -lceleritas $(LDFLAGS) -o $(BUILD_DIR)/cube.bin
MTL_DEBUG_LAYER=1 build/cube.bin
+.PHONY: format
+format:
+ clang-format -i $(FORMAT_FILES)
+
+.PHONY: tidy
+tidy:
+ clang-tidy $(SRCS) $(EXAMPLES_DIR)/*.c -- $(CFLAGS)
+
.PHONY: clean
clean:
rm -rf $(BUILD_DIR)
diff --git a/examples/triangle.c b/examples/triangle.c
index e5cf92d..7770fd1 100644
--- a/examples/triangle.c
+++ b/examples/triangle.c
@@ -16,13 +16,10 @@ typedef struct VertexData {
} VertexData;
VertexData squareVertices[] = {
- {{-0.5, -0.5, 0.5, 1.0f}, {0.0f, 0.0f}, 0.0, 0.0},
- {{-0.5, 0.5, 0.5, 1.0f}, {0.0f, 1.0f}, 0.0, 0.0},
- {{ 0.5, 0.5, 0.5, 1.0f}, {1.0f, 1.0f}, 0.0, 0.0},
- {{-0.5, -0.5, 0.5, 1.0f}, {0.0f, 0.0f}, 0.0, 0.0},
- {{ 0.5, 0.5, 0.5, 1.0f}, {1.0f, 1.0f}, 0.0, 0.0},
- {{ 0.5, -0.5, 0.5, 1.0f}, {1.0f, 0.0f}, 0.0, 0.0}
- };
+ { { -0.5, -0.5, 0.5, 1.0f }, { 0.0f, 0.0f }, 0.0, 0.0 }, { { -0.5, 0.5, 0.5, 1.0f }, { 0.0f, 1.0f }, 0.0, 0.0 },
+ { { 0.5, 0.5, 0.5, 1.0f }, { 1.0f, 1.0f }, 0.0, 0.0 }, { { -0.5, -0.5, 0.5, 1.0f }, { 0.0f, 0.0f }, 0.0, 0.0 },
+ { { 0.5, 0.5, 0.5, 1.0f }, { 1.0f, 1.0f }, 0.0, 0.0 }, { { 0.5, -0.5, 0.5, 1.0f }, { 1.0f, 0.0f }, 0.0, 0.0 }
+};
pipeline_handle draw_pipeline;
buf_handle tri_vert_buffer;
diff --git a/src/core.c b/src/core.c
index 9359a6b..0cbaa09 100644
--- a/src/core.c
+++ b/src/core.c
@@ -6,7 +6,7 @@
NAMESPACED_LOGGER(core);
-core g_core = {0};
+core g_core = { 0 };
#ifdef GPU_METAL
static const char* gapi = "Metal";
@@ -43,16 +43,12 @@ void core_shutdown() {
glfwTerminate();
}
-bool app_should_exit() {
- return glfwWindowShouldClose(g_core.window) || g_core.should_exit;
-}
+bool app_should_exit() { return glfwWindowShouldClose(g_core.window) || g_core.should_exit; }
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) {
- if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) {
- g_core.should_exit = true;
- }
+ if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) {
+ g_core.should_exit = true;
+ }
}
-void resize_callback(GLFWwindow* window, int width, int height) {
- ral_backend_resize_framebuffer(width, height);
-} \ No newline at end of file
+void resize_callback(GLFWwindow* window, int width, int height) { ral_backend_resize_framebuffer(width, height); } \ No newline at end of file
diff --git a/src/geometry.c b/src/geometry.c
index d9b0aee..05414d3 100644
--- a/src/geometry.c
+++ b/src/geometry.c
@@ -10,11 +10,11 @@ typedef struct static_3d_vert {
vertex_desc static_3d_vertex_format() {
vertex_desc desc;
desc.label = "Static 3D Vertex";
- desc.attributes[0] = ATTR_F32x4; // position
- desc.attributes[1] = ATTR_F32x4; // normal
- desc.attributes[2] = ATTR_F32x2; // tex coord
+ desc.attributes[0] = ATTR_F32x4; // position
+ desc.attributes[1] = ATTR_F32x4; // normal
+ desc.attributes[2] = ATTR_F32x2; // tex coord
desc.attribute_count = 3;
- desc.padding = 16; // 16 bytes padding
+ desc.padding = 16; // 16 bytes padding
return desc;
}
@@ -32,57 +32,54 @@ geometry geo_cuboid(f32 x_scale, f32 y_scale, f32 z_scale) {
// allocate the data
static_3d_vert* vertices = malloc(36 * 64);
- vertices[0] = (static_3d_vert){ .pos = BACK_TOP_RIGHT, .norm = (v3tov4(VEC3_NEG_Z)), .uv = {0, 0}};
- vertices[1] = (static_3d_vert){ .pos = BACK_BOT_LEFT, .norm = v3tov4(VEC3_NEG_Z), .uv = {0, 1} };
- vertices[2] = (static_3d_vert){ .pos = BACK_TOP_LEFT, .norm = v3tov4(VEC3_NEG_Z), .uv = {0, 0} };
- vertices[3] = (static_3d_vert){ .pos = BACK_TOP_RIGHT, .norm = v3tov4(VEC3_NEG_Z), .uv = {1, 0} };
- vertices[4] = (static_3d_vert){ .pos = BACK_BOT_RIGHT, .norm = v3tov4(VEC3_NEG_Z), .uv = {1, 1} };
- vertices[5] = (static_3d_vert){ .pos = BACK_BOT_LEFT, .norm = v3tov4(VEC3_NEG_Z), .uv = {0, 1} };
+ vertices[0] = (static_3d_vert){ .pos = BACK_TOP_RIGHT, .norm = (v3tov4(VEC3_NEG_Z)), .uv = { 0, 0 } };
+ vertices[1] = (static_3d_vert){ .pos = BACK_BOT_LEFT, .norm = v3tov4(VEC3_NEG_Z), .uv = { 0, 1 } };
+ vertices[2] = (static_3d_vert){ .pos = BACK_TOP_LEFT, .norm = v3tov4(VEC3_NEG_Z), .uv = { 0, 0 } };
+ vertices[3] = (static_3d_vert){ .pos = BACK_TOP_RIGHT, .norm = v3tov4(VEC3_NEG_Z), .uv = { 1, 0 } };
+ vertices[4] = (static_3d_vert){ .pos = BACK_BOT_RIGHT, .norm = v3tov4(VEC3_NEG_Z), .uv = { 1, 1 } };
+ vertices[5] = (static_3d_vert){ .pos = BACK_BOT_LEFT, .norm = v3tov4(VEC3_NEG_Z), .uv = { 0, 1 } };
// front faces
- vertices[6] = (static_3d_vert){ .pos = FRONT_BOT_LEFT, .norm = v3tov4(VEC3_Z), .uv = {0, 1} };
- vertices[7] = (static_3d_vert){ .pos = FRONT_TOP_RIGHT, .norm = v3tov4(VEC3_Z), .uv = {1, 0} };
- vertices[8] = (static_3d_vert){ .pos = FRONT_TOP_LEFT, .norm = v3tov4(VEC3_Z), .uv = {0, 0} };
- vertices[9] = (static_3d_vert){ .pos = FRONT_BOT_LEFT, .norm = v3tov4(VEC3_Z), .uv = {0, 1} };
- vertices[10] = (static_3d_vert){ .pos = FRONT_BOT_RIGHT, .norm = v3tov4(VEC3_Z), .uv = {1, 1} };
- vertices[11] = (static_3d_vert){ .pos = FRONT_TOP_RIGHT, .norm = v3tov4(VEC3_Z), .uv = {1, 0} };
+ vertices[6] = (static_3d_vert){ .pos = FRONT_BOT_LEFT, .norm = v3tov4(VEC3_Z), .uv = { 0, 1 } };
+ vertices[7] = (static_3d_vert){ .pos = FRONT_TOP_RIGHT, .norm = v3tov4(VEC3_Z), .uv = { 1, 0 } };
+ vertices[8] = (static_3d_vert){ .pos = FRONT_TOP_LEFT, .norm = v3tov4(VEC3_Z), .uv = { 0, 0 } };
+ vertices[9] = (static_3d_vert){ .pos = FRONT_BOT_LEFT, .norm = v3tov4(VEC3_Z), .uv = { 0, 1 } };
+ vertices[10] = (static_3d_vert){ .pos = FRONT_BOT_RIGHT, .norm = v3tov4(VEC3_Z), .uv = { 1, 1 } };
+ vertices[11] = (static_3d_vert){ .pos = FRONT_TOP_RIGHT, .norm = v3tov4(VEC3_Z), .uv = { 1, 0 } };
// top faces
- vertices[12] = (static_3d_vert){ .pos = BACK_TOP_LEFT, .norm = v3tov4(VEC3_Y), .uv = {0, 0} };
- vertices[13] = (static_3d_vert){ .pos = FRONT_TOP_LEFT, .norm = v3tov4(VEC3_Y), .uv = {0, 1} };
- vertices[14] = (static_3d_vert){ .pos = FRONT_TOP_RIGHT, .norm = v3tov4(VEC3_Y), .uv = {1, 1} };
- vertices[15] = (static_3d_vert){ .pos = BACK_TOP_LEFT, .norm = v3tov4(VEC3_Y), .uv = {0, 0} };
- vertices[16] = (static_3d_vert){ .pos = FRONT_TOP_RIGHT, .norm = v3tov4(VEC3_Y), .uv = {1, 1} };
- vertices[17] = (static_3d_vert){ .pos = BACK_TOP_RIGHT, .norm = v3tov4(VEC3_Y), .uv = {1, 0} };
+ vertices[12] = (static_3d_vert){ .pos = BACK_TOP_LEFT, .norm = v3tov4(VEC3_Y), .uv = { 0, 0 } };
+ vertices[13] = (static_3d_vert){ .pos = FRONT_TOP_LEFT, .norm = v3tov4(VEC3_Y), .uv = { 0, 1 } };
+ vertices[14] = (static_3d_vert){ .pos = FRONT_TOP_RIGHT, .norm = v3tov4(VEC3_Y), .uv = { 1, 1 } };
+ vertices[15] = (static_3d_vert){ .pos = BACK_TOP_LEFT, .norm = v3tov4(VEC3_Y), .uv = { 0, 0 } };
+ vertices[16] = (static_3d_vert){ .pos = FRONT_TOP_RIGHT, .norm = v3tov4(VEC3_Y), .uv = { 1, 1 } };
+ vertices[17] = (static_3d_vert){ .pos = BACK_TOP_RIGHT, .norm = v3tov4(VEC3_Y), .uv = { 1, 0 } };
// bottom faces
- vertices[18] = (static_3d_vert){ .pos = BACK_BOT_LEFT, .norm = v3tov4(VEC3_NEG_Y), .uv = {0, 1} };
- vertices[19] = (static_3d_vert){ .pos = FRONT_BOT_RIGHT, .norm = v3tov4(VEC3_NEG_Y), .uv = {1, 1} };
- vertices[20] = (static_3d_vert){ .pos = FRONT_BOT_LEFT, .norm = v3tov4(VEC3_NEG_Y), .uv = {0, 1} };
- vertices[21] = (static_3d_vert){ .pos = BACK_BOT_LEFT, .norm = v3tov4(VEC3_NEG_Y), .uv = {0, 1} };
- vertices[22] = (static_3d_vert){ .pos = BACK_BOT_RIGHT, .norm = v3tov4(VEC3_NEG_Y), .uv = {1, 1} };
- vertices[23] = (static_3d_vert){ .pos = FRONT_BOT_RIGHT, .norm = v3tov4(VEC3_NEG_Y), .uv = {0, 1} };
+ vertices[18] = (static_3d_vert){ .pos = BACK_BOT_LEFT, .norm = v3tov4(VEC3_NEG_Y), .uv = { 0, 1 } };
+ vertices[19] = (static_3d_vert){ .pos = FRONT_BOT_RIGHT, .norm = v3tov4(VEC3_NEG_Y), .uv = { 1, 1 } };
+ vertices[20] = (static_3d_vert){ .pos = FRONT_BOT_LEFT, .norm = v3tov4(VEC3_NEG_Y), .uv = { 0, 1 } };
+ vertices[21] = (static_3d_vert){ .pos = BACK_BOT_LEFT, .norm = v3tov4(VEC3_NEG_Y), .uv = { 0, 1 } };
+ vertices[22] = (static_3d_vert){ .pos = BACK_BOT_RIGHT, .norm = v3tov4(VEC3_NEG_Y), .uv = { 1, 1 } };
+ vertices[23] = (static_3d_vert){ .pos = FRONT_BOT_RIGHT, .norm = v3tov4(VEC3_NEG_Y), .uv = { 0, 1 } };
// right faces
- vertices[24] = (static_3d_vert){ .pos = FRONT_TOP_RIGHT, .norm = v3tov4(VEC3_X), .uv = {0, 0} };
- vertices[25] = (static_3d_vert){ .pos = BACK_BOT_RIGHT, .norm = v3tov4(VEC3_X), .uv = {1, 1} };
- vertices[26] = (static_3d_vert){ .pos = BACK_TOP_RIGHT, .norm = v3tov4(VEC3_X), .uv = {1, 0} };
- vertices[27] = (static_3d_vert){ .pos = BACK_BOT_RIGHT, .norm = v3tov4(VEC3_X), .uv = {1, 1} };
- vertices[28] = (static_3d_vert){ .pos = FRONT_TOP_RIGHT, .norm = v3tov4(VEC3_X), .uv = {0, 0} };
- vertices[29] = (static_3d_vert){ .pos = FRONT_BOT_RIGHT, .norm = v3tov4(VEC3_X), .uv = {0, 1} };
+ vertices[24] = (static_3d_vert){ .pos = FRONT_TOP_RIGHT, .norm = v3tov4(VEC3_X), .uv = { 0, 0 } };
+ vertices[25] = (static_3d_vert){ .pos = BACK_BOT_RIGHT, .norm = v3tov4(VEC3_X), .uv = { 1, 1 } };
+ vertices[26] = (static_3d_vert){ .pos = BACK_TOP_RIGHT, .norm = v3tov4(VEC3_X), .uv = { 1, 0 } };
+ vertices[27] = (static_3d_vert){ .pos = BACK_BOT_RIGHT, .norm = v3tov4(VEC3_X), .uv = { 1, 1 } };
+ vertices[28] = (static_3d_vert){ .pos = FRONT_TOP_RIGHT, .norm = v3tov4(VEC3_X), .uv = { 0, 0 } };
+ vertices[29] = (static_3d_vert){ .pos = FRONT_BOT_RIGHT, .norm = v3tov4(VEC3_X), .uv = { 0, 1 } };
// left faces
- vertices[30] = (static_3d_vert){ .pos = FRONT_TOP_LEFT, .norm = v3tov4(VEC3_NEG_X), .uv = {0, 0} };
- vertices[31] = (static_3d_vert){ .pos = BACK_TOP_LEFT, .norm = v3tov4(VEC3_NEG_X), .uv = {0, 0} };
- vertices[32] = (static_3d_vert){ .pos = BACK_BOT_LEFT, .norm = v3tov4(VEC3_NEG_X), .uv = {0, 0} };
- vertices[33] = (static_3d_vert){ .pos = BACK_BOT_LEFT, .norm = v3tov4(VEC3_NEG_X), .uv = {0, 0} };
- vertices[34] = (static_3d_vert){ .pos = FRONT_BOT_LEFT, .norm = v3tov4(VEC3_NEG_X), .uv = {0, 0} };
- vertices[35] = (static_3d_vert){ .pos = FRONT_TOP_LEFT, .norm = v3tov4(VEC3_NEG_X), .uv = {0, 0} };
+ vertices[30] = (static_3d_vert){ .pos = FRONT_TOP_LEFT, .norm = v3tov4(VEC3_NEG_X), .uv = { 0, 0 } };
+ vertices[31] = (static_3d_vert){ .pos = BACK_TOP_LEFT, .norm = v3tov4(VEC3_NEG_X), .uv = { 0, 0 } };
+ vertices[32] = (static_3d_vert){ .pos = BACK_BOT_LEFT, .norm = v3tov4(VEC3_NEG_X), .uv = { 0, 0 } };
+ vertices[33] = (static_3d_vert){ .pos = BACK_BOT_LEFT, .norm = v3tov4(VEC3_NEG_X), .uv = { 0, 0 } };
+ vertices[34] = (static_3d_vert){ .pos = FRONT_BOT_LEFT, .norm = v3tov4(VEC3_NEG_X), .uv = { 0, 0 } };
+ vertices[35] = (static_3d_vert){ .pos = FRONT_TOP_LEFT, .norm = v3tov4(VEC3_NEG_X), .uv = { 0, 0 } };
- return (geometry) {
- .vertex_format = static_3d_vertex_format(),
- .vertex_data = vertices,
- .has_indices = false,
- .indices = NULL
+ return (geometry){
+ .vertex_format = static_3d_vertex_format(), .vertex_data = vertices, .has_indices = false, .indices = NULL
};
} \ No newline at end of file
diff --git a/src/log.c b/src/log.c
index 1083f29..66ffe2d 100644
--- a/src/log.c
+++ b/src/log.c
@@ -1,8 +1,6 @@
#include <celeritas.h>
-static const char* log_level_strings[] = {
- "FATAL", "ERROR", "WARN", "INFO", "DEBUG", "TRACE"
-};
+static const char* log_level_strings[] = { "FATAL", "ERROR", "WARN", "INFO", "DEBUG", "TRACE" };
void log_output(char* module, loglevel level, const char* message, ...) {
char out_msg[4096];
diff --git a/src/maths.c b/src/maths.c
index 40223c6..fbfcd72 100644
--- a/src/maths.c
+++ b/src/maths.c
@@ -4,9 +4,7 @@ vec3 vec3_create(f32 x, f32 y, f32 z) { return (vec3){ x, y, z }; }
vec4 vec4_create(f32 x, f32 y, f32 z, f32 w) { return (vec4){ x, y, z, w }; }
-mat4 mat4_ident() {
- return (mat4){ .data = { 1.0, 0., 0., 0., 0., 1., 0., 0., 0., 0., 1., 0., 0., 0., 0., 1.0 } };
-}
+mat4 mat4_ident() { return (mat4){ .data = { 1.0, 0., 0., 0., 0., 1., 0., 0., 0., 0., 1., 0., 0., 0., 0., 1.0 } }; }
mat4 mat4_mult(mat4 lhs, mat4 rhs) {
mat4 out_matrix = mat4_ident();
diff --git a/src/mem.c b/src/mem.c
index ba122d7..dd8acda 100644
--- a/src/mem.c
+++ b/src/mem.c
@@ -22,8 +22,7 @@ void void_pool_free_all(void_pool* pool) {
// set all entries to be free
for (u64 i = 0; i < pool->capacity; i++) {
void* ptr = &pool->backing_buffer[i * pool->entry_size];
- void_pool_header* free_node =
- (void_pool_header*)ptr; // we reuse the actual entry itself to hold the header
+ void_pool_header* free_node = (void_pool_header*)ptr; // we reuse the actual entry itself to hold the header
if (i == (pool->capacity - 1)) {
// if the last one we make its next pointer NULL indicating its full
free_node->next = NULL;