Opened 8 years ago

Last modified 7 months ago

#4211 new defect

Remove references to globals — at Version 2

Reported by: elexis Owned by:
Priority: Nice to Have Milestone: Backlog
Component: Core engine Keywords:
Cc: Patch:

Description (last modified by Silier)

Globals should be avoided in C++, since they have to be checked for initialization in most cases. Instead a static GetFoo function could be used that does that check and returns the instance.

One example would be g_Game being used in various places of source/simulation/.

Change History (2)

comment:1 by elexis, 7 years ago

The ticket was created following #3991

See 2016-09-12-QuakeNet-#0ad-dev.log:

07:52 < elexis> Itms: so Game should become a member of SimContext?
07:58 < elexis> (or how should the ref to a global be removed if we dont have a playerID member var)
08:00 <@Itms> No, Game should be accessed with a static method instead of having g_Game
08:01 <@Itms> but that's a lot of work and it's not really an issue right now
08:03 < elexis> so just GetGame() instead of g_Game? The advantage is that we dont need check whether game is initialized when refering to  that function?
08:07 <@Itms> yes, the checks and possible initializations would happen inside GetGame()

comment:2 by Silier, 6 years ago

Description: modified (diff)

WIP

Note: See TracTickets for help on using tickets.