~rabbits/orca-toy

15b0f5c35ace37182687d4bd63e7d1aa0adb6d65 — neauoire 3 months ago 0e837bd
Implemented random operator
2 files changed, 13 insertions(+), 19 deletions(-)

M build.sh
M orca.c
M build.sh => build.sh +2 -7
@@ 5,14 5,9 @@ clang-format -i orca.c
## Cleanup
rm -f ./orca

# cli
# cc -std=c89 -DDEBUG -Wall -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined -o cli cli.c sim.c
# cc cli.c sim.c -std=c89 -O2 -DNDEBUG -g0 -s -Wall -o cli
# ./cli demo.orca

# client
# cc -std=c89 -DDEBUG -Wall -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined -L/usr/local/lib -lSDL2 -lportmidi orca.c sim.c -o orca
cc -std=c89 -O2 -DNDEBUG -g0 -s -Wall -L/usr/local/lib -lSDL2 -lportmidi orca.c -o orca
cc -std=c89 -DDEBUG -Wall -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined -L/usr/local/lib -lSDL2 -lportmidi orca.c -o orca
# cc -std=c89 -O2 -DNDEBUG -g0 -s -Wall -L/usr/local/lib -lSDL2 -lportmidi orca.c -o orca

# Size
echo "Size: $(du -sk ./orca)"

M orca.c => orca.c +11 -12
@@ 219,17 219,6 @@ valid(Grid *g, int x, int y)
	return x >= 0 && x <= g->w - 1 && y >= 0 && y <= g->h - 1;
}

int
random(Grid *g)
{
	(void)g;
	return 0;
	/* TODO
	g->r *= 1103515245;
	return ((g->r / 65536 * g->f) % 32768) ^ g->f;
	*/
}

/* IO */

char


@@ 530,7 519,17 @@ opr(Grid *g, int x, int y, char c)
	char max = getport(g, x + 1, y, 1);
	int min_ = cb36(min);
	int max_ = cb36(max);
	setport(g, x, y + 1, cchr((random(g) % ((cb36(max_) - min_) || 1)) + min_, ciuc(max)));
	unsigned int key = (g->r + y * g->w + x) ^ (g->f << 16);
	if(!max_)
		max_ = 36;
	if(min_ == max_)
		min_ = max_ - 1;
	key = (key ^ 61) ^ (key >> 16);
	key = key + (key << 3);
	key = key ^ (key >> 4);
	key = key * 0x27d4eb2d;
	key = key ^ (key >> 15);
	setport(g, x, y + 1, cchr(key % (max_ - min_) + min_, ciuc(max)));
	(void)c;
}