![]() |
#1 |
Rookie
Join Date: Jul 2018
Posts: 4
![]() |
Reading C code
So i've read
http://www.thangorodrim.net/developm...ing-guide.html but I was actually hoping for something more involved? Whats a good C++ source (book probably?) that can help me understand the logic behind the source code of angband? is there a more indepth guide to understanding angbands code? |
![]() |
![]() |
![]() |
#2 |
Prophet
Join Date: Dec 2009
Posts: 9,022
![]() |
First off, just to clarify: Angband is written in C, not C++.
Second, what kinds of things are you having trouble with? Do you know how to code? If not, that's where you should start. If you want to know where something specific is (e.g. "where are spells defined" or "how do I change the monster AI") then just go ahead and ask your more specific questions. If you want to figure out overall how the program works, then my advice would be to come up with some of those more specific questions, and try to figure them out. The usual way I do this is to find some in-game text that seems to be close to what I want to work on, and then search the code for that text, or a snippet of it. That should get me close to where I want to be, and then I just start tracing the program logic from there. |
![]() |
![]() |
![]() |
#3 |
Prophet
Join Date: Apr 2007
Location: Seattle, WA
Posts: 6,769
Donated: $40
![]() |
Kernighan and Richie is of course the classic. For basic programming design, it's hard to beat Design Patterns. (Some of them are used in Angband, and it really helps if you can recognize the general technique. There are some patterns that are not in the book, e.g. 'group join', which is used in the knowledge menu.)
|
![]() |
![]() |
![]() |
#4 |
Veteran
Join Date: Apr 2009
Location: Pisa / DL0
Posts: 1,023
![]() |
In any case, look for a book on C, not C++. C++ is a rabbit hole that goes as deep as the center of the Earth.
__________________
Dive fast, die young, leave a high-CHA corpse. -- You read a scroll labeled 'lol gtfo' of Teleport Level. |
![]() |
![]() |
![]() |
#5 |
Rookie
Join Date: Jul 2014
Posts: 17
![]() |
While this is for C++, if you want to learn, this site is probably one of the best I know of. (And free.)
www.learncpp.com |
![]() |
![]() |
![]() |
#6 |
Rookie
Join Date: Jul 2018
Posts: 4
![]() |
i have a hard time understanding why the folders are there and what they do in the games source code
all i know about programming i know from some javascript i know functions,assignment operators,loops,objects and i think struct in c/ c++ is just a way to create an object? thats just my guessing Code:
struct account { int account_number; char *first_name; char *last_name; float balance; }; var account = { account: undefined, first_name: undefined, last_name: undefined, balance: undefined }; Code:
bool feat_is_magma(int feat) { return tf_has(f_info[feat].flags, TF_MAGMA); } and this function is returning another function, taking the parameters of the first function (feat) and passing it and TF_MAGMA, into the inner function. but Id like to be able to see where the tf_has function is defined, but I dont know which folder to find it in, say, lib, or scripts or src Last edited by whiterhino123; July 12, 2018 at 22:53. |
![]() |
![]() |
![]() |
#7 |
Prophet
Join Date: Apr 2007
Location: Seattle, WA
Posts: 6,769
Donated: $40
![]() |
What OS are you on? You can find the definition for this function via grep on Linux, or on Windows if you have the unix tools installed (mingw or cygwin.) Windows PowerShell has it too, though the command is different. The function is declared in one or another .h file. The C file will have the corresponding definition. And you really need to look up how C works. I strongly recommend Kernighan and Ritchie. It is short and gets all the basics. Warning: C is Not object oriented. All functions are static. You can create "true" objects only with function pointers, which is done in a number of locations in Angband (Notably, in menus, spells, and commands.)
|
![]() |
![]() |
![]() |
#8 |
Rookie
Join Date: Jul 2018
Posts: 4
![]() |
thanks Pete, Could you explain how I'd find the definition with those tools?
I can search in windows for tf_has function, but that still pulls up a lot of files that have the function, meaning I still have to filter through all the files to see where it is declared, rather than called. Would grep or mingw do something differently? |
![]() |
![]() |
![]() |
#9 |
Prophet
Join Date: Apr 2007
Location: Seattle, WA
Posts: 6,769
Donated: $40
![]() |
Look at the .h files only. That is where functions are "declared", which makes them accessible from other files. So if function foo is defined in bar.c, it will be declared in bar.h
To find it: $ grep -l "foo" *.h #note: grep -l just lists files where it is present. bar.h $ <edit> bar.c or the Windows equivalent. |
![]() |
![]() |
![]() |
#10 |
Veteran
Join Date: Jun 2007
Posts: 1,391
![]() |
I would suggest trying QtCreator or a similar IDE. Then you can Ctrl-click to "go through" any function/typedef/etc. you see.
(I mean Pete's method sort-of works, but it's incredibly cumbersome for commonly used "names" and it's pointlessly tedious.) |
![]() |
![]() |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
crash on reading unknown scroll | quarague | Development | 7 | September 6, 2016 20:41 |
Reading Silmarillion | Bowman | Idle chatter | 53 | January 29, 2016 20:20 |
?Acquirement location of reading revisited | Ingwe Ingweron | Vanilla | 5 | October 20, 2014 13:56 |
Reading scrolls from inventory menu | Ingwe Ingweron | Vanilla | 1 | October 22, 2013 12:42 |
strange C code in Angband (am I reading this right?) | will_asher | Idle chatter | 3 | February 4, 2008 09:07 |