Add a build system

This commit is contained in:
2026-04-29 22:28:21 +01:00
parent 5cb47a17a2
commit fb83c3114f
22 changed files with 761 additions and 93 deletions

48
base.h
View File

@@ -104,7 +104,9 @@ typedef double f64;
#define ASSERT(x) assert(x)
#endif
#define NDEBUG // Comment to enable asserts
#ifndef NDEBUG
#define NDEBUG 1 // 0 to enable asserts
#endif
/* ------------------------------------------------------------
Some helper functions
@@ -130,9 +132,9 @@ static b32 plat_mem_commit(void *ptr, u64 size) {
return ret != NULL;
}
static b32 plat_mem_decommit(void *ptr, u64 size) {
return VirtualFree(ptr, size, MEM_DECOMMIT);
}
// static b32 plat_mem_decommit(void *ptr, u64 size) { // Comment to prevent warning: unused function
// return VirtualFree(ptr, size, MEM_DECOMMIT);
// }
static b32 plat_mem_release(void *ptr, u64 size) {
return VirtualFree(ptr, size, MEM_RELEASE);
@@ -152,21 +154,21 @@ static void plat_sem_wait(plat_sem *s) {
WaitForSingleObject(s->handle, INFINITE);
}
static b32 plat_sem_trywait(HANDLE sem) {
DWORD r = WaitForSingleObject(sem, 0);
return r == WAIT_OBJECT_0;
}
// static b32 plat_sem_trywait(HANDLE sem) { // Comment to prevent warning: unused function
// DWORD r = WaitForSingleObject(sem, 0);
// return r == WAIT_OBJECT_0;
// }
static void plat_sem_post(plat_sem *s, u32 count) {
ReleaseSemaphore(s->handle, count, NULL);
}
static void plat_sem_destroy(plat_sem *s) {
if (s->handle) {
CloseHandle(s->handle);
s->handle = NULL;
}
}
// static void plat_sem_destroy(plat_sem *s) { // Comment to prevent warning: unused function
// if (s->handle) {
// CloseHandle(s->handle);
// s->handle = NULL;
// }
// }
// Sleep
static void sleep_ms(int ms) { Sleep(ms); }
@@ -197,13 +199,13 @@ static b32 plat_mem_commit(void *ptr, u64 size) {
return ret == 0;
}
static b32 plat_mem_decommit(void *ptr, u64 size) {
i32 ret = mprotect(ptr, size, PROT_NONE);
if (ret != 0)
return false;
ret = madvise(ptr, size, MADV_DONTNEED);
return ret == 0;
}
// static b32 plat_mem_decommit(void *ptr, u64 size) { // Comment to prevent warning: unused function
// i32 ret = mprotect(ptr, size, PROT_NONE);
// if (ret != 0)
// return false;
// ret = madvise(ptr, size, MADV_DONTNEED);
// return ret == 0;
// }
static b32 plat_mem_release(void *ptr, u64 size) {
i32 ret = munmap(ptr, size);
@@ -226,7 +228,7 @@ static void plat_sem_wait(plat_sem *s) {
}
}
static b32 plat_sem_trywait(sem_t *sem) { return sem_trywait(sem) == 0; }
// static b32 plat_sem_trywait(sem_t *sem) { return sem_trywait(sem) == 0; } // Comment to prevent warning: unused function
static void plat_sem_post(plat_sem *s, u32 count) {
for (u32 i = 0; i < count; i++) {
@@ -234,7 +236,7 @@ static void plat_sem_post(plat_sem *s, u32 count) {
}
}
static void plat_sem_destroy(plat_sem *s) { sem_destroy(&s->sem); }
// static void plat_sem_destroy(plat_sem *s) { sem_destroy(&s->sem); } // Comment to prevent warning: unused function
// Sleep
static void sleep_ms(int ms) { usleep(ms * 1000); }