diff options
| author | Paul Oliver <contact@pauloliver.dev> | 2025-11-19 04:42:58 +0100 |
|---|---|---|
| committer | Paul Oliver <contact@pauloliver.dev> | 2025-11-19 16:40:08 +0100 |
| commit | 0075d1b10c475d303a314a3425ee472252855f32 (patch) | |
| tree | 2537411ad2b9691f413eeab62d7f541724ea47c6 /ui/daemon | |
| parent | d91b8a6196af711f9dface0c2a0d37794c12ac02 (diff) | |
Python/SQLite refactor
- Uses Python/Jinja2 to preprocess C files
- Uses SQLite3 for data compression
Diffstat (limited to 'ui/daemon')
| -rw-r--r-- | ui/daemon/ui.j2.c | 60 | ||||
| -rw-r--r-- | ui/daemon/ui_vars.py | 2 |
2 files changed, 62 insertions, 0 deletions
diff --git a/ui/daemon/ui.j2.c b/ui/daemon/ui.j2.c new file mode 100644 index 0000000..7d92f9d --- /dev/null +++ b/ui/daemon/ui.j2.c @@ -0,0 +1,60 @@ +// Author: Paul Oliver <contact@pauloliver.dev> +// Project: Salis + +// Lightweight UI for the Salis simulator with minimal output. +// Can be interrupted through OS signals. +// Ideal for running Salis in the background. + +volatile bool g_running; +uint64_t g_step_block; + +void sig_handler(int signo) { + switch (signo) { + case SIGINT: + case SIGTERM: + printf("Signal received, will stop simulator soon...\n"); + g_running = false; + break; + } +} + +void step_block() { + clock_t beg = clock(); + salis_step(g_step_block - (g_steps % g_step_block)); + clock_t end = clock(); + + if ((end - beg) < (CLOCKS_PER_SEC * 4)) { + g_step_block <<= 1; + } + + if ((end - beg) >= (CLOCKS_PER_SEC * 2) && g_step_block != 1) { + g_step_block >>= 1; + } + + printf("Simulator running on step '%#lx'\n", g_steps); +} + +int main() { + {% if args.command == "new" %} + salis_init(); + {% elif args.command == "load" %} + salis_load(); + {% endif %} + + g_running = true; + g_step_block = 1; + + signal(SIGINT, sig_handler); + signal(SIGTERM, sig_handler); + + while (g_running) { + step_block(); + } + + printf("Saving simulation...\n"); + salis_save("{{ sim_path }}"); + salis_free(); + + printf("Exiting salis...\n"); + return 0; +} diff --git a/ui/daemon/ui_vars.py b/ui/daemon/ui_vars.py new file mode 100644 index 0000000..9d0fc33 --- /dev/null +++ b/ui/daemon/ui_vars.py @@ -0,0 +1,2 @@ +flags = [] +includes = ["signal.h", "stdio.h", "unistd.h"] |
