Revert "Use smart pointers for basic libraries."
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This reverts commit 214ff819
This commit is contained in:
parent
91bea44113
commit
1e0d00d3b7
|
@ -5,16 +5,13 @@ using namespace CreatureLib::Library;
|
|||
export uint8_t CreatureLib_DataLibrary_Construct(const DataLibrary*& out, LibrarySettings* settings,
|
||||
SpeciesLibrary* species, AttackLibrary* attacks, ItemLibrary* items,
|
||||
GrowthRateLibrary* growthRates, TypeLibrary* typeLibrary) {
|
||||
Try(out = new DataLibrary(
|
||||
std::unique_ptr<const LibrarySettings>(settings), std::unique_ptr<const SpeciesLibrary>(species),
|
||||
std::unique_ptr<const AttackLibrary>(attacks), std::unique_ptr<const ItemLibrary>(items),
|
||||
std::unique_ptr<const GrowthRateLibrary>(growthRates), std::unique_ptr<const TypeLibrary>(typeLibrary));)
|
||||
Try(out = new DataLibrary(settings, species, attacks, items, growthRates, typeLibrary);)
|
||||
}
|
||||
|
||||
export void CreatureLib_DataLibrary_Destruct(const DataLibrary* p) { delete p; }
|
||||
|
||||
#define SIMPLE_GET_FUNC(type, name, returnType) \
|
||||
export returnType CreatureLib_##type##_##name(const type* p) { return p->name().get(); }
|
||||
export returnType CreatureLib_##type##_##name(const type* p) { return p->name(); }
|
||||
|
||||
SIMPLE_GET_FUNC(DataLibrary, GetSettings, const LibrarySettings*);
|
||||
SIMPLE_GET_FUNC(DataLibrary, GetSpeciesLibrary, const SpeciesLibrary*);
|
||||
|
|
|
@ -134,7 +134,7 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* targe
|
|||
auto attackData = attack->GetAttack()->GetAttack();
|
||||
auto library = user->GetBattle()->GetLibrary();
|
||||
AssertNotNull(library)
|
||||
auto& dmgLibrary = library->GetDamageLibrary();
|
||||
auto dmgLibrary = library->GetDamageLibrary();
|
||||
for (uint8_t hitIndex = 0; hitIndex < numHits; hitIndex++) {
|
||||
if (user->IsFainted()) {
|
||||
break;
|
||||
|
|
|
@ -2,24 +2,46 @@
|
|||
|
||||
using namespace CreatureLib::Battling;
|
||||
|
||||
BattleLibrary::BattleLibrary(const Library::DataLibrary* staticLib,
|
||||
std::unique_ptr<BattleStatCalculator> statCalculator,
|
||||
std::unique_ptr<DamageLibrary> damageLibrary,
|
||||
std::unique_ptr<ExperienceLibrary> experienceLibrary,
|
||||
std::unique_ptr<ScriptResolver> scriptResolver, std::unique_ptr<MiscLibrary> miscLibrary)
|
||||
: _staticLib(staticLib), _statCalculator(std::move(statCalculator)), _damageLibrary(std::move(damageLibrary)),
|
||||
_experienceLibrary(std::move(experienceLibrary)), _scriptResolver(std::move(scriptResolver)),
|
||||
_miscLibrary(std::move(miscLibrary)) {}
|
||||
BattleLibrary::BattleLibrary(const CreatureLib::Library::DataLibrary* staticLib, BattleStatCalculator* statCalculator,
|
||||
DamageLibrary* damageLibrary, ExperienceLibrary* experienceLibrary,
|
||||
ScriptResolver* scriptResolver, MiscLibrary* miscLibrary)
|
||||
: _staticLib(staticLib), _statCalculator(statCalculator), _damageLibrary(damageLibrary),
|
||||
_experienceLibrary(experienceLibrary), _scriptResolver(scriptResolver), _miscLibrary(miscLibrary) {}
|
||||
|
||||
BattleLibrary::~BattleLibrary() { delete _staticLib; }
|
||||
|
||||
const std::unique_ptr<BattleStatCalculator>& BattleLibrary::GetStatCalculator() const noexcept {
|
||||
return _statCalculator;
|
||||
BattleLibrary::~BattleLibrary() {
|
||||
delete _staticLib;
|
||||
delete _statCalculator;
|
||||
delete _damageLibrary;
|
||||
delete _experienceLibrary;
|
||||
delete _scriptResolver;
|
||||
delete _miscLibrary;
|
||||
}
|
||||
|
||||
const std::unique_ptr<DamageLibrary>& BattleLibrary::GetDamageLibrary() const noexcept { return _damageLibrary; }
|
||||
const CreatureLib::Library::LibrarySettings* BattleLibrary::GetSettings() const noexcept {
|
||||
return _staticLib->GetSettings();
|
||||
}
|
||||
|
||||
const std::unique_ptr<MiscLibrary>& BattleLibrary::GetMiscLibrary() const noexcept { return _miscLibrary; }
|
||||
const BattleStatCalculator* BattleLibrary::GetStatCalculator() const noexcept { return _statCalculator; }
|
||||
|
||||
const CreatureLib::Library::SpeciesLibrary* BattleLibrary::GetSpeciesLibrary() const noexcept {
|
||||
return _staticLib->GetSpeciesLibrary();
|
||||
}
|
||||
|
||||
const CreatureLib::Library::ItemLibrary* BattleLibrary::GetItemLibrary() const noexcept {
|
||||
return _staticLib->GetItemLibrary();
|
||||
}
|
||||
|
||||
const CreatureLib::Library::AttackLibrary* BattleLibrary::GetAttackLibrary() const noexcept {
|
||||
return _staticLib->GetAttackLibrary();
|
||||
}
|
||||
|
||||
const CreatureLib::Library::TypeLibrary* BattleLibrary::GetTypeLibrary() const noexcept {
|
||||
return _staticLib->GetTypeLibrary();
|
||||
}
|
||||
|
||||
const DamageLibrary* BattleLibrary::GetDamageLibrary() const noexcept { return _damageLibrary; }
|
||||
|
||||
const MiscLibrary* BattleLibrary::GetMiscLibrary() const noexcept { return _miscLibrary; }
|
||||
|
||||
Script* BattleLibrary::LoadScript(ScriptCategory category, const ConstString& scriptName) const {
|
||||
return _scriptResolver->LoadScript(category, scriptName);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef CREATURELIB_BATTLELIBRARY_HPP
|
||||
#define CREATURELIB_BATTLELIBRARY_HPP
|
||||
|
||||
#include <memory>
|
||||
#include "../../Library/DataLibrary.hpp"
|
||||
#include "../ScriptHandling/ScriptResolver.hpp"
|
||||
#include "BattleStatCalculator.hpp"
|
||||
|
@ -13,45 +12,32 @@ namespace CreatureLib::Battling {
|
|||
class BattleLibrary {
|
||||
protected:
|
||||
const Library::DataLibrary* _staticLib = nullptr;
|
||||
const std::unique_ptr<BattleStatCalculator> _statCalculator;
|
||||
const std::unique_ptr<DamageLibrary> _damageLibrary = nullptr;
|
||||
const std::unique_ptr<ExperienceLibrary> _experienceLibrary = nullptr;
|
||||
const std::unique_ptr<ScriptResolver> _scriptResolver = nullptr;
|
||||
const std::unique_ptr<MiscLibrary> _miscLibrary = nullptr;
|
||||
BattleStatCalculator* _statCalculator = nullptr;
|
||||
DamageLibrary* _damageLibrary = nullptr;
|
||||
ExperienceLibrary* _experienceLibrary = nullptr;
|
||||
ScriptResolver* _scriptResolver = nullptr;
|
||||
MiscLibrary* _miscLibrary = nullptr;
|
||||
|
||||
public:
|
||||
BattleLibrary(const Library::DataLibrary* staticLib, std::unique_ptr<BattleStatCalculator> statCalculator,
|
||||
std::unique_ptr<DamageLibrary> damageLibrary,
|
||||
std::unique_ptr<ExperienceLibrary> experienceLibrary,
|
||||
std::unique_ptr<ScriptResolver> scriptResolver, std::unique_ptr<MiscLibrary> miscLibrary);
|
||||
BattleLibrary(const Library::DataLibrary* staticLib, BattleStatCalculator* statCalculator,
|
||||
DamageLibrary* damageLibrary, ExperienceLibrary* experienceLibrary,
|
||||
ScriptResolver* scriptResolver, MiscLibrary* miscLibrary);
|
||||
~BattleLibrary();
|
||||
inline const Library::DataLibrary* GetStaticLib() const noexcept { return _staticLib; }
|
||||
|
||||
[[nodiscard]] const std::unique_ptr<const Library::LibrarySettings>& GetSettings() const noexcept {
|
||||
return _staticLib->GetSettings();
|
||||
}
|
||||
[[nodiscard]] const std::unique_ptr<const Library::SpeciesLibrary>& GetSpeciesLibrary() const noexcept {
|
||||
return _staticLib->GetSpeciesLibrary();
|
||||
}
|
||||
[[nodiscard]] const std::unique_ptr<const Library::ItemLibrary>& GetItemLibrary() const noexcept {
|
||||
return _staticLib->GetItemLibrary();
|
||||
}
|
||||
[[nodiscard]] const std::unique_ptr<const Library::AttackLibrary>& GetAttackLibrary() const noexcept {
|
||||
return _staticLib->GetAttackLibrary();
|
||||
}
|
||||
[[nodiscard]] const std::unique_ptr<const Library::TypeLibrary>& GetTypeLibrary() const noexcept {
|
||||
return _staticLib->GetTypeLibrary();
|
||||
}
|
||||
[[nodiscard]] const std::unique_ptr<const Library::GrowthRateLibrary>& GetGrowthRateLibrary() const noexcept {
|
||||
[[nodiscard]] const Library::LibrarySettings* GetSettings() const noexcept;
|
||||
[[nodiscard]] const Library::SpeciesLibrary* GetSpeciesLibrary() const noexcept;
|
||||
[[nodiscard]] const Library::ItemLibrary* GetItemLibrary() const noexcept;
|
||||
[[nodiscard]] const Library::AttackLibrary* GetAttackLibrary() const noexcept;
|
||||
[[nodiscard]] const Library::TypeLibrary* GetTypeLibrary() const noexcept;
|
||||
[[nodiscard]] const Library::GrowthRateLibrary* GetGrowthRateLibrary() const noexcept {
|
||||
return _staticLib->GetGrowthRates();
|
||||
}
|
||||
|
||||
[[nodiscard]] const std::unique_ptr<BattleStatCalculator>& GetStatCalculator() const noexcept;
|
||||
[[nodiscard]] const std::unique_ptr<DamageLibrary>& GetDamageLibrary() const noexcept;
|
||||
[[nodiscard]] const std::unique_ptr<MiscLibrary>& GetMiscLibrary() const noexcept;
|
||||
[[nodiscard]] const std::unique_ptr<ExperienceLibrary>& GetExperienceLibrary() const noexcept {
|
||||
return _experienceLibrary;
|
||||
}
|
||||
[[nodiscard]] const BattleStatCalculator* GetStatCalculator() const noexcept;
|
||||
[[nodiscard]] const DamageLibrary* GetDamageLibrary() const noexcept;
|
||||
[[nodiscard]] const MiscLibrary* GetMiscLibrary() const noexcept;
|
||||
[[nodiscard]] const ExperienceLibrary* GetExperienceLibrary() const noexcept { return _experienceLibrary; }
|
||||
|
||||
[[nodiscard]] Script* LoadScript(ScriptCategory category, const ConstString& scriptName) const;
|
||||
};
|
||||
|
|
|
@ -70,7 +70,7 @@ uint32_t Battling::Creature::GetBaseStat(Library::Statistic stat) const noexcept
|
|||
int8_t Battling::Creature::GetStatBoost(Library::Statistic stat) const noexcept { return _statBoost.GetStat(stat); }
|
||||
|
||||
void Battling::Creature::RecalculateFlatStats() {
|
||||
auto& statCalc = this->_library->GetStatCalculator();
|
||||
auto statCalc = this->_library->GetStatCalculator();
|
||||
this->_flatStats = statCalc->CalculateFlatStats(this);
|
||||
RecalculateBoostedStats();
|
||||
}
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
#include "DataLibrary.hpp"
|
||||
|
||||
CreatureLib::Library::DataLibrary::DataLibrary(std::unique_ptr<const LibrarySettings> settings,
|
||||
std::unique_ptr<const SpeciesLibrary> species,
|
||||
std::unique_ptr<const AttackLibrary> attacks,
|
||||
std::unique_ptr<const ItemLibrary> items,
|
||||
std::unique_ptr<const GrowthRateLibrary> growthRates,
|
||||
std::unique_ptr<const TypeLibrary> typeLibrary)
|
||||
: _settings(std::move(settings)), _species(std::move(species)), _attacks(std::move(attacks)),
|
||||
_items(std::move(items)), _growthRates(std::move(growthRates)), _typeLibrary(std::move(typeLibrary)) {
|
||||
CreatureLib::Library::DataLibrary::DataLibrary(LibrarySettings* settings, CreatureLib::Library::SpeciesLibrary* species,
|
||||
CreatureLib::Library::AttackLibrary* attacks,
|
||||
CreatureLib::Library::ItemLibrary* items,
|
||||
CreatureLib::Library::GrowthRateLibrary* growthRates,
|
||||
TypeLibrary* typeLibrary)
|
||||
: _settings(settings), _species(species), _attacks(attacks), _items(items), _growthRates(growthRates),
|
||||
_typeLibrary(typeLibrary) {
|
||||
AssertNotNull(_settings)
|
||||
AssertNotNull(_species)
|
||||
AssertNotNull(_attacks)
|
||||
|
@ -15,3 +14,27 @@ CreatureLib::Library::DataLibrary::DataLibrary(std::unique_ptr<const LibrarySett
|
|||
AssertNotNull(_growthRates)
|
||||
AssertNotNull(_typeLibrary)
|
||||
}
|
||||
|
||||
const CreatureLib::Library::LibrarySettings* CreatureLib::Library::DataLibrary::GetSettings() const noexcept {
|
||||
return _settings;
|
||||
}
|
||||
|
||||
const CreatureLib::Library::SpeciesLibrary* CreatureLib::Library::DataLibrary::GetSpeciesLibrary() const noexcept {
|
||||
return _species;
|
||||
}
|
||||
|
||||
const CreatureLib::Library::AttackLibrary* CreatureLib::Library::DataLibrary::GetAttackLibrary() const noexcept {
|
||||
return _attacks;
|
||||
}
|
||||
|
||||
const CreatureLib::Library::ItemLibrary* CreatureLib::Library::DataLibrary::GetItemLibrary() const noexcept {
|
||||
return _items;
|
||||
}
|
||||
|
||||
const CreatureLib::Library::GrowthRateLibrary* CreatureLib::Library::DataLibrary::GetGrowthRates() const noexcept {
|
||||
return _growthRates;
|
||||
}
|
||||
|
||||
const CreatureLib::Library::TypeLibrary* CreatureLib::Library::DataLibrary::GetTypeLibrary() const noexcept {
|
||||
return _typeLibrary;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef CREATURELIB_DATALIBRARY_HPP
|
||||
#define CREATURELIB_DATALIBRARY_HPP
|
||||
|
||||
#include <memory>
|
||||
#include "AttackLibrary.hpp"
|
||||
#include "GrowthRates/GrowthRateLibrary.hpp"
|
||||
#include "ItemLibrary.hpp"
|
||||
|
@ -15,31 +14,32 @@ namespace CreatureLib::Library {
|
|||
*/
|
||||
class DataLibrary {
|
||||
private:
|
||||
const std::unique_ptr<const LibrarySettings> _settings;
|
||||
const std::unique_ptr<const SpeciesLibrary> _species;
|
||||
const std::unique_ptr<const AttackLibrary> _attacks;
|
||||
const std::unique_ptr<const ItemLibrary> _items;
|
||||
const std::unique_ptr<const GrowthRateLibrary> _growthRates;
|
||||
const std::unique_ptr<const TypeLibrary> _typeLibrary;
|
||||
const LibrarySettings* _settings;
|
||||
const SpeciesLibrary* _species;
|
||||
const AttackLibrary* _attacks;
|
||||
const ItemLibrary* _items;
|
||||
const GrowthRateLibrary* _growthRates;
|
||||
const TypeLibrary* _typeLibrary;
|
||||
|
||||
public:
|
||||
DataLibrary(std::unique_ptr<const LibrarySettings> settings, std::unique_ptr<const SpeciesLibrary> species,
|
||||
std::unique_ptr<const AttackLibrary> attacks, std::unique_ptr<const ItemLibrary> items,
|
||||
std::unique_ptr<const GrowthRateLibrary> growthRates,
|
||||
std::unique_ptr<const TypeLibrary> typeLibrary);
|
||||
DataLibrary(LibrarySettings* settings, CreatureLib::Library::SpeciesLibrary* species,
|
||||
CreatureLib::Library::AttackLibrary* attacks, CreatureLib::Library::ItemLibrary* items,
|
||||
CreatureLib::Library::GrowthRateLibrary* growthRates, TypeLibrary* typeLibrary);
|
||||
|
||||
virtual ~DataLibrary() {}
|
||||
virtual ~DataLibrary() {
|
||||
delete _species;
|
||||
delete _attacks;
|
||||
delete _items;
|
||||
delete _growthRates;
|
||||
delete _typeLibrary;
|
||||
}
|
||||
|
||||
[[nodiscard]] const std::unique_ptr<const LibrarySettings>& GetSettings() const noexcept { return _settings; }
|
||||
[[nodiscard]] const std::unique_ptr<const SpeciesLibrary>& GetSpeciesLibrary() const noexcept {
|
||||
return _species;
|
||||
}
|
||||
[[nodiscard]] const std::unique_ptr<const AttackLibrary>& GetAttackLibrary() const noexcept { return _attacks; }
|
||||
[[nodiscard]] const std::unique_ptr<const ItemLibrary>& GetItemLibrary() const noexcept { return _items; }
|
||||
[[nodiscard]] const std::unique_ptr<const GrowthRateLibrary>& GetGrowthRates() const noexcept {
|
||||
return _growthRates;
|
||||
}
|
||||
[[nodiscard]] const std::unique_ptr<const TypeLibrary>& GetTypeLibrary() const noexcept { return _typeLibrary; }
|
||||
[[nodiscard]] const LibrarySettings* GetSettings() const noexcept;
|
||||
[[nodiscard]] const SpeciesLibrary* GetSpeciesLibrary() const noexcept;
|
||||
[[nodiscard]] const AttackLibrary* GetAttackLibrary() const noexcept;
|
||||
[[nodiscard]] const ItemLibrary* GetItemLibrary() const noexcept;
|
||||
[[nodiscard]] const GrowthRateLibrary* GetGrowthRates() const noexcept;
|
||||
[[nodiscard]] const TypeLibrary* GetTypeLibrary() const noexcept;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ TEST_CASE("Turn ordering: Attack before pass", "[Battling]") {
|
|||
}
|
||||
|
||||
TEST_CASE("Turn ordering: High priority goes before no priority", "[Battling]") {
|
||||
auto& l = TestLibrary::Get()->GetAttackLibrary();
|
||||
auto l = TestLibrary::Get()->GetAttackLibrary();
|
||||
auto a1 = new LearnedAttack(l->Get("standard"_cnc), AttackLearnMethod::Unknown);
|
||||
auto a2 = new LearnedAttack(l->Get("highPriority"_cnc), AttackLearnMethod::Unknown);
|
||||
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
|
||||
|
@ -51,7 +51,7 @@ TEST_CASE("Turn ordering: High priority goes before no priority", "[Battling]")
|
|||
}
|
||||
|
||||
TEST_CASE("Turn ordering: Higher priority goes before high priority", "[Battling]") {
|
||||
auto& l = TestLibrary::Get()->GetAttackLibrary();
|
||||
auto l = TestLibrary::Get()->GetAttackLibrary();
|
||||
auto a1 = new LearnedAttack(l->Get("highPriority"_cnc), AttackLearnMethod::Unknown);
|
||||
auto a2 = new LearnedAttack(l->Get("higherPriority"_cnc), AttackLearnMethod::Unknown);
|
||||
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
|
||||
|
@ -73,7 +73,7 @@ TEST_CASE("Turn ordering: Higher priority goes before high priority", "[Battling
|
|||
}
|
||||
|
||||
TEST_CASE("Turn ordering: High priority goes before low priority", "[Battling]") {
|
||||
auto& l = TestLibrary::Get()->GetAttackLibrary();
|
||||
auto l = TestLibrary::Get()->GetAttackLibrary();
|
||||
auto a1 = new LearnedAttack(l->Get("lowPriority"_cnc), AttackLearnMethod::Unknown);
|
||||
auto a2 = new LearnedAttack(l->Get("higherPriority"_cnc), AttackLearnMethod::Unknown);
|
||||
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
|
||||
|
@ -95,7 +95,7 @@ TEST_CASE("Turn ordering: High priority goes before low priority", "[Battling]")
|
|||
}
|
||||
|
||||
TEST_CASE("Turn ordering: No priority goes before low priority", "[Battling]") {
|
||||
auto& l = TestLibrary::Get()->GetAttackLibrary();
|
||||
auto l = TestLibrary::Get()->GetAttackLibrary();
|
||||
auto a1 = new LearnedAttack(l->Get("lowPriority"_cnc), AttackLearnMethod::Unknown);
|
||||
auto a2 = new LearnedAttack(l->Get("standard"_cnc), AttackLearnMethod::Unknown);
|
||||
auto choice1 = new AttackTurnChoice(nullptr, a1, CreatureIndex(0, 0));
|
||||
|
|
|
@ -9,14 +9,11 @@ BattleLibrary* TestLibrary::_library = nullptr;
|
|||
|
||||
BattleLibrary* TestLibrary::Get() {
|
||||
if (TestLibrary::_library == nullptr) {
|
||||
auto l = new DataLibrary(
|
||||
std::make_unique<LibrarySettings>(100, 4), std::unique_ptr<SpeciesLibrary>(BuildSpeciesLibrary()),
|
||||
std::unique_ptr<AttackLibrary>(BuildAttackLibrary()), std::unique_ptr<ItemLibrary>(BuildItemLibrary()),
|
||||
std::unique_ptr<GrowthRateLibrary>(BuildGrowthRateLibrary()),
|
||||
std::unique_ptr<TypeLibrary>(BuildTypeLibrary()));
|
||||
auto battleLib = new BattleLibrary(l, std::make_unique<BattleStatCalculator>(),
|
||||
std::make_unique<DamageLibrary>(), std::make_unique<ExperienceLibrary>(),
|
||||
std::make_unique<ScriptResolver>(), std::make_unique<MiscLibrary>());
|
||||
auto l = new DataLibrary(new LibrarySettings(100, 4), BuildSpeciesLibrary(), BuildAttackLibrary(),
|
||||
BuildItemLibrary(), BuildGrowthRateLibrary(), BuildTypeLibrary());
|
||||
auto statCalc = new BattleStatCalculator();
|
||||
auto battleLib = new BattleLibrary(l, statCalc, new DamageLibrary(), new ExperienceLibrary(),
|
||||
new ScriptResolver(), new MiscLibrary());
|
||||
TestLibrary::_library = battleLib;
|
||||
}
|
||||
return TestLibrary::_library;
|
||||
|
|
Loading…
Reference in New Issue