Open-Source Grand Strategy Game

Open-Source Grand Strategy Game

Postby Andrettin » 04 Aug 2019, 21:10

I am a big fan of grand strategy games, like those made by Paradox Interactive, which have a (pausable) real-time flow.

For Civilization we have FreeCiv, but for grand strategy there doesn't really seem to be an established open-source alternative. Any ideas as to why? The genre would seem to be very apt for an open-source game, since it doesn't require huge teams, and there is a lot of potential for contributions for the database and graphics.

In the absence of an established open-source GS game, I've begun working on my own GS engine, Metternich, programmed in C++ and using the Qt framework for the UI and such.
Andrettin
Wyrmsun Moderator
 
Posts: 220
Joined: 29 Mar 2015, 19:26

Re: Open-Source Grand Strategy Game

Postby fluffrabbit » 04 Aug 2019, 21:30

Great! Maybe add some documentation and move some of those files out of the root directory. I'm kinda lost as to where to start.
fluffrabbit
 
Posts: 448
Joined: 11 Apr 2019, 11:17

Re: Open-Source Grand Strategy Game

Postby Huitsi » 04 Aug 2019, 21:53

I enjoyed EU3/4 but I've been too frustrated with Paradox's DLC spam to play them for some years now. This project is thus extremely welcome. Some documentation would indeed be nice, especially on how to get started with building for those of us less versed in Qt and C++. Also, some general description of the current state of the project would be nice. I can see you have a lot of files but that doesn't tell me much.
User avatar
Huitsi
 
Posts: 8
Joined: 25 Jul 2018, 23:45

Re: Open-Source Grand Strategy Game

Postby Julius » 04 Aug 2019, 22:17

There is TripleA: https://triplea-game.org/
(but if I remember correctly it is turn-based)
User avatar
Julius
Community Moderator
 
Posts: 2550
Joined: 06 Dec 2009, 14:02

Re: Open-Source Grand Strategy Game

Postby dulsi » 04 Aug 2019, 22:57

I took a look at a list of grand strategy games on wikipedia. I don't think I've played any beyond Romance of the Three Kingdoms and Nobanaga's Ambition.

What do you want to see in a grand strategy game? For detailing your project, you might want to consider posting in the project showcase forum. (Or simply ask the admins move this thread there).
dulsi
 
Posts: 291
Joined: 18 Feb 2016, 15:24

Re: Open-Source Grand Strategy Game

Postby Andrettin » 06 Aug 2019, 21:12

fluffrabbit {l Wrote}:Great! Maybe add some documentation and move some of those files out of the root directory. I'm kinda lost as to where to start.


Huitsi {l Wrote}:I enjoyed EU3/4 but I've been too frustrated with Paradox's DLC spam to play them for some years now. This project is thus extremely welcome. Some documentation would indeed be nice, especially on how to get started with building for those of us less versed in Qt and C++. Also, some general description of the current state of the project would be nice. I can see you have a lot of files but that doesn't tell me much.


Thanks! I've added build instructions to the readme. Since there are no dependencies other than Qt, the process is relatively straightforward; the more bothersome aspect is the long time it takes to download and install Qt.

As for the current state of the project, it is still very early in development. Right now the engine is capable of processing character, country and province databases (along with a province map), including history, and provide a political map for the start date. Here is a screenshot (featuring beautiful programmer art):

Image

Most of the land in the map is black because provinces haven't been drawn in the province map for those areas yet.

About the lack of documentation, do you mean that there isn't an overview, or something else?

Julius {l Wrote}:There is TripleA: https://triplea-game.org/
(but if I remember correctly it is turn-based)


That one looks nice, thanks for posting it! I played with it a bit, but it looks to be almost solely focused on war, rather than containing a sphere of domestic development as well.

dulsi {l Wrote}:I took a look at a list of grand strategy games on wikipedia. I don't think I've played any beyond Romance of the Three Kingdoms and Nobanaga's Ambition.

What do you want to see in a grand strategy game? For detailing your project, you might want to consider posting in the project showcase forum. (Or simply ask the admins move this thread there).


