![]() |
#1 |
Prophet
Join Date: Apr 2008
Posts: 2,944
![]() |
Some stuff that is bothering me, but would be a nightmare to fix
Here's a simple example:
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...
__________________
PWMAngband variant maintainer - check http://powerwyrm.monsite-orange.fr (or http://www.mangband.org/forum/viewforum.php?f=9) to learn more about this new variant! |
![]() |
![]() |
![]() |
#2 |
Swordsman
Join Date: Aug 2019
Posts: 339
![]() |
It's a problem with both the player and cave globals - some functions have been modified to expect struct chunk * or struct player * arguments but end up calling functions that do not and internally use the globals. Given that it's fairly widespread, it's likely less daunting to fix it piecemeal - working up from the lowest levels where those globals should never be accessed.
The example of the multiple chunks that can be in use during cave generation leading to potentially inconsistent results isn't particularly relevant. At least in Vanilla, the global cave is NULL during cave generation (it's set to that by prepare_next_level() at generate.c:1381 and then reset to point to the fully generated cave at points later in prepare_next_level()) so any use of a function that accesses that global without some guard to handle it being NULL is going to crash and burn (thus this issue, https://github.com/NickMcConnell/Fir...and/issues/223 , with First Age Angband and a contributor to this one, https://github.com/NickMcConnell/Fir...and/issues/188 ). |
![]() |
![]() |
![]() |
#3 |
Vanilla maintainer
Join Date: Apr 2007
Location: Canberra, Australia
Age: 57
Posts: 9,424
Donated: $60
![]() ![]() |
I feel like this is a bit of a balancing act. On one hand, any function with 'player' or 'cave' probably "should" take a struct player * or struct chunk * argument. On the other hand, giving a whole lot of functions an extra one or two arguments that are only ever going to take one value is a lot of work and makes the code harder to read.
I think that adding the arguments when we're working on code and it seems like a good idea is probably enough, rather than doing a big seek out and change program. I did one of those for replacing single coordinates with struct grids, so it's possible, but I feel like that made the code unambiguously better and this doesn't. Of course, I'm not maintaining a variant with multiple players ![]()
__________________
One for the Dark Lord on his dark throne In the Land of Mordor where the Shadows lie. |
![]() |
![]() |
![]() |
#4 |
Vanilla maintainer
Join Date: Apr 2007
Location: Canberra, Australia
Age: 57
Posts: 9,424
Donated: $60
![]() ![]() |
OK, having gone some way down the road of fixing this, I'm looking to simplify and clarify wherever possible. Here are some thoughts:
__________________
One for the Dark Lord on his dark throne In the Land of Mordor where the Shadows lie. |
![]() |
![]() |
![]() |
#5 |
Prophet
Join Date: Apr 2007
Location: Seattle, WA
Posts: 6,703
Donated: $40
![]() |
Nick--what about Single Combat?
|
![]() |
![]() |
![]() |
#6 |
Vanilla maintainer
Join Date: Apr 2007
Location: Canberra, Australia
Age: 57
Posts: 9,424
Donated: $60
![]() ![]() |
I don't think it's related to this issue, unless you're seeing something I'm not.
__________________
One for the Dark Lord on his dark throne In the Land of Mordor where the Shadows lie. |
![]() |
![]() |
![]() |
#7 | |
Vanilla maintainer
Join Date: Apr 2007
Location: Canberra, Australia
Age: 57
Posts: 9,424
Donated: $60
![]() ![]() |
Quote:
__________________
One for the Dark Lord on his dark throne In the Land of Mordor where the Shadows lie. |
|
![]() |
![]() |
![]() |
#8 |
Prophet
Join Date: Apr 2008
Posts: 2,944
![]() |
For PWMAngband, prepare_next_level() is different since it's called only when the cave doesn't exist and therefore uses a "struct chunk *prepare_next_level(struct player *p)" prototype.
Code:
struct chunk *c = chunk_get(&p->wpos); if (!c) c = prepare_next_level(p); else { cave_illuminate and other stuff related to "c"... }
__________________
PWMAngband variant maintainer - check http://powerwyrm.monsite-orange.fr (or http://www.mangband.org/forum/viewforum.php?f=9) to learn more about this new variant! |
![]() |
![]() |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Where is stuff? | Speusippus | Vanilla | 13 | January 24, 2011 23:55 |
Too much stuff. | Zappa | AAR | 26 | June 16, 2010 19:04 |
Should I be bothering to collect loot to sell? | BlackFlame | Vanilla | 14 | October 5, 2009 09:36 |
[Z2.74c] (Nightmare mode) - Suicide's Mission | quaxocal | AAR | 7 | October 24, 2008 20:24 |
[Z] Anyone ever beat the nightmare or ironman modes? | quaxocal | Variants | 8 | July 26, 2007 20:18 |