Here's a simple example:
with:
Half of the code assumes there is only one chunk "cave" and the other half takes into account the possibility of more. This doesn't feel right. Now imagine you're in the cave generation code where for some profiles there are multiple chunks generated, you could end up with:
generate(c) -> calls f() -> calls g(cave != c)
then you would be in big trouble...
A thorough approach would be to remove all occurences of "cave" and replace them with a "struct chunk *c" parameter in the functions. For example:
with:
but of course that would be an insane amount of work.
I know the feeling, I've been through this with my variant which has a similar problem: since it's multiplayer, the "cave" parameter is saved on each player, but most functions use "struct player *p" as a parameter and then use p->cave inside, while some functions use a double parameter signature (struct player *p, struct chunk *c)... and of course I had to track every occurence of p->cave and replace them with "c". And at this time there are still some intertwined functions that don't use a cave parameter inside functions that use one and I fix this as I discover them...
Code:
bool multiply_monster(struct chunk *c, const struct monster *mon) { ... become_aware(child); ... }
Code:
void become_aware(struct monster *mon) { ... if (square_isseen(cave, obj->grid)) ... if (! monster_carry(cave, mon, given)) ... square_delete_object(cave, obj->grid, obj, false, false); ... }
generate(c) -> calls f() -> calls g(cave != c)
then you would be in big trouble...
A thorough approach would be to remove all occurences of "cave" and replace them with a "struct chunk *c" parameter in the functions. For example:
Code:
bool multiply_monster(struct chunk *c, const struct monster *mon) { ... become_aware(c, child); ... }
Code:
void become_aware(struct chunk *c, struct monster *mon) { ... if (square_isseen(c, obj->grid)) ... if (! monster_carry(c, mon, given)) ... square_delete_object(c, obj->grid, obj, false, false); ... }
I know the feeling, I've been through this with my variant which has a similar problem: since it's multiplayer, the "cave" parameter is saved on each player, but most functions use "struct player *p" as a parameter and then use p->cave inside, while some functions use a double parameter signature (struct player *p, struct chunk *c)... and of course I had to track every occurence of p->cave and replace them with "c". And at this time there are still some intertwined functions that don't use a cave parameter inside functions that use one and I fix this as I discover them...
Comment