commit 293fb5ec7b6beb6313f560309a2cd1cc07960f05
parent bcc7a806756427240bb9f33d7c89007d41b97bef
Author: amin <dev@aminmesbah.com>
Date: Fri, 1 Mar 2024 06:36:51 +0000
Make clangd work with unity build
FossilOrigin-Name: 5152cc6fb058ade833686fd2a6a7d6c74b49f861ef79be9506ab090318906f09
Diffstat:
11 files changed, 37 insertions(+), 18 deletions(-)
diff --git a/.clangd b/.clangd
@@ -0,0 +1,7 @@
+# Workaround for https://github.com/clangd/clangd/issues/1949
+
+If:
+ PathMatch: src/types\.h|src/webgl.h
+CompileFlags:
+ Add: [-include stdint.h]
+ Remove: [-include src/game.h]
diff --git a/compile_flags.txt b/compile_flags.txt
@@ -0,0 +1,3 @@
+--std=c11
+-ferror-limit=0
+-include src/game.h
diff --git a/src/am_gl.c b/src/am_gl.c
@@ -1,5 +1,3 @@
-#include "am_gl.h"
-
#if defined(PLATFORM_LINUX)
#include <dlfcn.h>
int am_gl_init()
diff --git a/src/game.h b/src/game.h
@@ -1,3 +1,6 @@
+#ifndef GAME_H
+#define GAME_H
+
#include <limits.h>
#include <stdalign.h>
#include <stdbool.h>
@@ -94,3 +97,5 @@ struct GameState
internal void game_init(struct GameMemory *game_memory, v2u framebuffer);
internal void game_cleanup(struct GameMemory *game_memory);
+
+#endif //GAME_H
diff --git a/src/memory.c b/src/memory.c
@@ -1,7 +1,3 @@
-#define mem_st_alloc_struct(allocator, type) mem_st_alloc((allocator), sizeof(type), alignof(type))
-#define mem_st_alloc_buffer(allocator, type, count) mem_st_alloc((allocator), sizeof(type) * (count), alignof(type))
-#define mem_move_buffer(d, s, t, c) mem_move((d), (s), sizeof(t) * (c))
-
// TODO: test that alignment is working properly
internal uintptr_t mem_align_address(uintptr_t address, size_t alignment)
{
diff --git a/src/memory.h b/src/memory.h
@@ -7,3 +7,15 @@ struct StackAllocator
#define KIBIBYTES(n) (n) * 1024LL
#define MEBIBYTES(n) KIBIBYTES((n) * 1024LL)
+
+#define mem_st_alloc_struct(allocator, type) mem_st_alloc((allocator), sizeof(type), alignof(type))
+#define mem_st_alloc_buffer(allocator, type, count) mem_st_alloc((allocator), sizeof(type) * (count), alignof(type))
+#define mem_move_buffer(d, s, t, c) mem_move((d), (s), sizeof(t) * (c))
+
+internal uintptr_t mem_align_address(uintptr_t address, size_t alignment);
+internal void mem_st_init(struct StackAllocator *allocator, void *backing_buffer, size_t backing_buffer_bytes);
+internal void *mem_st_alloc(struct StackAllocator *allocator, size_t bytes, size_t alignment);
+internal size_t mem_st_get_marker(struct StackAllocator *allocator);
+internal void mem_st_free_to_marker(struct StackAllocator *allocator, size_t marker);
+internal void mem_st_free_all(struct StackAllocator *allocator);
+internal void mem_move(void *dest, void *source, size_t num_bytes);
diff --git a/src/platform_linux.c b/src/platform_linux.c
@@ -11,6 +11,9 @@
#include "platform.h"
#include "platform_linux.h"
+internal void framebuffer_size_callback(GLFWwindow* window, int width, int height);
+internal void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods);
+
// TODO: map this in a nicer way
global_variable int platform_input_map[NUM_GAME_BUTTONS] = {
[BTN_LEFT] = GLFW_KEY_LEFT,
diff --git a/src/platform_linux.h b/src/platform_linux.h
@@ -2,8 +2,6 @@
#define PLATFORM_SCR_HEIGHT 238u
internal void error_callback(int error, const char* description);
-internal void framebuffer_size_callback(GLFWwindow* window, int width, int height);
-internal void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods);
internal PLATFORM_READ_ENTIRE_FILE(linux_read_entire_file);
PLATFORM_MEMORY_FREE(linux_memory_free);
diff --git a/src/platform_windows.c b/src/platform_windows.c
@@ -16,6 +16,9 @@
#include "platform.h"
#include "platform_windows.h"
+internal void framebuffer_size_callback(GLFWwindow* window, int width, int height);
+internal void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods);
+
// TODO: map this in a nicer way
global_variable int platform_input_map[NUM_GAME_BUTTONS] = {
[BTN_LEFT] = GLFW_KEY_LEFT,
diff --git a/src/platform_windows.h b/src/platform_windows.h
@@ -2,7 +2,5 @@
#define PLATFORM_SCR_HEIGHT 238u
internal void error_callback(int error, const char* description);
-internal void framebuffer_size_callback(GLFWwindow* window, int width, int height);
-internal void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods);
internal PLATFORM_READ_ENTIRE_FILE(windows_read_entire_file);
PLATFORM_MEMORY_FREE(windows_memory_free);
diff --git a/src/webgl.h b/src/webgl.h
@@ -1,4 +1,5 @@
-#pragma once
+#ifndef WEBGL_H
+#define WEBGL_H
typedef int i32;
typedef float f32;
@@ -183,7 +184,6 @@ static GLuint glCreateShader(GLenum type)
static void glDeleteBuffers(GLsizei n, const GLuint *buffers)
{
- assert(n == 1);
i32 the_buffer = WEBGL_CAST_I32(buffers[0]);
webglDeleteBuffer(the_buffer);
}
@@ -195,7 +195,6 @@ static void glDeleteShader(GLuint shader)
static void glDeleteVertexArrays(GLsizei n, const GLuint *arrays)
{
- assert(n == 1);
i32 the_array = WEBGL_CAST_I32(arrays[0]);
webglDeleteVertexArray(the_array);
}
@@ -227,9 +226,7 @@ static void glEnableVertexAttribArray(GLuint index)
static void glGenBuffers(GLsizei n, GLuint *buffers)
{
- assert(n == 1);
i32 buffer_id = webglCreateBuffer();
- assert(buffer_id >= 0);
*buffers = (GLuint)buffer_id;
}
@@ -240,16 +237,13 @@ static void glGenerateMipmap(GLenum target)
static void glGenTextures(GLsizei n, GLuint *textures)
{
- assert(n == 1);
i32 texture_id = webglCreateTexture();
*textures = (GLuint)texture_id;
}
static void glGenVertexArrays(GLsizei n, GLuint *arrays)
{
- assert(n == 1);
i32 vao_id = webglCreateVertexArray();
- assert(vao_id >= 0);
*arrays = (GLuint)vao_id;
}
@@ -382,3 +376,5 @@ static void glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
}
#undef WEBGL_CAST_I32
+
+#endif //WEBGL_H