aboutsummaryrefslogtreecommitdiff
path: root/dc/dc.c
diff options
context:
space:
mode:
authoriamcheeseman <[email protected]>2026-05-26 15:35:13 -0400
committeriamcheeseman <[email protected]>2026-05-26 15:35:13 -0400
commited7dfaad432b6e3fe838b9a2b5fe225abea5365d (patch)
tree0af2e01a688d963ec6d2977802dbeb9156335845 /dc/dc.c
parent8122098e3854bf68ca63cc25e082ba51a27b8615 (diff)
tbh i did a lot
Diffstat (limited to 'dc/dc.c')
-rw-r--r--dc/dc.c204
1 files changed, 2 insertions, 202 deletions
diff --git a/dc/dc.c b/dc/dc.c
index e700415..c855845 100644
--- a/dc/dc.c
+++ b/dc/dc.c
@@ -1,207 +1,7 @@
-#include <stdio.h>
-
-#include <math.h>
#include <teensy.h>
-#include <teensy_ui.h>
-#include <time.h>
-
-#define QOI_IMPLEMENTATION
-#include "third/qoi.h"
-
-#define SCREEN_WIDTH 256
-#define SCREEN_HEIGHT 256
-
-#define TILE_SIZE 16
-
-ty_Image img;
-ty_Font font;
-tyui_Id winid1;
-tyui_Id winid2;
-
-double last_frame = 0;
-
-bool toggled = false;
-
-void tick(void)
-{
- ty_draw_clear(TY_COLOR_BLACK);
-
- ty_draw_image(
- img,
- ty_vec2i(
- SCREEN_WIDTH*0.5 + sin(ty_get_time()) * 50 - (img.width*0.5),
- SCREEN_HEIGHT*0.5 - (img.height*0.5)
- )
- );
-
- ty_draw_image_ex(
- img,
- ty_recti(
- 0, 0,
- img.width, img.height
- ),
- ty_recti(
- sin(-ty_get_time()) * 50, SCREEN_HEIGHT / 2,
- 32, 64
- )
- );
-
- ty_draw_image_rot(
- img,
- ty_vec2i(SCREEN_WIDTH/2, SCREEN_HEIGHT/2),
- ty_vec2i(-img.width/2, -img.height/2),
- ty_get_time() * TY_PI / 2
- );
-
- ty_draw_text(&font, ty_vec2i(5, SCREEN_HEIGHT - 5 - 8), "hello, world!");
-
- if (ty_button_pressed(TY_BTN_LEFT_UP)) {
- toggled = !toggled;
- }
-
- if (toggled) {
- ty_draw_image(img, ty_vec2i(200, 200));
- }
-
- double frame_time = ty_get_time() - last_frame;
- last_frame = ty_get_time();
-
- if (tyui_begin_window("Test Window", ty_recti(5, 5, 100, 120), &winid1)) {
- tyui_button("before");
-
- tyui_push_layout((float[]){0.5, -1, 0});
- tyui_push_layout((float[]){-1, 0});
- tyui_text_ex(TYUI_ALIGN_CENTER, "Buttons");
- tyui_button("test1");
- tyui_button("test2");
- tyui_button("test3");
- tyui_button("test4");
- tyui_button("test5");
- tyui_pop_layout();
-
- tyui_push_layout((float[]){-1, 0});
- tyui_text_ex(TYUI_ALIGN_CENTER, "Stats");
- tyui_text_ex(TYUI_ALIGN_RIGHT, "%.2g ms", frame_time * 1000);
- tyui_text_ex(TYUI_ALIGN_RIGHT, "%.2d fps", (int)(1.0 / frame_time));
- tyui_text_ex(TYUI_ALIGN_RIGHT, "%d alloc", ty_alloc_count());
- tyui_text_ex(TYUI_ALIGN_RIGHT, "%dM mem", ty_alloc_size() / 1000);
- tyui_pop_layout();
- tyui_pop_layout();
-
- tyui_button("after");
-
- tyui_end_window();
- }
-
- if (tyui_begin_window("2nd Window", ty_recti(110, 5, 100, 120), &winid2)) {
- static bool opened = false;
-
- if (tyui_button("sliders"))
- opened = !opened;
-
- if (opened) {
- static float value = 100;
- tyui_slider(0, 100, &value);
- tyui_slider_ex(0, 100, &value, true, TYUI_ALIGN_LEFT);
- tyui_slider_ex(0, 100, &value, true, TYUI_ALIGN_RIGHT);
- tyui_blank_slider(0, 100, &value);
-
- tyui_push_layout((float[]){50, -1, 0});
- tyui_slider(0, 100, &value);
- if (tyui_button("inc"))
- value++;
- tyui_slider(0, 100, &value);
- if (tyui_button("dec"))
- value--;
- tyui_pop_layout();
- }
-
- static char string[16];
- static tyui_Text_Input tinput;
- tinput.chars = string;
- tinput.max_len = 16;
- tyui_text_input(&tinput);
-
- tyui_end_window();
- }
-
- tyui_draw();
-
- ty_Vec2i mouse_pos = ty_mouse_pos();
- ty_draw_rect(ty_recti(mouse_pos.x, mouse_pos.y, 1, 1), TY_COLOR_RED);
-
- ty_draw_end();
-}
-
-ty_Image load_qoi_image(const char *path)
-{
- qoi_desc desc;
- void *data = qoi_read(path, &desc, 3);
- if (!data)
- ty_log_fatal(TY_ERR_IO, "failed to read image");
- ty_Image img = ty_create_image(desc.width, desc.height, data);
- free(data);
-
- return img;
-}
+#include <editor.h>
int main(void)
{
- ty_Hints hints = {
- .scr_width = SCREEN_WIDTH,
- .scr_height = SCREEN_HEIGHT,
- .game_title = "Demonchime",
- .ticrate = 60,
- };
- ty_init(hints);
- tyui_init(&font);
-
- img = load_qoi_image("test_img.qoi");
-
- char font_chars[] =
- "abcdefghijklmnopqrstuvwxyz0123456789"
- "!\"'#$%&()*+,-./@[]\\^_`{}|~:;<>=? "
- ;
- ty_Image font_img = load_qoi_image("font.qoi");
-
- int glyph_height = 8;
-
- for (int i = 0; font_chars[i] != '\0'; i++) {
- ty_Image glyph = ty_create_image(
- font_img.width,
- glyph_height,
- font_img.data + font_img.width * glyph_height * i
- );
-
- uint8_t c = *(uint8_t*)&font_chars[i];
-
- ty_font_add_glyph(&font, c, glyph);
- if (c >= 'a' && c <= 'z')
- ty_font_add_glyph(&font, c - ('a' - 'A'), glyph);
- }
-
- while (ty_is_game_running()) {
- int ticks = ty_tick();
- for (int i = 0; i < ticks; i++)
- tick();
-
- ty_free_temp_allocs();
- //ty_sleep(1000 / hints.ticrate);
- }
-
- ty_free_image(img);
- ty_free_image(font_img);
-
- for (int i = 0; i < CHAR_MAX; i++) {
- if (i >= 'a' && i <= 'z')
- continue;
- ty_Image glyph = font.glyphs[i];
- if (glyph.width * glyph.height == 0)
- continue;
- ty_free_image(glyph);
- }
-
- tyui_deinit();
- ty_deinit();
- return 0;
+ return editor_main();
}