From bdab446ef1b3b2cd44aebc8d267ff8e33ce53963 Mon Sep 17 00:00:00 2001 From: Mitya Selivanov Date: Tue, 19 Nov 2024 04:18:51 +0100 Subject: Remove codegen; Use graphics from reduced_system_layer.c --- saw.c | 136 ++---------------------------------------------------------------- 1 file changed, 4 insertions(+), 132 deletions(-) diff --git a/saw.c b/saw.c index 0a7c1f5..e3dde4e 100755 --- a/saw.c +++ b/saw.c @@ -13,7 +13,7 @@ #/ - Single source file #/ - All dependencies are included with the code #/ - No configuration required -#/ - Cross-platform thanks to sokol and miniaudio +#/ - Cross-platform thanks to reduced_system_layer.c #/ #/ ---------------------------------------------------------------- #/ @@ -89,15 +89,9 @@ #/ Bugs #/ #/ - Sampler clicking -#/ - Different build types don't work without manual full rebuild because they store object files in the same folder #/ #/ Done features #/ -#/ - Build -#/ - Code setup for dependencies -#/ - nanovg and miniaudio setup -#/ - Faster recompilation -#/ - WebAssembly #/ - Sound #/ - Track looping #/ - Buffering @@ -255,9 +249,7 @@ exit $? # */ // // ================================================================ // Define one of the options for the linter -#if !CODEGEN && \ - !EXE && \ - !TESTS +#if !EXE && !TESTS #define EXE 1 #endif #define _GNU_SOURCE @@ -286,131 +278,12 @@ typedef double f64; #endif // TYPES_HEADER_GUARD_ // ================================================================ // -// CODE GENERATION -// -// ================================================================ -#if CODEGEN - -#include -#include - -#define FONT_TEXT "Domitian Roman.ttf" -#define FONT_ICONS "FontAwesome 6 Free Solid 900.ttf" -#define INL_FONTS "fonts.inl.c" - -enum { - MAX_LENGTH = 200, -}; - -i64 int_len(u32 x) { - i64 len = 0; - - do { - x /= 10; - ++len; - } while (x > 0); - - return len; -} - -i64 print_bytes(FILE *out, FILE *in) { - i64 size = 0, line_len = MAX_LENGTH; - - while (!feof(in)) { - u32 x = 0; - - i64 n = fread(&x, 1, sizeof x, in); - if (n <= 0) - break; - - i64 len = int_len(x); - - line_len += len + 2; - - if (line_len >= MAX_LENGTH) { - fprintf(out, "\n "); - line_len = 3 + len; - } - - fprintf(out, " %u,", x); - - size += n; - } - - return size; -} - -i32 main(void) { - printf("Code generation\n"); - fflush(stdout); - - FILE *out = fopen(INL_FONTS, "wb"); - - if (out == NULL) { - printf("Unable to write `%s`", INL_FONTS); - exit(-1); - } - - fprintf(out, "// Saw generated code\n\n"); - - { - FILE *in = fopen(FONT_TEXT, "rb"); - - if (in == NULL) { - printf("Unable to read `%s`", FONT_TEXT); - exit(-1); - } - - fprintf(out, "u32 ttf_text[] = {"); - - i64 n = print_bytes(out, in); - - fprintf(out, "\n};\n\n"); - fprintf(out, "enum { TTF_TEXT_SIZE = %lld, };\n\n", n); - - fclose(in); - } - - { - FILE *in = fopen(FONT_ICONS, "rb"); - - if (in == NULL) { - printf("Unable to read `%s`", FONT_ICONS); - exit(-1); - } - - - fprintf(out, "u32 ttf_icons[] = {"); - - i64 n = print_bytes(out, in); - - fprintf(out, "\n};\n\n"); - fprintf(out, "enum { TTF_ICONS_SIZE = %lld, };\n\n", n); - - fclose(in); - } - - fclose(out); - return 0; -} -// ================================================================ -// // EXECUTABLE // // ================================================================ -#elif EXE -// ================================================================ -// -// Headers -// -// ================================================================ - -#include -#include +#if EXE -// ttf_text, TTF_TEXT_SIZE -// ttf_icons, TTF_ICONS_SIZE -#include "fonts.inl.c" +#include "graphics.c" // ================================================================ // @@ -429,7 +302,6 @@ i32 main(void) { // Configuration // -#define EPS 1e-7 #define REFERENCE_PITCH 440.0 // A_4 #define EQUAL_TEMPERAMENT_FACTOR 1.05946309436 // 2^(1/12) #define GLOBAL_VOLUME 2.0 -- cgit v1.2.3