aliens

Author Topic: [Suggestion] Don't shuffle discovered section in sav file  (Read 223 times)

Online Delian

  • Colonel
  • ****
  • Posts: 382
    • View Profile
[Suggestion] Don't shuffle discovered section in sav file
« on: September 14, 2024, 10:58:58 pm »
Whenever you save your game (after passing a bit of time), the "discovered" section (string list of discovered research topics) gets randomly shuffled, making it impractical when trying to compare differences of two save files.

It would make my life easier if this shuffling didn't occur. Either by sorting this list on game save, or if the newly researched topics were always added to the bottom of the list and then remained in the order they were added.

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 8888
    • View Profile
Re: [Suggestion] Don't shuffle discovered section in sav file
« Reply #1 on: September 15, 2024, 11:13:57 am »
Just FYI, we don't shuffle it randomly, there's no reason to do that.
The list is ordered by internal ID to allow binary search.

Online Delian

  • Colonel
  • ****
  • Posts: 382
    • View Profile
Re: [Suggestion] Don't shuffle discovered section in sav file
« Reply #2 on: September 15, 2024, 04:04:09 pm »
Hmm. I'm checking the code, but I can't find where this internal ID is.

In the SavedGame.cpp
it's calling sortReserchVector(_discovered);,
which calls std::sort(vec.begin(), vec.end(), researchLess); where researchLess is the element comparator function,
which compares the two elements by calling std::less<const RuleResearch *>{}(a, b);

I don't understand this. The RuleResearch class doesn't overload the < operator, so how exactly are two RuleResearch objects compared?

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 8888
    • View Profile
Re: [Suggestion] Don't shuffle discovered section in sav file
« Reply #3 on: September 15, 2024, 04:09:08 pm »
They are compared by the numeric value of the pointer to the object.

I used the word ID because I didn't want to explain all this.

Online Delian

  • Colonel
  • ****
  • Posts: 382
    • View Profile
Re: [Suggestion] Don't shuffle discovered section in sav file
« Reply #4 on: September 15, 2024, 05:14:39 pm »
numeric value of the pointer

Oof... but, that numeric value is inherently random because that's how memory allocation works. Every time you re-launch the game, the raw memory address values of objects get randomized (technically they should also get reversed because the last added element has the lowest address on the heap, which would give it the first place on the list).

Yeah, it would be nice if this was changed to something more stable.

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 8888
    • View Profile
Re: [Suggestion] Don't shuffle discovered section in sav file
« Reply #5 on: September 15, 2024, 05:40:43 pm »
It's not going to change, because that's exactly what we need.

For the purpose of saving (only), I can do something different.