![]() |
#301 | |
Knight
Join Date: Mar 2015
Location: Moscow, Russia
Posts: 553
![]() |
Quote:
![]()
__________________
http://tangaria.com - persistent online multiplayer roguelike game tangar.info - my website ⍽⍽⍽⍽⍽⍽⍽⍽⍽⍽⍽⍽ My chars @ angband.oook.cz youtube.com/GlazGame — streams in English ⍽ youtube.com/StreamGuild — streams in Russian |
|
![]() |
![]() |
![]() |
#302 |
Prophet
Join Date: Apr 2007
Location: Seattle, WA
Posts: 5,420
Donated: $40
![]() |
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); Last edited by Pete Mack; July 31, 2019 at 22:52. |
![]() |
![]() |
![]() |
#303 |
Veteran
Join Date: May 2012
Location: Adelaide, Australia
Posts: 2,109
![]() |
|
![]() |
![]() |
![]() |
#304 | |
Knight
Join Date: Mar 2015
Location: Moscow, Russia
Posts: 553
![]() |
Quote:
![]() ![]()
__________________
http://tangaria.com - persistent online multiplayer roguelike game tangar.info - my website ⍽⍽⍽⍽⍽⍽⍽⍽⍽⍽⍽⍽ My chars @ angband.oook.cz youtube.com/GlazGame — streams in English ⍽ youtube.com/StreamGuild — streams in Russian |
|
![]() |
![]() |
![]() |
#305 |
Apprentice
Join Date: May 2007
Posts: 63
![]() |
|
![]() |
![]() |
![]() |
#306 |
Prophet
Join Date: Apr 2007
Location: Seattle, WA
Posts: 5,420
Donated: $40
![]() |
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.
|
![]() |
![]() |
![]() |
#307 | |
Rookie
Join Date: Jan 2019
Posts: 6
![]() |
Quote:
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); } |
|
![]() |
![]() |
![]() |
#308 |
Apprentice
Join Date: May 2007
Posts: 63
![]() |
|
![]() |
![]() |
![]() |
#309 |
Knight
Join Date: Jan 2017
Posts: 778
![]() |
For my part the nested for loops are intuitive and I know what they do but the custom iterators look unreadable
|
![]() |
![]() |
![]() |
#310 |
Prophet
Join Date: Apr 2007
Location: Seattle, WA
Posts: 5,420
Donated: $40
![]() |
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. |
![]() |
![]() |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
First release | Quirk | Sil | 18 | November 14, 2017 23:45 |
3.4.0 Release Candidate is available | fizzix | Vanilla | 111 | July 5, 2012 13:39 |
3.2 release candidate is upon us! | d_m | Vanilla | 147 | January 19, 2011 11:10 |
Release HellBand 0.8.7 | konijn_ | Variants | 4 | December 27, 2009 05:14 |
reactions to changes in new V release | will_asher | Vanilla | 50 | April 9, 2008 19:47 |