From b03bde3d412148cd573f5f14012cdd270f309947 Mon Sep 17 00:00:00 2001
From: omniscient <17525998+omnisci3nce@users.noreply.github.com>
Date: Sun, 11 Aug 2024 23:00:26 +1000
Subject: starting work on immediate mode drawing

---
 src/platform/mutex.c            |  9 ---------
 src/platform/mutex.h            | 28 ----------------------------
 src/platform/path.c             | 35 -----------------------------------
 src/platform/path.h             | 16 ----------------
 src/platform/platform.h         | 37 +++++++++++++++++++++++++++++++++++++
 src/platform/platform_unix.c    | 16 ++++++++++++++++
 src/platform/platform_windows.c | 22 ++++++++++++++++++++++
 src/platform/thread.c           |  0
 src/platform/thread.h           | 17 -----------------
 9 files changed, 75 insertions(+), 105 deletions(-)
 delete mode 100644 src/platform/mutex.c
 delete mode 100644 src/platform/mutex.h
 delete mode 100644 src/platform/path.c
 delete mode 100644 src/platform/path.h
 create mode 100644 src/platform/platform.h
 create mode 100644 src/platform/platform_unix.c
 create mode 100644 src/platform/platform_windows.c
 delete mode 100644 src/platform/thread.c
 delete mode 100644 src/platform/thread.h

(limited to 'src/platform')

