Today's Project Special K ponderings
Size of the Villager class: 1472 bytes.
Amount of villagers currently in the set: 55, including ACNH cats.
Amount of villagers planned: 110.
Projected total size of the villager dataset in memory: 161,920 bytes or 158 KiB.
Size of an std::string: 40 bytes, assuming MSVC 2015.
Size of a CRC32 hash: 4 bytes, obviously.
Therefore, you could decimate the part of a villager where it specifies the item ID for their default outfit, their raincoat, rain hat, umbrella, photograph, and portrait, from 240 to only 24.
But this doesn't work because those items can and do have variants specified — Audie's tropical muumuu is specifically mint, and "acnh:tropicalmuumuu" does not have the same hash as "achnh:tropicalmuumuu/mint", obviously.
So that idea is no good.
Size of a TextureArray*: 8 bytes. This is a 64-bit application.
Size of an std::array<TextureArray*, 24>: 192 bytes.
With 24 textures for the character and another 32 for their clothing (gotta support the lowest common denominator and that means more than just tops and accessories), that makes 448 bytes per villager for their textures, even if they're not physically present and no textures are loaded.
Projected total size of these texture pointers: 49,280 bytes or 48 KiB, not counting the actual textures.
I could replace these std::array<>s with a single pointer. When the villager is spawned in, 56 TextureArray* are allocated and used, and freed along with their contents when the villager is despawned.
But is that really worth it for 448 bytes?
House data is left unloaded. It's in the JSON file, but nothing actually loads it into the Villager class, which has no fields for it.
But villagers, like all NameableThings, remember which JSON file they were loaded from.
Therefore, when the topic of home decorations comes up, the relevant data can be pulled out on the spot.
This is for later, we don't even have map transitions yet.
Parsing a reference like "acnh:tropicalmuumuu/mint" involves a couple string creations and destructions.
I'd use std::string_view but I'm stuck with C++11.
I also don't get to use std::format for the same reason, but I do get to use fmt::format to fill that gap quite nicely. Likewise, I could probably dig up some library to give me string views.
But parsing these references isn't exactly something that happens every frame, or every few seconds.
So is it worth the effort to find a string view "polyfill" and use it? Are there other places in the code where using a view would be a boon? Finding file entries in the VFS certainly goes fast when running a release build...













