PDA

View Full Version : Looking through the code


K.I.L.E.R
July 10, 2007, 14:34
Sorry but some of the things in there really needs to be replaced with mathematical functions. For example look at line 795 in monster1.c. Surely you could construct a function to generate indices to access the string data in an array?

I'm doing that right now, but felt necessary to ask if there is an interest in rewriting code to simplify some constructs like the one mentioned?

Daven_26d1
July 10, 2007, 19:39
Don't forget that many, many coders haved hacked on Angband over the years, and the projects have generally favoured readability / ease of modification over 1337 and speedy code.

I've tried not to delve into the source too much yet myself, as I don't want to soak up too much internal workings - I'm still enjoying playing it like a closed box; however it seems to me like you might be thinking about hardcoding string data from the text files directly into arrays in the source?

If so it's worth remembering that at one point all the those hard coded tables and messy constructs were pulled out into files / rewritten so that coders and non-coders alike would have a much easier time modifying the game... its a big part of why there are so many variants.

On the other hand, if you genuinely found some way to speed up the code without detracting from clarity then go for it... I'm certain that many maintainers would integrate such patches into their own projects.

takkaria
July 10, 2007, 20:56
Sorry

No need to be, especially not in the first post in a thread. :)

but some of the things in there really needs to be replaced with mathematical functions. For example look at line 795 in monster1.c. Surely you could construct a function to generate indices to access the string data in an array?

I'm doing that right now, but felt necessary to ask if there is an interest in rewriting code to simplify some constructs like the one mentioned?

I don't understand what you mean there.

FWIW, this is the latest version of that code in the development version: http://dev.rephial.org/trac/browser/trunk/src/monster1.c#L689

Are you suggestion turning it into e.g.

{ 200, "prefers to ignore" },
{ 95, "pays very little attention to" },

If so, I don't see much benefit there -- it's used all of once and I believe it's probably quicker to use if() than to loop over an array of entries just to do the same thing. If this isn't what you had in mind, then please paste an example of the code?

BTW, suggestions on how to improve the code's clarity and patches to do the same are almost always welcome.

K.I.L.E.R
July 11, 2007, 04:16
You're definitely right, the logical construct would be much faster but my idea is:


arr[] = {"string1", "string2", "string3"}

unsigned int idx = FourierFunction()
sz = arr[idx]


It' just makes the more important code cleaner. The "FourierFunction" would be a mess though.

I've actually looked at the problem now, common sense suggests that maybe placing the conditional statement within it's own function would also achieve the exact same thing.
I'm just looking for an excuse to use mathematics.

Bill Peterson
July 11, 2007, 05:37
I'm just looking for an excuse to use mathematics.

I guess you didn't read this -

http://developers.slashdot.org/article.pl?sid=07/07/08/0547234

or don't agree. :)

K.I.L.E.R
July 11, 2007, 09:01
That article was just making a point. Personally I've become more interested in mathematics because coupled with computing knowledge you can bring down complex models into compting and mathematical representations, (aka data structures and equations).