diff options
author | kdx <kikoodx@paranoici.org> | 2023-11-24 04:01:47 +0100 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-11-24 04:01:47 +0100 |
commit | eb8634cc44594a7c2d392553f407de864f200590 (patch) | |
tree | 565dea41a7b43e16e12d1f256a20d5dcc183ce11 | |
parent | 447c82adb31163a1e57b5a9b2ec4c1697bd3c473 (diff) | |
download | aancyk-eb8634cc44594a7c2d392553f407de864f200590.tar.gz |
write world cell backwards
-rw-r--r-- | src/world.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/world.c b/src/world.c index 3c026d2..babac9b 100644 --- a/src/world.c +++ b/src/world.c @@ -51,6 +51,14 @@ world_destroy(World *this) free(this); } +static void +_recursive_write(FILE *fp, Cell *cell) +{ + if (cell->next != NULL) + _recursive_write(fp, cell->next); + fprintf(fp, "%d,%d,%d\n", cell->id, cell->x, cell->y); +} + int world_write(World *this, const char *path) { @@ -64,8 +72,7 @@ world_write(World *this, const char *path) } fprintf(fp, "%d,%d,%d\n", world_cell_count(this), this->x, this->y); - foreach(cell, this->root_cell) - fprintf(fp, "%d,%d,%d\n", cell->id, cell->x, cell->y); + _recursive_write(fp, this->root_cell); fclose(fp); return 0; |