aboutsummaryrefslogtreecommitdiff
path: root/plat.h
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-09-23 21:11:29 +1000
committerquou <quou@disroot.org>2024-09-23 21:11:29 +1000
commit259237fae792e8f19d9b7920b2354f75bc1789e2 (patch)
treeaf079430f30f7df1b76efc4f96f520b0b6eee0af /plat.h
initial commit, basic platform and rendering code.
Diffstat (limited to 'plat.h')
-rw-r--r--plat.h76
1 files changed, 76 insertions, 0 deletions
diff --git a/plat.h b/plat.h
new file mode 100644
index 0000000..27d8d0a
--- /dev/null
+++ b/plat.h
@@ -0,0 +1,76 @@
+#ifndef plat_h
+#define plat_h
+
+#include "error.h"
+
+struct Heap;
+
+#ifdef assert
+#undef assert
+#endif
+
+#define assert(expr) \
+ imp_assert( \
+ expr, \
+ #expr, \
+ __FILE__, \
+ __LINE__ \
+ )
+
+int imp_assert(
+ int val,
+ const char* expr,
+ const char* file,
+ int line
+);
+
+void print(const char* fmt, ...);
+void print_err(const char* fmt, ...);
+void print_war(const char* fmt, ...);
+void pbreak(Error code);
+
+typedef struct {
+ int mpf;
+ int fps;
+ unsigned long pt, ct;
+ unsigned long now, next;
+} FPS;
+
+void init_fps(FPS* f, int mpf);
+void fps_begin(FPS* f);
+void fps_end(FPS* f);
+void fps_update(FPS* f);
+
+typedef enum {
+ btn_unknown,
+ btn_left,
+ btn_right,
+ btn_up,
+ btn_down,
+ btn_shoot,
+ btn_jump,
+ btn_start,
+ btn_count
+} Btn;
+
+typedef enum {
+ btn_state_pressed = 1 << 0,
+ btn_state_just_pressed = 1 << 1,
+ btn_state_just_released = 1 << 2
+} Key_State;
+
+typedef struct App {
+ int o, s;
+ int fps;
+ Error err;
+ unsigned* fb;
+ struct Heap* heap;
+ unsigned char btn_states[btn_count];
+} App;
+
+App* new_app(struct Heap* mem, const char* n);
+void deinit_app(App* a);
+void app_begin(App* a);
+void app_end(App* a);
+
+#endif