Angband Forums (http://angband.oook.cz/forum/index.php)
-   Vanilla (http://angband.oook.cz/forum/forumdisplay.php?f=3)
-   -   Preparing for 4.2 release (http://angband.oook.cz/forum/showthread.php?t=9455)

 tangar July 31, 2019 15:36

Quote:
 Originally Posted by Nick (Post 139416) [*]Shockbolt tiles for the new foods (if someone wants to do something about the other tilesets, great)
I wonder is there a post about new food, like a list what's were added? I'm greatly interested in *band gastronomy :D

 Pete Mack July 31, 2019 15:41

Here ya go
Code:

```# define loc_iterate(p0, p1, p) \       for(p = p0; p.x < p1.x; p.x++) \             for(p.y = p0.y; p.y < p1.y; p.y++) .....       point p0 ,p1, p;       loc_iterate(p0, p1, p)           foo(p);```
Edit: fixed for correctness, thanks Diego

 wobbly July 31, 2019 16:43

Quote:
 Originally Posted by tangar (Post 139443) I wonder is there a post about new food, like a list what's were added? I'm greatly interested in *band gastronomy :D
They'll be in object.txt

Just taking a quick peek, there's: kobold entrails, jackal "steak", blue worm broth, fried grey rat on a stick ….

 tangar July 31, 2019 16:50

Quote:
 Originally Posted by wobbly (Post 139445) They'll be in object.txt Just taking a quick peek, there's: kobold entrails, jackal "steak", blue worm broth, fried grey rat on a stick ….
Thanks :) This sounds delicious :D

 Diego Gonzalez July 31, 2019 16:54

Quote:
 Originally Posted by Pete Mack (Post 139444) Here ya go Code: ```# define loc_iterate(p0, p1, p) \       for(p = p0; p.x < p1.x; p.x++) \             for(; p.y < p1.y; p.y++) .....       point p0 ,p1, p;       loc_iterate(p0, p1, p)           foo(p);```
You must reset the y coordinate in the inner loop. I like your solution. Very C-ish ;)

 Pete Mack July 31, 2019 16:58

Thanks Diego. Fixed the loop in original. And yeah, macros kind of suck as an alternate to more modern techniques. But in C, you get no choice.

 Kusunose July 31, 2019 21:16

Quote:
 Originally Posted by Pete Mack (Post 139444) Here ya go Code: ```# define loc_iterate(p0, p1, p) \       for(p = p0; p.x < p1.x; p.x++) \             for(p.y = 0; p.y < p1.y; p.y++) .....       point p0 ,p1, p;       loc_iterate(p0, p1, p)           foo(p);``` Edit: fixed for correctness, thanks Diego
It's nice and short.

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);         }```
An advantage of my version is that "begin" and "end" are
evaluated only once so using temporaries returned from
loc() is not a performance hit. Though you can use verbose
Code:

```        loc_iterate(((struct loc) { x1, y1 }), ((struct loc) { x2, y2 }), iter) {                 foo(iter.cur);         }```

 Diego Gonzalez July 31, 2019 21:46

Quote:
 Originally Posted by Pete Mack (Post 139448) Thanks Diego. Fixed the loop in original. And yeah, macros kind of suck as an alternate to more modern techniques. But in C, you get no choice.
p.y = p0.y

;)

 Gwarl July 31, 2019 23:05

For my part the nested for loops are intuitive and I know what they do but the custom iterators look unreadable

 Pete Mack July 31, 2019 23:31

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.

All times are GMT +1. The time now is 05:10.