A few questions about FreeOrion programming

Discussion about the project in general, organization, website, or any other details that aren't directly about the game.
Post Reply
Message
Author
Voyager
Space Krill
Posts: 4
Joined: Sun Apr 16, 2017 4:29 pm

A few questions about FreeOrion programming

#1 Post 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.

User avatar
Dilvish
AI Lead and Programmer Emeritus
Posts: 4768
Joined: Sat Sep 22, 2012 6:25 pm

Re: A few questions about FreeOrion programming

#2 Post 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.
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

dbenage-cx
Programmer
Posts: 389
Joined: Sun Feb 14, 2016 12:08 am

Re: A few questions about FreeOrion programming

#3 Post 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

defaultuser
Juggernaut
Posts: 854
Joined: Wed Aug 26, 2015 6:15 pm

Re: A few questions about FreeOrion programming

#4 Post by defaultuser »

From what I know of C++ work, the answer for a project as complex as this would be "lots and lots".

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: A few questions about FreeOrion programming

#5 Post 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.

User avatar
adrian_broher
Programmer
Posts: 1156
Joined: Fri Mar 01, 2013 9:52 am
Location: Germany

Re: A few questions about FreeOrion programming

#6 Post 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.
Resident code gremlin
Attached patches are released under GPL 2.0 or later.
Git author: Marcel Metz

User avatar
Oberlus
Cosmic Dragon
Posts: 5714
Joined: Mon Apr 10, 2017 4:25 pm

Re: A few questions about FreeOrion programming

#7 Post 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!

User avatar
adrian_broher
Programmer
Posts: 1156
Joined: Fri Mar 01, 2013 9:52 am
Location: Germany

Re: A few questions about FreeOrion programming

#8 Post 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)
Resident code gremlin
Attached patches are released under GPL 2.0 or later.
Git author: Marcel Metz

Post Reply