alloc big buffers on heap

This commit is contained in:
2026-01-09 05:42:08 +05:00
parent 01df4abcfb
commit bd23c66607
14 changed files with 245 additions and 230 deletions

View File

@@ -1,7 +1,7 @@
#include "tim.h"
i32 main(void) {
while (tim_run(0)) { // event loop
while (tim_run(0)) { // init state and start event loop
tim_scope(A, A, 24, 8) { // centered 24x8 scope
u64 c = 0x0a060f; // three colors
tim_frame(0, 0, ~0, ~0, c); // draw frame for scope
@@ -11,5 +11,5 @@ i32 main(void) {
if (tim_is_key_press('q')) // ctrl-c is masked
return 0; // exit on 'q' press
}
} //TODO: remove atexit cleanup
} // atexit() cleanup
}

View File

@@ -33,8 +33,8 @@ static struct {
static void start(void) {
memset(snek.body, -1, sizeof(snek.body));
snek.len = 2;
snek.body[0] = (point){{1, tim.h / 2}};
snek.food = (point){{tim.w / 8, tim.h / 2}};
snek.body[0] = (point){{1, tim->h / 2}};
snek.food = (point){{tim->w / 8, tim->h / 2}};
snek.look = (point){{1, 0}};
}
@@ -53,19 +53,19 @@ static void game(void) {
crash |= snek.body[0].xy == snek.body[i].xy;
}
// border crash
crash |= snek.body[0].x < 0 || snek.body[0].x >= tim.w / 2 ||
snek.body[0].y < 0 || snek.body[0].y >= tim.h;
crash |= snek.body[0].x < 0 || snek.body[0].x >= tim->w / 2 ||
snek.body[0].y < 0 || snek.body[0].y >= tim->h;
snek.state = crash ? OVER : snek.state;
// food
if (snek.food.xy == snek.body[0].xy) {
snek.len = MIN(snek.len + 2, (i32)ARRAY_SIZE(snek.body));
snek.food.x = rand() % (tim.w / 2 - 2) + 1;
snek.food.y = rand() % (tim.h - 2) + 1;
snek.food.x = rand() % (tim->w / 2 - 2) + 1;
snek.food.y = rand() % (tim->h - 2) + 1;
}
}
// draw
if (tim.event.type == TimEvent_Draw) {
if (tim->event.type == TimEvent_Draw) {
// food
tim_draw_chr(tim_cell(" ", 0, 0xc5), snek.food.x * 2 + 0, snek.food.y);
tim_draw_chr(tim_cell(" ", 0, 0xc5), snek.food.x * 2 + 1, snek.food.y);
@@ -81,8 +81,8 @@ static void game(void) {
}
// user input
if (tim.event.type == KEY_EVENT) {
i32 key = tim.event.key;
if (tim->event.type == KEY_EVENT) {
i32 key = tim->event.key;
if ((key == TimKey_Right || key == 'd') && snek.look.x != -1) {
snek.look = (point){{1, 0}};
} else if ((key == TimKey_Left || key == 'a') && snek.look.x != 1) {
@@ -119,7 +119,7 @@ i32 main(void) {
// draw every 10 ms
while (tim_run(60)) {
TimCell bg = tim_cell(" ", 0, BG);
tim_draw_lot(bg, 0, 0, tim.w, tim.h);
tim_draw_lot(bg, 0, 0, tim->w, tim->h);
if (snek.state == RUN) {
game();