~rabbits/orca-toy

183a6b1207c4b288d1ba6e168be46fba50088c18 — neauoire 2 years ago c1af5c0
Starting IO messages
5 files changed, 30 insertions(+), 20 deletions(-)

A font-bold.chr
A font-light.chr
M sim.c
M sim.h
M toy.c
A font-bold.chr => font-bold.chr +0 -0
A font-light.chr => font-light.chr +0 -0
M sim.c => sim.c +14 -8
@@ 275,7 275,7 @@ opj(Grid *g, int x, int y, char c)
	char link = getport(g, x, y - 1, 0);
	int i;
	if(link != c) {
		for(i = 1; y + i < g->h; ++i)
		for(i = 1; y + i < 256; ++i)
			if(get(g, x, y + i) != c)
				break;
		setport(g, x, y + i, link);


@@ 453,7 453,7 @@ opy(Grid *g, int x, int y, char c)
	char link = getport(g, x - 1, y, 0);
	int i;
	if(link != c) {
		for(i = 1; x + i < g->w; ++i)
		for(i = 1; x + i < 256; ++i)
			if(get(g, x + i, y) != c)
				break;
		setport(g, x + i, y, link);


@@ 477,7 477,7 @@ void
opcomment(Grid *g, int x, int y)
{
	int i;
	for(i = 1; x + i < g->w; ++i) {
	for(i = 1; x + i < 256; ++i) {
		lock(g, x + i, y);
		if(get(g, x + i, y) == '#')
			break;


@@ 488,15 488,14 @@ void
opspecial(Grid *g, int x, int y)
{
	int i, b = bang(g, x, y);
	for(i = 0; x + i < g->w; ++i) {
	for(i = 0; x + i < 256; ++i) {
		char c = getport(g, x + i, y, 1);
		if(c == '.')
			break;
		if(b)
			printf("%c", c);
			g->msg[g->msg_len++] = c;
	}
	if(b)
		printf("\n");
	settype(g, x, y, b ? 3 : 2);
}

void


@@ 542,7 541,7 @@ void
print(Grid *g)
{
	/* TODO: only print once, merge into a buf */
	int x, y;
	int x, y, i = 0;
	for(y = 0; y < g->h; ++y)
		for(x = 0; x < g->w; ++x) {
			putchar(get(g, x, y));


@@ 557,6 556,9 @@ print(Grid *g)
				putchar('\n');
		}
	putchar('\n');
	while(g->msg[i])
		putchar(g->msg[i++]);
	putchar('\n');
}

int


@@ 567,6 569,8 @@ run(Grid *g)
		g->lock[i] = 0;
		g->type[i] = 0;
	}
	g->msg[0] = '\0';
	g->msg_len = 0;
	for(i = 0; i < g->l; ++i) {
		char c = g->data[i];
		x = i % g->w;


@@ 613,4 617,6 @@ create(Grid *g, int w, int h)
	for(i = 0; i < w * h; ++i) {
		g->data[i] = '.';
	}
	g->msg[0] = '\0';
	g->msg_len = 0;
}

M sim.h => sim.h +2 -0
@@ 10,6 10,8 @@ typedef struct Grid {
	int type[MAXSZ];
	char vars[36];
	char data[MAXSZ];
	char msg[36];
	int msg_len;
} Grid;

char get(Grid *g, int x, int y);

M toy.c => toy.c +14 -12
@@ 109,13 109,11 @@ getfont(int x, int y, char c, int type, int sel)
		return 65;
	if(x % 8 == 0 && y % 8 == 0)
		return 68;
	if(c == '.' && type)
		return 64;
	if(c == '.' && !sel)
		return 70;
	if(selection.x == x && selection.y == y)
		return 66;
	if(sel)
	if(sel || type)
		return 64;
	if(x % 2 == 0 && y % 2 == 0)
		return 64;
	return 70;
}


@@ 205,6 203,15 @@ error(char *msg, const char *err)
}

void
play(void)
{
	int i;
	for(i = 0; i < g.msg_len; ++i) {
		printf("%c", g.msg[i]);
	}
}

void
quit(void)
{
	free(pixels);


@@ 219,12 226,6 @@ quit(void)
}

void
render(void)
{
	draw(pixels);
}

void
domouse(SDL_Event *event)
{
	Point2d touch = clampt(


@@ 336,7 337,7 @@ init(void)
int
loadfont(void)
{
	FILE *f = fopen("font.chr", "rb");
	FILE *f = fopen("font-bold.chr", "rb");
	if(f == NULL)
		return error("Font", "Invalid input file");
	if(!fread(font, sizeof(font), 1, f))


@@ 369,6 370,7 @@ main(int argc, char *argv[])

		if(tickrun == 8) {
			run(&g);
			play();
			draw(pixels);
			tickrun = 0;
		}