renamed types and constants
This commit is contained in:
23
.gitignore
vendored
23
.gitignore
vendored
@@ -1,2 +1,21 @@
|
|||||||
out/
|
# build results
|
||||||
tools/
|
bin/
|
||||||
|
obj/
|
||||||
|
|
||||||
|
# IDE files
|
||||||
|
.vs/
|
||||||
|
.vshistory/
|
||||||
|
.editorconfig
|
||||||
|
*.user
|
||||||
|
*.vcxproj.filters
|
||||||
|
|
||||||
|
# other files
|
||||||
|
.old*/
|
||||||
|
old/
|
||||||
|
tmp/
|
||||||
|
temp/
|
||||||
|
*.tmp
|
||||||
|
*.temp
|
||||||
|
logs/
|
||||||
|
log/
|
||||||
|
*.log
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ int main(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get text properties
|
// get text properties
|
||||||
struct text msg = scan_str(argv[1]);
|
TimText_t msg = scan_str(argv[1]);
|
||||||
|
|
||||||
while (tim_run(0)) {
|
while (tim_run(0)) {
|
||||||
// calculate size of message box
|
// calculate size of message box
|
||||||
@@ -41,7 +41,7 @@ int main(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// return with 1 when q or esc is pressed
|
// 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);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "../tim.h" // one header, no lib
|
#include "../tim.h"
|
||||||
int main(void) { //
|
|
||||||
|
int main(void) {
|
||||||
while (tim_run(0)) { // event loop
|
while (tim_run(0)) { // event loop
|
||||||
scope (A, A, 24, 8) { // centered 24x8 scope
|
scope (A, A, 24, 8) { // centered 24x8 scope
|
||||||
uint64_t c = 0x0a060f; // three colors
|
uint64_t c = 0x0a060f; // three colors
|
||||||
@@ -9,7 +10,7 @@ int main(void) { //
|
|||||||
return 0; // exit on button click
|
return 0; // exit on button click
|
||||||
if (is_key_press('q')) // ctrl-c is masked
|
if (is_key_press('q')) // ctrl-c is masked
|
||||||
return 0; // exit on 'q' press
|
return 0; // exit on 'q' press
|
||||||
} //
|
}
|
||||||
} // atexit cleanup
|
} //TODO: remove atexit cleanup
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,12 +63,12 @@ static void game(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// draw
|
// draw
|
||||||
if (tim.event.type == DRAW_EVENT) {
|
if (tim.event.type == TimEvent_Draw) {
|
||||||
// food
|
// food
|
||||||
draw_chr(cell(" ", 0, 0xc5), snek.food.x * 2 + 0, snek.food.y);
|
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);
|
draw_chr(cell(" ", 0, 0xc5), snek.food.x * 2 + 1, snek.food.y);
|
||||||
// snek
|
// snek
|
||||||
struct cell s = cell(" ", 0, 0);
|
TimCell_t s = cell(" ", 0, 0);
|
||||||
for (int i = 0; i < snek.len; i++) {
|
for (int i = 0; i < snek.len; i++) {
|
||||||
s.bg = (i / 2) % 2 ? 0xe3 : 0xea;
|
s.bg = (i / 2) % 2 ? 0xe3 : 0xea;
|
||||||
int x = snek.body[i].x * 2;
|
int x = snek.body[i].x * 2;
|
||||||
@@ -81,13 +81,13 @@ static void game(void) {
|
|||||||
// user input
|
// user input
|
||||||
if (tim.event.type == KEY_EVENT) {
|
if (tim.event.type == KEY_EVENT) {
|
||||||
int key = tim.event.key;
|
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}};
|
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}};
|
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}};
|
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}};
|
snek.look = (point){{0, -1}};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,13 +98,13 @@ static void menu(void) {
|
|||||||
char* lbl = snek.state == OVER ? "GAME OVER" : "SNEK - THE GAME";
|
char* lbl = snek.state == OVER ? "GAME OVER" : "SNEK - THE GAME";
|
||||||
char* btn = snek.state == PAUSE ? "Resume" : "Play";
|
char* btn = snek.state == PAUSE ? "Resume" : "Play";
|
||||||
label(lbl, A, 0, A, A, BTN);
|
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) {
|
if (snek.state != PAUSE) {
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
snek.state = RUN;
|
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);
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -113,7 +113,7 @@ static void menu(void) {
|
|||||||
int main(void) {
|
int main(void) {
|
||||||
// draw every 10 ms
|
// draw every 10 ms
|
||||||
while (tim_run(10)) {
|
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);
|
draw_lot(bg, 0, 0, tim.w, tim.h);
|
||||||
|
|
||||||
if (snek.state == RUN) {
|
if (snek.state == RUN) {
|
||||||
@@ -122,7 +122,7 @@ int main(void) {
|
|||||||
menu();
|
menu();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_key_press(ESCAPE_KEY)) {
|
if (is_key_press(TimKey_Escape)) {
|
||||||
snek.state = PAUSE;
|
snek.state = PAUSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
20
makefile
20
makefile
@@ -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 $@
|
$(CC) $< -Wall $(CFLAGS) -o $@
|
||||||
out/string: test/string.c out
|
bin/string: test/string.c bin
|
||||||
$(CC) $< -Wall $(CFLAGS) -o $@
|
$(CC) $< -Wall $(CFLAGS) -o $@
|
||||||
out/color: test/color.c out
|
bin/color: test/color.c bin
|
||||||
$(CC) $< -Wall $(CFLAGS) -o $@
|
$(CC) $< -Wall $(CFLAGS) -o $@
|
||||||
out/hello: example/hello.c out
|
bin/hello: example/hello.c bin
|
||||||
$(CC) $< -Wall $(CFLAGS) -o $@
|
$(CC) $< -Wall $(CFLAGS) -o $@
|
||||||
out/ask: example/ask.c out
|
bin/ask: example/ask.c bin
|
||||||
$(CC) $< -Wall $(CFLAGS) -o $@
|
$(CC) $< -Wall $(CFLAGS) -o $@
|
||||||
out/snek: example/snek.c out
|
bin/snek: example/snek.c bin
|
||||||
$(CC) $< -Wall $(CFLAGS) -o $@
|
$(CC) $< -Wall $(CFLAGS) -o $@
|
||||||
|
|
||||||
out:
|
bin:
|
||||||
mkdir -p out
|
mkdir -p bin
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf out
|
rm -rf bin
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ int main(void) {
|
|||||||
for (int i = 0; i < 24; i++) {
|
for (int i = 0; i < 24; i++) {
|
||||||
foo(i % 12, i / 12 + 22, i + 232);
|
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);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ int main(void) {
|
|||||||
TEST(scan_str("a").width == 1);
|
TEST(scan_str("a").width == 1);
|
||||||
TEST(scan_str("äß\no").width == 2);
|
TEST(scan_str("äß\no").width == 2);
|
||||||
|
|
||||||
struct line ln = {.s = "foo\nbar"};
|
TimLine_t ln = {.s = "foo\nbar"};
|
||||||
TEST(next_line(&ln) == true);
|
TEST(next_line(&ln) == true);
|
||||||
TEST(!memcmp(ln.line, "foo", ln.size));
|
TEST(!memcmp(ln.line, "foo", ln.size));
|
||||||
TEST(next_line(&ln) == true);
|
TEST(next_line(&ln) == true);
|
||||||
|
|||||||
18
test/test.c
18
test/test.c
@@ -1,8 +1,8 @@
|
|||||||
#include "../tim.h"
|
#include "../tim.h"
|
||||||
|
|
||||||
static inline void test_screen(struct event* e) {
|
static inline void test_screen(TimEvent_t* e) {
|
||||||
static struct event me;
|
static TimEvent_t me;
|
||||||
static struct event ke;
|
static TimEvent_t ke;
|
||||||
static int render_us;
|
static int render_us;
|
||||||
char buf[64];
|
char buf[64];
|
||||||
|
|
||||||
@@ -37,9 +37,9 @@ static inline void test_screen(struct event* e) {
|
|||||||
render_us += tim.render_us;
|
render_us += tim.render_us;
|
||||||
sprintf(buf, "%d µs (Ø %d µs)", tim.render_us, render_us / MAX(tim.frame, 1));
|
sprintf(buf, "%d µs (Ø %d µs)", tim.render_us, render_us / MAX(tim.frame, 1));
|
||||||
label(buf, ~2, ~2, A, A, 0xf);
|
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);
|
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);
|
label(buf, ~2, ~0, A, A, 0xf);
|
||||||
|
|
||||||
// multi line label
|
// multi line label
|
||||||
@@ -63,8 +63,10 @@ static inline void test_screen(struct event* e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// edit
|
// edit
|
||||||
static struct edit ed1 = {.s = "Edit 1"};
|
static TimEdit_t ed1;
|
||||||
static struct edit ed2 = {0};
|
static TimEdit_t ed2;
|
||||||
|
edit_init(&ed1, 32, "Edit 1");
|
||||||
|
edit_init(&ed2, 32, "");
|
||||||
edit(&ed1, 1, 10, 32, 0xff00ff);
|
edit(&ed1, 1, 10, 32, 0xff00ff);
|
||||||
sprintf(buf, "cursor: %d length: %d", ed1.cursor, ed1.length);
|
sprintf(buf, "cursor: %d length: %d", ed1.cursor, ed1.length);
|
||||||
label(buf, 2, 13, A, A, 0xf);
|
label(buf, 2, 13, A, A, 0xf);
|
||||||
@@ -111,7 +113,7 @@ static inline void test_screen(struct event* e) {
|
|||||||
int main(void) {
|
int main(void) {
|
||||||
while (tim_run(1.5)) {
|
while (tim_run(1.5)) {
|
||||||
test_screen(&tim.event);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user