Good idea :) This post was more intended to discuss open-source grand strategy in general, so I will make a new one about the project itself in the showcase forum later on :)
Andrettin
Wyrmsun Moderator
 
Posts: 220
Joined: 29 Mar 2015, 19:26

Re: Open-Source Grand Strategy Game

Postby Huitsi » 07 Aug 2019, 12:02

Andrettin {l Wrote}:I've added build instructions to the readme.

Thank you for the instructions. I tried to build the project with my distro-provided Qt Creator and Qt (supposedly 5.13) but unfortunately ran into some errors.

First I got some erros like:
{l Code}: {l Select All Code}
[--]Metternich/map/province.h:154: error: declaration of ‘Metternich::Religion* Metternich::Province::Religion’ changes meaning of ‘Religion’ [-fpermissive]
  154 |  Religion *Religion = nullptr;
      |            ^~~~~~~~

which I was able to turn into warnings by adding
{l Code}: {l Select All Code}
QMAKE_CXXFLAGS += -fpermissive
to the .pro-file.

Then I got a
{l Code}: {l Select All Code}
[--]Metternich/database/gsml_data.h:55: error: ‘sort’ is not a member of ‘std’
   55 |   std::sort(this->Children.begin(), this->Children.end(), [](GSMLData &a, GSMLData &b) {
      |        ^~~~

which I solved by adding
{l Code}: {l Select All Code}
#include <algorithm>
to that file.

Now I get a bunch of erros like:
{l Code}: {l Select All Code}
/usr/include/c++/9/type_traits:672: error: invalid use of incomplete type ‘class QVariant’
  672 |     struct is_trivial
      |            ^~~~~~~~~~

and am stumped. How is there an error in a distro-provided include file?

Andrettin {l Wrote}:About the lack of documentation, do you mean that there isn't an overview, or something else?

An overview would be a good start. I'm also thinking about information on how the game is supposed to work ("grand strategy" only tells so much) and how you add stuff to or "mod" the game.
User avatar
Huitsi
 
Posts: 8
Joined: 25 Jul 2018, 23:45

Re: Open-Source Grand Strategy Game

Postby Andrettin » 07 Aug 2019, 18:54

Thanks for the feedback!

Huitsi {l Wrote}:Thank you for the instructions. I tried to build the project with my distro-provided Qt Creator and Qt (supposedly 5.13) but unfortunately ran into some errors.

First I got some erros like:
{l Code}: {l Select All Code}
[--]Metternich/map/province.h:154: error: declaration of ‘Metternich::Religion* Metternich::Province::Religion’ changes meaning of ‘Religion’ [-fpermissive]
  154 |  Religion *Religion = nullptr;
      |            ^~~~~~~~

which I was able to turn into warnings by adding
{l Code}: {l Select All Code}
QMAKE_CXXFLAGS += -fpermissive
to the .pro-file.


I am compiling the engine with MSVC, which doesn't issue an error for that. I changed those variable definitions now to use the type's namespace:
https://github.com/Andrettin/Metternich ... 3a2cbfbd9d

Does that fix the error for you?

Then I got a
{l Code}: {l Select All Code}
[--]Metternich/database/gsml_data.h:55: error: ‘sort’ is not a member of ‘std’
   55 |   std::sort(this->Children.begin(), this->Children.end(), [](GSMLData &a, GSMLData &b) {
      |        ^~~~

which I solved by adding
{l Code}: {l Select All Code}
#include <algorithm>
to that file.


It looks like <filesystem> (which is included in that file) includes <algorithm> as well with MSVC, hence why I didn't get that error. Thanks for the heads up, I've fixed the issue now!

Now I get a bunch of erros like:
{l Code}: {l Select All Code}
/usr/include/c++/9/type_traits:672: error: invalid use of incomplete type ‘class QVariant’
  672 |     struct is_trivial
      |            ^~~~~~~~~~

and am stumped. How is there an error in a distro-provided include file?


<QVariant> wasn't included in the province.h header file, which is why you got the error. The file compiled alright for me because I am using precompiled headers. I had taken care to make the engine compile without PCH, but I missed that one, so thanks for letting me know! Apparently QMAKE doesn't use the define for precompiled headers under GCC by default, but they can be activated if so desired.

As an aside, I am using precompiled headers *only* for library headers, so that there isn't the risk of triggering a full recompilation just because a piece of code was changed in one of the application's headers. I added the missing include in this commit here (along with <algorithm> in the file noted above):
https://github.com/Andrettin/Metternich ... 4642208cb0

About the lack of documentation, do you mean that there isn't an overview, or something else?

An overview would be a good start. I'm also thinking about information on how the game is supposed to work ("grand strategy" only tells so much) and how you add stuff to or "mod" the game.[/quote]

I have a data repository for the game itself as well, Iron Barons.

The game is intended to be a character-driven grand strategy game set in the 19th century.

To run the game, just set its directory as the working directory when running the engine; you can set the working directory in the Qt Creator by going to Projects->Run. Note that the setting is not saved by the Qt Creator between debug and release configurations, so it has to be set for each of them if you want to use both.

Most of what the engine can do so far is used there.

In the /data/commons/ files, the following can be done:
* Defining cultures and culture groups, as well as personal name lists for them
* Defining dynasties for characters
* Defining holding types (e.g. settlements in a province)
* Defining landed titles/countries, which are ranked in a barony/county/duchy/kingdom/empire tier system, along with their map color, de jure liege and capital province
* Defining provinces, detailing what is their respective county landed title, and what is their color in the provincial map (/map/provinces.png)
* Defining religions
* Defining character traits
* In defines.txt, delineating the start date and player character (as there isn't a main menu yet; right now when the game starts it goes directly to the map)

And in /data/history/:
* Defining historical characters, with their dynasty, culture, religion, traits, and birth/death dates; note that character aspects can be changed in a given date (e.g. a trait added in a given date); the existing character definitions are the result of my own research, mostly in the Almanach de Gotha for 1815
* Defining landed title history, e.g. who is the title's holder in a given date
* Defining province history, detailing the province's culture and religion (and their changes in given dates), as well as which settlements exist in the province

The whole database is licensed under the CC0.

In /graphics/ there are a number of resource icons I commissioned from an artist (Jinn), and which are currently unused in the game (since I haven't gotten to deal with resources yet).

in /localization/ the translations for the localization tags are defined. Culture and culture group specific names for landed titles are supported, e.g.:
{l Code}: {l Select All Code}
d_carinthia = "Carinthia"
d_carinthia_german = "Kärnten"


In /map/ there is a terrain map, as well as a province map. The province map only has a few provinces drawn so far, all in Austria as of yet; I am drawing more by hand as I go along.
https://www.lib.utexas.edu/maps/histori ... 58-159.jpg

In the root directory are some QML files, which define how the interface works.
Andrettin
Wyrmsun Moderator
 
Posts: 220
Joined: 29 Mar 2015, 19:26

Re: Open-Source Grand Strategy Game

Postby Huitsi » 08 Aug 2019, 12:26

Andrettin {l Wrote}:Does that fix the error for you?

That particular one seem to be gone, but I still get others like it:
{l Code}: {l Select All Code}
Metternich/culture/culture.h:46: error: declaration of ‘Metternich::CultureGroup* Metternich::Culture::CultureGroup’ changes meaning of ‘CultureGroup’ [-fpermissive]
   46 |  Metternich::CultureGroup *CultureGroup = nullptr;
      |                            ^~~~~~~~~~~~
Metternich/character/dynasty.h:32: error: declaration of ‘Metternich::Culture* Metternich::Dynasty::Culture’ changes meaning of ‘Culture’ [-fpermissive]
   32 |  Culture *Culture = nullptr;
      |           ^~~~~~~
Metternich/character/dynasty.h:32: error: declaration of ‘Metternich::Culture* Metternich::Dynasty::Culture’ changes meaning of ‘Culture’ [-fpermissive]
   32 |  Culture *Culture = nullptr;
      |           ^~~~~~~
Metternich/culture/culture.h:46: error: declaration of ‘Metternich::CultureGroup* Metternich::Culture::CultureGroup’ changes meaning of ‘CultureGroup’ [-fpermissive]
   46 |  Metternich::CultureGroup *CultureGroup = nullptr;
      |                            ^~~~~~~~~~~~
Metternich/character/character.h:374: error: declaration of ‘Metternich::Dynasty* Metternich::Character::Dynasty’ changes meaning of ‘Dynasty’ [-fpermissive]
  374 |  Dynasty *Dynasty = nullptr;
      |           ^~~~~~~
Metternich/character/character.h:375: error: declaration of ‘Metternich::Culture* Metternich::Character::Culture’ changes meaning of ‘Culture’ [-fpermissive]
  375 |  Culture *Culture = nullptr;
      |           ^~~~~~~
Metternich/character/character.h:376: error: declaration of ‘Metternich::Religion* Metternich::Character::Religion’ changes meaning of ‘Religion’ [-fpermissive]
  376 |  Religion *Religion = nullptr;
      |            ^~~~~~~~
Metternich/character/dynasty.h:32: error: declaration of ‘Metternich::Culture* Metternich::Dynasty::Culture’ changes meaning of ‘Culture’ [-fpermissive]
   32 |  Culture *Culture = nullptr;
      |           ^~~~~~~
Metternich/culture/culture.h:46: error: declaration of ‘Metternich::CultureGroup* Metternich::Culture::CultureGroup’ changes meaning of ‘CultureGroup’ [-fpermissive]
   46 |  Metternich::CultureGroup *CultureGroup = nullptr;
      |                            ^~~~~~~~~~~~
Metternich/landed_title/landed_title.h:122: error: declaration of ‘Metternich::Holding* Metternich::LandedTitle::Holding’ changes meaning of ‘Holding’ [-fpermissive]
  122 |  Metternich::Holding *Holding = nullptr; //this title's holding, if it is a non-titular barony
      |                       ^~~~~~~
Metternich/landed_title/landed_title.h:123: error: declaration of ‘Metternich::Province* Metternich::LandedTitle::Province’ changes meaning of ‘Province’ [-fpermissive]
  123 |  Metternich::Province *Province = nullptr; //this title's province, if it is a non-titular county
      |                        ^~~~~~~~

Sorry I didn't put these here initially, but (AFAICT) I had to copy-paste each error individually.
Anyway, once I used -fpermissive to bypass those the project built successfully!

Andrettin {l Wrote}:I have a data repository for the game itself as well, Iron Barons.
[--]
To run the game, just set its directory as the working directory when running the engine; you can set the working directory in the Qt Creator by going to Projects->Run.

This however just makes the game print 'Invalid "dynasty" instance: "de_penthievre".' and exit with code 255.
You should definitely reference this in the game's readme though.
User avatar
Huitsi
 
Posts: 8
Joined: 25 Jul 2018, 23:45

Re: Open-Source Grand Strategy Game

Postby GunChleoc » 10 Aug 2019, 08:35

{l Code}: {l Select All Code}
d_carinthia_german = "Kärnten"

Is this for localization or for switching native/English names? If it's for the latter, calling it "native" rather than "german" might be clearer.

If it's for localization, it would be be better to call this

{l Code}: {l Select All Code}
d_carinthia_de = "Kärnten"


to avoid confusion.

QT offers a translation system that will produce bilingual .ts files. It's better to use those than invent your own system, because a plain text editor is not a good tool for translators.

I know I'm nitpicking, but it will make your life easier down the road :)
User avatar
GunChleoc
 
Posts: 419
Joined: 20 Sep 2012, 22:45

Re: Open-Source Grand Strategy Game

Postby Andrettin » 10 Aug 2019, 14:24

GunChleoc {l Wrote}:
{l Code}: {l Select All Code}
d_carinthia_german = "Kärnten"

Is this for localization or for switching native/English names? If it's for the latter, calling it "native" rather than "german" might be clearer.

If it's for localization, it would be be better to call this

{l Code}: {l Select All Code}
d_carinthia_de = "Kärnten"


to avoid confusion.


Neither, actually, it is a culture-specific variation, to give flavor (this can change if the culture of the region changes).

QT offers a translation system that will produce bilingual .ts files. It's better to use those than invent your own system, because a plain text editor is not a good tool for translators.

I know I'm nitpicking, but it will make your life easier down the road :)


I did look into Qt's translation system, but I found it to be suboptimal for the following reasons:

1. The translation files have to be compiled by the Qt Creator, which is modder-unfriendly.
2. They use XML, which in my opinion is overly verbose and ugly. That is a matter of taste, of course.

The localization files for the engine work in a way not too dissimilar from gettext. They are basically conversions of tags to text; the same tags are used for different translations, but the files for each translation would be in different folders.

The syntax I used above has the advantage of being consistent with the markup language used for the engine, and it supports optional tag name variations according to e.g. culture.
Andrettin
Wyrmsun Moderator
 
Posts: 220
Joined: 29 Mar 2015, 19:26

Re: Open-Source Grand Strategy Game

Postby Andrettin » 10 Aug 2019, 14:57

Huitsi {l Wrote}:
Andrettin {l Wrote}:Does that fix the error for you?

That particular one seem to be gone, but I still get others like it:
{l Code}: {l Select All Code}
Metternich/culture/culture.h:46: error: declaration of ‘Metternich::CultureGroup* Metternich::Culture::CultureGroup’ changes meaning of ‘CultureGroup’ [-fpermissive]
   46 |  Metternich::CultureGroup *CultureGroup = nullptr;
      |                            ^~~~~~~~~~~~
Metternich/character/dynasty.h:32: error: declaration of ‘Metternich::Culture* Metternich::Dynasty::Culture’ changes meaning of ‘Culture’ [-fpermissive]
   32 |  Culture *Culture = nullptr;
      |           ^~~~~~~
Metternich/character/dynasty.h:32: error: declaration of ‘Metternich::Culture* Metternich::Dynasty::Culture’ changes meaning of ‘Culture’ [-fpermissive]
   32 |  Culture *Culture = nullptr;
      |           ^~~~~~~
Metternich/culture/culture.h:46: error: declaration of ‘Metternich::CultureGroup* Metternich::Culture::CultureGroup’ changes meaning of ‘CultureGroup’ [-fpermissive]
   46 |  Metternich::CultureGroup *CultureGroup = nullptr;
      |                            ^~~~~~~~~~~~
Metternich/character/character.h:374: error: declaration of ‘Metternich::Dynasty* Metternich::Character::Dynasty’ changes meaning of ‘Dynasty’ [-fpermissive]
  374 |  Dynasty *Dynasty = nullptr;
      |           ^~~~~~~
Metternich/character/character.h:375: error: declaration of ‘Metternich::Culture* Metternich::Character::Culture’ changes meaning of ‘Culture’ [-fpermissive]
  375 |  Culture *Culture = nullptr;
      |           ^~~~~~~
Metternich/character/character.h:376: error: declaration of ‘Metternich::Religion* Metternich::Character::Religion’ changes meaning of ‘Religion’ [-fpermissive]
  376 |  Religion *Religion = nullptr;
      |            ^~~~~~~~
Metternich/character/dynasty.h:32: error: declaration of ‘Metternich::Culture* Metternich::Dynasty::Culture’ changes meaning of ‘Culture’ [-fpermissive]
   32 |  Culture *Culture = nullptr;
      |           ^~~~~~~
Metternich/culture/culture.h:46: error: declaration of ‘Metternich::CultureGroup* Metternich::Culture::CultureGroup’ changes meaning of ‘CultureGroup’ [-fpermissive]
   46 |  Metternich::CultureGroup *CultureGroup = nullptr;
      |                            ^~~~~~~~~~~~
Metternich/landed_title/landed_title.h:122: error: declaration of ‘Metternich::Holding* Metternich::LandedTitle::Holding’ changes meaning of ‘Holding’ [-fpermissive]
  122 |  Metternich::Holding *Holding = nullptr; //this title's holding, if it is a non-titular barony
      |                       ^~~~~~~
Metternich/landed_title/landed_title.h:123: error: declaration of ‘Metternich::Province* Metternich::LandedTitle::Province’ changes meaning of ‘Province’ [-fpermissive]
  123 |  Metternich::Province *Province = nullptr; //this title's province, if it is a non-titular county
      |                        ^~~~~~~~

Sorry I didn't put these here initially, but (AFAICT) I had to copy-paste each error individually.
Anyway, once I used -fpermissive to bypass those the project built successfully!

This however just makes the game print 'Invalid "dynasty" instance: "de_penthievre".' and exit with code 255.
You should definitely reference this in the game's readme though.


Thanks! I updated the readme now :)
https://github.com/Andrettin/Metternich ... f0d661dee5

About the error, I suspect that the file having been ANSI-encoded may somehow have caused an issue; in any case it is correctly UTF-8 encoded now:
https://github.com/Andrettin/Iron-Baron ... 91a7bd8491

Does that fix the issue for you?
Andrettin
Wyrmsun Moderator
 
Posts: 220
Joined: 29 Mar 2015, 19:26

Re: Open-Source Grand Strategy Game

Postby Huitsi » 10 Aug 2019, 15:41

Andrettin {l Wrote}:Does that fix the issue for you?

Actually there appears to be no change in either issue. :?
User avatar
Huitsi
 
Posts: 8
Joined: 25 Jul 2018, 23:45

Re: Open-Source Grand Strategy Game

Postby Andrettin » 10 Aug 2019, 23:08

Huitsi {l Wrote}:Actually there appears to be no change in either issue. :?


Alright, so to be able to debug the issue properly, I created an Ubuntu 18.04 VM, installed Qt and compiled the engine there. I could reproduce the error with the missing dynasty; GCC was optimizing away the variable that initialized the processing of database entries for each class. So the entire database was not being loaded (except for the "history" part). I've fixed that issue here:
https://github.com/Andrettin/Metternich ... a13e3a7476

With the fix in place, I was able to start the game, so the issue should be resolved for you now as well :)
Andrettin
Wyrmsun Moderator
 
Posts: 220
Joined: 29 Mar 2015, 19:26

Re: Open-Source Grand Strategy Game

Postby Huitsi » 11 Aug 2019, 10:34

Andrettin {l Wrote}:Alright, so to be able to debug the issue properly, I created an Ubuntu 18.04 VM, installed Qt and compiled the engine there. I could reproduce the error with the missing dynasty; GCC was optimizing away the variable that initialized the processing of database entries for each class. So the entire database was not being loaded (except for the "history" part). I've fixed that issue here:
https://github.com/Andrettin/Metternich ... a13e3a7476

With the fix in place, I was able to start the game, so the issue should be resolved for you now as well :)

Thank you very much! I was indeed able to play the game now. I did still have to use -fpermissive though. Did you not encounter that at all?
User avatar
Huitsi
 
Posts: 8
Joined: 25 Jul 2018, 23:45

Re: Open-Source Grand Strategy Game

Postby Andrettin » 11 Aug 2019, 13:14

Huitsi {l Wrote}:
Andrettin {l Wrote}:Alright, so to be able to debug the issue properly, I created an Ubuntu 18.04 VM, installed Qt and compiled the engine there. I could reproduce the error with the missing dynasty; GCC was optimizing away the variable that initialized the processing of database entries for each class. So the entire database was not being loaded (except for the "history" part). I've fixed that issue here:
https://github.com/Andrettin/Metternich ... a13e3a7476

With the fix in place, I was able to start the game, so the issue should be resolved for you now as well :)

Thank you very much! I was indeed able to play the game now. I did still have to use -fpermissive though. Did you not encounter that at all?


Great to hear that it works for you now!

About -fpermissive, yes I did, sorry I didn't mention it. I had to do some research on the origin of the issue, and I have fixed it now in the last couple of commits.
Andrettin
Wyrmsun Moderator
 
Posts: 220
Joined: 29 Mar 2015, 19:26

Re: Open-Source Grand Strategy Game

Postby Lyberta » 11 Aug 2019, 13:39

Andrettin {l Wrote}:About -fpermissive, yes I did, sorry I didn't mention it. I had to do some research on the origin of the issue, and I have fixed it now in the last couple of commits.


Don't mixup types and variable names.
⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧
User avatar
Lyberta
 
Posts: 583
Joined: 19 Jun 2013, 10:45

Re: Open-Source Grand Strategy Game

Postby Andrettin » 11 Aug 2019, 15:27

Lyberta {l Wrote}:Don't mixup types and variable names.


It is actually possible to use the same name for types and variables, as long as you qualify the namespace of the type in variable declarations and function return types.

Ultimately, the issue boils down to it being impossible to have all the following at the same time:

1. Variables with different name as classes.
2. Not using any prefixes or suffixes à la Hungarian notation.
3. Consistent casing for non-local type, function and variable names.
4. Avoiding pleonasm.

I could give up 2., and have variable definitions like either "CCultureGroup *CultureGroup" or "CultureGroup *m_CultureGroup" (which in my opinion looks a bit ugly), or I could have given up 3. and have variable definitions like "CultureGroup *cultureGroup" or "CultureGroup *culture_group", which IMO looks ugly and disorganized, making code less readable.

Camel case I find specially chaotic-looking, since the casing of a word can be different in similar circumstances just because of the word order, e.g. "int cpuUsage; int netCpuUsage;"; "cpu" is capitalized in the second one despite there not being much semantic difference between the role of the word in that variable name compared to the other definition.

I could also have given up avoiding pleonasm, and have variable names like "Culture *ProvinceCulture;" for a "Province" class. But that is useless repetition, and it could be problematic for possible future updates of deserialization to use the Reflection proposal (when it is implemented into the standard). At present deserialization uses the Qt property system, in which the name of the property is explicitly given. But deserialization could instead (when that becomes possible in C++) use reflection to treat class variable names as property names for the purpose of the markup language. If the variable is called "ProvinceCulture", then suddenly all usages of "culture = x" for province entries in the database (written in the markup language) would become invalid, having to be changed instead "province_culture = x".

Having the same name for classes and certain variables is suboptimal, I agree, but from several suboptimal choices it seemed to be the least bad one to me, specially since class names be referred to by qualifying them with their namespace, and as class and variable names are used in rather different contexts. Mixing class and *function* names would be more problematic, since then the function call can easily be confused for the constructor of the class, but I am not doing that.

In the end, it is a matter of opinion which of the four items I mentioned above should be given up.
Andrettin
Wyrmsun Moderator
 
Posts: 220
Joined: 29 Mar 2015, 19:26

Re: Open-Source Grand Strategy Game

Postby Lyberta » 11 Aug 2019, 15:42

I use PascalCase for types and snake_case for variables. I also recently started to prefix member variables with m_ and it greatly helped me understand my own code.
⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧
User avatar
Lyberta
 
Posts: 583
Joined: 19 Jun 2013, 10:45

Re: Open-Source Grand Strategy Game

Postby Andrettin » 11 Aug 2019, 16:34

Lyberta {l Wrote}:I use PascalCase for types and snake_case for variables. I also recently started to prefix member variables with m_ and it greatly helped me understand my own code.


I will admit I have considered using m_ for variables. Out of curiosity, how do you call your static variables? Prefix them with "s_"?
Andrettin
Wyrmsun Moderator
 
Posts: 220
Joined: 29 Mar 2015, 19:26

Re: Open-Source Grand Strategy Game

Postby Lyberta » 11 Aug 2019, 18:57

Andrettin {l Wrote}:I will admit I have considered using m_ for variables. Out of curiosity, how do you call your static variables? Prefix them with "s_"?


Oh, right, I also use PascalCase for constants. Static variables? Like, file-level static or static members?

I don't really have file-level statics because they are global state and I avoid global state at all costs. Static members... couldn't find any. I did find Meyers singleton but you obviously don't need m_ there:

{l Code}: {l Select All Code}
const std::regex& SymbolBase::GetNameRegex() noexcept
{
   static const std::regex name_regex{R"([+-]?\w+)"};
   return name_regex;
}
⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧⚧
User avatar
Lyberta
 
Posts: 583
Joined: 19 Jun 2013, 10:45

Who is online

Users browsing this forum: No registered users and 1 guest