life

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 3d740795a3ca1b1f8ca69a8174f095a31f1e8801
parent bc926c4c872b10bbe89fb891230bb1612ce4ecb4
Author: Wilson Gheen <wilson@wilsonrgheen.com>
Date:   Fri,  9 Dec 2022 15:49:27 -0600

Clean up memcpy??

Diffstat:
Mlife.c | 10++++------
1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/life.c b/life.c @@ -23,6 +23,7 @@ static uint64_t gliderShootsImmortalFlower[MAX_ROWS] = static uint64_t hline[MAX_ROWS] = {0, 0, 114688, 0, 0, 0, 0, 0}; static uint64_t sqtoad[MAX_ROWS] = {0, 786432, 786432, 196608, 196608, 0, 0, 0}; static uint64_t gosper[MAX_ROWS] = {0x0000000800000000, 0x0000001400000000, 0x0030001a18000000, 0x0028001b18000000, 0x6604001a00000000, 0x6924001400000000, 0x0604000800000000, 0x0028000000000000, 0x0030000000000000}; +static uint64_t gosperToHalfPulsar[MAX_ROWS] = {0x0000000800000000, 0x0000001400000000, 0x0030001a18000000, 0x0028001b18000000, 0x6604001a00000000, 0x6924001400000000, 0x0604000800000000, 0x0028000000000000, 0x0030000000000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0000000078000000, 0}; #define BOARD gosper void print_bw(int x, int y, uint64_t ch) { @@ -61,7 +62,7 @@ void print_board(uint64_t board[], int rows, int cols) { tb_present(); } -uint64_t *get_next_state(uint64_t board[], int rows, int cols) { +uint64_t *get_next_state(uint64_t *newBoard, uint64_t board[], int rows, int cols) { uint64_t m[MAX_ROWS]; for(int r=0; r < rows; r++) { uint64_t newRow = board[r]; @@ -96,9 +97,7 @@ uint64_t *get_next_state(uint64_t board[], int rows, int cols) { } m[r] = newRow; } - static uint64_t tmp[MAX_ROWS]; - memcpy(tmp, m, sizeof m); - return tmp; + memcpy(newBoard, m, sizeof m); } void play(uint64_t board[], int rows, int cols) { @@ -110,8 +109,7 @@ void play(uint64_t board[], int rows, int cols) { if (tb_peek_event(&ev, 300) == TB_OK && ev.type == TB_EVENT_KEY) if(ev.key == TB_KEY_CTRL_C) return; - uint64_t *l2 = get_next_state(board, rows, cols); - memcpy(board, l2, (sizeof *l2) * rows ); + get_next_state(board, board, rows, cols); } }