renamed types and constants

This commit is contained in:
2026-01-09 02:21:50 +05:00
parent b725182544
commit f7b4809db8
9 changed files with 300 additions and 524 deletions

23
.gitignore vendored
View File

@@ -1,2 +1,21 @@
out/
tools/
# build results
bin/
obj/
# IDE files
.vs/
.vshistory/
.editorconfig
*.user
*.vcxproj.filters
# other files
.old*/
old/
tmp/
temp/
*.tmp
*.temp
logs/
log/
*.log

View File

@@ -16,7 +16,7 @@ int main(int argc, char** argv) {
}
// get text properties
struct text msg = scan_str(argv[1]);
TimText_t msg = scan_str(argv[1]);
while (tim_run(0)) {
// calculate size of message box
@@ -41,7 +41,7 @@ int main(int argc, char** argv) {
}
// return with 1 when q or esc is pressed
if (is_key_press('q') || is_key_press(ESCAPE_KEY)) {
if (is_key_press('q') || is_key_press(TimKey_Escape)) {
exit(1);
}
}

View File

@@ -1,5 +1,6 @@
#include "../tim.h" // one header, no lib
int main(void) { //
#include "../tim.h"
int main(void) {
while (tim_run(0)) { // event loop
scope (A, A, 24, 8) { // centered 24x8 scope
uint64_t c = 0x0a060f; // three colors
@@ -9,7 +10,7 @@ int main(void) { //
return 0; // exit on button click
if (is_key_press('q')) // ctrl-c is masked
return 0; // exit on 'q' press
} //
} // atexit cleanup
}
} //TODO: remove atexit cleanup
}

View File

@@ -63,12 +63,12 @@ static void game(void) {
}
// draw
if (tim.event.type == DRAW_EVENT) {
if (tim.event.type == TimEvent_Draw) {
// food
draw_chr(cell(" ", 0, 0xc5), snek.food.x * 2 + 0, snek.food.y);
draw_chr(cell(" ", 0, 0xc5), snek.food.x * 2 + 1, snek.food.y);
// snek
struct cell s = cell(" ", 0, 0);
TimCell_t s = cell(" ", 0, 0);
for (int i = 0; i < snek.len; i++) {
s.bg = (i / 2) % 2 ? 0xe3 : 0xea;
int x = snek.body[i].x * 2;
@@ -81,13 +81,13 @@ static void game(void) {
// user input
if (tim.event.type == KEY_EVENT) {
int key = tim.event.key;
if ((key == RIGHT_KEY || key == 'd') && snek.look.x != -1) {
if ((key == TimKey_Right || key == 'd') && snek.look.x != -1) {
snek.look = (point){{1, 0}};
} else if ((key == LEFT_KEY || key == 'a') && snek.look.x != 1) {
} else if ((key == TimKey_Left || key == 'a') && snek.look.x != 1) {
snek.look = (point){{-1, 0}};
} else if ((key == DOWN_KEY || key == 's') && snek.look.y != -1) {
} else if ((key == TimKey_Down || key == 's') && snek.look.y != -1) {
snek.look = (point){{0, 1}};
} else if ((key == UP_KEY || key == 'w') && snek.look.y != 1) {
} else if ((key == TimKey_Up || key == 'w') && snek.look.y != 1) {
snek.look = (point){{0, -1}};
}
}
@@ -98,13 +98,13 @@ static void menu(void) {
char* lbl = snek.state == OVER ? "GAME OVER" : "SNEK - THE GAME";
char* btn = snek.state == PAUSE ? "Resume" : "Play";
label(lbl, A, 0, A, A, BTN);
if (button(btn, A, 2, 20, 5, BTN) || is_key_press(ENTER_KEY)) {
if (button(btn, A, 2, 20, 5, BTN) || is_key_press(TimKey_Enter)) {
if (snek.state != PAUSE) {
start();
}
snek.state = RUN;
}
if (button("Exit", A, 8, 20, 5, BTN) || is_key_press(ESCAPE_KEY)) {
if (button("Exit", A, 8, 20, 5, BTN) || is_key_press(TimKey_Escape)) {
exit(0);
}
}
@@ -113,7 +113,7 @@ static void menu(void) {
int main(void) {
// draw every 10 ms
while (tim_run(10)) {
struct cell bg = cell(" ", 0, BG);
TimCell_t bg = cell(" ", 0, BG);
draw_lot(bg, 0, 0, tim.w, tim.h);
if (snek.state == RUN) {
@@ -122,7 +122,7 @@ int main(void) {
menu();
}
if (is_key_press(ESCAPE_KEY)) {
if (is_key_press(TimKey_Escape)) {
snek.state = PAUSE;
}
}

View File

@@ -1,20 +1,20 @@
all: out/test out/string out/color out/hello out/ask out/snek
all: bin/test bin/string bin/color bin/hello bin/ask bin/snek
out/test: test/test.c out
bin/test: test/test.c bin
$(CC) $< -Wall $(CFLAGS) -o $@
out/string: test/string.c out
bin/string: test/string.c bin
$(CC) $< -Wall $(CFLAGS) -o $@
out/color: test/color.c out
bin/color: test/color.c bin
$(CC) $< -Wall $(CFLAGS) -o $@
out/hello: example/hello.c out
bin/hello: example/hello.c bin
$(CC) $< -Wall $(CFLAGS) -o $@
out/ask: example/ask.c out
bin/ask: example/ask.c bin
$(CC) $< -Wall $(CFLAGS) -o $@
out/snek: example/snek.c out
bin/snek: example/snek.c bin
$(CC) $< -Wall $(CFLAGS) -o $@
out:
mkdir -p out
bin:
mkdir -p bin
clean:
rm -rf out
rm -rf bin

View File

@@ -22,7 +22,7 @@ int main(void) {
for (int i = 0; i < 24; i++) {
foo(i % 12, i / 12 + 22, i + 232);
}
if (is_key_press('q') || is_key_press(ESCAPE_KEY)) {
if (is_key_press('q') || is_key_press(TimKey_Escape)) {
exit(1);
}
}

View File

@@ -51,7 +51,7 @@ int main(void) {
TEST(scan_str("a").width == 1);
TEST(scan_str("äß\no").width == 2);
struct line ln = {.s = "foo\nbar"};
TimLine_t ln = {.s = "foo\nbar"};
TEST(next_line(&ln) == true);
TEST(!memcmp(ln.line, "foo", ln.size));
TEST(next_line(&ln) == true);

View File

@@ -1,8 +1,8 @@
#include "../tim.h"
static inline void test_screen(struct event* e) {
static struct event me;
static struct event ke;
static inline void test_screen(TimEvent_t* e) {
static TimEvent_t me;
static TimEvent_t ke;
static int render_us;
char buf[64];
@@ -37,9 +37,9 @@ static inline void test_screen(struct event* e) {
render_us += tim.render_us;
sprintf(buf, "%d µs (Ø %d µs)", tim.render_us, render_us / MAX(tim.frame, 1));
label(buf, ~2, ~2, A, A, 0xf);
sprintf(buf, "%d cells (%.0f %%)", tim.w * tim.h, 100.0 * tim.w * tim.h / MAX_CELLS);
sprintf(buf, "%d cells (%.0f %%)", tim.w * tim.h, 100.0 * tim.w * tim.h / TIM_MAX_CELLS);
label(buf, ~2, ~1, A, A, 0xf);
sprintf(buf, "%d bytes (%.0f %%)", tim.buf_size, 100.0 * tim.buf_size / MAX_BUF);
sprintf(buf, "%d bytes (%.0f %%)", tim.buf_size, 100.0 * tim.buf_size / TIM_MAX_BUF);
label(buf, ~2, ~0, A, A, 0xf);
// multi line label
@@ -63,8 +63,10 @@ static inline void test_screen(struct event* e) {
}
// edit
static struct edit ed1 = {.s = "Edit 1"};
static struct edit ed2 = {0};
static TimEdit_t ed1;
static TimEdit_t ed2;
edit_init(&ed1, 32, "Edit 1");
edit_init(&ed2, 32, "");
edit(&ed1, 1, 10, 32, 0xff00ff);
sprintf(buf, "cursor: %d length: %d", ed1.cursor, ed1.length);
label(buf, 2, 13, A, A, 0xf);
@@ -111,7 +113,7 @@ static inline void test_screen(struct event* e) {
int main(void) {
while (tim_run(1.5)) {
test_screen(&tim.event);
if (is_key_press('q') || is_key_press(ESCAPE_KEY)) {
if (is_key_press('q') || is_key_press(TimKey_Escape)) {
break;
}
}

722
tim.h

File diff suppressed because it is too large Load Diff