aboutsummaryrefslogtreecommitdiff
path: root/teensy/context.c
diff options
context:
space:
mode:
authoriamcheeseman <[email protected]>2026-05-08 19:30:44 -0400
committeriamcheeseman <[email protected]>2026-05-08 19:30:44 -0400
commit5625a8626fe303748b205c80f87035593cf2f561 (patch)
tree5e5a5adb6f1265358ae21ec47cd384362345df5a /teensy/context.c
Initial commit
Diffstat (limited to 'teensy/context.c')
-rw-r--r--teensy/context.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/teensy/context.c b/teensy/context.c
new file mode 100644
index 0000000..7095fe3
--- /dev/null
+++ b/teensy/context.c
@@ -0,0 +1,51 @@
+#include "context.h"
+#include "renderer.h"
+
+#include <math.h>
+
+#include "platform.h"
+
+struct ty_ctx ctx;
+extern struct ty_renderer r;
+
+void ty_init(struct ty_creation_hints creation_hints)
+{
+ ty_init_mem();
+
+ ctx.creation_hints = creation_hints;
+ ctx.ticrate = 1.0 / creation_hints.ticrate;
+ ctx.prev_tic_ts = 0;
+
+ ty_platform_init(&ctx);
+ ty_init_renderer();
+}
+
+void ty_deinit(void)
+{
+ ty_platform_deinit();
+ ty_deinit_renderer();
+ ty_deinit_mem();
+}
+
+bool ty_is_game_running(void)
+{
+ return !ty_platform_os_wants_quit();
+}
+
+double ty_get_time(void)
+{
+ return ty_platform_get_time();
+}
+
+int ty_tick(void)
+{
+ double current_time = ty_get_time();
+ double time_since_tic = current_time - ctx.prev_tic_ts;
+
+ int tics = time_since_tic / ctx.ticrate;
+ if (tics > 0) {
+ ctx.prev_tic_ts = current_time;
+ ty_platform_frame(r.screen);
+ }
+ return tics;
+}