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 ProfileManager/ProfileManager.cpp
Profile/Profile.h Profile/Profile.h
Profile/Profile.cpp Profile/Profile.cpp
Profile/ResourceIDs.h
MassManager/MassManager.h MassManager/MassManager.h
MassManager/MassManager.cpp MassManager/MassManager.cpp
Mass/Locators.h Mass/Locators.h

View File

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

View File

@ -45,81 +45,81 @@ class Profile {
void refreshValues(); void refreshValues();
auto companyName() -> std::string const&; auto companyName() const -> std::string const&;
auto renameCompany(const std::string& new_name) -> bool; 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 setCredits(Int credits) -> bool;
auto storyProgress() -> Int; auto storyProgress() const -> Int;
auto setStoryProgress(Int progress) -> bool; 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 setVerseSteel(Int amount) -> bool;
auto undinium() -> Int; auto undinium() const -> Int;
auto setUndinium(Int amount) -> bool; auto setUndinium(Int amount) -> bool;
auto necriumAlloy() -> Int; auto necriumAlloy() const -> Int;
auto setNecriumAlloy(Int amount) -> bool; auto setNecriumAlloy(Int amount) -> bool;
auto lunarite() -> Int; auto lunarite() const -> Int;
auto setLunarite(Int amount) -> bool; auto setLunarite(Int amount) -> bool;
auto asterite() -> Int; auto asterite() const -> Int;
auto setAsterite(Int amount) -> bool; auto setAsterite(Int amount) -> bool;
auto ednil() -> Int; auto ednil() const -> Int;
auto setEdnil(Int amount) -> bool; auto setEdnil(Int amount) -> bool;
auto nuflalt() -> Int; auto nuflalt() const -> Int;
auto setNuflalt(Int amount) -> bool; auto setNuflalt(Int amount) -> bool;
auto aurelene() -> Int; auto aurelene() const -> Int;
auto setAurelene(Int amount) -> bool; auto setAurelene(Int amount) -> bool;
auto soldus() -> Int; auto soldus() const -> Int;
auto setSoldus(Int amount) -> bool; auto setSoldus(Int amount) -> bool;
auto synthesizedN() -> Int; auto synthesisedN() const -> Int;
auto setSynthesizedN(Int amount) -> bool; auto setSynthesisedN(Int amount) -> bool;
auto alcarbonite() -> Int; auto alcarbonite() const -> Int;
auto setAlcarbonite(Int amount) -> bool; auto setAlcarbonite(Int amount) -> bool;
auto keriphene() -> Int; auto keriphene() const -> Int;
auto setKeriphene(Int amount) -> bool; auto setKeriphene(Int amount) -> bool;
auto nitinolCM() -> Int; auto nitinolCM() const -> Int;
auto setNitinolCM(Int amount) -> bool; auto setNitinolCM(Int amount) -> bool;
auto quarkium() -> Int; auto quarkium() const -> Int;
auto setQuarkium(Int amount) -> bool; auto setQuarkium(Int amount) -> bool;
auto alterene() -> Int; auto alterene() const -> Int;
auto setAlterene(Int amount) -> bool; auto setAlterene(Int amount) -> bool;
auto mixedComposition() -> Int; auto mixedComposition() const -> Int;
auto setMixedComposition(Int amount) -> bool; auto setMixedComposition(Int amount) -> bool;
auto voidResidue() -> Int; auto voidResidue() const -> Int;
auto setVoidResidue(Int amount) -> bool; auto setVoidResidue(Int amount) -> bool;
auto muscularConstruction() -> Int; auto muscularConstruction() const -> Int;
auto setMuscularConstruction(Int amount) -> bool; auto setMuscularConstruction(Int amount) -> bool;
auto mineralExoskeletology() -> Int; auto mineralExoskeletology() const -> Int;
auto setMineralExoskeletology(Int amount) -> bool; auto setMineralExoskeletology(Int amount) -> bool;
auto carbonizedSkin() -> Int; auto carbonisedSkin() const -> Int;
auto setCarbonizedSkin(Int amount) -> bool; auto setCarbonisedSkin(Int amount) -> bool;
private: 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; auto setResource(const char* container, Int id, Int amount) -> bool;
std::string _profileDirectory; std::string _profileDirectory;
@ -129,6 +129,36 @@ class Profile {
UESaveFile _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; std::string _steamId;
bool _valid = false; 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
};