Angband.oook.cz
Angband.oook.cz
AboutVariantsLadderForumCompetitionComicScreenshotsFunniesLinks

Go Back   Angband Forums > Angband > Vanilla

Reply
 
Thread Tools Display Modes
Old July 10, 2007, 13:34   #1
K.I.L.E.R
Apprentice
 
Join Date: May 2007
Posts: 56
K.I.L.E.R is on a distinguished road
Looking through the code

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?
K.I.L.E.R is offline   Reply With Quote
Old July 10, 2007, 18:39   #2
Daven_26d1
Adept
 
Daven_26d1's Avatar
 
Join Date: Jun 2007
Location: North of England.
Posts: 211
Daven_26d1 is on a distinguished road
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.
__________________
You sold a Broken Sword (1d2) (-2,-4) {average} (j) for 1 gold.
The shopkeeper howls in agony!
You say "Dude, the clue is in the name...".
Daven_26d1 is offline   Reply With Quote
Old July 10, 2007, 19:56   #3
takkaria
Veteran
 
takkaria's Avatar
 
Join Date: Apr 2007
Posts: 1,951
Donated: $40
takkaria is on a distinguished road
Quote:
Originally Posted by K.I.L.E.R View Post
Sorry
No need to be, especially not in the first post in a thread.

Quote:
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/...onster1.c#L689

Are you suggestion turning it into e.g.

Code:
{ 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.
takkaria is offline   Reply With Quote
Old July 11, 2007, 03:16   #4
K.I.L.E.R
Apprentice
 
Join Date: May 2007
Posts: 56
K.I.L.E.R is on a distinguished road
You're definitely right, the logical construct would be much faster but my idea is:

Code:
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.

Last edited by K.I.L.E.R; July 11, 2007 at 03:51.
K.I.L.E.R is offline   Reply With Quote
Old July 11, 2007, 04:37   #5
Bill Peterson
Adept
 
Bill Peterson's Avatar
 
Join Date: Jul 2007
Location: Flyover country
Posts: 190
Bill Peterson is on a distinguished road
Send a message via AIM to Bill Peterson
Quote:
Originally Posted by K.I.L.E.R View Post
I'm just looking for an excuse to use mathematics.
I guess you didn't read this -

http://developers.slashdot.org/artic.../07/08/0547234

or don't agree.
Bill Peterson is offline   Reply With Quote
Old July 11, 2007, 08:01   #6
K.I.L.E.R
Apprentice
 
Join Date: May 2007
Posts: 56
K.I.L.E.R is on a distinguished road
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).
K.I.L.E.R 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
The safe_setuid code CJNyfalt Vanilla 11 June 26, 2007 03:25


All times are GMT +1. The time now is 12:49.


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