Angband.oook.cz
Angband.oook.cz
AboutVariantsLadderForumCompetitionComicScreenshotsFunniesLinks

Go Back   Angband Forums > Angband > Vanilla

Reply
 
Thread Tools Display Modes
Old July 31, 2019, 23:27   #311
Pete Mack
Prophet
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 5,348
Donated: $40
Pete Mack is on a distinguished road
Gwarl--
Custom loop iterator functions don't make a lot of sense in C. They are great in C# and other languages with anonymous and/or lambda functions.

Quote:
Originally Posted by Gwarl View Post
For my part the nested for loops are intuitive and I know what they do but the custom iterators look unreadable
Pete Mack is online now   Reply With Quote
Old August 1, 2019, 00:25   #312
Derakon
Prophet
 
Derakon's Avatar
 
Join Date: Dec 2009
Posts: 8,876
Derakon is on a distinguished road
Quote:
Originally Posted by Pete Mack View Post
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.
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.
Derakon is offline   Reply With Quote
Old August 1, 2019, 02:11   #313
Diego Gonzalez
Apprentice
 
Join Date: May 2007
Posts: 58
Diego Gonzalez is on a distinguished road
Quote:
Originally Posted by Pete Mack View Post
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.
You are right. Early optimization was always a hidden enemy in programming...

I remember that noise and smell tracking was a big bottleneck in NPP. Vanilla use those?
Diego Gonzalez is offline   Reply With Quote
Old August 1, 2019, 02:35   #314
Pete Mack
Prophet
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 5,348
Donated: $40
Pete Mack is on a distinguished road
Yeah, that is sometimes a problem, too. But it was the illumination code that used to have "show reduced light radius while running" performance optimization. And it is running--and only runnning--where performance matters.
Pete Mack is online now   Reply With Quote
Old August 1, 2019, 10:46   #315
PowerWyrm
Prophet
 
PowerWyrm's Avatar
 
Join Date: Apr 2008
Posts: 2,653
PowerWyrm is on a distinguished road
Quote:
Originally Posted by Kusunose View Post
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++;
	}
}
This code
Code:
	for (y = y1; y < y2; y++) {
		for (x = x1; x < x2; x++) {
can be translated as
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;
and this
Code:
	for (y = y1 - 1; y < y2 + 1; y++) {
		for (x = x1 - 1; x < x2 + 1; x++) {
can be translated as
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)) {
Values for initializers and conditions can be directly translated, provided conditions are exclusive (if inclusive, add +1 for x and y for loc end).
It is indeed much nicer. I've updated my iterator to reflect on this, keeping pointers instead of structures because I don't like passing structs to functions.
__________________
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!
PowerWyrm is offline   Reply With Quote
Old August 1, 2019, 10:48   #316
Gwarl
Knight
 
Join Date: Jan 2017
Posts: 730
Gwarl is on a distinguished road
Quote:
Originally Posted by Pete Mack View Post
Yeah, that is sometimes a problem, too. But it was the illumination code that used to have "show reduced light radius while running" performance optimization. And it is running--and only runnning--where performance matters.
Not quite true, resting near a pack of hounds that you can't see also take a while.

But what you're saying makes sense and is interesting.
Gwarl is offline   Reply With Quote
Old August 1, 2019, 14:44   #317
Pete Mack
Prophet
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 5,348
Donated: $40
Pete Mack is on a distinguished road
Fair enough. Running, resting and digging near a vault. They all share the same issue: multiple turns in a single command. Running is the one most used, and digging the one most likely to be slowed by monsters.
Pete Mack is online now   Reply With Quote
Old August 1, 2019, 14:56   #318
Diego Gonzalez
Apprentice
 
Join Date: May 2007
Posts: 58
Diego Gonzalez is on a distinguished road
Quote:
Originally Posted by Pete Mack View Post
Fair enough. Running, resting and digging near a vault. They all share the same issue: multiple turns in a single command. Running is the one most used, and digging the one most likely to be slowed by monsters.
The amount of visible subwindows (monsters, objetcs) also affects the performance of running. Sometimes too many redraws is a problem. Perhaps this was solved long ago with an optimization. I don't remember.
Diego Gonzalez is offline   Reply With Quote
Old August 1, 2019, 15:00   #319
Pete Mack
Prophet
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 5,348
Donated: $40
Pete Mack is on a distinguished road
Hmm. Redrawing subwindows when the command line is inactive seems particularly useless. Definitely worth checking.
Pete Mack is online now   Reply With Quote
Old August 1, 2019, 17:41   #320
khearn
Rookie
 
Join Date: Jul 2007
Posts: 18
khearn is on a distinguished road
Quote:
Originally Posted by Derakon View Post
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.
Back in the early 90's, I was working in a group doing compiler optimization, and function inlining was definitely a thing way back then.
khearn is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
First release Quirk Sil 18 November 14, 2017 22:45
3.4.0 Release Candidate is available fizzix Vanilla 111 July 5, 2012 12:39
3.2 release candidate is upon us! d_m Vanilla 147 January 19, 2011 10:10
Release HellBand 0.8.7 konijn_ Variants 4 December 27, 2009 04:14
reactions to changes in new V release will_asher Vanilla 50 April 9, 2008 18:47


All times are GMT +1. The time now is 04:18.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.