Profile: add data caching.

Querying the properties each frame isn't performant because of all the
casts and pointer indirections.
This commit is contained in:
Guillaume Jacquemin 2021-09-24 21:51:06 +02:00
parent 79e3193309
commit 9bc4aaf66b
4 changed files with 231 additions and 106 deletions

View File

@ -121,6 +121,7 @@ add_executable(MassBuilderSaveTool WIN32
ProfileManager/ProfileManager.cpp
Profile/Profile.h
Profile/Profile.cpp
Profile/ResourceIDs.h
MassManager/MassManager.h
MassManager/MassManager.cpp
Mass/Locators.h

View File

@ -27,6 +27,8 @@
#include "../UESaveFile/Types/IntProperty.h"
#include "../UESaveFile/Types/StringProperty.h"
#include "ResourceIDs.h"
#include "Profile.h"
using namespace Corrade;
@ -70,11 +72,52 @@ auto Profile::steamId() const -> std::string const& {
}
void Profile::refreshValues() {
_profile.reloadData();
if(!_profile.reloadData()) {
_lastError = _profile.lastError();
return;
}
_name = _profile.at<StringProperty>("CompanyName")->value;
auto prop = _profile.at<IntProperty>("ActiveFrameSlot");
_activeFrameSlot = prop ? prop->value : 0;
prop = _profile.at<IntProperty>("Credit");
_credits = prop ? prop->value : 0;
prop = _profile.at<IntProperty>("StoryProgress");
_storyProgress = prop ? prop->value : 0;
prop = _profile.at<IntProperty>("LastMissionID");
_lastMissionId = prop ? prop->value : 0;
_verseSteel = getResource("ResourceMaterial", VerseSteel);
_undinium = getResource("ResourceMaterial", Undinium);
_necriumAlloy = getResource("ResourceMaterial", NecriumAlloy);
_lunarite = getResource("ResourceMaterial", Lunarite);
_asterite = getResource("ResourceMaterial", Asterite);
_ednil = getResource("ResourceMaterial", Ednil);
_nuflalt = getResource("ResourceMaterial", Nuflalt);
_aurelene = getResource("ResourceMaterial", Aurelene);
_soldus = getResource("ResourceMaterial", Soldus);
_synthesisedN = getResource("ResourceMaterial", SynthesisedN);
_alcarbonite = getResource("ResourceMaterial", Alcarbonite);
_keriphene = getResource("ResourceMaterial", Keriphene);
_nitinolCM = getResource("ResourceMaterial", NitinolCM);
_quarkium = getResource("ResourceMaterial", Quarkium);
_alterene = getResource("ResourceMaterial", Alterene);
_mixedComposition = getResource("ResourceQuarkData", MixedComposition);
_voidResidue = getResource("ResourceQuarkData", VoidResidue);
_muscularConstruction = getResource("ResourceQuarkData", MuscularConstruction);
_mineralExoskeletology = getResource("ResourceQuarkData", MineralExoskeletology);
_carbonisedSkin = getResource("ResourceQuarkData", CarbonisedSkin);
}
auto Profile::companyName() -> std::string const& {
return _profile.at<StringProperty>("CompanyName")->value;
auto Profile::companyName() const -> std::string const& {
return _name;
}
auto Profile::renameCompany(const std::string& new_name) -> bool {
@ -90,14 +133,12 @@ auto Profile::renameCompany(const std::string& new_name) -> bool {
return true;
}
auto Profile::activeFrameSlot() -> Int {
auto active_frame_slot_prop = _profile.at<IntProperty>("ActiveFrameSlot");
return active_frame_slot_prop ? active_frame_slot_prop->value : 0;
auto Profile::activeFrameSlot() const -> Int {
return _activeFrameSlot;
}
auto Profile::credits() -> Int {
auto credits_prop = _profile.at<IntProperty>("Credit");
return credits_prop ? credits_prop->value : 0;
auto Profile::credits() const -> Int {
return _credits;
}
auto Profile::setCredits(Int amount) -> bool {
@ -118,9 +159,8 @@ auto Profile::setCredits(Int amount) -> bool {
return true;
}
auto Profile::storyProgress() -> Int {
auto story_progress_prop = _profile.at<IntProperty>("StoryProgress");
return story_progress_prop ? story_progress_prop->value : 0;
auto Profile::storyProgress() const -> Int {
return _storyProgress;
}
auto Profile::setStoryProgress(Int progress) -> bool {
@ -141,174 +181,177 @@ auto Profile::setStoryProgress(Int progress) -> bool {
return true;
}
auto Profile::lastMissionId() -> Int {
auto last_mission_id_prop = _profile.at<IntProperty>("LastMissionID");
return last_mission_id_prop ? last_mission_id_prop->value : 0;
auto Profile::lastMissionId() const -> Int {
return _lastMissionId;
}
auto Profile::verseSteel() -> Int {
return resource("ResourceMaterial", 0xC3500);
auto Profile::verseSteel() const -> Int {
return _verseSteel;
}
auto Profile::setVerseSteel(Int amount) -> bool {
return setResource("ResourceMaterial", 0xC3500, amount);
return setResource("ResourceMaterial", VerseSteel, amount);
}
auto Profile::undinium() -> Int {
return resource("ResourceMaterial", 0xC3501);
auto Profile::undinium() const -> Int {
return _undinium;
}
auto Profile::setUndinium(Int amount) -> bool {
return setResource("ResourceMaterial", 0xC3501, amount);
return setResource("ResourceMaterial", Undinium, amount);
}
auto Profile::necriumAlloy() -> Int {
return resource("ResourceMaterial", 0xC3502);
auto Profile::necriumAlloy() const -> Int {
return _necriumAlloy;
}
auto Profile::setNecriumAlloy(Int amount) -> bool {
return setResource("ResourceMaterial", 0xC3502, amount);
return setResource("ResourceMaterial", NecriumAlloy, amount);
}
auto Profile::lunarite() -> Int {
return resource("ResourceMaterial", 0xC3503);
auto Profile::lunarite() const -> Int {
return _lunarite;
}
auto Profile::setLunarite(Int amount) -> bool {
return setResource("ResourceMaterial", 0xC3503, amount);
return setResource("ResourceMaterial", Lunarite, amount);
}
auto Profile::asterite() -> Int {
return resource("ResourceMaterial", 0xC3504);
auto Profile::asterite() const -> Int {
return _asterite;
}
auto Profile::setAsterite(Int amount) -> bool {
return setResource("ResourceMaterial", 0xC3504, amount);
return setResource("ResourceMaterial", Asterite, amount);
}
auto Profile::ednil() -> Int {
return resource("ResourceMaterial", 0xC350A);
auto Profile::ednil() const -> Int {
return _ednil;
}
auto Profile::setEdnil(Int amount) -> bool {
return setResource("ResourceMaterial", 0xC350A, amount);
return setResource("ResourceMaterial", Ednil, amount);
}
auto Profile::nuflalt() -> Int {
return resource("ResourceMaterial", 0xC350B);
auto Profile::nuflalt() const -> Int {
return _nuflalt;
}
auto Profile::setNuflalt(Int amount) -> bool {
return setResource("ResourceMaterial", 0xC350B, amount);
return setResource("ResourceMaterial", Nuflalt, amount);
}
auto Profile::aurelene() -> Int {
return resource("ResourceMaterial", 0xC350C);
auto Profile::aurelene() const -> Int {
return _aurelene;
}
auto Profile::setAurelene(Int amount) -> bool {
return setResource("ResourceMaterial", 0xC350C, amount);
return setResource("ResourceMaterial", Aurelene, amount);
}
auto Profile::soldus() -> Int {
return resource("ResourceMaterial", 0xC350D);
auto Profile::soldus() const -> Int {
return _soldus;
}
auto Profile::setSoldus(Int amount) -> bool {
return setResource("ResourceMaterial", 0xC350D, amount);
return setResource("ResourceMaterial", Soldus, amount);
}
auto Profile::synthesizedN() -> Int {
return resource("ResourceMaterial", 0xC350E);
auto Profile::synthesisedN() const -> Int {
return _synthesisedN;
}
auto Profile::setSynthesizedN(Int amount) -> bool {
return setResource("ResourceMaterial", 0xC350E, amount);
auto Profile::setSynthesisedN(Int amount) -> bool {
return setResource("ResourceMaterial", SynthesisedN, amount);
}
auto Profile::alcarbonite() -> Int {
return resource("ResourceMaterial", 0xC3514);
auto Profile::alcarbonite() const -> Int {
return _alcarbonite;
}
auto Profile::setAlcarbonite(Int amount) -> bool {
return setResource("ResourceMaterial", 0xC3514, amount);
return setResource("ResourceMaterial", Alcarbonite, amount);
}
auto Profile::keriphene() -> Int {
return resource("ResourceMaterial", 0xC3515);
auto Profile::keriphene() const -> Int {
return _keriphene;
}
auto Profile::setKeriphene(Int amount) -> bool {
return setResource("ResourceMaterial", 0xC3515, amount);
return setResource("ResourceMaterial", Keriphene, amount);
}
auto Profile::nitinolCM() -> Int {
return resource("ResourceMaterial", 0xC3516);
auto Profile::nitinolCM() const -> Int {
return _nitinolCM;
}
auto Profile::setNitinolCM(Int amount) -> bool {
return setResource("ResourceMaterial", 0xC3516, amount);
return setResource("ResourceMaterial", NitinolCM, amount);
}
auto Profile::quarkium() -> Int {
return resource("ResourceMaterial", 0xC3517);
auto Profile::quarkium() const -> Int {
return _quarkium;
}
auto Profile::setQuarkium(Int amount) -> bool {
return setResource("ResourceMaterial", 0xC3517, amount);
return setResource("ResourceMaterial", Quarkium, amount);
}
auto Profile::alterene() -> Int {
return resource("ResourceMaterial", 0xC3518);
auto Profile::alterene() const -> Int {
return _alterene;
}
auto Profile::setAlterene(Int amount) -> bool {
return setResource("ResourceMaterial", 0xC3518, amount);
return setResource("ResourceMaterial", Alterene, amount);
}
auto Profile::mixedComposition() -> Int {
return resource("ResourceQuarkData", 0xDBBA0);
auto Profile::mixedComposition() const -> Int {
return _mixedComposition;
}
auto Profile::setMixedComposition(Int amount) -> bool {
return setResource("ResourceQuarkData", 0xDBBA0, amount);
return setResource("ResourceQuarkData", MixedComposition, amount);
}
auto Profile::voidResidue() -> Int {
return resource("ResourceQuarkData", 0xDBBA1);
auto Profile::voidResidue() const -> Int {
return _voidResidue;
}
auto Profile::setVoidResidue(Int amount) -> bool {
return setResource("ResourceQuarkData", 0xDBBA1, amount);
return setResource("ResourceQuarkData", VoidResidue, amount);
}
auto Profile::muscularConstruction() -> Int {
return resource("ResourceQuarkData", 0xDBBA2);
auto Profile::muscularConstruction() const -> Int {
return _muscularConstruction;
}
auto Profile::setMuscularConstruction(Int amount) -> bool {
return setResource("ResourceQuarkData", 0xDBBA2, amount);
return setResource("ResourceQuarkData", MuscularConstruction, amount);
}
auto Profile::mineralExoskeletology() -> Int {
return resource("ResourceQuarkData", 0xDBBA3);
auto Profile::mineralExoskeletology() const -> Int {
return _mineralExoskeletology;
}
auto Profile::setMineralExoskeletology(Int amount) -> bool {
return setResource("ResourceQuarkData", 0xDBBA3, amount);
return setResource("ResourceQuarkData", MineralExoskeletology, amount);
}
auto Profile::carbonizedSkin() -> Int {
return resource("ResourceQuarkData", 0xDBBA4);
auto Profile::carbonisedSkin() const -> Int {
return _carbonisedSkin;
}
auto Profile::setCarbonizedSkin(Int amount) -> bool {
return setResource("ResourceQuarkData", 0xDBBA4, amount);
auto Profile::setCarbonisedSkin(Int amount) -> bool {
return setResource("ResourceQuarkData", CarbonisedSkin, amount);
}
auto Profile::resource(const char* container, Int id) -> Int {
auto Profile::getResource(const char* container, Int id) -> Int {
auto mats_prop = _profile.at<ArrayProperty>(container);
if(!mats_prop) {
return 0;
}
static auto predicate = [&id](UnrealPropertyBase::ptr& prop){
auto res_prop = static_cast<ResourceItemValue*>(prop.get());
return res_prop->id == id;
@ -321,6 +364,10 @@ auto Profile::resource(const char* container, Int id) -> Int {
auto Profile::setResource(const char* container, Int id, Int amount) -> bool {
auto mats_prop = _profile.at<ArrayProperty>(container);
if(!mats_prop) {
return false;
}
static auto predicate = [&id](UnrealPropertyBase::ptr& prop){
auto res_prop = static_cast<ResourceItemValue*>(prop.get());
return res_prop->id == id;

View File

@ -45,81 +45,81 @@ class Profile {
void refreshValues();
auto companyName() -> std::string const&;
auto companyName() const -> std::string const&;
auto renameCompany(const std::string& new_name) -> bool;
auto activeFrameSlot() -> Int;
auto activeFrameSlot() const -> Int;
auto credits() -> Int;
auto credits() const -> Int;
auto setCredits(Int credits) -> bool;
auto storyProgress() -> Int;
auto storyProgress() const -> Int;
auto setStoryProgress(Int progress) -> bool;
auto lastMissionId() -> Int;
auto lastMissionId() const -> Int;
auto verseSteel() -> Int;
auto verseSteel() const -> Int;
auto setVerseSteel(Int amount) -> bool;
auto undinium() -> Int;
auto undinium() const -> Int;
auto setUndinium(Int amount) -> bool;
auto necriumAlloy() -> Int;
auto necriumAlloy() const -> Int;
auto setNecriumAlloy(Int amount) -> bool;
auto lunarite() -> Int;
auto lunarite() const -> Int;
auto setLunarite(Int amount) -> bool;
auto asterite() -> Int;
auto asterite() const -> Int;
auto setAsterite(Int amount) -> bool;
auto ednil() -> Int;
auto ednil() const -> Int;
auto setEdnil(Int amount) -> bool;
auto nuflalt() -> Int;
auto nuflalt() const -> Int;
auto setNuflalt(Int amount) -> bool;
auto aurelene() -> Int;
auto aurelene() const -> Int;
auto setAurelene(Int amount) -> bool;
auto soldus() -> Int;
auto soldus() const -> Int;
auto setSoldus(Int amount) -> bool;
auto synthesizedN() -> Int;
auto setSynthesizedN(Int amount) -> bool;
auto synthesisedN() const -> Int;
auto setSynthesisedN(Int amount) -> bool;
auto alcarbonite() -> Int;
auto alcarbonite() const -> Int;
auto setAlcarbonite(Int amount) -> bool;
auto keriphene() -> Int;
auto keriphene() const -> Int;
auto setKeriphene(Int amount) -> bool;
auto nitinolCM() -> Int;
auto nitinolCM() const -> Int;
auto setNitinolCM(Int amount) -> bool;
auto quarkium() -> Int;
auto quarkium() const -> Int;
auto setQuarkium(Int amount) -> bool;
auto alterene() -> Int;
auto alterene() const -> Int;
auto setAlterene(Int amount) -> bool;
auto mixedComposition() -> Int;
auto mixedComposition() const -> Int;
auto setMixedComposition(Int amount) -> bool;
auto voidResidue() -> Int;
auto voidResidue() const -> Int;
auto setVoidResidue(Int amount) -> bool;
auto muscularConstruction() -> Int;
auto muscularConstruction() const -> Int;
auto setMuscularConstruction(Int amount) -> bool;
auto mineralExoskeletology() -> Int;
auto mineralExoskeletology() const -> Int;
auto setMineralExoskeletology(Int amount) -> bool;
auto carbonizedSkin() -> Int;
auto setCarbonizedSkin(Int amount) -> bool;
auto carbonisedSkin() const -> Int;
auto setCarbonisedSkin(Int amount) -> bool;
private:
auto resource(const char* container, Int id) -> Int;
auto getResource(const char* container, Int id) -> Int;
auto setResource(const char* container, Int id, Int amount) -> bool;
std::string _profileDirectory;
@ -129,6 +129,36 @@ class Profile {
UESaveFile _profile;
std::string _name;
Int _activeFrameSlot;
Int _credits;
Int _storyProgress;
Int _lastMissionId;
Int _verseSteel = 0;
Int _undinium = 0;
Int _necriumAlloy = 0;
Int _lunarite = 0;
Int _asterite = 0;
Int _ednil = 0;
Int _nuflalt = 0;
Int _aurelene = 0;
Int _soldus = 0;
Int _synthesisedN = 0;
Int _alcarbonite = 0;
Int _keriphene = 0;
Int _nitinolCM = 0;
Int _quarkium = 0;
Int _alterene = 0;
Int _mixedComposition = 0;
Int _voidResidue = 0;
Int _muscularConstruction = 0;
Int _mineralExoskeletology = 0;
Int _carbonisedSkin = 0;
std::string _steamId;
bool _valid = false;

47
src/Profile/ResourceIDs.h Normal file
View File

@ -0,0 +1,47 @@
#pragma once
// MassBuilderSaveTool
// Copyright (C) 2021 Guillaume Jacquemin
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Magnum/Types.h>
using namespace Magnum;
enum MaterialID : Int {
VerseSteel = 0xC3500,
Undinium = 0xC3501,
NecriumAlloy = 0xC3502,
Lunarite = 0xC3503,
Asterite = 0xC3504,
Ednil = 0xC350A,
Nuflalt = 0xC350B,
Aurelene = 0xC350C,
Soldus = 0xC350D,
SynthesisedN = 0xC350E,
Alcarbonite = 0xC3514,
Keriphene = 0xC3515,
NitinolCM = 0xC3516,
Quarkium = 0xC3517,
Alterene = 0xC3518,
MixedComposition = 0xDBBA0,
VoidResidue = 0xDBBA1,
MuscularConstruction = 0xDBBA2,
MineralExoskeletology = 0xDBBA3,
CarbonisedSkin = 0xDBBA4
};