Angband.oook.cz
Angband.oook.cz
AboutVariantsLadderForumCompetitionComicScreenshotsFunniesLinks

Go Back   Angband Forums > Angband > Development

Reply
 
Thread Tools Display Modes
Old July 18, 2010, 12:02   #1
Timo Pietilä
Prophet
 
Join Date: Apr 2007
Location: Climbing up from hole I just dug.
Posts: 4,093
Timo Pietilä is on a distinguished road
Angband code for dummies?

I used to be able to interpreter vanilla angband code and what does what, but currently I find it more a uncommented spaghetti code that is impossible to follow. Is there any Angband code for dummies around? Some sort of flowchart that tells which function is doing what? Which files have which purpose? Anything?
Timo Pietilä is offline   Reply With Quote
Old July 18, 2010, 15:50   #2
konijn_
Hellband maintainer
 
konijn_'s Avatar
 
Join Date: Jul 2007
Location: New York, the Big Apple
Age: 41
Posts: 367
Donated: $120
konijn_ is on a distinguished road
Quote:
Originally Posted by Timo Pietilä View Post
I used to be able to interpreter vanilla angband code and what does what, but currently I find it more a uncommented spaghetti code that is impossible to follow. Is there any Angband code for dummies around? Some sort of flowchart that tells which function is doing what? Which files have which purpose? Anything?
Ew, can you point us to some places that you found not documented enough to or too spaghetti-like ?

T.
__________________
* Are you ready for something else ? Hellband 0.8.8 is out! *
konijn_ is offline   Reply With Quote
Old July 18, 2010, 15:57   #3
Timo Pietilä
Prophet
 
Join Date: Apr 2007
Location: Climbing up from hole I just dug.
Posts: 4,093
Timo Pietilä is on a distinguished road
Quote:
Originally Posted by konijn_ View Post
Ew, can you point us to some places that you found not documented enough to or too spaghetti-like ?

T.
Everywhere. File relations, function relations etc. For example I need to look inside three different files to figure out simple damage calculation for manastorm: what exactly does it do, and I'm not sure that is even enough. Nobody can figure out that without some help or memorizing out every single file what they contain.
Timo Pietilä is offline   Reply With Quote
Old July 18, 2010, 18:10   #4
Derakon
Prophet
 
Derakon's Avatar
 
Join Date: Dec 2009
Posts: 8,500
Derakon is on a distinguished road
Hm, I'm generally able to find what I need, by searching for a string I know occurs in-game, and then working back from there. For example, if I want to look up shards damage, I would search for "You are hit by something sharp!" (the message you get when hit by shards while blind), which would get me to the code that processes shards hits, and I can search for what calls that function, and find one for breathing which refers to BR_SHAR_MAX, which I can search for to find that the damage cap for shards is 500.

Ultimately it's mostly a matter of being good at using search utilities. I will freely admit that Angband would be easier for me to read if it had a more object-oriented design, mostly because that's the kind of design I'm used to dealing with. But we'd need a full-on recoding effort to make that happen. I'd recommend just learning how to navigate unfamiliar code that isn't laid out the way you expect. If you're expecting to program as part of your career, it's a skill that will hold you in good stead.
Derakon is offline   Reply With Quote
Old July 18, 2010, 18:18   #5
Timo Pietilä
Prophet
 
Join Date: Apr 2007
Location: Climbing up from hole I just dug.
Posts: 4,093
Timo Pietilä is on a distinguished road
Quote:
Originally Posted by Derakon View Post
I'd recommend just learning how to navigate unfamiliar code that isn't laid out the way you expect. If you're expecting to program as part of your career, it's a skill that will hold you in good stead.
A flowchart of somekind would help as well as documentation what is the purpose of each file.

I already have IT career (have been over a decade now), but all I need is some scripting skills which I already have.
Timo Pietilä is offline   Reply With Quote
Old July 18, 2010, 21:25   #6
Magnate
Angband Devteam member
 
