Page 1 of 1

A few questions about FreeOrion programming

Posted: Sat Apr 29, 2017 1:53 am
by Voyager
I am learning C++ and I am curious to know a few things about the games code. How many source files does FreeOrion use? About how many functions does the game use in the code? How long basically is the games code? I am at still just learning so I don't know how advanced the code in this game is. Do my questions make sense? I just know that a function is a group of statements with a certain job to do, and that many source files may be used for organizational purposes. That's where my questions stem from, some basic knowledge.

Re: A few questions about FreeOrion programming

Posted: Sat Apr 29, 2017 3:02 am
by Dilvish
Your questions make sense in terms of semantics, but a quick check of the FO executable and associated libraries should tell you that FO is complex enough that we couldn't answer those "how many" questions from mere visual inspection, and there is not enough point to them for my IDE to even offer me a report of the statistics you ask about.

You can peruse or download/clone the code from our GitHub repository.

Re: A few questions about FreeOrion programming

Posted: Sat Apr 29, 2017 4:57 am
by dbenage-cx
It may be down for scheduled maintenance today, but some of that info can be seen on https://www.openhub.net/p/freeorion

Re: A few questions about FreeOrion programming

Posted: Sat Apr 29, 2017 6:01 am
by defaultuser
From what I know of C++ work, the answer for a project as complex as this would be "lots and lots".

Re: A few questions about FreeOrion programming

Posted: Sat Apr 29, 2017 8:55 am
by Geoff the Medio
Not all of it should "count", but a quick search for *.cpp lists 250 files. *.h lists 237 files. This is an incomplete count of "source" files, however.

Re: A few questions about FreeOrion programming

Posted: Sat Apr 29, 2017 9:14 am
by adrian_broher
Voyager wrote:How many source files does FreeOrion use?
Around 561 C++ and Python files with GG included. Without GG it's around 433 files. GG is the UI library we use and should be considered a separate project which just happen to live inside the FreeOrion source tree. This is not an exact number as there are probably Python scripts in this result that are not part of the game but utilities to build the project or do other utility non-game related thingies.

Code: Select all

find -type f -iname '*.h' -or -iname '*.cpp' -or -iname '*.hpp' -or -iname '*.ipp' -or -iname '*.py' | wc -l
About how many functions does the game use in the code?
Around 1936 python functions within default/python. Around 4122 C++ functions (class members or not) for FreeOrion only, around 6012 for FreeOrion and GG. However the method of measurement may gobble up inlined functions and I didn't clear out some symbols that are compiler internal, but that's around 10 or so.

Code: Select all

grep -r '\<def\>' default/python/ | wc -l

Code: Select all

# needs to be compiled without -fvisibility=hidden
# FreeOrion only
nm -D --demangle --defined-only freeorion libfreeorion* | grep -vE '(\<(boost|std|vtable|typeinfo|GG|thunk|utf8)\>|_br_)' | grep -E '\<[TW]\>' | cut -c 20- | sort -u | wc -l
# FreeOrion + GG
nm -D --demangle --defined-only freeorion libfreeorion* libGiGi* | grep -vE '(\<(boost|std|vtable|typeinfo|thunk|utf8)\>|_br_)' | grep -E '\<[TW]\>' | cut -c 20- | sort -u | wc -l
How long basically is the games code?
sloccount reports the following source lines of code, but I didn't bother code check if it counts the right thing:

Code: Select all

$ sloccount .
# … left out for brevity …
Totals grouped by language (dominant language first):
cpp:         150985 (88.65%)
python:       18691 (10.97%)
ansic:          645 (0.38%)
I am at still just learning so I don't know how advanced the code in this game is.
I would consider this Project medium sized by contributors and general metrics. The code is more complex as we use some advanced language features and have an average amount of code cruft and inconsistencies due to project age.
Do my questions make sense? I just know that a function is a group of statements with a certain job to do, and that many source files may be used for organizational purposes. That's where my questions stem from, some basic knowledge.
That depends on what knowledge you want to gain. The questions you asked do make sense by itself, but they are mostly of technical nature and are only interesting for project management.

Re: A few questions about FreeOrion programming

Posted: Sat Apr 29, 2017 9:30 am
by Oberlus
adrian_broher wrote:

Code: Select all

find -type f -iname '*.h' -or -iname '*.cpp' -or -iname '*.hpp' -or -iname '*.ipp' -or -iname '*.py' | wc -l

Code: Select all

grep -r '\<def\>' default/python/ | wc -l

Code: Select all

# needs to be compiled without -fvisibility=hidden
# FreeOrion only
nm -D --demangle --defined-only freeorion libfreeorion* | grep -vE '(\<(boost|std|vtable|typeinfo|GG|thunk|utf8)\>|_br_)' | grep -E '\<[TW]\>' | cut -c 20- | sort -u | wc -l
# FreeOrion + GG
nm -D --demangle --defined-only freeorion libfreeorion* libGiGi* | grep -vE '(\<(boost|std|vtable|typeinfo|thunk|utf8)\>|_br_)' | grep -E '\<[TW]\>' | cut -c 20- | sort -u | wc -l

Code: Select all

$ sloccount .
Although I'm using Linux since I finished my degree in 2005, half of this commands (sloccount, nm) I haven't ever seen. Good to know!

Re: A few questions about FreeOrion programming

Posted: Sat Apr 29, 2017 9:41 am
by adrian_broher
Oberlus wrote:Although I'm using Linux since I finished my degree in 2005, half of this commands (sloccount, nm) I haven't ever seen. Good to know!
Here, have two additional ones:

Code: Select all

$ whatis -s 1 sloccount nm cut find grep cut sort wc
sloccount (1)        - count source lines of code (SLOC)
nm (1p)              - write the name list of an object file (DEVELOPMENT)
nm (1)               - list symbols from object files
cut (1p)             - cut out selected fields of each line of a file
cut (1)              - remove sections from each line of files
find (1p)            - find files
find (1)             - search for files in a directory hierarchy
grep (1p)            - search a file for a pattern
grep (1)             - print lines matching a pattern
sort (1p)            - sort, merge, or sequence check text files
sort (1)             - sort lines of text files
wc (1p)              - word, line, and byte or character count
wc (1)               - print newline, word, and byte counts for each file

Code: Select all

$ apropos -a count lines
sloccount (1)        - count source lines of code (SLOC)