Change levelstats data type from vector to map

As described in #1016, there used to be a bug that inflated
levelstats.vvv in 2.3, which was fixed in 2.4, but there was no way
for inflated files to get smaller yet.

This commit changes the storage of levelstats from a std::vector of
structs to a std::map, so that uniqueness is guaranteed and thus the
stats can be optimized automatically. And it also simplifies *and*
optimizes the code that handles the levelstats - no more big loops that
iterated over every element to find the matching level.
(Farewell to the "life optimisation and all that" comment, too)

I tested this with both my own levelstats.vvv, as well as some inflated
ones (including Balneor's 93 MB one) and saw this code correctly reduce
the filesize and speed up the levels list.

Fixes #1016.
This commit is contained in:
Dav999
2023-10-25 04:05:23 +02:00
committed by Misa Elizabeth Kai
parent 82240d262b
commit e0e902d717
2 changed files with 67 additions and 83 deletions

View File

@@ -2,6 +2,7 @@
#define GAME_H
#include <SDL.h>
#include <map>
#include <string>
#include <vector>
@@ -176,12 +177,6 @@ struct MenuStackFrame
enum Menu::MenuName name;
};
struct CustomLevelStat
{
std::string name;
int score; //0 - not played, 1 - finished, 2 - all trinkets, 3 - finished, all trinkets
};
class Game
{
@@ -526,7 +521,8 @@ public:
void updatecustomlevelstats(std::string clevel, int cscore);
void deletecustomlevelstats(void);
std::vector<CustomLevelStat> customlevelstats;
// name -> score. 0 - not played, 1 - finished, 2 - all trinkets, 3 - finished, all trinkets
std::map<std::string, int> customlevelstats;
std::vector<SDL_GameControllerButton> controllerButton_map;