#1 2016-06-06 02:15:42

gaya
Member

Why so many globals?

I've noticed that tesseract makes extensive use of global variables... everywhere. From engine to game code, everywhere. Is there any special reason for this?

https://websvn.tuxfamily.org/filedetail … 2Fgame.cpp
player1, players, all global.
playermodel, global.

Offline

#2 2016-06-07 06:22:36

chasester
Member

Re: Why so many globals?

So, this code is very old.

Most code in sauer is.

Whoever wrote this where originally C coders not C++ coders. So if you look at standards say 10 years ago this is proper coding. There is really no reason for this in particular just personal preference. Its written to be simi modular, but inside the modules everything is global. So instead of wrapping inside of classes of classes, and using instancing, or static functions/varibles. A namespace is declared and then all the functions relating to that module are global. This allows easy movement inside a "module" but limits access to outside modules. Its similar to an object oriented design (which you are probably use to), but instead of having class objects you have namespaces, and things are less protective. This is also the reason why there is 3 classes (idb) in the whole code base, and the keyword struct is used (struct is from C you didnt originally have classes).

Technically player1 players etc arent globals. They are just namespace globals that are externed out to other namespaces :) there are parts of the code (say physics) where you cant use player1 rather the keyword is player :P Just to be confusing.

Also a really interesting side note, every ICommand, Command, VARP etc are all globals too. if you dig through the macro code every one is defined as __dummy__##n wereas n is the function name :)

Last edited by chasester (2016-06-07 06:22:54)

Offline

Board footer