Preparing for 4.2 release
Collapse
X
-
https://tangaria.com - Angband multiplayer variant
tangaria.com/variants - Angband variants table
tangar.info - my website ⍽⍽⍽⍽⍽⍽⍽⍽⍽⍽⍽⍽
youtube.com/GameGlaz — streams in English ⍽ youtube.com/StreamGuild — streams in Russian -
-
👍 1Comment
-
https://tangaria.com - Angband multiplayer variant
tangaria.com/variants - Angband variants table
tangar.info - my website ⍽⍽⍽⍽⍽⍽⍽⍽⍽⍽⍽⍽
youtube.com/GameGlaz — streams in English ⍽ youtube.com/StreamGuild — streams in RussianComment
-
Comment
-
My version of loc_iterator can be also behind the same macro
interface. Though you have to refer to the current loc as "iter.cur"
rather than just "iter".
Code:#define loc_iterate(begin, end, iter) \ for (struct loc_iterator iter = loc_iterator(begin, end); \ loc_iterator_test(&iter); loc_iterator_next(&iter)) ... struct loc p1, p2; loc_iterate(p1, p2, iter) { foo(iter.cur); } or loc_iterate(loc(x1, y1), loc(x2, y2), iter) { foo(iter.cur); }
evaluated only once so using temporaries returned from
loc() is not a performance hit. Though you can use verbose
compound literals within parenthesis instead.
Code:loc_iterate(((struct loc) { x1, y1 }), ((struct loc) { x2, y2 }), iter) { foo(iter.cur); }
Comment
-
Comment
-
Kusunose--
Notice that the macro definition requires no subroutine calls at all. It is just a transliteration of existing code idiom into a single location. So there should be no performance hit at all. In any case, there is only a single place in the code where performance matters: in determining visible monsters, walls, and objects. No other loop matters.
Diego--
Sigh. Really fixed now.Comment
-
Comment
-
It wouldn't surprise me if modern compilers are capable of saying "Ah, you're invoking this simple function here, we can just inline it" and get the same performance as a macro. In any case, the performance hit of invoking a function is miniscule in this day and age.Comment
-
I remember that noise and smell tracking was a big bottleneck in NPP. Vanilla use those?Comment
-
It's nice but I think something like this is nicer because you can keep using for loop, though bit wordy.
Code:struct loc_iterator { struct loc cur; struct loc begin; struct loc end; }; struct loc_iterator loc_iterator(struct loc begin, struct loc end) { struct loc_iterator iter; iter.cur = iter.begin = begin; iter.end = end; return iter; } bool loc_iterator_test(const struct loc_iterator* iter) { return iter->cur.y != iter->end.y; } void loc_iterator_next(struct loc_iterator* iter) { iter->cur.x++; if (iter->cur.x == iter->end.x) { iter->cur.x = iter->begin.x; iter->cur.y++; } }
Code:for (y = y1; y < y2; y++) { for (x = x1; x < x2; x++) {
Code:for (struct loc_iterator iter = loc_iterator(loc(x1, y1), loc(x2, y2)); loc_iterator_test(&iter); loc_iterator_next(&iter)) { /* use iter.cur */ int x = iter.cur.x; int y = iter.cur.y;
Code:for (y = y1 - 1; y < y2 + 1; y++) { for (x = x1 - 1; x < x2 + 1; x++) {
Code:for (struct loc_iterator iter = loc_iterator(loc(x1 - 1, y1 - 1), loc(x2 + 1, y2 + 1)); loc_iterator_test(&iter); loc_iterator_next(&iter)) {
PWMAngband variant maintainer - check https://github.com/draconisPW/PWMAngband (or http://www.mangband.org/forum/viewforum.php?f=9) to learn more about this new variant!Comment
Comment