diff --git a/src/platform/mutex.c b/src/platform/mutex.c
deleted file mode 100644
index 2aeb825..0000000
--- a/src/platform/mutex.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include "mutex.h"
-
-#if defined(CEL_PLATFORM_LINUX) || defined(CEL_PLATFORM_MAC)
-// TODO: implement in terms of pthreads
-#endif
-
-#if defined(CEL_PLATFORM_WINDOWS)
-// TODO: implement using win32 api
-#endif
\ No newline at end of file
diff --git a/src/platform/mutex.h b/src/platform/mutex.h
deleted file mode 100644
index a0a4208..0000000
--- a/src/platform/mutex.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/**
- * @file mutex.h
- * @author your name (you@domain.com)
- * @brief
- * @version 0.1
- * @date 2024-04-27
- *
- * @copyright Copyright (c) 2024
- *
- */
-#include <stdbool.h>
-
-typedef struct cel_mutex cel_mutex;
-
-cel_mutex mutex_create();
-
-void mutex_destroy(cel_mutex* mutex);
-
-/** @brief Blocks until the mutex can be acquired. if returns false then an error occurred and can
- * be checked (TODO) */
-bool mutex_lock(cel_mutex* mutex);
-
-/** @brief Tries to acquire the mutex like `mutex_lock` but returns immediately if the mutex has
- * already been locked */
-bool mutex_try_lock(cel_mutex* mutex);
-
-/** @brief Releases a mutex. If it is already unlocked then does nothing */
-void mutex_unlock(cel_mutex* mutex);
\ No newline at end of file
diff --git a/src/platform/path.c b/src/platform/path.c
deleted file mode 100644
index f43d954..0000000
--- a/src/platform/path.c
+++ /dev/null
@@ -1,35 +0,0 @@
-#include "path.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include "mem.h"
-#include "str.h"
-
-#if defined(CEL_PLATFORM_LINUX) || defined(CEL_PLATFORM_MAC)
-#include <libgen.h>
-path_opt path_parent(arena* a, const char* path) {
-  // Duplicate the string because dirname doesnt like const literals
-  char* path_copy = arena_alloc(a, strlen(path) + 1);
-  strcpy(path_copy, path);
-  char* path_dirname = dirname(path_copy);
-  return (path_opt){ .path = Str8_cstr_view(path_dirname), .has_value = true };
-}
-#endif
-#ifdef CEL_PLATFORM_WINDOWS
-#include <shlwapi.h>
-#include <windows.h>
-#pragma comment(lib, "Shlwapi.lib")
-
-path_opt path_parent(arena* a, const char* path) {
-  // Duplicate the string because PathRemoveFileSpec mutates in-place
-  size_t len = strlen(path) + 1;
-  char* path_copy = arena_alloc(a, len);
-  strcpy_s(path_copy, len, path);
-
-  if (PathRemoveFileSpecA(path_copy)) {
-    return (path_opt){ .path = Str8_cstr_view(path_copy), .has_value = true };
-  } else {
-    return (path_opt){ .has_value = false };
-  }
-}
-#endif
diff --git a/src/platform/path.h b/src/platform/path.h
deleted file mode 100644
index ce53339..0000000
--- a/src/platform/path.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/**
- * @file path.h
- * @brief
- * @date 2024-03-11
- * @copyright Copyright (c) 2024
- */
-#pragma once
-
-#include "str.h"
-
-typedef struct path_opt {
-  Str8 path;
-  bool has_value;
-} path_opt;
-
-path_opt path_parent(arena* a, const char* path);  // TODO: convert to using str8
diff --git a/src/platform/platform.h b/src/platform/platform.h
new file mode 100644
index 0000000..c2be630
--- /dev/null
+++ b/src/platform/platform.h
@@ -0,0 +1,37 @@
+#pragma once
+
+#include "defines.h"
+#include "str.h"
+
+// -- Paths
+typedef struct path_opt {
+  Str8 path;
+  bool has_value;
+} path_opt;
+
+// TODO: convert to using str8
+// TODO: use uppercase code style
+path_opt path_parent(arena* a, const char* path);
+
+// --- Threads
+typedef struct CelThread CelThread;
+
+CelThread Thread_Create();
+void Thread_Destroy(CelThread* thread);
+
+// --- Mutexes
+typedef struct CelMutex CelMutex;
+
+CelMutex Mutex_Create();
+void Mutex_Destroy(CelMutex* mutex);
+
+/** @brief Blocks until the mutex can be acquired. if returns false then an error occurred and can
+ * be checked (TODO) */
+bool Mutex_Lock(CelMutex* mutex);
+
+/** @brief Tries to acquire the mutex like `mutex_lock` but returns immediately if the mutex has
+ * already been locked */
+bool Mutex_TryLock(CelMutex* mutex);
+
+/** @brief Releases a mutex. If it is already unlocked then does nothing */
+void Mutex_Unlock(CelMutex* mutex);
diff --git a/src/platform/platform_unix.c b/src/platform/platform_unix.c
new file mode 100644
index 0000000..86ac170
--- /dev/null
+++ b/src/platform/platform_unix.c
@@ -0,0 +1,16 @@
+#include "platform.h"
+
+#if defined(CEL_PLATFORM_LINUX) || defined(CEL_PLATFORM_MAC)
+
+#include <libgen.h>
+#include <string.h>
+
+path_opt path_parent(arena* a, const char* path) {
+  // Duplicate the string because dirname doesnt like const literals
+  char* path_copy = arena_alloc(a, strlen(path) + 1);
+  strcpy(path_copy, path);
+  char* path_dirname = dirname(path_copy);
+  return (path_opt){ .path = Str8_cstr_view(path_dirname), .has_value = true };
+}
+
+#endif
diff --git a/src/platform/platform_windows.c b/src/platform/platform_windows.c
new file mode 100644
index 0000000..21ef359
--- /dev/null
+++ b/src/platform/platform_windows.c
@@ -0,0 +1,22 @@
+#include "platform.h"
+
+#if defined(CEL_PLATFORM_WINDOWS)
+
+#include <shlwapi.h>
+#include <windows.h>
+#pragma comment(lib, "Shlwapi.lib")
+
+path_opt path_parent(arena* a, const char* path) {
+  // Duplicate the string because PathRemoveFileSpec mutates in-place
+  size_t len = strlen(path) + 1;
+  char* path_copy = arena_alloc(a, len);
+  strcpy_s(path_copy, len, path);
+
+  if (PathRemoveFileSpecA(path_copy)) {
+    return (path_opt){ .path = Str8_cstr_view(path_copy), .has_value = true };
+  } else {
+    return (path_opt){ .has_value = false };
+  }
+}
+
+#endif
diff --git a/src/platform/thread.c b/src/platform/thread.c
deleted file mode 100644
index e69de29..0000000
diff --git a/src/platform/thread.h b/src/platform/thread.h
deleted file mode 100644
index af07d3f..0000000
--- a/src/platform/thread.h
+++ /dev/null
@@ -1,17 +0,0 @@
-/**
- * @file thread.h
- * @author your name (you@domain.com)
- * @brief
- * @version 0.1
- * @date 2024-04-27
- *
- * @copyright Copyright (c) 2024
- *
- */
-
-typedef struct cel_thread cel_thread;
-
-cel_thread thread_create();
-void thread_destroy(cel_thread* thread);
-
-// join
\ No newline at end of file
-- 
cgit v1.2.3-70-g09d2