Join Date: May 2007
Location: London, UK
Posts: 5,057
Magnate is on a distinguished road
Send a message via MSN to Magnate Send a message via Yahoo to Magnate
Quote:
Originally Posted by Timo Pietilä View Post
A flowchart of somekind would help as well as documentation what is the purpose of each file.

I already have IT career (have been over a decade now), but all I need is some scripting skills which I already have.
It's not that difficult. Start with main.c, find the function called "main". See that it does init_stuff, makes paths, processes command line arguments, sorts out gfx and sound, then calls play_game. Now, at this point it's not clear which file play_game is in - this is a fair cop. I use a grep alias which searches recursively through src/, so "grip play_game *" tells me it's in dungeon.c (if you're a programmer then your favourite IDE will do this much more easily than using grep).

So you open up dungeon.c and find play_game, and you notice that everything else follows from there. In general, the z-* files are the really low level things - messing with numbers, strings and files. The subdirs player/, object/ and monster/ are pretty self-explanatory. I guess the tricky stuff is in the cmdX.c files, which take a bit of getting used to.
Magnate is offline   Reply With Quote
Old July 18, 2010, 21:53   #7
Derakon
Prophet
 
Derakon's Avatar
 
Join Date: Dec 2009
Posts: 8,500
Derakon is on a distinguished road
Quote:
Originally Posted by Magnate View Post
(if you're a programmer then your favourite IDE will do this much more easily than using grep).
My favorite IDE is grep. ¬.¬
Derakon is offline   Reply With Quote
Old July 18, 2010, 23:40   #8
Timo Pietilä
Prophet
 
Join Date: Apr 2007
Location: Climbing up from hole I just dug.
Posts: 4,093
Timo Pietilä is on a distinguished road
Quote:
Originally Posted by Magnate View Post
It's not that difficult. Start with main.c ... it's not clear which file play_game is in - this is a fair cop. I use a grep alias ... open up dungeon.c and find play_game, and you notice that everything else follows from there
In other words in order to find something you need to memorize entire code or if not that do multiple searches for every single function in order to figure out what they do.

A spaghetti code. A very hard to figure out spaghetti code.

Except maybe if you are a professional coder.
Timo Pietilä is offline   Reply With Quote
Old July 19, 2010, 00:03   #9
Ycombinator
Adept
 
Join Date: Apr 2010
Location: Zürich, Switzerland
Age: 30
Posts: 156
Ycombinator is on a distinguished road
IMO Angband is in pretty much good shape for a 20-year old C project maintained by a team of volunteers.
I think the biggest source of complexity isn't the hairy call graph (grep and ctags really rock at finding what is where), but lots of global state and inherent algorithmic complexity of some parts of the code.
Ycombinator is offline   Reply With Quote
Old July 19, 2010, 02:01   #10
Pete Mack
Prophet
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 4,981
Donated: $40
Pete Mack is on a distinguished road
Timo, I think you are wrong on this.
It used to be, the damage calculation was mixed up in the code, and if you changed how (say) darkness worked, you would have to change code in two or three places.
Now it's all in a single .h file.
It could be better (and is, in NPP and Un). But it's much better than it was.

My preference would be to have spell and breath damage in a single .txt (or .xml) file.

The recent complaint about poison damage is an exception to the rule: the .H file was wrong. The complaint about that was well taken.

But the code is certainly less spaghetti-like than it was in 3.0.6
Pete Mack 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
Trying to understand the Angband 3.X source code nppangband Development 62 July 11, 2010 19:20
Angband Code Interface to GUI meeshoo Vanilla 50 February 3, 2009 18:18
strange C code in Angband (am I reading this right?) will_asher Idle chatter 3 February 4, 2008 10:07
Updating Vanilla for dummies Dragonboneman Vanilla 7 August 12, 2007 23:12
Looking through the code K.I.L.E.R Vanilla 5 July 11, 2007 09:01


All times are GMT +1. The time now is 14:36.


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